-
-
Save maor/4687745 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Start up the engine | |
class CPT_Archive_Content | |
{ | |
/** | |
* Static property to hold our singleton instance | |
* @var CPT_Archive_Content | |
* | |
* @since 1.0 | |
*/ | |
static $instance = false; | |
/** | |
* This is our constructor, which is private to force the use of | |
* getInstance() to make this a Singleton | |
* | |
* @return CPT_Archive_Content | |
* | |
* @since 1.0 | |
*/ | |
public function __construct() { | |
add_action ( 'admin_menu', array( $this, 'menu_create' ) ); | |
} | |
/** | |
* If an instance exists, this returns it. If not, it creates one and | |
* retuns it. | |
* | |
* @return CPT_Archive_Content | |
*/ | |
public static function getInstance() { | |
if ( !self::$instance ) | |
self::$instance = new self; | |
return self::$instance; | |
} | |
/** | |
* Post type helper | |
* | |
* @return CPT_Archive_Content | |
*/ | |
private function post_types() { | |
// grab post types | |
$args = array( | |
'public' => true, | |
'_builtin' => false | |
); | |
$output = 'objects'; | |
$types = get_post_types($args, $output); | |
return $types; | |
} | |
/** | |
* call loop of types and add page | |
* | |
* @return CPT_Archive_Content | |
*/ | |
public function menu_create() { | |
// get post type array | |
$types = $this->post_types(); | |
foreach ($types as $type ): | |
// variables | |
$slug = $type->name; | |
$name = $type->label; | |
// page call | |
add_submenu_page('edit.php?post_type='.$slug.'', __( $name .' Archives', 'cptarch' ), __( $name .' Archives', 'cptarch' ), 'edit_posts', $slug.'-archive', array( $this, 'layout_setup' )); | |
endforeach; | |
} | |
public function layout_setup() { | |
$screen = get_current_screen(); | |
// get post type array | |
$types = $this->post_types(); | |
// do foreach on $types, check if current post-type (with "-archive' appended) equals to $screen->id | |
// if that matches, do as you wish | |
} | |
/// end class | |
} | |
// Instantiate our class | |
$CPT_Archive_Content = new CPT_Archive_Content(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment