Skip to content

Instantly share code, notes, and snippets.

@michaeluno
Last active February 22, 2021 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeluno/1f876f725b546ecd9b9409a40c9f1605 to your computer and use it in GitHub Desktop.
Save michaeluno/1f876f725b546ecd9b9409a40c9f1605 to your computer and use it in GitHub Desktop.
A WordPress plugin that tests Admin Page Framework to see how to add a custom post type sub-menu item to another custom post type.
<?php
class APFTest_CPTGroup_Admin extends AdminPageFramework {
public function setUp() {
$this->setRootMenuPageBySlug( 'edit.php?post_type=cpt_a' );
$this->addSubMenuItems(
array(
'title' => 'Settings',
'page_slug' => 'apf_test_multiple_cpt_group',
         'order' => 30,
)
);
}
}
<?php
class APFTest_CPTGroup_PostType_A extends AdminPageFramework_PostType {
public function setUp() {
$this->setArguments(
array(
'labels' => array(
'name' => 'CPT A',
'menu_name' => 'CPT A',
),
'show_ui' => true,
'menu_position' => 200,
'show_submenu_add_new' => false, // an admin page will be placed instead
'submenu_order_manage' => 10,
)
);
}
}
<?php
class APFTest_CPTGroup_PostType_B extends AdminPageFramework_PostType {
public function setUp() {
$this->setArguments(
array(
'labels' => array(
'name' => 'CPT B',
'menu_name' => 'CPT B',
),
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=cpt_a',
'submenu_order_manage' => 20,
)
);
}
}
<?php
/**
* Plugin Name: Admin Page Framework - Test CPT Group
* Plugin URI: http://admin-page-framework.michaeluno.jp/
* Description: Demonstrates how to add a custom post type sub-menu item to another custom post type.
* Author: Michael Uno
* Author URI: http://en.michaeluno.jp/
* Version: 0.0.1
*/
class APFTest_CPTGroup {
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'load' ) );
}
public function load() {
if ( ! class_exists( 'AdminPageFramework' ) ) {
return;
}
include( dirname( __FILE__ ) . '/APFTest_CPTGroup_Admin.php' );
include( dirname( __FILE__ ) . '/APFTest_CPTGroup_PostType_A.php' );
include( dirname( __FILE__ ) . '/APFTest_CPTGroup_PostType_B.php' );
new APFTest_CPTGroup_PostType_A( 'cpt_a', null, __FILE__ );
new APFTest_CPTGroup_PostType_B( 'cpt_b', null, __FILE__ );
new APFTest_CPTGroup_Admin;
}
}
new APFTest_CPTGroup;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment