WPLib::on_load PHP Method

on_load() static public method

static public on_load ( )
    static function on_load()
    {
        /**
         * @var bool Flag to ensure this method is only ever called once.
         */
        static $done_once = false;
        if (!$done_once) {
            $done_once = true;
        } else {
            $err_msg = __('The %s::on_load() method should not call its parent class, e.g. remove parent::on_load(). Report generated ', 'wplib');
            self::trigger_error(sprintf($err_msg, get_called_class()), E_USER_ERROR);
        }
        if (!class_exists('WPLib_Enum', false)) {
            /**
             *  defines.php can be included in local-config.php, but if
             *  not then we need to include it here.
             */
            require __DIR__ . '/defines.php';
        }
        if (!defined('WPLIB_STABILITY')) {
            /* @note THIS IS NOT WIDELY IMPLEMENTED YET.
             *
             * WPLib follows the convention of Node.js in having a Stability Index.
             * Every class, property, method, constant, etc. will have a Stability value,
             * except for those that do not (yet.)
             *
             * The stability will be specified by an @stability PHPDoc comment with one
             * of the following values:
             *
             *    Stability:  0 - Deprecated
             *    Stability:  1 - Experimental
             *    Stability:  2 - Stable
             *    Stability:  3 - Locked
             *
             * The default stability is 2 - Stable. However you can set the stability
             * you want in your wp-local-config.php file using the WPLIB_STABILITY constant.
             *
             * You can check (for example) for EXPERIMENTAL stability in a method using:
             *
             *      self::stability()->check_method( __METHOD__, WPLib::EXPERIMENTAL );
             *
             * Internal methods -- ones with a leading underscore -- will not be marked with
             * a stability level.
             *
             * To read more about the concept of stability:
             *
             * @see https://nodejs.org/api/documentation.html#documentation_stability_index
             */
            define('WPLIB_STABILITY', is_null(self::stability()) ? WPLib_Stability::__default : self::stability()->get_value());
        }
        if (is_null(self::stability())) {
            self::set_stability(new WPLib_Stability(WPLIB_STABILITY));
        }
        if (!defined('WPLIB_RUNMODE')) {
            define('WPLIB_RUNMODE', is_null(self::runmode()) ? WPLib_Runmode::__default : self::runmode()->get_value());
        }
        if (is_null(self::runmode())) {
            self::set_runmode(new WPLib_Runmode(WPLIB_RUNMODE));
        }
        spl_autoload_register(array(__CLASS__, '_autoloader'), true, true);
        /**
         * Set a marker to ignore classes declared before this class.
         */
        self::$_non_app_class_count = count(get_declared_classes()) - 1;
        self::register_module('posts', 0);
        self::register_module('terms', 0);
        self::register_module('roles', 0);
        self::register_module('users', 0);
        self::register_module('post-type-post', 0);
        self::register_module('post-type-page', 0);
        self::register_module('taxonomy-categories', 0);
        self::register_module('taxonomy-post-tags', 0);
        self::register_module('helpers-html', 0);
        self::register_module('helpers-wp', 0);
        self::register_module('theme', 0);
        self::register_module('commit-reviser', 0);
        /**
         * Register default User Roles
         */
        self::register_module('role-administrator', 4);
        self::register_module('role-contributor', 4);
        self::register_module('role-subscriber', 4);
        self::register_module('role-editor', 4);
        self::register_module('role-author', 4);
        self::add_class_action('init', 9);
        self::add_class_action('plugins_loaded', 11);
        self::add_class_action('after_setup_theme');
        self::add_class_action('after_setup_theme', 11);
        self::add_class_action('xmlrpc_call');
        self::add_class_action('shutdown');
    }

Usage Example

Ejemplo n.º 1
0
                    }
                    $child_classes[$constant_value] = $class_name;
                } while (false);
            }
            WPLib::cache_set($cache_key, $child_classes);
        }
        return $child_classes;
    }
    /**
     * @return bool|string
     */
    static function short_prefix()
    {
        return WPLib::get_constant('SHORT_PREFIX', get_called_class());
    }
    /**
     * Returns the raw meta fieldname given a non-prefixed field name.
     * Adds both a leading underscore and a short prefix to the meta name.
     *
     * @param string $meta_name
     *
     * @return string
     */
    static function _get_raw_meta_fieldname($meta_name)
    {
        $prefix = static::get_constant('SHORT_PREFIX');
        return "_{$prefix}{$meta_name}";
    }
}
WPLib::on_load();