/** * Load post new action * Redirect to right url if no page type is set. */ public function load_post_new() { $request_uri = $_SERVER['REQUEST_URI']; $post_types = papi_get_post_types(); if (in_array($this->post_type, $post_types, true) && strpos($request_uri, 'page_type=') === false) { $parsed_url = parse_url($request_uri); $only_page_type = papi_filter_settings_only_page_type($this->post_type); $page_types = papi_get_all_page_types($this->post_type); $show_standard = false; if (count($page_types) === 1 && empty($only_page_type)) { $show_standard = $page_types[0]->standard_type; $show_standard = $show_standard ? papi_filter_settings_show_standard_page_type($this->post_type) : $show_standard; $only_page_type = $show_standard ? '' : $page_types[0]->get_id(); } // Check if we should show one post type or not and // create the right url for that. if (!empty($only_page_type) && !$show_standard) { $url = papi_get_page_new_url($only_page_type, false); } else { $page = 'page=papi-add-new-page,' . $this->post_type; if ($this->post_type !== 'post') { $page = '&' . $page; } $url = 'edit.php?' . $parsed_url['query'] . $page; } wp_safe_redirect($url); is_admin() && exit; } }
<?php echo esc_html($post_type->labels->search_items); ?> </label> <input placeholder="<?php echo esc_html($post_type->labels->search_items); ?> ..." type="search" name="add-new-page-search" id="add-new-page-search" class="papi-search"> </h1> <div class="papi-box-list"> <?php $parent_page_type = papi_get_entry_type_by_id(papi_get_entry_type_id()); $page_types = papi_get_all_page_types($post_type_name); $show_standard = papi_filter_settings_show_standard_page_type($post_type_name); if ($parent_page_type instanceof Papi_Page_Type) { $child_types = $parent_page_type->get_child_types(); $page_types = empty($child_types) ? $page_types : $child_types; if (!$show_standard) { $show_standard = $parent_page_type->standard_type; } } if ($show_standard) { $id = sprintf('papi-standard-%s-type', $post_type_name); $page_type = new Papi_Page_Type($id); $page_type->id = $id; $page_type->name = papi_filter_settings_standard_page_type_name($post_type_name); $page_type->description = papi_filter_settings_standard_page_type_description($post_type_name); $page_type->thumbnail = papi_filter_settings_standard_page_type_thumbnail($post_type_name); $page_type->post_type = [$post_type_name];
/** * Show standard page type in filter dropdown on the given post type. * * @param string $post_type * * @return bool */ function papi_filter_settings_show_standard_page_type_in_filter($post_type) { return !apply_filters('papi/settings/show_standard_page_type_in_filter_' . $post_type, papi_filter_settings_show_standard_page_type($post_type)) === false; }
/** * Setup menu items for real post types. */ public function post_types_menu() { global $submenu; $post_types = papi_get_post_types(); foreach ($post_types as $post_type) { if (!post_type_exists($post_type)) { continue; } if ($post_type === 'post') { $edit_url = 'edit.php'; } else { $edit_url = 'edit.php?post_type=' . $post_type; } if (!isset($submenu[$edit_url]) || !isset($submenu[$edit_url][10]) || !isset($submenu[$edit_url][10][2])) { $post_type_object = get_post_type_object($post_type); if (!$post_type_object->show_in_menu) { $submenu[$edit_url] = [10 => [__('Add New', 'papi'), 'edit_posts', 'post-new.php']]; } else { continue; } } $only_page_type = papi_filter_settings_only_page_type($post_type); $page_types = papi_get_all_page_types(false, $post_type); $show_standard = false; // Don't change menu item when no page types is found. // @codeCoverageIgnoreStart if (empty($page_types)) { continue; } // @codeCoverageIgnoreEnd if (count($page_types) === 1 && empty($only_page_type)) { $show_standard = $page_types[0]->standard_type; $show_standard = $show_standard ? papi_filter_settings_show_standard_page_type($post_type) : $show_standard; $only_page_type = $show_standard ? '' : $page_types[0]->get_id(); } if (!empty($only_page_type) && !$show_standard) { $submenu[$edit_url][10][2] = papi_get_page_new_url($only_page_type, false, $post_type, ['action', 'message', 'page_type', 'post', 'post_type']); } else { $page = 'papi-add-new-page,' . $post_type; $start = strpos($edit_url, 'post_type') === false ? '?' : '&'; $submenu[$edit_url][10][2] = sprintf('%s%spage=%s', $edit_url, $start, $page); // Add menu item. add_menu_page(__('Add New', 'papi'), __('Add New', 'papi'), 'read', $page, [$this, 'render_view']); // Remove the menu item so it's hidden. remove_menu_page($page); } } }