Plugin generated N unexpected exit characters during activation

I want to create a wordpress plugin by simply following the example here based on the OOP class architecture with an external installer and adapting the source code in my own way: main plugin file:

<?php
/*
Plugin Name: My Plugin
Description: My Plugin
Version: 1.0
Author: drwhite
Author URL:  drwhite-site
Plugin URL:  drwhite-site/video-ad-overlay
*/

register_activation_hook(__FILE__, array( 'VAO_Setup_File_Inc', 'on_activation'));
register_deactivation_hook(__FILE__, array( 'VAO_Setup_File_Inc', 'on_deactivation'));
register_uninstall_hook(__FILE__, array( 'VAO_Setup_File_Inc', 'on_uninstall'));

add_action('plugins_loaded', array( 'VAO_Setup_File', 'init'));
class VAO_Setup_File{

    protected static $instance;

    public static function init()
    {
        is_null( self::$instance ) AND self::$instance = new self;
        return self::$instance;
    }

    public function __construct()
    {
        add_action( current_filter(), array( $this, 'load_files' ));
    }

    public function load_files()
    {
        foreach ( glob( plugin_dir_path( __FILE__ ).'includes/*.php' ) as $file ){
            include_once $file;
        }
    }
}

      

In my plugin root directory, I created a subdirectory that includes inside i to install an installation file loaded when the plugin is loaded called setup.class.php

:

<?php
class VAO_Setup_File_Inc
{
    public static function on_activation()
    {
        if ( ! current_user_can( 'activate_plugins' ) )
            return;
        $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
        check_admin_referer( "activate-plugin_{$plugin}" );
    }

    public static function on_deactivation()
    {
        if ( ! current_user_can( 'activate_plugins' ) )
            return;
        $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
        check_admin_referer( "deactivate-plugin_{$plugin}" );
    }

    public static function on_uninstall()
    {
        if ( ! current_user_can( 'activate_plugins' ) )
            return;
        check_admin_referer( 'bulk-plugins' );

        // Important: Check if the file is the one
        // that was registered during the uninstall hook.
        if ( __FILE__ != WP_UNINSTALL_PLUGIN )
            return;
    }
}

      

When I activate the plugin, I got an error like: enter image description here

I read several questions asked by other users here and it may be a duplicate question, but any of the suggested answers worked for me, including:

  • Remove space from start tags and even remove end php tag: nothing has changed

  • to the wp_config.php

    file i have set wp_DEBUG

    to true

    but it shows no errors

  • I converted the file to UTF8 (without BOM)

    nothing changed

Are you throwing an eye into the problem?

+3


source to share


1 answer


You are getting this error because your plugin is generating a PHP error that is being printed to the page and is causing the messages sent error. The problem with your code is that your function

public function load_files()
    {
        foreach ( glob( plugin_dir_path( __FILE__ ).'includes/*.php' ) as $file ){
            include_once $file;
        }
    }

      

is not called in time, so

register_activation_hook(__FILE__, array( 'VAO_Setup_File_Inc', 'on_activation'));

      

looking for a function that doesn't exist inside a class that doesn't exist. Move



foreach ( glob( plugin_dir_path( __FILE__ ).'includes/*.php' ) as $file ){
            include_once $file;
        }

      

outside of the class as a whole and it will load just fine. This may require you to rethink your use of

add_action('plugins_loaded', array( 'VAO_Setup_File', 'init'));

      

and a way to create your plugin, but this is a step in the right direction. If you copy and paste the code with the link you got this code from, its code displays the same problem ...

0


source







All Articles