您使用GET是正确的,这可能是最容易使用的。
试试这个:
Add_Child_Page::on_load();
class Add_Child_Page {
static function on_load() {
add_action( \'init\', array( __CLASS__, \'init\' ) );
add_action( \'admin_init\', array( __CLASS__, \'admin_init\' ) );
}
static function init() {
add_action( \'admin_bar_menu\', array( __CLASS__, \'admin_bar_menu\' ), 90 );
}
static function admin_bar_menu( $wp_admin_bar ) {
if( is_page() ) {
$wp_admin_bar->add_node( array(
\'id\' => \'add_child_page\',
\'title\' => \'Add Child Page\',
\'href\' => add_query_arg( array( \'post_type\' => \'page\', \'page_parent\' => get_the_ID() ), admin_url( \'post-new.php\' ) ),
) );
}
}
static function admin_init() {
add_filter( \'page_attributes_dropdown_pages_args\', array( __CLASS__, \'page_attributes_dropdown_pages_args\' ) );
}
static function page_attributes_dropdown_pages_args( $dropdown_args ) {
if ( ! empty($_REQUEST[\'page_parent\']) )
$dropdown_args[\'selected\'] = (int) $_REQUEST[\'page_parent\'];
return $dropdown_args;
}
}