1: <?php
2: /**
3: * Menus
4: *
5: * @package EPL
6: * @subpackage Admin/Menus
7: * @copyright Copyright (c) 2020, Merv Barrett
8: * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9: * @since 1.0
10: */
11:
12: // Exit if accessed directly.
13: if ( ! defined( 'ABSPATH' ) ) {
14: exit;
15: }
16:
17: global $epl_contact_page_hook;
18:
19: add_action( 'admin_menu', 'epl_admin_menu' );
20:
21: /**
22: * Admin Menus
23: *
24: * @since 1.0
25: * @since 3.4.48 fixed warnings when no user role set for user.
26: */
27: function epl_admin_menu() {
28: global $epl_contact_page_hook;
29: // Contributors and above can access these options.
30: $menu_title = __( 'Easy Property Listings', 'easy-property-listings' );
31: $page_title = __( 'Easy Property Listings', 'easy-property-listings' );
32: $capability = 'edit_posts';
33: $menu_slug = 'epl-general';
34: $main_menu_slug = $menu_slug;
35: $function = 'epl_menu_general';
36: $icon = 'dashicons-portfolio';
37: $position = '25.9';
38: add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon, $position );
39:
40: $page_title = __( 'Help', 'easy-property-listings' );
41: $menu_title = __( 'Help', 'easy-property-listings' );
42: add_submenu_page( $menu_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
43:
44: // Administrator and above can see these options.
45: $page_title = __( 'Settings', 'easy-property-listings' );
46: $menu_title = __( 'Settings', 'easy-property-listings' );
47: $capability = 'manage_options';
48: $function = 'epl_menu_settings';
49: $menu_slug = 'epl-settings';
50: add_submenu_page( $main_menu_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
51:
52: // Contacts Menu item.
53: $page_title = __( 'Contacts', 'easy-property-listings' );
54: $menu_title = __( 'Contacts', 'easy-property-listings' );
55: $menu_slug = 'epl-contacts';
56: $function = 'epl_contacts_page';
57: $this_user = wp_get_current_user();
58: if ( epl_contact_access() ) {
59: $capability = ! empty( $this_user->roles[0] ) ? $this_user->roles[0] : 'manage_options';
60: $epl_contact_page_hook = add_submenu_page( $main_menu_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
61: }
62:
63: // Reports Access, $this_user is common with contacts.
64: $page_title = __( 'Reports', 'easy-property-listings' );
65: $menu_title = __( 'Reports', 'easy-property-listings' );
66: $capability = 'edit_published_posts';
67: $menu_slug = 'epl-reports';
68: $function = 'epl_reports_page';
69: if ( epl_reports_access() ) {
70: $capability = $this_user->roles[0];
71: $epl_reports_page_hook = add_submenu_page( $main_menu_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
72: }
73:
74: // Administrator and above can see these options.
75: $capability = 'manage_options';
76:
77: // Enable Menu if extension requires extension options.
78: if ( has_filter( 'epl_extensions_options_filter_new' ) ) {
79: $page_title = __( 'Extensions', 'easy-property-listings' );
80: $menu_title = __( 'Extensions', 'easy-property-listings' );
81: $menu_slug = 'epl-extensions';
82: $function = 'epl_menu_extensions';
83: add_submenu_page( $main_menu_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
84: }
85:
86: if ( has_filter( 'epl_extensions_options_filter' ) ) {
87: // Show their menu on separate page.
88: $page_title_old = __( 'Extensions Updates', 'easy-property-listings' );
89: $menu_title_old = '<span style="color:#ff0000">' . __( 'Update Extensions', 'easy-property-listings' ) . '</span>';
90: $menu_slug_old = 'epl-extensions-compat';
91: $function_old = 'epl_menu_extensions_compat';
92: add_submenu_page( $main_menu_slug, $page_title_old, $menu_title_old, $capability, $menu_slug_old, $function_old );
93: }
94:
95: // Enable Menu if extension requires license options.
96: if ( has_filter( 'epl_license_options_filter' ) ) {
97: $page_title = __( 'Licenses', 'easy-property-listings' );
98: $menu_title = __( 'Licenses', 'easy-property-listings' );
99: $menu_slug = 'epl-licenses';
100: $function = 'epl_menu_licenses';
101: add_submenu_page( $main_menu_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
102: }
103:
104: // Author level and above can see these options.
105: $page_title = __( 'Add Ons', 'easy-property-listings' );
106: $menu_title = __( 'Add Ons', 'easy-property-listings' );
107: $capability = 'edit_published_posts';
108: $menu_slug = 'epl-addons';
109: $function = 'epl_menu_addons';
110: add_submenu_page( $main_menu_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
111:
112: // Administrator level and above can see these options.
113: $page_title = __( 'Tools', 'easy-property-listings' );
114: $menu_title = __( 'Tools', 'easy-property-listings' );
115: $capability = 'manage_options';
116: $menu_slug = 'epl-tools';
117: $function = 'epl_menu_tools';
118: add_submenu_page( $main_menu_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
119: }
120:
121: /**
122: * General Menu
123: *
124: * @since 1.0
125: */
126: function epl_menu_general() {
127: if ( ! current_user_can( 'edit_posts' ) ) {
128: wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'easy-property-listings' ) );
129: }
130: require_once 'menu-help.php';
131: }
132:
133: /**
134: * Settings Menu
135: *
136: * @since 1.0
137: */
138: function epl_menu_settings() {
139: if ( ! current_user_can( 'manage_options' ) ) {
140: wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'easy-property-listings' ) );
141: }
142: require_once 'menu-general.php';
143: }
144:
145: /**
146: * Extensions Menu
147: *
148: * @since 1.0
149: */
150: function epl_menu_extensions() {
151: if ( ! current_user_can( 'manage_options' ) ) {
152: wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'easy-property-listings' ) );
153: }
154: require_once 'menu-extensions.php';
155: }
156:
157: /**
158: * Licenses Menu
159: *
160: * @since 1.0
161: */
162: function epl_menu_licenses() {
163: if ( ! current_user_can( 'manage_options' ) ) {
164: wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'easy-property-listings' ) );
165: }
166: require_once 'menu-licenses.php';
167: }
168:
169: /**
170: * Addons Menu
171: *
172: * @since 1.0
173: */
174: function epl_menu_addons() {
175: if ( ! current_user_can( 'edit_published_posts' ) ) {
176: wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'easy-property-listings' ) );
177: }
178: require_once 'menu-addons.php';
179: }
180:
181: /**
182: * Help Menu
183: *
184: * @since 1.0
185: */
186: function epl_menu_help() {
187: if ( ! current_user_can( 'edit_posts' ) ) {
188: wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'easy-property-listings' ) );
189: }
190: require_once 'menu-help.php';
191: }
192:
193: /**
194: * Tools Menu
195: *
196: * @since 3.3
197: */
198: function epl_menu_tools() {
199: if ( ! current_user_can( 'manage_options' ) ) {
200: wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'easy-property-listings' ) );
201: }
202: require_once 'menu-tools.php';
203: }
204: