WPLib_Posts::on_load PHP Method

on_load() static public method

Run on WordPress's 'init' hook to register all the post types defined in classes that extend this class.
static public on_load ( )
    static function on_load()
    {
        /**
         * Add this class as a helper to WPLib
         */
        WPLib::register_helper(__CLASS__);
        /*
         * Process these templates once for language translation.
         * Use this base class' name used to find the templates.
         */
        self::$_default_labels = array('add_new_item' => _x('Add New %s', 'posts', 'wplib'), 'new_item' => _x('New %s', 'posts', 'wplib'), 'edit_item' => _x('Edit %s', 'posts', 'wplib'), 'view_item' => _x('View %s', 'posts', 'wplib'), 'all_items' => _x('All %s', 'posts', 'wplib'), 'search_items' => _x('Search %s', 'posts', 'wplib'), 'parent_item_colon' => _x('Parent %s:', 'posts', 'wplib'), 'not_found' => _x('No %s found.', 'posts', 'wplib'), 'not_found_in_trash' => _x('No %s found in Trash.', 'posts', 'wplib'));
        self::add_class_action('init');
        self::add_class_action('init', 99);
        self::add_class_action('wp_loaded');
    }

Usage Example

Example #1
0
        if (count(self::$_post_stack)) {
            $post = array_pop(self::$_post_stack);
        }
    }
    /**
     * Return the post type of the queried object.
     *
     * @return false|null|string
     */
    static function get_queried_post_type()
    {
        $queried_object = get_queried_object();
        return $queried_object instanceof WP_Post ? get_post_type($queried_object) : null;
    }
    /**
     * @return int
     */
    static function max_posts_per_page()
    {
        return self::$_max_posts_per_page;
    }
    /**
     * @param int $value
     */
    static function set_max_posts_per_page($value)
    {
        self::$_max_posts_per_page = absint($value);
    }
}
WPLib_Posts::on_load();