public static function load($class)
    {
        $instance = new $class;
        $post_type = $instance->getPostType();

        // WordPress has a limit of 20 characters per
        if (strlen($post_type) > 20) {
            throw new \Exception('Post Type name exceeds maximum 20 characters: '.$post_type);
        }

        // This might happen if you're introducing a middle class between your post type and TacoPost
        // Ex: Foo extends \ClientTacoPost extends Taco\Post
        if (!$post_type) {
            return false;
        }
        
        //add_action('init', array($instance, 'registerPostType'));
        $instance->registerPostType();
        add_action('save_post', array($instance, 'addSaveHooks'));

        if (is_admin()) {
            // If we're in the edit screen, we want the post loaded
            // so that TacoPost::getFields knows which post it's working with.
            // This helps if you want TacoPost::getFields to use conditional logic
            // based on which post is currently being edited.
            $is_edit_screen = (
                is_array($_SERVER)
                && preg_match('/post.php\?post=[\d]{1,}/i', $_SERVER['REQUEST_URI'])
                && !Arr::iterable($_POST)
            );
            $is_edit_save = (
                preg_match('/post.php/i', $_SERVER['REQUEST_URI'])
                && Arr::iterable($_POST)
            );
            $post = null;
            if ($is_edit_screen && array_key_exists('post', $_GET)) {
                    $post = get_post($_GET['post']);
            } elseif ($is_edit_save) {
                $post = get_post($_POST['post_ID']);
            }
            if ($post && $post->post_type === $instance->getPostType()) {
                $instance->load($post);
            }
            
            add_action('admin_menu', array($instance, 'addMetaBoxes'));
            add_action(sprintf('manage_%s_posts_columns', $post_type), array($instance, 'addAdminColumns'), 10, 2);
            add_action(sprintf('manage_%s_posts_custom_column', $post_type), array($instance, 'renderAdminColumn'), 10, 2);
            add_filter(sprintf('manage_edit-%s_sortable_columns', $post_type), array($instance, 'makeAdminColumnsSortable'));
            add_filter('request', array($instance, 'sortAdminColumns'));
            add_filter('posts_clauses', array($instance, 'makeAdminTaxonomyColumnsSortable'), 10, 2);
            
            // Hide the title column in the browse view of the admin UI
            $is_browsing_index = (
                is_array($_SERVER)
                && preg_match('/edit.php\?post_type='.$post_type.'$/i', $_SERVER['REQUEST_URI'])
            );
            if ($is_browsing_index && $instance->getHideTitleFromAdminColumns()) {
                add_action('admin_init', function () {
                    wp_register_style('hide_title_column_css', plugins_url('taco/base/hide_title_column.css'));
                    wp_enqueue_style('hide_title_column_css');
                });
            }
        }
    }
public static function load($class)
    {
        $instance = new $class;
        $post_type = $instance->getPostType();

        // WordPress has a limit of 20 characters per
        if (strlen($post_type) > 20) {
            throw new \Exception('Post Type name exceeds maximum 20 characters: '.$post_type);
        }

        // This might happen if you're introducing a middle class between your post type and TacoPost
        // Ex: Foo extends \ClientTacoPost extends Taco\Post
        if (!$post_type) {
            return false;
        }
        
        //add_action('init', array($instance, 'registerPostType'));
        $instance->registerPostType();
        add_action('save_post', array($instance, 'addSaveHooks'));

        if (is_admin()) {
            // If we're in the edit screen, we want the post loaded
            // so that TacoPost::getFields knows which post it's working with.
            // This helps if you want TacoPost::getFields to use conditional logic
            // based on which post is currently being edited.
            $is_edit_screen = (
                is_array($_SERVER)
                && preg_match('/post.php\?post=[\d]{1,}/i', $_SERVER['REQUEST_URI'])
                && !Arr::iterable($_POST)
            );
            $is_edit_save = (
                preg_match('/post.php/i', $_SERVER['REQUEST_URI'])
                && Arr::iterable($_POST)
            );
            $post = null;
            if ($is_edit_screen && array_key_exists('post', $_GET)) {
                    $post = get_post($_GET['post']);
            } elseif ($is_edit_save) {
                $post = get_post($_POST['post_ID']);
            }
            if ($post && $post->post_type === $instance->getPostType()) {
                $instance->load($post);
            }
            
            add_action('admin_menu', array($instance, 'addMetaBoxes'));
            add_action(sprintf('manage_%s_posts_columns', $post_type), array($instance, 'addAdminColumns'), 10, 2);
            add_action(sprintf('manage_%s_posts_custom_column', $post_type), array($instance, 'renderAdminColumn'), 10, 2);
            add_filter(sprintf('manage_edit-%s_sortable_columns', $post_type), array($instance, 'makeAdminColumnsSortable'));
            add_filter('request', array($instance, 'sortAdminColumns'));
            add_filter('posts_clauses', array($instance, 'makeAdminTaxonomyColumnsSortable'), 10, 2);
            
            // Hide the title column in the browse view of the admin UI
            $is_browsing_index = (
                is_array($_SERVER)
                && preg_match('/edit.php\?post_type='.$post_type.'$/i', $_SERVER['REQUEST_URI'])
            );
            if ($is_browsing_index && $instance->getHideTitleFromAdminColumns()) {
                add_action('admin_init', function () {
                    wp_register_style('hide_title_column_css', plugins_url('taco/base/hide_title_column.css'));
                    wp_enqueue_style('hide_title_column_css');
                });
            }
        }
    }
