Ejemplo n.º 1
0
 /**
  * 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;
     }
 }
Ejemplo n.º 2
0
}
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];
    $page_types[] = $page_type;
}
usort($page_types, function ($a, $b) {
    return strcmp($a->name, $b->name);
});
$page_types = papi_sort_order(array_reverse($page_types));
$use_thumbnail = false;
foreach ($page_types as $key => $page_type) {
    if (!empty($page_type->get_thumbnail())) {
        $use_thumbnail = true;
    }
}
foreach ($page_types as $key => $page_type) {
    if (!papi_display_page_type($page_type)) {
        continue;
    }
    papi_include_template('admin/views/partials/add-new-item.php', ['title' => $page_type->name, 'description' => $page_type->description, 'thumbnail' => $page_type->get_thumbnail(), 'url' => papi_get_page_new_url($page_type->get_id(), true, null), 'use_thumbnail' => $use_thumbnail]);
}
?>
	</div>
</div>
Ejemplo n.º 3
0
 /**
  * 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);
         }
     }
 }