0

I try to create a simple plugin following by the guid http://docs.layerswp.com/plugin-creation-guide

So I've created main file functions.php

<?php /*
* Plugin Name: Layers - Demo Extension
* Version: 1.0
* Plugin URI: http://www.yourpluginpage.com
* Description: What does your Extension do for Layers?
* Author: You
* Author URI: http://www.yoursite.com/
*
* Requires at least: 4.5
* Tested up to: 4.5.3
*
* Layers Plugin: True
* Layers Required Version: 1.5.4
*
* Text Domain: layers-demo-plugin
* Domain Path: /lang/
*/
if ( ! defined( 'ABSPATH' ) ) exit;

// define constants (optional)

// Load plugin class files
require_once( 'includes/class-layers-demo-extension.php' );

// Instantiate Plugin
function layers_demo_extension_init() {
    global $layers_demo_extension;
    $layers_demo_extension = Layers_Demo_Extension::get_instance();
}
add_action( 'plugins_loaded', 'layers_demo_extension_init' );

// Additional Functionality

and the file includes/class-layers-demo-extension.php

<?php /**
* Layers Demo Extension
*
* What your plugin does
*
* @package Layers
* @since Layers 1.2.4
*/

class Layers_Demo_Extension {

//Initiator
private static $instance;

public static function get_instance() {
    if ( ! self::$instance ) {
        self::$instance = new self();
        self::$instance->construct();
    }
    return self::$instance;
}

// Constructor
private function __construct() {
    // Hooks go here
}

//Custom Functions

}

But when I go to admin panel, I get the 500 error.

When I enable WP_DEBUG I see this

Fatal error: Uncaught Error: Call to undefined method Layers_Demo_Extension::construct() in /.../wp-content/plugins/layers-demo-extension/includes/class-layers-demo-extension.php:18 Stack trace:
#0 /.../wp-content/plugins/layers-demo-extension/functions.php(29): Layers_Demo_Extension::get_instance()
#1 /.../wp-includes/class-wp-hook.php(286): layers_demo_extension_init('')
#2 /.../wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
#3 /.../wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#4 /.../wp-settings.php(327): do_action('plugins_loaded')
#5 /.../wp-config.php(89): require_once('...')
#6 /.../wp-load.php(37): require_once('...')
#7 /.../wp-admin/admin.php(31): require_once('...')
#8 /.../wp-admin/tools.php(10): in /.../wp-content/plugins/layers-demo-extension/includes/class-layers-demo-extension.php on line 18

But I don't know how to fix the problem...

1 Answer 1

2

In your get_instance() method, you call self::$instance->construct() not self::$instance->__construct(). Also, there's no reason to call the constructor like that; it will be called when you invoke new self();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.