public static function load ( $ class ) { $ instance = new $ class ; $ post_type = $ instance -> getPostType ( ) ; // WordPress has a limit of 20 characters per if ( strlen ( $ post_type ) > 20 ) { throw new \ Exception ( 'Post Type name exceeds maximum 20 characters: ' . $ post_type ) ; } // This might happen if you're introducing a middle class between your post type and TacoPost // Ex: Foo extends \ClientTacoPost extends Taco\Post if ( ! $ post_type ) { return false ; } //add_action('init', array($instance, 'registerPostType')); $ instance -> registerPostType ( ) ; add_action ( 'save_post' , array ( $ instance , 'addSaveHooks' ) ) ; if ( is_admin ( ) ) { // If we're in the edit screen, we want the post loaded // so that TacoPost::getFields knows which post it's working with. // This helps if you want TacoPost::getFields to use conditional logic // based on which post is currently being edited. $ is_edit_screen = ( is_array ( $ _SERVER ) && preg_match ( '/post.php\?post=[\d]{1,}/i' , $ _SERVER [ 'REQUEST_URI' ] ) && ! Arr :: iterable ( $ _POST ) ) ; $ is_edit_save = ( preg_match ( '/post.php/i' , $ _SERVER [ 'REQUEST_URI' ] ) && Arr :: iterable ( $ _POST ) ) ; $ post = null ; if ( $ is_edit_screen && array_key_exists ( 'post' , $ _GET ) ) { $ post = get_post ( $ _GET [ 'post' ] ) ; } elseif ( $ is_edit_save ) { $ post = get_post ( $ _POST [ 'post_ID' ] ) ; } if ( $ post && $ post -> post_type === $ instance -> getPostType ( ) ) { $ instance -> load ( $ post ) ; } add_action ( 'admin_menu' , array ( $ instance , 'addMetaBoxes' ) ) ; add_action ( sprintf ( 'manage_%s_posts_columns' , $ post_type ) , array ( $ instance , 'addAdminColumns' ) , 10 , 2 ) ; add_action ( sprintf ( 'manage_%s_posts_custom_column' , $ post_type ) , array ( $ instance , 'renderAdminColumn' ) , 10 , 2 ) ; add_filter ( sprintf ( 'manage_edit-%s_sortable_columns' , $ post_type ) , array ( $ instance , 'makeAdminColumnsSortable' ) ) ; add_filter ( 'request' , array ( $ instance , 'sortAdminColumns' ) ) ; add_filter ( 'posts_clauses' , array ( $ instance , 'makeAdminTaxonomyColumnsSortable' ) , 10 , 2 ) ; // Hide the title column in the browse view of the admin UI $ is_browsing_index = ( is_array ( $ _SERVER ) && preg_match ( '/edit.php\?post_type=' . $ post_type . '$/i' , $ _SERVER [ 'REQUEST_URI' ] ) ) ; if ( $ is_browsing_index && $ instance -> getHideTitleFromAdminColumns ( ) ) { add_action ( 'admin_init' , function ( ) { wp_register_style ( 'hide_title_column_css' , plugins_url ( 'taco/base/hide_title_column.css' ) ) ; wp_enqueue_style ( 'hide_title_column_css' ) ; } ) ; } } }
Load a post type
@param string $class
Load a post type