Skip to content

Getting Started

picasso edited this page Feb 9, 2021 · 9 revisions

Getting Started

After you have added the Zukit framework in your project folder you can start using it.

There are three simple steps involved in doing so:

  1. Create a new class for your plugin/theme.
  2. Init class instance with the plugin/theme path.
  3. Provide the plugin/theme configuration.

Create a new class inheriting the class zukit_Plugin

class my_Plugin extends zukit_Plugin {

}

Attention! You should not define a class constructor __construct in a new class.

Since zukit_Plugin is based on the singleton concept, you can access the instance of your class through the static method instance. But be sure to pass the path for your plugin/theme there at the first call (the easiest way is to pass the magic constant __FILE__). For convenience, I recommend creating a function that makes it easier to access the instance of your class:

function myplugin($file = null) {
	return my_Plugin::instance($file);
}
/*
Plugin Name: My Plugin
Description: Wonderful plugin that will change this world.
Version: 1.0.0
Author: John Appleseed
*/
defined('ABSPATH') || die('No direct script access allowed!');

// some other logic...

// somewhere at the bottom of the my-plugin.php file which contains your plugin description
myplugin(__FILE__);

❗ If you want to use the built-in compatibility test then it is better to initialize your plugin/theme using the method described in Compatibility Check.

Alternative to class constructor

If you need to do something in the class constructor, you should override the construct_more method.

🙅 Attention! You cannot use the functions for working with options (see the Options section) in construct_more method, since the options there are not yet synchronized with the class methods:

protected function construct_more() {
    add_action('add_attachment', [$this, 'attachment_save']);
    add_filter('attachment_fields_to_edit', [$this, 'add_attachment_field'], 10, 2);

    // you should avoid ‘options’ getter and setter here!!
    // wrong!!!
    // if($this->is_option('option1')) {
    //     add_action('pre_get_posts', [$this, 'pre_get_attachments']);
    // }
}

Configuration

You also need to customize the framework to work with your plugin or theme - this is done via configuration.