• jamapla

    (@jamapla)


    Hi everybody,

    I am developing a plugin for my wordpress instance and I invoke a function of the plugin from the functions.php file of my theme (after invoke this function from functions.php I’ll call it from the header.php theme itself) and there is no way, or I get no value or get the next error:

    Fatal error: Call to undefined function…

    To test this plugin-theme communication I have made a hello_world function that I try to call. My plugin definition is as follows:

    /*
    Plugin Name: Notificador de Entradas
    Plugin URI: #
    Description: Notifica la creacion de una Entrada al Grupo de Supervision de Analisis.
    Version: 1.0
    Author: Jose
    Author URI: #
    */
    class notificador_entradas {
    
    	var $opt;
    	var $nombre_tabla;
    
    	// inicializamos plugin
    	function notificador_entradas_mapfre() {
    		global $wpdb;
    
    		$this->nombre_tabla = $wpdb->prefix.'notificador_entradas';
    
    		register_activation_hook(__FILE__, array(&$this, 'install'));
    		register_deactivation_hook(__FILE__, array(&$this, 'uninstall'));
    	}
    
    	public function hello_world () {
    		return "Hola mundo!!!";
    	}
    
    	public function install () {
    		create table...
    	}
    
    	public function uninstall () {
    		drop table...
    	}
    }
    
    $miplugin = new notificador_entradas ();

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    after from my functions.php theme file, I’ve try to invoke the function in different ways, all unsuccesfully:

    – Direct call to the hello_world function. I get the error told above. If I call this way… if (function_exists (hello_world)) I get no error message, but I also get no result.

    – Tell plugin class constructor that the function is an action (three ways to do this):
    add_action (‘hello_world’, ‘hello_world’);
    add_action (‘hello_world’, array(&$this, ‘hello_world’));
    add_action(‘init’, array(&$this, ‘hello_world’));

    and make the functions.php call as:
    do_action (hello_world);

    neither the two ways works.

    – Try to declare the plugin object as a gloval variable so to invoke it from the functions.php this way:

    Plugin:

    global $miplugin;
    $miplugin = new notificador_entradas ();

    Theme functions.php:

    global $miplugin;
    $miplugin->hello_world ();

    no results get.

    I dont know what to do, I think it must be some silly thing, but I cant see it. I’ve watch over www.remarpro.com and stackoverflow forums but the things they say doesnt work for me :(.

    ?Does anybody have any good idea of whats going on?… any response will be welcome :).

    Thx all!!
    Regards.

    José.

  • The topic ‘Call plugin function from functions.php theme file’ is closed to new replies.