I wan't to include his instant messaging app in Wordpress. I can't find the issue even with the multiple same questions in the multiple forums.
My code : intrachat.php
<?php
/*
Plugin Name: Intrachat
Plugin URI: *************
Description: Chattez en temps réel sur votre intranet
Version: 0.1
Author: *********
License: GPL2
*/
class Intrachat_Plugin
{
public function __construct()
{
include_once plugin_dir_path( __FILE__ ).'/page_title.php';
include_once plugin_dir_path( __FILE__ ).'/chat.php';
new IC_Page_Title();
$chat = new IC_Chat();
}
}
new Intrachat_Plugin();
?>
chat.php :
<?php
class IC_Chat {
public function __construct()
{
add_action( 'init', ic_show_chat_bar());
}
public function ic_show_chat_bar() {
if(is_user_logged_in()){
echo "<script>alert(\"Connecté\")</script>";
}
}
}
?>
My problem :
Fatal error: Call to undefined function ic_show_chat_bar() in /var/www/vhosts/dev/html/wp-content/plugins/Intrachat/chat.php on line 7
EDIT :
Trying this :
<?php
class IC_Chat {
public function __construct()
{
add_action( 'init', array($this, 'ic_show_chat_bar()'));
}
public function ic_show_chat_bar() {
if(is_user_logged_in()){
echo "<script>alert(\"Connecté\")</script>";
}
}
}
?>
Still same error.
add_action( 'init', ic_show_chat_bar());
toadd_action( 'init', array( $this, ic_show_chat_bar() ) );
. – Luis Sanz Apr 18 '16 at 10:16add_action( 'init', ic_show_chat_bar());
toadd_action( 'init', array( $this, 'ic_show_chat_bar' ) );
. Note the back-ticks wrapping the function call. – Luis Sanz Apr 18 '16 at 10:35