From 1c895ca5c631b5a85ed08c72c43a1f95cf807653 Mon Sep 17 00:00:00 2001 From: William Tam Date: Thu, 20 Aug 2020 19:16:17 +0000 Subject: [PATCH 1/2] Show the "Get NPR Stories" admin menu on the "NPR Pull Post Type" menu instead of always on the default "Post" menu --- get_stories.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/get_stories.php b/get_stories.php index 2e7deae..9e19081 100644 --- a/get_stories.php +++ b/get_stories.php @@ -179,10 +179,12 @@ public function __construct() { } /** - * Register the admin menu for "Get NPR Stories" + * Register the admin menu for "Get NPR Stories" for the post type assigned as the "Pull Post Type" */ public function admin_menu() { - add_posts_page( 'Get NPR Stories', 'Get NPR Stories', 'edit_posts', 'get-npr-stories', 'nprstory_get_stories' ); + $pull_post_type = $this->nprstory_get_pull_post_type(); + $slug_args = ( $pull_post_type != 'post' ) ? "?post_type=$pull_post_type" : ''; + add_submenu_page( "edit.php$slug_args", 'Get NPR Stories', 'Get NPR Stories', 'edit_posts', 'get-npr-stories', 'nprstory_get_stories' ); } } From ebce6adafdea1d560da53d70b76416945f288f9b Mon Sep 17 00:00:00 2001 From: William Tam Date: Thu, 20 Aug 2020 20:42:13 +0000 Subject: [PATCH 2/2] properly handle creating and registering the action hooks and menu links --- get_stories.php | 4 ++-- get_stories_ui.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/get_stories.php b/get_stories.php index 9e19081..d407c2a 100644 --- a/get_stories.php +++ b/get_stories.php @@ -175,7 +175,6 @@ public function __construct() { return; } add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); - add_action( 'load-posts_page_get-npr-stories', array( $this, 'load_page_hook' ) ); } /** @@ -184,7 +183,8 @@ public function __construct() { public function admin_menu() { $pull_post_type = $this->nprstory_get_pull_post_type(); $slug_args = ( $pull_post_type != 'post' ) ? "?post_type=$pull_post_type" : ''; - add_submenu_page( "edit.php$slug_args", 'Get NPR Stories', 'Get NPR Stories', 'edit_posts', 'get-npr-stories', 'nprstory_get_stories' ); + $hook_suffix = add_submenu_page( "edit.php$slug_args", 'Get NPR Stories', 'Get NPR Stories', 'edit_posts', 'get-npr-stories', 'nprstory_get_stories' ); + add_action( 'load-' . $hook_suffix, array( $this, 'load_page_hook' ) ); } } diff --git a/get_stories_ui.php b/get_stories_ui.php index f8f2c74..f9d4431 100644 --- a/get_stories_ui.php +++ b/get_stories_ui.php @@ -32,7 +32,9 @@ function nprstory_update_column_content ( $column_name, $post_ID ) { $retrieved = get_post_meta( $post_ID, NPR_RETRIEVED_STORY_META_KEY, true ); if ($retrieved) { $api_id = get_post_meta( $post_ID, NPR_STORY_ID_META_KEY, TRUE ); - echo ( ' Update ' ); + $pull_post_type = DS_NPR_API::nprstory_get_pull_post_type(); + $post_type_arg = ($pull_post_type != 'post') ? "&post_type=$pull_post_type" : ''; + echo ( ' Update ' ); } } }