| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Menus |
| 4 |
* |
| 5 |
* @package Cooked |
| 6 |
* @subpackage Admin Menus |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly |
| 11 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Cooked_Post_Types Class |
| 15 |
* |
| 16 |
* This class handles the post type creation. |
| 17 |
* |
| 18 |
* @since 1.0.0 |
| 19 |
*/ |
| 20 |
|
| 21 |
class Cooked_Admin_Menus { |
| 22 |
|
| 23 |
function __construct() { |
| 24 |
add_action( 'admin_menu', [&$this, 'add_menu'] ); |
| 25 |
|
| 26 |
if (!is_admin()) { |
| 27 |
add_action( 'admin_bar_menu', [&$this, 'add_admin_bar_menu'], 100 ); |
| 28 |
} |
| 29 |
|
| 30 |
add_action('parent_file', [&$this, 'parent_file_filter']); |
| 31 |
} |
| 32 |
|
| 33 |
public function add_menu() { |
| 34 |
global $cooked_taxonomies_for_menu; |
| 35 |
|
| 36 |
add_menu_page( __( 'Recipes', 'cooked' ), __( 'Recipes', 'cooked' ), 'edit_cooked_recipes', 'cooked_recipes_menu', '', 'none', 58 ); |
| 37 |
add_submenu_page('cooked_recipes_menu', __('Add New','cooked'), __('Add New','cooked'), 'edit_cooked_recipes', 'post-new.php?post_type=cp_recipe', '' ); |
| 38 |
|
| 39 |
if ( isset($cooked_taxonomies_for_menu) && !empty($cooked_taxonomies_for_menu) ) { |
| 40 |
foreach ( $cooked_taxonomies_for_menu as $menu_item ) { |
| 41 |
add_submenu_page($menu_item['menu'], $menu_item['name'], $menu_item['name'], $menu_item['capability'], $menu_item['url'], '', null ); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
add_submenu_page('cooked_recipes_menu', __('Settings', 'cooked'), __('Settings','cooked'), 'edit_cooked_settings', 'cooked_settings', [&$this, 'cooked_settings_page'] ); |
| 46 |
add_submenu_page('cooked_recipes_menu', __('Import', 'cooked'), __('Import','cooked'), 'edit_cooked_settings', 'cooked_import', [&$this, 'cooked_import_page'] ); |
| 47 |
add_submenu_page('cooked_recipes_menu', __('What\'s New?','cooked'), __('What\'s New?','cooked'), 'edit_cooked_settings', 'cooked_welcome', [&$this, 'cooked_welcome_content'] ); |
| 48 |
|
| 49 |
if ( !class_exists( 'Cooked_Pro_Plugin' ) ) { |
| 50 |
add_submenu_page('cooked_recipes_menu', __('Upgrade to Pro','cooked'), '<span class="admin-menu-cooked-upgrade">' . __('Upgrade to Pro','cooked') . '</span>', 'edit_cooked_settings', 'cooked_pro', [&$this, 'cooked_pro'] ); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
public function add_admin_bar_menu() { |
| 55 |
global $wp_admin_bar; |
| 56 |
|
| 57 |
if (is_admin_bar_showing()) { |
| 58 |
if (current_user_can('edit_cooked_recipes')) { |
| 59 |
$wp_admin_bar->add_menu(['id' => 'cooked-ab', 'title' => '<span class="ab-icon"></span>' . __('Recipes', 'cooked'), 'href' => get_admin_url() . 'edit.php?post_type=cp_recipe'] ); |
| 60 |
$wp_admin_bar->add_menu(['parent' => 'cooked-ab', 'title' => __('All Recipes', 'cooked'), 'id' => 'cooked-recipes-ab', 'href' => get_admin_url() . 'edit.php?post_type=cp_recipe'] ); |
| 61 |
$wp_admin_bar->add_menu(['parent' => 'cooked-ab', 'title' => __('Add New', 'cooked'), 'id' => 'cooked-add-new-ab', 'href' => get_admin_url() . 'post-new.php?post_type=cp_recipe'] ); |
| 62 |
} |
| 63 |
|
| 64 |
if (current_user_can('edit_cooked_settings')) { |
| 65 |
$wp_admin_bar->add_menu(['parent' => 'cooked-ab', 'title' => __('Settings', 'cooked'), 'id' => 'cooked-settings-ab', 'href' => get_admin_url() . 'admin.php?page=cooked_settings'] ); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
public function parent_file_filter($parent_file) { |
| 71 |
global $submenu_file, $current_screen, $pagenow; |
| 72 |
$post_type = 'cp_recipe'; |
| 73 |
|
| 74 |
if ($current_screen->post_type === $post_type && $pagenow === 'edit-tags.php') { |
| 75 |
$_cooked_taxonomies = Cooked_Taxonomies::get(); |
| 76 |
|
| 77 |
if (array_key_exists($current_screen->taxonomy, $_cooked_taxonomies)) { |
| 78 |
$submenu_file = 'edit-tags.php?taxonomy=' . $current_screen->taxonomy . '&post_type=' . $post_type; |
| 79 |
} |
| 80 |
|
| 81 |
$parent_file = 'cooked_recipes_menu'; |
| 82 |
} |
| 83 |
|
| 84 |
return $parent_file; |
| 85 |
} |
| 86 |
|
| 87 |
// Settings Panel |
| 88 |
public function cooked_settings_page() { |
| 89 |
if (!current_user_can('edit_cooked_settings')) { |
| 90 |
wp_die(__('You do not have sufficient permissions to access this page.', 'cooked')); |
| 91 |
} |
| 92 |
|
| 93 |
include COOKED_DIR . 'templates/admin/settings.php'; |
| 94 |
} |
| 95 |
|
| 96 |
// Settings Panel |
| 97 |
public function cooked_import_page() { |
| 98 |
if (!current_user_can('edit_cooked_settings')) { |
| 99 |
wp_die(__('You do not have sufficient permissions to access this page.', 'cooked')); |
| 100 |
} |
| 101 |
|
| 102 |
include COOKED_DIR . 'templates/admin/import.php'; |
| 103 |
} |
| 104 |
|
| 105 |
// Welcome Page |
| 106 |
public function cooked_welcome_content() { |
| 107 |
if (!current_user_can('edit_cooked_settings')) { |
| 108 |
wp_die(__('You do not have sufficient permissions to access this page.', 'cooked')); |
| 109 |
} |
| 110 |
|
| 111 |
include COOKED_DIR . 'templates/admin/welcome.php'; |
| 112 |
} |
| 113 |
|
| 114 |
// Cooked Pro |
| 115 |
public function cooked_pro() { |
| 116 |
if (!current_user_can('edit_cooked_settings')) { |
| 117 |
wp_die(__('You do not have sufficient permissions to access this page.', 'cooked')); |
| 118 |
} |
| 119 |
|
| 120 |
include COOKED_DIR . 'templates/admin/pro.php'; |
| 121 |
} |
| 122 |
|
| 123 |
} |
| 124 |
|