Support » Plugin: Bannerspace Slideshow » Static Methods need updating

  • Resolved Andi Lee Davis

    (@andi-lee-davis)


    I’m getting the warning below because my dev server error reporting is set to E_ALL, but this sometimes helps with feedback to the developers of the plugins I use.

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method bannerspace_plugin_options::update() should not be called statically in /media/DriveD/sdb1/www/www.website.dev/wp-includes/plugin.php on line 470

    Strict Standards: Non-static method bannerspace_plugin_options::BS_getOptions() should not be called statically in /media/DriveD/sdb1/www/www.website.dev/wp-content/plugins/bannerspace/bannerspace.php on line 124

    You may need to update the function call from the class.

    I.E.

    class myClass {
         public function helloWorld() {
            echo "Hello, World!";
        }
    }
    $example = new myClass();
    call_user_func(array($example, 'helloWorld'));

    Not sure, I believe the issue may actually occur on line 315

    // register functions
    add_action('admin_menu', array('bannerspace_plugin_options', 'update'));

    You are calling the function directly in the add action without creating the class? But then the add_action should be also declared in the construct method of the class:

    Please see here about this:
    http://codex.wordpress.org/Function_Reference/add_action

    public function __construct() {
             //add your actions to the constructor!
             add_action( 'admin_menu', array( $this, 'update' ) );
        }

    As I say this is not a problem on as is a warning but you may want to consider fixing it.

    thanks

    Andi

    https://wordpress.org/plugins/bannerspace/

Viewing 7 replies - 1 through 7 (of 7 total)
  • ok Here is the solution:

    on line 35 in bannerspace.php put in the constructor to add the action

    public function __construct() {
             //add your actions to the constructor!
             add_action( 'admin_menu', array( $this, 'update' ) );
        }

    on Line 324 rplace

    add_action('admin_menu', array('bannerspace_plugin_options','construct'));

    with this

    $banner_space = new bannerspace_plugin_options;

    That calls the class and the constructor adds the action.

    Thanks

    Andi

    however… there are other errors on other lines now with the same message. If you do this you will have to re-write several lines.

    using this within the class to get the instance may help:
    Not sure will have a look into it further at some other point

    private static $__instance = NULL;
    	public function __construct() {
             //add your actions to the constructor!
    		 add_action( 'admin_menu', array( $this, 'update' ) );
        }
    	private function __clone(){}
       	static public function getInstance(){
            if(self::$__instance == NULL) self::$__instance = new bannerspace_plugin_options;
            return self::$__instance;
        }

    when calling the from inside the methods we can use

    $banner_space = bannerspace_plugin_options::getInstance();
    		$options = $banner_space->BS_getOptions();

    ok fixed all these errors now.

    line 35 within the class add this construct

    public function __construct() {
             //add your actions to the constructor!
    		 add_action( 'admin_menu', array( $this, 'update' ) );
        }

    line 132 call the class object by $this keyword instead…
    See here… http://codex.wordpress.org/Function_Reference/add_submenu_page

    /// replace - add_submenu_page( 'options-general.php', 'Bannerspace Options', 'Bannerspace Options', 'edit_theme_options', basename(__FILE__), array('bannerspace_plugin_options', 'display'));
    
    add_submenu_page( 'options-general.php', 'Bannerspace Options', 'Bannerspace Options', 'edit_theme_options', basename(__FILE__), array($this, 'display'));

    around line 319 call the class instead.

    // register functions
    // - replaced add_action('admin_menu', array('bannerspace_plugin_options','construct'));
    
    $banner_space = new bannerspace_plugin_options;

    Hope this helps.

    thanks

    Andi

    Also you should consider changing these bool checks as result in undefined variable errors
    around line 95
    if ($_POST['hide_content'])

    this will work better instead
    if (isset($_POST['hide_content']) && $_POST['hide_content'])

    thanks

    Andi

    Same with these…

    if (isset($_POST['show_arrows']) && $_POST['show_arrows'])
    				$options['show_arrows'] = (bool)true;
    			else
    				$options['show_arrows'] = (bool)false;
    
    			if (isset($_POST['show_paging']) && $_POST['show_paging'])
    				$options['show_paging'] = (bool)true;
    			else
    				$options['show_paging'] = (bool)false;

    If the developer of this plugin contacts me I can send an updated zipped file with all the fixes to this plugin.

    Hi Andi. Thanks for this. Feel free to email me at contact@thriveweb.com.au. I’ll include it in the next update 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Static Methods need updating’ is closed to new replies.