@@ -11,25 +11,25 @@ |
||
11 | 11 | */ |
12 | 12 | class AttributesSanitizer |
13 | 13 | { |
14 | - /** |
|
15 | - * @param string $attributes |
|
16 | - * @param array $allowed_tags |
|
17 | - * @param string $tag |
|
18 | - * @return mixed|string |
|
19 | - */ |
|
20 | - public static function clean(string $attributes, array $allowed_tags, string $tag = 'div') |
|
21 | - { |
|
22 | - if (trim($attributes) === '') { |
|
23 | - return ''; |
|
24 | - } |
|
25 | - $html = '<' . $tag . ' ' . $attributes . '>'; |
|
26 | - $escaped = wp_kses($html, $allowed_tags); |
|
27 | - $start = strpos($escaped, ' '); |
|
28 | - $end = strpos($escaped, '>'); |
|
29 | - if ($start === false || $end === false) { |
|
30 | - return ''; |
|
31 | - } |
|
32 | - $length = $end - $start; |
|
33 | - return trim(substr($escaped, $start, $length)); |
|
34 | - } |
|
14 | + /** |
|
15 | + * @param string $attributes |
|
16 | + * @param array $allowed_tags |
|
17 | + * @param string $tag |
|
18 | + * @return mixed|string |
|
19 | + */ |
|
20 | + public static function clean(string $attributes, array $allowed_tags, string $tag = 'div') |
|
21 | + { |
|
22 | + if (trim($attributes) === '') { |
|
23 | + return ''; |
|
24 | + } |
|
25 | + $html = '<' . $tag . ' ' . $attributes . '>'; |
|
26 | + $escaped = wp_kses($html, $allowed_tags); |
|
27 | + $start = strpos($escaped, ' '); |
|
28 | + $end = strpos($escaped, '>'); |
|
29 | + if ($start === false || $end === false) { |
|
30 | + return ''; |
|
31 | + } |
|
32 | + $length = $end - $start; |
|
33 | + return trim(substr($escaped, $start, $length)); |
|
34 | + } |
|
35 | 35 | } |
@@ -22,7 +22,7 @@ |
||
22 | 22 | if (trim($attributes) === '') { |
23 | 23 | return ''; |
24 | 24 | } |
25 | - $html = '<' . $tag . ' ' . $attributes . '>'; |
|
25 | + $html = '<'.$tag.' '.$attributes.'>'; |
|
26 | 26 | $escaped = wp_kses($html, $allowed_tags); |
27 | 27 | $start = strpos($escaped, ' '); |
28 | 28 | $end = strpos($escaped, '>'); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function registerCustomTaxonomyTerm($taxonomy, $term_slug, array $cpt_slugs = array()) |
66 | 66 | { |
67 | - $this->custom_taxonomy_terms[][ $term_slug ] = new CustomTaxonomyTerm( |
|
67 | + $this->custom_taxonomy_terms[][$term_slug] = new CustomTaxonomyTerm( |
|
68 | 68 | $taxonomy, |
69 | 69 | $term_slug, |
70 | 70 | $cpt_slugs |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function saveDefaultTerm(int $post_id, ?WP_Post $post) |
83 | 83 | { |
84 | - if (! $post || empty($this->custom_taxonomy_terms)) { |
|
84 | + if ( ! $post || empty($this->custom_taxonomy_terms)) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | 87 | // no default terms set so lets just exit. |
@@ -16,181 +16,181 @@ |
||
16 | 16 | */ |
17 | 17 | class RegisterCustomTaxonomyTerms |
18 | 18 | { |
19 | - /** |
|
20 | - * @var array[] $custom_taxonomy_terms |
|
21 | - */ |
|
22 | - public $custom_taxonomy_terms = array(); |
|
19 | + /** |
|
20 | + * @var array[] $custom_taxonomy_terms |
|
21 | + */ |
|
22 | + public $custom_taxonomy_terms = array(); |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * RegisterCustomTaxonomyTerms constructor. |
|
27 | - */ |
|
28 | - public function __construct() |
|
29 | - { |
|
30 | - // hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts |
|
31 | - // IF they don't have a term for that taxonomy set. |
|
32 | - add_action('save_post', array($this, 'saveDefaultTerm'), 100, 2); |
|
33 | - do_action( |
|
34 | - 'AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end', |
|
35 | - $this |
|
36 | - ); |
|
37 | - } |
|
25 | + /** |
|
26 | + * RegisterCustomTaxonomyTerms constructor. |
|
27 | + */ |
|
28 | + public function __construct() |
|
29 | + { |
|
30 | + // hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts |
|
31 | + // IF they don't have a term for that taxonomy set. |
|
32 | + add_action('save_post', array($this, 'saveDefaultTerm'), 100, 2); |
|
33 | + do_action( |
|
34 | + 'AHEE__EventEspresso_core_domain_services_custom_post_types_RegisterCustomTaxonomyTerms__construct_end', |
|
35 | + $this |
|
36 | + ); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - public function registerCustomTaxonomyTerms() |
|
41 | - { |
|
42 | - // setup default terms in any of our taxonomies (but only if we're in admin). |
|
43 | - // Why not added via register_activation_hook? |
|
44 | - // Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies |
|
45 | - // (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin. |
|
46 | - // Keep in mind that this will READ these terms if they are deleted by the user. Hence MUST use terms. |
|
47 | - // if ( is_admin() ) { |
|
48 | - // $this->set_must_use_event_types(); |
|
49 | - // } |
|
50 | - // set default terms |
|
51 | - $this->registerCustomTaxonomyTerm( |
|
52 | - 'espresso_event_type', |
|
53 | - 'single-event', |
|
54 | - [EspressoPostType::EVENTS] |
|
55 | - ); |
|
56 | - } |
|
40 | + public function registerCustomTaxonomyTerms() |
|
41 | + { |
|
42 | + // setup default terms in any of our taxonomies (but only if we're in admin). |
|
43 | + // Why not added via register_activation_hook? |
|
44 | + // Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies |
|
45 | + // (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin. |
|
46 | + // Keep in mind that this will READ these terms if they are deleted by the user. Hence MUST use terms. |
|
47 | + // if ( is_admin() ) { |
|
48 | + // $this->set_must_use_event_types(); |
|
49 | + // } |
|
50 | + // set default terms |
|
51 | + $this->registerCustomTaxonomyTerm( |
|
52 | + 'espresso_event_type', |
|
53 | + 'single-event', |
|
54 | + [EspressoPostType::EVENTS] |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Allows us to set what the default will be for terms when a cpt is PUBLISHED. |
|
61 | - * |
|
62 | - * @param string $taxonomy The taxonomy we're using for the default term |
|
63 | - * @param string $term_slug The slug of the term that will be the default. |
|
64 | - * @param array $cpt_slugs An array of custom post types we want the default assigned to |
|
65 | - */ |
|
66 | - public function registerCustomTaxonomyTerm($taxonomy, $term_slug, array $cpt_slugs = array()) |
|
67 | - { |
|
68 | - $this->custom_taxonomy_terms[][ $term_slug ] = new CustomTaxonomyTerm( |
|
69 | - $taxonomy, |
|
70 | - $term_slug, |
|
71 | - $cpt_slugs |
|
72 | - ); |
|
73 | - } |
|
59 | + /** |
|
60 | + * Allows us to set what the default will be for terms when a cpt is PUBLISHED. |
|
61 | + * |
|
62 | + * @param string $taxonomy The taxonomy we're using for the default term |
|
63 | + * @param string $term_slug The slug of the term that will be the default. |
|
64 | + * @param array $cpt_slugs An array of custom post types we want the default assigned to |
|
65 | + */ |
|
66 | + public function registerCustomTaxonomyTerm($taxonomy, $term_slug, array $cpt_slugs = array()) |
|
67 | + { |
|
68 | + $this->custom_taxonomy_terms[][ $term_slug ] = new CustomTaxonomyTerm( |
|
69 | + $taxonomy, |
|
70 | + $term_slug, |
|
71 | + $cpt_slugs |
|
72 | + ); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property |
|
78 | - * |
|
79 | - * @param int $post_id ID of CPT being saved |
|
80 | - * @param WP_Post|null $post Post object |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function saveDefaultTerm(int $post_id, ?WP_Post $post) |
|
84 | - { |
|
85 | - if (! $post || empty($this->custom_taxonomy_terms)) { |
|
86 | - return; |
|
87 | - } |
|
88 | - // no default terms set so lets just exit. |
|
89 | - foreach ($this->custom_taxonomy_terms as $custom_taxonomy_terms) { |
|
90 | - foreach ($custom_taxonomy_terms as $custom_taxonomy_term) { |
|
91 | - if ( |
|
92 | - $post->post_status === 'publish' |
|
93 | - && $custom_taxonomy_term instanceof CustomTaxonomyTerm |
|
94 | - && in_array($post->post_type, $custom_taxonomy_term->customPostTypeSlugs(), true) |
|
95 | - ) { |
|
96 | - // note some error proofing going on here to save unnecessary db queries |
|
97 | - $taxonomies = get_object_taxonomies($post->post_type); |
|
98 | - foreach ($taxonomies as $taxonomy) { |
|
99 | - $terms = wp_get_post_terms($post_id, $taxonomy); |
|
100 | - if (empty($terms) && $taxonomy === $custom_taxonomy_term->taxonomySlug()) { |
|
101 | - wp_set_object_terms( |
|
102 | - $post_id, |
|
103 | - array($custom_taxonomy_term->termSlug()), |
|
104 | - $taxonomy |
|
105 | - ); |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
76 | + /** |
|
77 | + * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property |
|
78 | + * |
|
79 | + * @param int $post_id ID of CPT being saved |
|
80 | + * @param WP_Post|null $post Post object |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function saveDefaultTerm(int $post_id, ?WP_Post $post) |
|
84 | + { |
|
85 | + if (! $post || empty($this->custom_taxonomy_terms)) { |
|
86 | + return; |
|
87 | + } |
|
88 | + // no default terms set so lets just exit. |
|
89 | + foreach ($this->custom_taxonomy_terms as $custom_taxonomy_terms) { |
|
90 | + foreach ($custom_taxonomy_terms as $custom_taxonomy_term) { |
|
91 | + if ( |
|
92 | + $post->post_status === 'publish' |
|
93 | + && $custom_taxonomy_term instanceof CustomTaxonomyTerm |
|
94 | + && in_array($post->post_type, $custom_taxonomy_term->customPostTypeSlugs(), true) |
|
95 | + ) { |
|
96 | + // note some error proofing going on here to save unnecessary db queries |
|
97 | + $taxonomies = get_object_taxonomies($post->post_type); |
|
98 | + foreach ($taxonomies as $taxonomy) { |
|
99 | + $terms = wp_get_post_terms($post_id, $taxonomy); |
|
100 | + if (empty($terms) && $taxonomy === $custom_taxonomy_term->taxonomySlug()) { |
|
101 | + wp_set_object_terms( |
|
102 | + $post_id, |
|
103 | + array($custom_taxonomy_term->termSlug()), |
|
104 | + $taxonomy |
|
105 | + ); |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * @return void |
|
116 | - */ |
|
117 | - public function setMustUseEventTypes() |
|
118 | - { |
|
119 | - $term_details = array( |
|
120 | - // Attendee's register for the first date-time only |
|
121 | - 'single-event' => array( |
|
122 | - 'term' => esc_html__('Single Event', 'event_espresso'), |
|
123 | - 'desc' => esc_html__( |
|
124 | - 'A single event that spans one or more consecutive days.', |
|
125 | - 'event_espresso' |
|
126 | - ), |
|
127 | - ), |
|
128 | - // example: a party or two-day long workshop |
|
129 | - // Attendee's can register for any of the date-times |
|
130 | - 'multi-event' => array( |
|
131 | - 'term' => esc_html__('Multi Event', 'event_espresso'), |
|
132 | - 'desc' => esc_html__( |
|
133 | - 'Multiple, separate, but related events that occur on consecutive days.', |
|
134 | - 'event_espresso' |
|
135 | - ), |
|
136 | - ), |
|
137 | - // example: a three day music festival or week long conference |
|
138 | - // Attendee's register for the first date-time only |
|
139 | - 'event-series' => array( |
|
140 | - 'term' => esc_html__('Event Series', 'event_espresso'), |
|
141 | - 'desc' => esc_html__( |
|
142 | - ' Multiple events that occur over multiple non-consecutive days.', |
|
143 | - 'event_espresso' |
|
144 | - ), |
|
145 | - ), |
|
146 | - // example: an 8 week introduction to basket weaving course |
|
147 | - // Attendee's can register for any of the date-times. |
|
148 | - 'recurring-event' => array( |
|
149 | - 'term' => esc_html__('Recurring Event', 'event_espresso'), |
|
150 | - 'desc' => esc_html__( |
|
151 | - 'Multiple events that occur over multiple non-consecutive days.', |
|
152 | - 'event_espresso' |
|
153 | - ), |
|
154 | - ), |
|
155 | - // example: a yoga class |
|
156 | - 'ongoing' => array( |
|
157 | - 'term' => esc_html__('Ongoing Event', 'event_espresso'), |
|
158 | - 'desc' => esc_html__( |
|
159 | - 'An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event', |
|
160 | - 'event_espresso' |
|
161 | - ), |
|
162 | - ) |
|
163 | - // example: access to a museum |
|
164 | - // 'walk-in' => array( esc_html__('Walk In', 'event_espresso'), esc_html__('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ), |
|
165 | - // 'reservation' => array( esc_html__('Reservation', 'event_espresso'), esc_html__('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1 |
|
166 | - // 'multiple-session' => array( esc_html__('Multiple Session', 'event_espresso'), esc_html__('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1 |
|
167 | - // 'appointment' => array( esc_html__('Appointments', 'event_espresso'), esc_html__('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') ) |
|
168 | - ); |
|
169 | - $this->setMustUseTerms('espresso_event_type', $term_details); |
|
170 | - } |
|
114 | + /** |
|
115 | + * @return void |
|
116 | + */ |
|
117 | + public function setMustUseEventTypes() |
|
118 | + { |
|
119 | + $term_details = array( |
|
120 | + // Attendee's register for the first date-time only |
|
121 | + 'single-event' => array( |
|
122 | + 'term' => esc_html__('Single Event', 'event_espresso'), |
|
123 | + 'desc' => esc_html__( |
|
124 | + 'A single event that spans one or more consecutive days.', |
|
125 | + 'event_espresso' |
|
126 | + ), |
|
127 | + ), |
|
128 | + // example: a party or two-day long workshop |
|
129 | + // Attendee's can register for any of the date-times |
|
130 | + 'multi-event' => array( |
|
131 | + 'term' => esc_html__('Multi Event', 'event_espresso'), |
|
132 | + 'desc' => esc_html__( |
|
133 | + 'Multiple, separate, but related events that occur on consecutive days.', |
|
134 | + 'event_espresso' |
|
135 | + ), |
|
136 | + ), |
|
137 | + // example: a three day music festival or week long conference |
|
138 | + // Attendee's register for the first date-time only |
|
139 | + 'event-series' => array( |
|
140 | + 'term' => esc_html__('Event Series', 'event_espresso'), |
|
141 | + 'desc' => esc_html__( |
|
142 | + ' Multiple events that occur over multiple non-consecutive days.', |
|
143 | + 'event_espresso' |
|
144 | + ), |
|
145 | + ), |
|
146 | + // example: an 8 week introduction to basket weaving course |
|
147 | + // Attendee's can register for any of the date-times. |
|
148 | + 'recurring-event' => array( |
|
149 | + 'term' => esc_html__('Recurring Event', 'event_espresso'), |
|
150 | + 'desc' => esc_html__( |
|
151 | + 'Multiple events that occur over multiple non-consecutive days.', |
|
152 | + 'event_espresso' |
|
153 | + ), |
|
154 | + ), |
|
155 | + // example: a yoga class |
|
156 | + 'ongoing' => array( |
|
157 | + 'term' => esc_html__('Ongoing Event', 'event_espresso'), |
|
158 | + 'desc' => esc_html__( |
|
159 | + 'An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event', |
|
160 | + 'event_espresso' |
|
161 | + ), |
|
162 | + ) |
|
163 | + // example: access to a museum |
|
164 | + // 'walk-in' => array( esc_html__('Walk In', 'event_espresso'), esc_html__('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ), |
|
165 | + // 'reservation' => array( esc_html__('Reservation', 'event_espresso'), esc_html__('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1 |
|
166 | + // 'multiple-session' => array( esc_html__('Multiple Session', 'event_espresso'), esc_html__('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1 |
|
167 | + // 'appointment' => array( esc_html__('Appointments', 'event_espresso'), esc_html__('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') ) |
|
168 | + ); |
|
169 | + $this->setMustUseTerms('espresso_event_type', $term_details); |
|
170 | + } |
|
171 | 171 | |
172 | 172 | |
173 | - /** |
|
174 | - * wrapper method for handling the setting up of initial terms in the db (if they don't already exist). |
|
175 | - * Note this should ONLY be used for terms that always must be present. Be aware that if an initial term is |
|
176 | - * deleted then it WILL be recreated. |
|
177 | - * |
|
178 | - * @param string $taxonomy The name of the taxonomy |
|
179 | - * @param array $term_details An array of term details indexed by slug and containing Name of term, and |
|
180 | - * description as the elements in the array |
|
181 | - * @return void |
|
182 | - */ |
|
183 | - public function setMustUseTerms($taxonomy, $term_details) |
|
184 | - { |
|
185 | - $term_details = (array) $term_details; |
|
186 | - foreach ($term_details as $slug => $details) { |
|
187 | - if (isset($details['term'], $details['desc']) && ! term_exists($slug, $taxonomy)) { |
|
188 | - $insert_arr = array( |
|
189 | - 'slug' => $slug, |
|
190 | - 'description' => $details['desc'], |
|
191 | - ); |
|
192 | - wp_insert_term($details['term'], $taxonomy, $insert_arr); |
|
193 | - } |
|
194 | - } |
|
195 | - } |
|
173 | + /** |
|
174 | + * wrapper method for handling the setting up of initial terms in the db (if they don't already exist). |
|
175 | + * Note this should ONLY be used for terms that always must be present. Be aware that if an initial term is |
|
176 | + * deleted then it WILL be recreated. |
|
177 | + * |
|
178 | + * @param string $taxonomy The name of the taxonomy |
|
179 | + * @param array $term_details An array of term details indexed by slug and containing Name of term, and |
|
180 | + * description as the elements in the array |
|
181 | + * @return void |
|
182 | + */ |
|
183 | + public function setMustUseTerms($taxonomy, $term_details) |
|
184 | + { |
|
185 | + $term_details = (array) $term_details; |
|
186 | + foreach ($term_details as $slug => $details) { |
|
187 | + if (isset($details['term'], $details['desc']) && ! term_exists($slug, $taxonomy)) { |
|
188 | + $insert_arr = array( |
|
189 | + 'slug' => $slug, |
|
190 | + 'description' => $details['desc'], |
|
191 | + ); |
|
192 | + wp_insert_term($details['term'], $taxonomy, $insert_arr); |
|
193 | + } |
|
194 | + } |
|
195 | + } |
|
196 | 196 | } |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | $admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties)); |
218 | 218 | } |
219 | 219 | $admin_menu = $admin_page_init->adminMenu(); |
220 | - if (! $admin_menu instanceof AdminMenuItem) { |
|
220 | + if ( ! $admin_menu instanceof AdminMenuItem) { |
|
221 | 221 | throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
222 | 222 | } |
223 | - if (! is_callable($admin_menu->menuCallback())) { |
|
223 | + if ( ! is_callable($admin_menu->menuCallback())) { |
|
224 | 224 | $admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']); |
225 | 225 | } |
226 | 226 | // get the menu group that this menu item belongs to and then add it |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | */ |
260 | 260 | private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup |
261 | 261 | { |
262 | - if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) { |
|
262 | + if ( ! isset($this->menu_items[$admin_menu->menuGroup()])) { |
|
263 | 263 | throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso')); |
264 | 264 | } |
265 | - $admin_group = $this->menu_items[ $admin_menu->menuGroup() ]; |
|
266 | - if (! $admin_group instanceof AdminMenuGroup) { |
|
265 | + $admin_group = $this->menu_items[$admin_menu->menuGroup()]; |
|
266 | + if ( ! $admin_group instanceof AdminMenuGroup) { |
|
267 | 267 | throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso')); |
268 | 268 | } |
269 | 269 | return $admin_group; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | } |
312 | 312 | try { |
313 | 313 | $wp_page_slug = $menu_item->registerAdminMenuItem($network_admin); |
314 | - $admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null; |
|
314 | + $admin_init_page = $this->installed_pages[$menu_item->menuSlug()] ?? null; |
|
315 | 315 | if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) { |
316 | 316 | $admin_init_page->setWpPageSlug($wp_page_slug); |
317 | 317 | $admin_init_page->set_page_dependencies($wp_page_slug); |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | public function sortMenu(array $admin_menu): array |
369 | 369 | { |
370 | 370 | foreach ($admin_menu as $menu_group) { |
371 | - if (! $menu_group instanceof AdminMenuItem) { |
|
371 | + if ( ! $menu_group instanceof AdminMenuItem) { |
|
372 | 372 | throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
373 | 373 | } |
374 | 374 | if ($menu_group instanceof AdminMenuGroup) { |
@@ -15,434 +15,434 @@ |
||
15 | 15 | |
16 | 16 | class AdminMenuManager |
17 | 17 | { |
18 | - /** |
|
19 | - * Default: null - defaults to below Comments |
|
20 | - * |
|
21 | - * 5 - below Posts |
|
22 | - * 10 - below Media |
|
23 | - * 15 - below Links |
|
24 | - * 20 - below Pages |
|
25 | - * 25 - below comments |
|
26 | - * 60 - below first separator |
|
27 | - * 65 - below Plugins |
|
28 | - * 70 - below Users |
|
29 | - * 75 - below Tools |
|
30 | - * 80 - below Settings |
|
31 | - * 100 - below second separator |
|
32 | - */ |
|
33 | - const DEFAULT_MENU_POSITION = 100; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @var AdminMenuItem[] |
|
38 | - */ |
|
39 | - private array $menu_items = []; |
|
40 | - |
|
41 | - /** |
|
42 | - * objects for page_init objects detected and loaded |
|
43 | - * |
|
44 | - * @var EE_Admin_Page_Init[] |
|
45 | - */ |
|
46 | - private array $installed_pages = []; |
|
47 | - |
|
48 | - /** |
|
49 | - * set to TRUE if site is currently in maintenance mode level 2 |
|
50 | - * |
|
51 | - * @var bool |
|
52 | - */ |
|
53 | - protected bool $maintenance_mode = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * same values used by AdminMenuManager::DEFAULT_MENU_POSITION |
|
57 | - * |
|
58 | - * @var int |
|
59 | - */ |
|
60 | - private int $menu_position; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var AdminMenuItem |
|
64 | - */ |
|
65 | - private AdminMenuItem $top_level_menu_item; |
|
66 | - |
|
67 | - |
|
68 | - public function __construct() |
|
69 | - { |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - public function initialize() |
|
74 | - { |
|
75 | - $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
76 | - $this->menu_position = apply_filters( |
|
77 | - 'FHEE__EventEspresso_core_domain_services_admin_menu_AdminMenuManager__initialize__menu_position', |
|
78 | - AdminMenuManager::DEFAULT_MENU_POSITION, |
|
79 | - $this->maintenance_mode |
|
80 | - ); |
|
81 | - $this->addTopLevelMenuItem(); |
|
82 | - $this->initializeMenuGroups(); |
|
83 | - add_action('admin_menu', [$this, 'generateAdminMenu']); |
|
84 | - add_action('network_admin_menu', [$this, 'generateNetworkAdminMenu']); |
|
85 | - add_filter('custom_menu_order', '__return_true'); |
|
86 | - add_filter('menu_order', [$this, 'reorderAdminMenu']); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * adds the top level menu item that everything else descends from. |
|
92 | - * changes depending on whether site is in full maintenance mode or not |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - private function addTopLevelMenuItem() |
|
97 | - { |
|
98 | - $this->top_level_menu_item = $this->maintenance_mode |
|
99 | - ? $this->instantiateAdminMenu( |
|
100 | - [ |
|
101 | - 'menu_slug' => 'espresso_maintenance_settings', |
|
102 | - 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
103 | - 'capability' => 'manage_options', |
|
104 | - 'menu_group' => 'main', |
|
105 | - 'menu_order' => 10, |
|
106 | - 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
107 | - 'parent_slug' => 'espresso_maintenance_settings', |
|
108 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
109 | - ] |
|
110 | - ) |
|
111 | - : $this->instantiateAdminMenu( |
|
112 | - [ |
|
113 | - 'menu_slug' => 'espresso_events', |
|
114 | - 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
115 | - 'capability' => 'ee_read_events', |
|
116 | - 'menu_group' => 'main', |
|
117 | - 'menu_order' => 10, |
|
118 | - 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
119 | - 'parent_slug' => 'espresso_events', |
|
120 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
121 | - ] |
|
122 | - ); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
128 | - * |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - private function initializeMenuGroups() |
|
132 | - { |
|
133 | - $this->menu_items = apply_filters( |
|
134 | - 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
135 | - [ |
|
136 | - 'main' => $this->instantiateAdminMenu( |
|
137 | - [ |
|
138 | - 'menu_slug' => 'main', |
|
139 | - 'menu_label' => esc_html__('Main', 'event_espresso'), |
|
140 | - 'capability' => $this->maintenance_mode ? 'manage_options' : 'ee_read_ee', |
|
141 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
142 | - 'menu_order' => 0, |
|
143 | - 'parent_slug' => 'espresso_events', |
|
144 | - 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
145 | - ] |
|
146 | - ), |
|
147 | - 'management' => $this->instantiateAdminMenu( |
|
148 | - [ |
|
149 | - 'menu_slug' => 'management', |
|
150 | - 'menu_label' => esc_html__('Management', 'event_espresso'), |
|
151 | - 'capability' => 'ee_read_ee', |
|
152 | - 'menu_order' => 10, |
|
153 | - 'parent_slug' => 'espresso_events', |
|
154 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
155 | - ] |
|
156 | - ), |
|
157 | - 'addons' => $this->instantiateAdminMenu( |
|
158 | - [ |
|
159 | - 'menu_slug' => 'addons', |
|
160 | - 'menu_label' => esc_html__('Add-ons', 'event_espresso'), |
|
161 | - 'capability' => 'ee_read_ee', |
|
162 | - 'menu_order' => 20, |
|
163 | - 'parent_slug' => 'espresso_events', |
|
164 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
165 | - ] |
|
166 | - ), |
|
167 | - 'settings' => $this->instantiateAdminMenu( |
|
168 | - [ |
|
169 | - 'menu_slug' => 'settings', |
|
170 | - 'menu_label' => esc_html__('Settings', 'event_espresso'), |
|
171 | - 'capability' => 'ee_read_ee', |
|
172 | - 'menu_order' => 30, |
|
173 | - 'parent_slug' => 'espresso_events', |
|
174 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
175 | - ] |
|
176 | - ), |
|
177 | - 'templates' => $this->instantiateAdminMenu( |
|
178 | - [ |
|
179 | - 'menu_slug' => 'templates', |
|
180 | - 'menu_label' => esc_html__('Templates', 'event_espresso'), |
|
181 | - 'capability' => 'ee_read_ee', |
|
182 | - 'menu_order' => 40, |
|
183 | - 'parent_slug' => 'espresso_events', |
|
184 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
185 | - ] |
|
186 | - ), |
|
187 | - 'extras' => $this->instantiateAdminMenu( |
|
188 | - [ |
|
189 | - 'menu_slug' => 'extras', |
|
190 | - 'menu_label' => esc_html__('Extras', 'event_espresso'), |
|
191 | - 'capability' => 'ee_read_ee', |
|
192 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
193 | - 'menu_order' => 50, |
|
194 | - 'parent_slug' => 'espresso_events', |
|
195 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
196 | - ] |
|
197 | - ), |
|
198 | - 'tools' => $this->instantiateAdminMenu( |
|
199 | - [ |
|
200 | - 'menu_slug' => 'tools', |
|
201 | - 'menu_label' => esc_html__('Tools', 'event_espresso'), |
|
202 | - 'capability' => 'ee_read_ee', |
|
203 | - 'menu_order' => 60, |
|
204 | - 'parent_slug' => 'espresso_events', |
|
205 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
206 | - ] |
|
207 | - ), |
|
208 | - ] |
|
209 | - ); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * adds an AdminMenuItem |
|
215 | - * |
|
216 | - * @param AdminMenuItem $admin_menu_item |
|
217 | - * @return AdminMenuItem |
|
218 | - */ |
|
219 | - public function addAdminMenuItem(AdminMenuItem $admin_menu_item): AdminMenuItem |
|
220 | - { |
|
221 | - // get the menu group that this menu item belongs to and then add it |
|
222 | - $admin_group = $this->getMenuGroup($admin_menu_item); |
|
223 | - $admin_group->addMenuItem($admin_menu_item); |
|
224 | - return $admin_menu_item; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * instantiates and returns the appropriate AdminMenuItem for the provided EE_Admin_Page_Init |
|
230 | - * |
|
231 | - * @param EE_Admin_Page_Init $admin_page_init |
|
232 | - * @return AdminMenuItem |
|
233 | - */ |
|
234 | - public function getAdminMenu(EE_Admin_Page_Init $admin_page_init): AdminMenuItem |
|
235 | - { |
|
236 | - // see if admin page init is using new classes |
|
237 | - $menu_properties = $admin_page_init->getMenuProperties(); |
|
238 | - if (empty($menu_properties)) { |
|
239 | - // no? ok setup the admin menu item the old way |
|
240 | - $admin_page_init->setupLegacyAdminMenuItem(); |
|
241 | - } else { |
|
242 | - // adding the admin page init callback here means the menu doesn't have to cart that object around |
|
243 | - $menu_properties['menu_callback'] = [$admin_page_init, 'initialize_admin_page']; |
|
244 | - $admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties)); |
|
245 | - } |
|
246 | - $admin_menu = $admin_page_init->adminMenu(); |
|
247 | - if (! $admin_menu instanceof AdminMenuItem) { |
|
248 | - throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
249 | - } |
|
250 | - if (! is_callable($admin_menu->menuCallback())) { |
|
251 | - $admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']); |
|
252 | - } |
|
253 | - // get the menu group that this menu item belongs to and then add it |
|
254 | - $admin_group = $this->getMenuGroup($admin_menu); |
|
255 | - $admin_group->addMenuItem($admin_menu); |
|
256 | - return $admin_menu; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * @param array $menu_properties |
|
262 | - * @return AdminMenuItem|null |
|
263 | - */ |
|
264 | - private function instantiateAdminMenu(array $menu_properties): ?AdminMenuItem |
|
265 | - { |
|
266 | - $type = $menu_properties['menu_type'] ?? AdminMenuItem::TYPE_MENU_GROUP; |
|
267 | - unset($menu_properties['menu_type']); |
|
268 | - switch ($type) { |
|
269 | - case AdminMenuItem::TYPE_MENU_GROUP: |
|
270 | - unset($menu_properties['menu_callback']); |
|
271 | - return new AdminMenuGroup($menu_properties); |
|
272 | - case AdminMenuItem::TYPE_MENU_TOP: |
|
273 | - return new AdminMenuTopLevel($menu_properties); |
|
274 | - case AdminMenuItem::TYPE_MENU_SUB_ITEM: |
|
275 | - return new AdminMenuSubItem($menu_properties); |
|
276 | - } |
|
277 | - return null; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @param AdminMenuItem $admin_menu |
|
283 | - * @return AdminMenuGroup |
|
284 | - * @throws DomainException |
|
285 | - * @throws OutOfRangeException |
|
286 | - */ |
|
287 | - private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup |
|
288 | - { |
|
289 | - if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) { |
|
290 | - throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso')); |
|
291 | - } |
|
292 | - $admin_group = $this->menu_items[ $admin_menu->menuGroup() ]; |
|
293 | - if (! $admin_group instanceof AdminMenuGroup) { |
|
294 | - throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso')); |
|
295 | - } |
|
296 | - return $admin_group; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * set_network_menus |
|
302 | - * This method sets up the menus for network EE Admin Pages. |
|
303 | - * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
304 | - * are only added to the menu map if they are intended for the admin menu |
|
305 | - * |
|
306 | - * @return void |
|
307 | - * @throws DomainException |
|
308 | - */ |
|
309 | - public function generateNetworkAdminMenu() |
|
310 | - { |
|
311 | - $this->generateAdminMenu(true); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * This method sets up the menus for EE Admin Pages |
|
317 | - * |
|
318 | - * @return void |
|
319 | - * @throws DomainException |
|
320 | - */ |
|
321 | - public function generateAdminMenu(bool $network_admin = false) |
|
322 | - { |
|
323 | - $admin_menu = $this->sortMenu($this->menu_items); |
|
324 | - $this->top_level_menu_item->registerAdminMenuItem($network_admin); |
|
325 | - $this->registerAdminMenu($admin_menu, $network_admin); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @param array $admin_menu |
|
331 | - * @param bool $network_admin |
|
332 | - */ |
|
333 | - private function registerAdminMenu(array $admin_menu, bool $network_admin) |
|
334 | - { |
|
335 | - foreach ($admin_menu as $menu_item) { |
|
336 | - if ($this->skipMenuItem($menu_item)) { |
|
337 | - continue; |
|
338 | - } |
|
339 | - try { |
|
340 | - $wp_page_slug = $menu_item->registerAdminMenuItem($network_admin); |
|
341 | - $admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null; |
|
342 | - if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) { |
|
343 | - $admin_init_page->setWpPageSlug($wp_page_slug); |
|
344 | - $admin_init_page->set_page_dependencies($wp_page_slug); |
|
345 | - } |
|
346 | - if ($menu_item instanceof AdminMenuGroup) { |
|
347 | - $this->registerAdminMenu($menu_item->getMenuItems(), $network_admin); |
|
348 | - } |
|
349 | - } catch (Exception $e) { |
|
350 | - EE_Error::add_error($e->getMessage(), $e->getFile(), __FUNCTION__, $e->getLine()); |
|
351 | - } |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * returns TRUE if any of the following conditions is met: |
|
358 | - * - menu item is NOT an instanceof AdminMenuItem |
|
359 | - * - menu item has already been registered |
|
360 | - * - menu item should not be shown when site is in full maintenance mode |
|
361 | - * - current user does not have the required access permission |
|
362 | - * - menu item is a group but has no sub items |
|
363 | - * |
|
364 | - * @param AdminMenuItem|null $menu_item |
|
365 | - * @return bool |
|
366 | - */ |
|
367 | - private function skipMenuItem(?AdminMenuItem $menu_item): bool |
|
368 | - { |
|
369 | - return ! $menu_item instanceof AdminMenuItem |
|
370 | - || $menu_item->isRegistered() |
|
371 | - || ! $menu_item->showOnMaintenanceModeMenu() |
|
372 | - || ! $menu_item->currentUserHasAccess() |
|
373 | - || ( |
|
374 | - $menu_item instanceof AdminMenuGroup |
|
375 | - && $menu_item->hasNoMenuItems() |
|
376 | - ); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * @param EE_Admin_Page_Init[] $installed_pages |
|
382 | - */ |
|
383 | - public function setInstalledPages(array $installed_pages): void |
|
384 | - { |
|
385 | - $this->installed_pages = $installed_pages; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Recursively sort menu groups and their sub items |
|
391 | - * |
|
392 | - * @return AdminMenuItem[] |
|
393 | - * @throws DomainException |
|
394 | - */ |
|
395 | - public function sortMenu(array $admin_menu): array |
|
396 | - { |
|
397 | - foreach ($admin_menu as $menu_group) { |
|
398 | - if (! $menu_group instanceof AdminMenuItem) { |
|
399 | - throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
400 | - } |
|
401 | - if ($menu_group instanceof AdminMenuGroup) { |
|
402 | - // sort sub items |
|
403 | - $menu_items = $this->sortMenu($menu_group->getMenuItems()); |
|
404 | - $menu_group->setMenuItems($menu_items); |
|
405 | - } |
|
406 | - } |
|
407 | - // sort incoming array AFTER it's been looped through and elements have been validated |
|
408 | - usort($admin_menu, [$this, 'sortMenuItems']); |
|
409 | - return $admin_menu; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * sort sub menu items |
|
415 | - * |
|
416 | - * @param AdminMenuItem $a menu_item |
|
417 | - * @param AdminMenuItem $b being compared to |
|
418 | - * @return int sort order |
|
419 | - */ |
|
420 | - private function sortMenuItems(AdminMenuItem $a, AdminMenuItem $b): int |
|
421 | - { |
|
422 | - if ($a->menuOrder() === $b->menuOrder()) { |
|
423 | - return 0; |
|
424 | - } |
|
425 | - return $a->menuOrder() < $b->menuOrder() ? -1 : 1; |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Moves the Event Espresso admin menu to the position set by $this->menu_position |
|
431 | - * |
|
432 | - * @param array $menu_order |
|
433 | - * @return array |
|
434 | - */ |
|
435 | - public function reorderAdminMenu(array $menu_order): array |
|
436 | - { |
|
437 | - $menu_slug = $this->maintenance_mode ? 'espresso_maintenance_settings' : 'espresso_events'; |
|
438 | - $current_index = array_search($menu_slug, $menu_order); |
|
439 | - if ($current_index === false) { |
|
440 | - return $menu_order; |
|
441 | - } |
|
442 | - // chop out the espresso admin menu if found |
|
443 | - $espresso_menu = array_splice($menu_order, $current_index, 1); |
|
444 | - // reinsert at position set by $this->menu_position |
|
445 | - array_splice($menu_order, $this->menu_position, 0, $espresso_menu); |
|
446 | - return $menu_order; |
|
447 | - } |
|
18 | + /** |
|
19 | + * Default: null - defaults to below Comments |
|
20 | + * |
|
21 | + * 5 - below Posts |
|
22 | + * 10 - below Media |
|
23 | + * 15 - below Links |
|
24 | + * 20 - below Pages |
|
25 | + * 25 - below comments |
|
26 | + * 60 - below first separator |
|
27 | + * 65 - below Plugins |
|
28 | + * 70 - below Users |
|
29 | + * 75 - below Tools |
|
30 | + * 80 - below Settings |
|
31 | + * 100 - below second separator |
|
32 | + */ |
|
33 | + const DEFAULT_MENU_POSITION = 100; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @var AdminMenuItem[] |
|
38 | + */ |
|
39 | + private array $menu_items = []; |
|
40 | + |
|
41 | + /** |
|
42 | + * objects for page_init objects detected and loaded |
|
43 | + * |
|
44 | + * @var EE_Admin_Page_Init[] |
|
45 | + */ |
|
46 | + private array $installed_pages = []; |
|
47 | + |
|
48 | + /** |
|
49 | + * set to TRUE if site is currently in maintenance mode level 2 |
|
50 | + * |
|
51 | + * @var bool |
|
52 | + */ |
|
53 | + protected bool $maintenance_mode = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * same values used by AdminMenuManager::DEFAULT_MENU_POSITION |
|
57 | + * |
|
58 | + * @var int |
|
59 | + */ |
|
60 | + private int $menu_position; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var AdminMenuItem |
|
64 | + */ |
|
65 | + private AdminMenuItem $top_level_menu_item; |
|
66 | + |
|
67 | + |
|
68 | + public function __construct() |
|
69 | + { |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + public function initialize() |
|
74 | + { |
|
75 | + $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
76 | + $this->menu_position = apply_filters( |
|
77 | + 'FHEE__EventEspresso_core_domain_services_admin_menu_AdminMenuManager__initialize__menu_position', |
|
78 | + AdminMenuManager::DEFAULT_MENU_POSITION, |
|
79 | + $this->maintenance_mode |
|
80 | + ); |
|
81 | + $this->addTopLevelMenuItem(); |
|
82 | + $this->initializeMenuGroups(); |
|
83 | + add_action('admin_menu', [$this, 'generateAdminMenu']); |
|
84 | + add_action('network_admin_menu', [$this, 'generateNetworkAdminMenu']); |
|
85 | + add_filter('custom_menu_order', '__return_true'); |
|
86 | + add_filter('menu_order', [$this, 'reorderAdminMenu']); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * adds the top level menu item that everything else descends from. |
|
92 | + * changes depending on whether site is in full maintenance mode or not |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + private function addTopLevelMenuItem() |
|
97 | + { |
|
98 | + $this->top_level_menu_item = $this->maintenance_mode |
|
99 | + ? $this->instantiateAdminMenu( |
|
100 | + [ |
|
101 | + 'menu_slug' => 'espresso_maintenance_settings', |
|
102 | + 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
103 | + 'capability' => 'manage_options', |
|
104 | + 'menu_group' => 'main', |
|
105 | + 'menu_order' => 10, |
|
106 | + 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
107 | + 'parent_slug' => 'espresso_maintenance_settings', |
|
108 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
109 | + ] |
|
110 | + ) |
|
111 | + : $this->instantiateAdminMenu( |
|
112 | + [ |
|
113 | + 'menu_slug' => 'espresso_events', |
|
114 | + 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
115 | + 'capability' => 'ee_read_events', |
|
116 | + 'menu_group' => 'main', |
|
117 | + 'menu_order' => 10, |
|
118 | + 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
119 | + 'parent_slug' => 'espresso_events', |
|
120 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
121 | + ] |
|
122 | + ); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
128 | + * |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + private function initializeMenuGroups() |
|
132 | + { |
|
133 | + $this->menu_items = apply_filters( |
|
134 | + 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
135 | + [ |
|
136 | + 'main' => $this->instantiateAdminMenu( |
|
137 | + [ |
|
138 | + 'menu_slug' => 'main', |
|
139 | + 'menu_label' => esc_html__('Main', 'event_espresso'), |
|
140 | + 'capability' => $this->maintenance_mode ? 'manage_options' : 'ee_read_ee', |
|
141 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
142 | + 'menu_order' => 0, |
|
143 | + 'parent_slug' => 'espresso_events', |
|
144 | + 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
145 | + ] |
|
146 | + ), |
|
147 | + 'management' => $this->instantiateAdminMenu( |
|
148 | + [ |
|
149 | + 'menu_slug' => 'management', |
|
150 | + 'menu_label' => esc_html__('Management', 'event_espresso'), |
|
151 | + 'capability' => 'ee_read_ee', |
|
152 | + 'menu_order' => 10, |
|
153 | + 'parent_slug' => 'espresso_events', |
|
154 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
155 | + ] |
|
156 | + ), |
|
157 | + 'addons' => $this->instantiateAdminMenu( |
|
158 | + [ |
|
159 | + 'menu_slug' => 'addons', |
|
160 | + 'menu_label' => esc_html__('Add-ons', 'event_espresso'), |
|
161 | + 'capability' => 'ee_read_ee', |
|
162 | + 'menu_order' => 20, |
|
163 | + 'parent_slug' => 'espresso_events', |
|
164 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
165 | + ] |
|
166 | + ), |
|
167 | + 'settings' => $this->instantiateAdminMenu( |
|
168 | + [ |
|
169 | + 'menu_slug' => 'settings', |
|
170 | + 'menu_label' => esc_html__('Settings', 'event_espresso'), |
|
171 | + 'capability' => 'ee_read_ee', |
|
172 | + 'menu_order' => 30, |
|
173 | + 'parent_slug' => 'espresso_events', |
|
174 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
175 | + ] |
|
176 | + ), |
|
177 | + 'templates' => $this->instantiateAdminMenu( |
|
178 | + [ |
|
179 | + 'menu_slug' => 'templates', |
|
180 | + 'menu_label' => esc_html__('Templates', 'event_espresso'), |
|
181 | + 'capability' => 'ee_read_ee', |
|
182 | + 'menu_order' => 40, |
|
183 | + 'parent_slug' => 'espresso_events', |
|
184 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
185 | + ] |
|
186 | + ), |
|
187 | + 'extras' => $this->instantiateAdminMenu( |
|
188 | + [ |
|
189 | + 'menu_slug' => 'extras', |
|
190 | + 'menu_label' => esc_html__('Extras', 'event_espresso'), |
|
191 | + 'capability' => 'ee_read_ee', |
|
192 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
193 | + 'menu_order' => 50, |
|
194 | + 'parent_slug' => 'espresso_events', |
|
195 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
196 | + ] |
|
197 | + ), |
|
198 | + 'tools' => $this->instantiateAdminMenu( |
|
199 | + [ |
|
200 | + 'menu_slug' => 'tools', |
|
201 | + 'menu_label' => esc_html__('Tools', 'event_espresso'), |
|
202 | + 'capability' => 'ee_read_ee', |
|
203 | + 'menu_order' => 60, |
|
204 | + 'parent_slug' => 'espresso_events', |
|
205 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
206 | + ] |
|
207 | + ), |
|
208 | + ] |
|
209 | + ); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * adds an AdminMenuItem |
|
215 | + * |
|
216 | + * @param AdminMenuItem $admin_menu_item |
|
217 | + * @return AdminMenuItem |
|
218 | + */ |
|
219 | + public function addAdminMenuItem(AdminMenuItem $admin_menu_item): AdminMenuItem |
|
220 | + { |
|
221 | + // get the menu group that this menu item belongs to and then add it |
|
222 | + $admin_group = $this->getMenuGroup($admin_menu_item); |
|
223 | + $admin_group->addMenuItem($admin_menu_item); |
|
224 | + return $admin_menu_item; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * instantiates and returns the appropriate AdminMenuItem for the provided EE_Admin_Page_Init |
|
230 | + * |
|
231 | + * @param EE_Admin_Page_Init $admin_page_init |
|
232 | + * @return AdminMenuItem |
|
233 | + */ |
|
234 | + public function getAdminMenu(EE_Admin_Page_Init $admin_page_init): AdminMenuItem |
|
235 | + { |
|
236 | + // see if admin page init is using new classes |
|
237 | + $menu_properties = $admin_page_init->getMenuProperties(); |
|
238 | + if (empty($menu_properties)) { |
|
239 | + // no? ok setup the admin menu item the old way |
|
240 | + $admin_page_init->setupLegacyAdminMenuItem(); |
|
241 | + } else { |
|
242 | + // adding the admin page init callback here means the menu doesn't have to cart that object around |
|
243 | + $menu_properties['menu_callback'] = [$admin_page_init, 'initialize_admin_page']; |
|
244 | + $admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties)); |
|
245 | + } |
|
246 | + $admin_menu = $admin_page_init->adminMenu(); |
|
247 | + if (! $admin_menu instanceof AdminMenuItem) { |
|
248 | + throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
249 | + } |
|
250 | + if (! is_callable($admin_menu->menuCallback())) { |
|
251 | + $admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']); |
|
252 | + } |
|
253 | + // get the menu group that this menu item belongs to and then add it |
|
254 | + $admin_group = $this->getMenuGroup($admin_menu); |
|
255 | + $admin_group->addMenuItem($admin_menu); |
|
256 | + return $admin_menu; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * @param array $menu_properties |
|
262 | + * @return AdminMenuItem|null |
|
263 | + */ |
|
264 | + private function instantiateAdminMenu(array $menu_properties): ?AdminMenuItem |
|
265 | + { |
|
266 | + $type = $menu_properties['menu_type'] ?? AdminMenuItem::TYPE_MENU_GROUP; |
|
267 | + unset($menu_properties['menu_type']); |
|
268 | + switch ($type) { |
|
269 | + case AdminMenuItem::TYPE_MENU_GROUP: |
|
270 | + unset($menu_properties['menu_callback']); |
|
271 | + return new AdminMenuGroup($menu_properties); |
|
272 | + case AdminMenuItem::TYPE_MENU_TOP: |
|
273 | + return new AdminMenuTopLevel($menu_properties); |
|
274 | + case AdminMenuItem::TYPE_MENU_SUB_ITEM: |
|
275 | + return new AdminMenuSubItem($menu_properties); |
|
276 | + } |
|
277 | + return null; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @param AdminMenuItem $admin_menu |
|
283 | + * @return AdminMenuGroup |
|
284 | + * @throws DomainException |
|
285 | + * @throws OutOfRangeException |
|
286 | + */ |
|
287 | + private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup |
|
288 | + { |
|
289 | + if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) { |
|
290 | + throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso')); |
|
291 | + } |
|
292 | + $admin_group = $this->menu_items[ $admin_menu->menuGroup() ]; |
|
293 | + if (! $admin_group instanceof AdminMenuGroup) { |
|
294 | + throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso')); |
|
295 | + } |
|
296 | + return $admin_group; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * set_network_menus |
|
302 | + * This method sets up the menus for network EE Admin Pages. |
|
303 | + * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
304 | + * are only added to the menu map if they are intended for the admin menu |
|
305 | + * |
|
306 | + * @return void |
|
307 | + * @throws DomainException |
|
308 | + */ |
|
309 | + public function generateNetworkAdminMenu() |
|
310 | + { |
|
311 | + $this->generateAdminMenu(true); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * This method sets up the menus for EE Admin Pages |
|
317 | + * |
|
318 | + * @return void |
|
319 | + * @throws DomainException |
|
320 | + */ |
|
321 | + public function generateAdminMenu(bool $network_admin = false) |
|
322 | + { |
|
323 | + $admin_menu = $this->sortMenu($this->menu_items); |
|
324 | + $this->top_level_menu_item->registerAdminMenuItem($network_admin); |
|
325 | + $this->registerAdminMenu($admin_menu, $network_admin); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @param array $admin_menu |
|
331 | + * @param bool $network_admin |
|
332 | + */ |
|
333 | + private function registerAdminMenu(array $admin_menu, bool $network_admin) |
|
334 | + { |
|
335 | + foreach ($admin_menu as $menu_item) { |
|
336 | + if ($this->skipMenuItem($menu_item)) { |
|
337 | + continue; |
|
338 | + } |
|
339 | + try { |
|
340 | + $wp_page_slug = $menu_item->registerAdminMenuItem($network_admin); |
|
341 | + $admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null; |
|
342 | + if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) { |
|
343 | + $admin_init_page->setWpPageSlug($wp_page_slug); |
|
344 | + $admin_init_page->set_page_dependencies($wp_page_slug); |
|
345 | + } |
|
346 | + if ($menu_item instanceof AdminMenuGroup) { |
|
347 | + $this->registerAdminMenu($menu_item->getMenuItems(), $network_admin); |
|
348 | + } |
|
349 | + } catch (Exception $e) { |
|
350 | + EE_Error::add_error($e->getMessage(), $e->getFile(), __FUNCTION__, $e->getLine()); |
|
351 | + } |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * returns TRUE if any of the following conditions is met: |
|
358 | + * - menu item is NOT an instanceof AdminMenuItem |
|
359 | + * - menu item has already been registered |
|
360 | + * - menu item should not be shown when site is in full maintenance mode |
|
361 | + * - current user does not have the required access permission |
|
362 | + * - menu item is a group but has no sub items |
|
363 | + * |
|
364 | + * @param AdminMenuItem|null $menu_item |
|
365 | + * @return bool |
|
366 | + */ |
|
367 | + private function skipMenuItem(?AdminMenuItem $menu_item): bool |
|
368 | + { |
|
369 | + return ! $menu_item instanceof AdminMenuItem |
|
370 | + || $menu_item->isRegistered() |
|
371 | + || ! $menu_item->showOnMaintenanceModeMenu() |
|
372 | + || ! $menu_item->currentUserHasAccess() |
|
373 | + || ( |
|
374 | + $menu_item instanceof AdminMenuGroup |
|
375 | + && $menu_item->hasNoMenuItems() |
|
376 | + ); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * @param EE_Admin_Page_Init[] $installed_pages |
|
382 | + */ |
|
383 | + public function setInstalledPages(array $installed_pages): void |
|
384 | + { |
|
385 | + $this->installed_pages = $installed_pages; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Recursively sort menu groups and their sub items |
|
391 | + * |
|
392 | + * @return AdminMenuItem[] |
|
393 | + * @throws DomainException |
|
394 | + */ |
|
395 | + public function sortMenu(array $admin_menu): array |
|
396 | + { |
|
397 | + foreach ($admin_menu as $menu_group) { |
|
398 | + if (! $menu_group instanceof AdminMenuItem) { |
|
399 | + throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
400 | + } |
|
401 | + if ($menu_group instanceof AdminMenuGroup) { |
|
402 | + // sort sub items |
|
403 | + $menu_items = $this->sortMenu($menu_group->getMenuItems()); |
|
404 | + $menu_group->setMenuItems($menu_items); |
|
405 | + } |
|
406 | + } |
|
407 | + // sort incoming array AFTER it's been looped through and elements have been validated |
|
408 | + usort($admin_menu, [$this, 'sortMenuItems']); |
|
409 | + return $admin_menu; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * sort sub menu items |
|
415 | + * |
|
416 | + * @param AdminMenuItem $a menu_item |
|
417 | + * @param AdminMenuItem $b being compared to |
|
418 | + * @return int sort order |
|
419 | + */ |
|
420 | + private function sortMenuItems(AdminMenuItem $a, AdminMenuItem $b): int |
|
421 | + { |
|
422 | + if ($a->menuOrder() === $b->menuOrder()) { |
|
423 | + return 0; |
|
424 | + } |
|
425 | + return $a->menuOrder() < $b->menuOrder() ? -1 : 1; |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Moves the Event Espresso admin menu to the position set by $this->menu_position |
|
431 | + * |
|
432 | + * @param array $menu_order |
|
433 | + * @return array |
|
434 | + */ |
|
435 | + public function reorderAdminMenu(array $menu_order): array |
|
436 | + { |
|
437 | + $menu_slug = $this->maintenance_mode ? 'espresso_maintenance_settings' : 'espresso_events'; |
|
438 | + $current_index = array_search($menu_slug, $menu_order); |
|
439 | + if ($current_index === false) { |
|
440 | + return $menu_order; |
|
441 | + } |
|
442 | + // chop out the espresso admin menu if found |
|
443 | + $espresso_menu = array_splice($menu_order, $current_index, 1); |
|
444 | + // reinsert at position set by $this->menu_position |
|
445 | + array_splice($menu_order, $this->menu_position, 0, $espresso_menu); |
|
446 | + return $menu_order; |
|
447 | + } |
|
448 | 448 | } |
@@ -4,15 +4,15 @@ |
||
4 | 4 | |
5 | 5 | class AdminMenuSubItem extends AdminMenuTopLevel |
6 | 6 | { |
7 | - protected function registerMenuItem(): string |
|
8 | - { |
|
9 | - return add_submenu_page( |
|
10 | - $this->parentSlug(), |
|
11 | - $this->title(), |
|
12 | - $this->menuLabel(), |
|
13 | - $this->capability(), |
|
14 | - $this->menuSlug(), |
|
15 | - $this->menuCallback() |
|
16 | - ); |
|
17 | - } |
|
7 | + protected function registerMenuItem(): string |
|
8 | + { |
|
9 | + return add_submenu_page( |
|
10 | + $this->parentSlug(), |
|
11 | + $this->title(), |
|
12 | + $this->menuLabel(), |
|
13 | + $this->capability(), |
|
14 | + $this->menuSlug(), |
|
15 | + $this->menuCallback() |
|
16 | + ); |
|
17 | + } |
|
18 | 18 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | public const DISPLAY_NETWORK_ONLY = 3; |
21 | 21 | |
22 | - public const TYPE_MENU_TOP = 'top'; |
|
22 | + public const TYPE_MENU_TOP = 'top'; |
|
23 | 23 | |
24 | 24 | public const TYPE_MENU_GROUP = 'group'; |
25 | 25 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | // verify that required keys are present in the incoming array. |
190 | 190 | $missing = array_diff($required, array_keys($menu_args)); |
191 | 191 | |
192 | - if (! empty($missing)) { |
|
192 | + if ( ! empty($missing)) { |
|
193 | 193 | throw new DomainException( |
194 | 194 | sprintf( |
195 | 195 | esc_html__( |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | $this->capability = $capability; |
272 | 272 | // filter capabilities (both static and dynamic) |
273 | 273 | $this->capability = apply_filters('FHEE_management_capability', $this->capability, null); |
274 | - $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null); |
|
274 | + $this->capability = apply_filters('FHEE_'.$this->menu_slug.'_capability', $this->capability, null); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
492 | 492 | AdminMenuItem::DISPLAY_NETWORK_ONLY, |
493 | 493 | ]; |
494 | - if (! in_array($show_on_menu, $valid_menu_options, true)) { |
|
494 | + if ( ! in_array($show_on_menu, $valid_menu_options, true)) { |
|
495 | 495 | throw new DomainException( |
496 | 496 | sprintf( |
497 | 497 | esc_html__( |
@@ -11,517 +11,517 @@ |
||
11 | 11 | |
12 | 12 | abstract class AdminMenuItem |
13 | 13 | { |
14 | - public const DISPLAY_NONE = 0; |
|
15 | - |
|
16 | - public const DISPLAY_BLOG_ONLY = 1; |
|
17 | - |
|
18 | - public const DISPLAY_BLOG_AND_NETWORK = 2; |
|
19 | - |
|
20 | - public const DISPLAY_NETWORK_ONLY = 3; |
|
21 | - |
|
22 | - public const TYPE_MENU_TOP = 'top'; |
|
23 | - |
|
24 | - public const TYPE_MENU_GROUP = 'group'; |
|
25 | - |
|
26 | - public const TYPE_MENU_SUB_ITEM = 'sub-item'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * What capability is required to access this page. |
|
31 | - * |
|
32 | - * @since 4.4.0 |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $capability = 'administrator'; |
|
36 | - |
|
37 | - /** |
|
38 | - * set to TRUE if site is currently in maintenance mode level 2 |
|
39 | - * |
|
40 | - * @var bool |
|
41 | - */ |
|
42 | - protected bool $maintenance_mode = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * Menu maps can define a parent slug that gets used instead of the main parent slug for the menu when |
|
46 | - * EE_Maintenance_Mode::STATUS_FULL_SITE is active. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $maintenance_mode_parent = ''; |
|
51 | - |
|
52 | - /** |
|
53 | - * The callback for displaying the page that the menu references. |
|
54 | - * |
|
55 | - * @since 4.4.0 |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - protected $menu_callback; |
|
59 | - |
|
60 | - /** |
|
61 | - * The EE specific group this menu item belongs in (group slug). |
|
62 | - * |
|
63 | - * @since 4.4.0 |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - protected $menu_group; |
|
67 | - |
|
68 | - /** |
|
69 | - * The label for the menu item. (What shows up in the actual menu). |
|
70 | - * |
|
71 | - * @since 4.4.0 |
|
72 | - * @var string |
|
73 | - */ |
|
74 | - protected $menu_label; |
|
75 | - |
|
76 | - /** |
|
77 | - * What order this item should be in the menu. |
|
78 | - * |
|
79 | - * @since 4.4.0 |
|
80 | - * @var int |
|
81 | - */ |
|
82 | - protected $menu_order; |
|
83 | - |
|
84 | - /** |
|
85 | - * What slug should be used to reference this menu item. |
|
86 | - * |
|
87 | - * @since 4.4.0 |
|
88 | - * @var string |
|
89 | - */ |
|
90 | - protected $menu_slug; |
|
91 | - |
|
92 | - /** |
|
93 | - * What menu item is the parent of this menu item. |
|
94 | - * |
|
95 | - * @since 4.4.0 |
|
96 | - * @var string |
|
97 | - */ |
|
98 | - protected $parent_slug; |
|
99 | - |
|
100 | - /** |
|
101 | - * set to TRUE once menu item has been added to generated menu |
|
102 | - * |
|
103 | - * @var bool |
|
104 | - */ |
|
105 | - protected $registered = false; |
|
106 | - |
|
107 | - /** |
|
108 | - * Whether this item is displayed in the menu or not. |
|
109 | - * Sometimes an EE Admin Page needs to register itself but is not accessible via the WordPress |
|
110 | - * admin menu. |
|
111 | - * |
|
112 | - * @since 4.4.0 |
|
113 | - * @var int |
|
114 | - */ |
|
115 | - protected $show_on_menu = self::DISPLAY_BLOG_ONLY; |
|
116 | - |
|
117 | - /** |
|
118 | - * The title for the menu page. (the page the menu links to) |
|
119 | - * |
|
120 | - * @since 4.4.0 |
|
121 | - * @var string |
|
122 | - */ |
|
123 | - protected $title; |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param array $menu_args An array of arguments used to setup the menu properties on construct. |
|
128 | - * @param array $required An array of keys that should be in the $menu_args, |
|
129 | - * this is used to validate that the items that should be defined are present. |
|
130 | - * @return void |
|
131 | - * @throws DomainException |
|
132 | - * @throws InvalidArgumentException |
|
133 | - * @throws OutOfBoundsException |
|
134 | - */ |
|
135 | - public function __construct(array $menu_args, array $required) |
|
136 | - { |
|
137 | - // we don't want this coupling anymore >:( |
|
138 | - unset($menu_args['admin_init_page'], $required['admin_init_page']); |
|
139 | - $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
140 | - |
|
141 | - // filter all args before processing so plugins can manipulate various settings for menus. |
|
142 | - $menu_args = apply_filters( |
|
143 | - 'FHEE__EE_Admin_Page_Menu_Map__construct__menu_args', |
|
144 | - $menu_args, |
|
145 | - $required, |
|
146 | - get_class($this) |
|
147 | - ); |
|
148 | - |
|
149 | - $this->verifyRequired($menu_args, $required); |
|
150 | - $this->setProperties($menu_args); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * This method should define how the menu page gets added for this particular item |
|
156 | - * and go ahead and define it. Note that child classes MUST also return the result of |
|
157 | - * the function used to register the WordPress admin page (the wp_page_slug string) |
|
158 | - * |
|
159 | - * @return string wp_page_slug. |
|
160 | - * @since 4.4.0 |
|
161 | - */ |
|
162 | - abstract protected function registerMenuItem(): string; |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Called by client code to use this menu map for registering a WordPress admin page |
|
167 | - * |
|
168 | - * @param boolean $network_admin whether this is being added to the network admin page or not |
|
169 | - * @since 4.4.0 |
|
170 | - */ |
|
171 | - public function registerAdminMenuItem(bool $network_admin = false): string |
|
172 | - { |
|
173 | - $this->registered = true; |
|
174 | - return $this->displayOnBlogAndNetworkAdmin() |
|
175 | - || $this->displayOnBlogAdmin($network_admin) |
|
176 | - || $this->displayOnNetworkAdmin($network_admin) |
|
177 | - ? $this->registerMenuItem() |
|
178 | - : ''; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param array $menu_args |
|
184 | - * @param array $required |
|
185 | - * @throws DomainException |
|
186 | - */ |
|
187 | - private function verifyRequired(array $menu_args, array $required) |
|
188 | - { |
|
189 | - // verify that required keys are present in the incoming array. |
|
190 | - $missing = array_diff($required, array_keys($menu_args)); |
|
191 | - |
|
192 | - if (! empty($missing)) { |
|
193 | - throw new DomainException( |
|
194 | - sprintf( |
|
195 | - esc_html__( |
|
196 | - '%1$s is missing some expected keys in the argument array. The following keys are missing: %2$s', |
|
197 | - 'event_espresso' |
|
198 | - ), |
|
199 | - get_class($this), |
|
200 | - implode(', ', $missing) |
|
201 | - ) |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - if ( |
|
206 | - in_array('admin_init_page', $required, true) |
|
207 | - && ! (isset($menu_args['admin_init_page']) && $menu_args['admin_init_page'] instanceof EE_Admin_Page_Init) |
|
208 | - ) { |
|
209 | - throw new InvalidArgumentException( |
|
210 | - sprintf( |
|
211 | - esc_html__( |
|
212 | - 'The value for the "admin_init_page" argument must be an instance of an EE_Admin_Page_Init object. Instead %s was given as the value.', |
|
213 | - 'event_espresso' |
|
214 | - ), |
|
215 | - print_r($menu_args['admin_init_page'] ?? null, true) |
|
216 | - ) |
|
217 | - ); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param array $menu_args |
|
224 | - * @throws InvalidArgumentException |
|
225 | - * @throws OutOfBoundsException |
|
226 | - */ |
|
227 | - private function setProperties(array $menu_args) |
|
228 | - { |
|
229 | - $menu_args += [ |
|
230 | - 'capability' => 'ee_read_ee', |
|
231 | - 'maintenance_mode_parent' => '', |
|
232 | - 'menu_callback' => null, |
|
233 | - 'menu_group' => '', |
|
234 | - 'menu_label' => '', |
|
235 | - 'menu_order' => 100, |
|
236 | - 'menu_slug' => '', |
|
237 | - 'parent_slug' => 'espresso_events', |
|
238 | - 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
239 | - 'title' => '', |
|
240 | - ]; |
|
241 | - |
|
242 | - $this->setMenuSlug($menu_args['menu_slug']); |
|
243 | - $this->setCapability($menu_args['capability']); |
|
244 | - $this->setMaintenanceModeParent($menu_args['maintenance_mode_parent']); |
|
245 | - $this->setMenuCallback($menu_args['menu_callback']); |
|
246 | - $this->setMenuGroup($menu_args['menu_group']); |
|
247 | - $this->setMenuLabel($menu_args['menu_label']); |
|
248 | - $this->setMenuOrder($menu_args['menu_order']); |
|
249 | - $this->setParentSlug($menu_args['parent_slug']); |
|
250 | - $this->setShowOnMenu($menu_args['show_on_menu']); |
|
251 | - $this->setTitle($menu_args['title']); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * The capability required for this menu to be displayed to the user. |
|
257 | - * |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public function capability(): string |
|
261 | - { |
|
262 | - return $this->capability; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * @param string $capability |
|
268 | - */ |
|
269 | - public function setCapability(string $capability): void |
|
270 | - { |
|
271 | - $this->capability = $capability; |
|
272 | - // filter capabilities (both static and dynamic) |
|
273 | - $this->capability = apply_filters('FHEE_management_capability', $this->capability, null); |
|
274 | - $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - public function currentUserHasAccess(): bool |
|
279 | - { |
|
280 | - return EE_Capabilities::instance()->current_user_can($this->capability(), $this->menuSlug()); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @param bool $network_admin |
|
286 | - * @return bool |
|
287 | - */ |
|
288 | - public function displayOnBlogAdmin(bool $network_admin): bool |
|
289 | - { |
|
290 | - return ! $network_admin && $this->show_on_menu === AdminMenuItem::DISPLAY_BLOG_ONLY; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @return bool |
|
296 | - */ |
|
297 | - public function displayOnBlogAndNetworkAdmin(): bool |
|
298 | - { |
|
299 | - return $this->show_on_menu === AdminMenuItem::DISPLAY_BLOG_AND_NETWORK; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @param bool $network_admin |
|
305 | - * @return bool |
|
306 | - */ |
|
307 | - public function displayOnNetworkAdmin(bool $network_admin): bool |
|
308 | - { |
|
309 | - return $network_admin && $this->show_on_menu === AdminMenuItem::DISPLAY_NETWORK_ONLY; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * parent slug to use when site is in full maintenance mode |
|
315 | - * |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - public function maintenanceModeParent(): string |
|
319 | - { |
|
320 | - return $this->maintenance_mode_parent; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @param string $maintenance_mode_parent |
|
326 | - */ |
|
327 | - public function setMaintenanceModeParent(string $maintenance_mode_parent): void |
|
328 | - { |
|
329 | - $this->maintenance_mode_parent = $maintenance_mode_parent; |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * Optional. The function to be called to output the content for this page. |
|
335 | - * |
|
336 | - * @return callable|null |
|
337 | - */ |
|
338 | - public function menuCallback(): ?callable |
|
339 | - { |
|
340 | - return $this->menu_callback; |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * @param callable|null $menu_callback |
|
346 | - */ |
|
347 | - public function setMenuCallback(?callable $menu_callback): void |
|
348 | - { |
|
349 | - $this->menu_callback = $menu_callback; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * Slug for menu group that this menu item will appear under |
|
355 | - * |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function menuGroup(): string |
|
359 | - { |
|
360 | - return $this->menu_group; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @param string $menu_group |
|
366 | - */ |
|
367 | - public function setMenuGroup(string $menu_group): void |
|
368 | - { |
|
369 | - $this->menu_group = $menu_group; |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * The text to be used for the menu. |
|
375 | - * |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public function menuLabel(): string |
|
379 | - { |
|
380 | - return $this->menu_label; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * @param string $menu_label |
|
386 | - */ |
|
387 | - public function setMenuLabel(string $menu_label): void |
|
388 | - { |
|
389 | - $this->menu_label = $menu_label; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * Optional. The position in the menu order this item should appear. |
|
395 | - * |
|
396 | - * @return int |
|
397 | - */ |
|
398 | - public function menuOrder(): int |
|
399 | - { |
|
400 | - return $this->menu_order; |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * @param int $menu_order |
|
406 | - */ |
|
407 | - public function setMenuOrder(int $menu_order): void |
|
408 | - { |
|
409 | - $this->menu_order = absint($menu_order); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * The slug name to refer to this menu by. Should be unique for this menu |
|
415 | - * |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function menuSlug(): string |
|
419 | - { |
|
420 | - return $this->menu_slug; |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * @param string $menu_slug |
|
426 | - */ |
|
427 | - public function setMenuSlug(string $menu_slug): void |
|
428 | - { |
|
429 | - $this->menu_slug = sanitize_key($menu_slug); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * The slug name for the parent menu (or the file name of a standard WordPress admin page). |
|
435 | - * |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - public function parentSlug(): string |
|
439 | - { |
|
440 | - return $this->parent_slug; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * if site is in full maintenance mode, |
|
446 | - * then parent slug will be swapped with the maintenance_mode_parent if that property has been set |
|
447 | - * |
|
448 | - * @param string $parent_slug |
|
449 | - */ |
|
450 | - public function setParentSlug(string $parent_slug): void |
|
451 | - { |
|
452 | - $this->parent_slug = $this->maintenance_mode && $this->maintenance_mode_parent |
|
453 | - ? $this->maintenance_mode_parent |
|
454 | - : $parent_slug; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * returns true if menu item has already been registered with WP core |
|
460 | - * |
|
461 | - * @return bool |
|
462 | - */ |
|
463 | - public function isRegistered(): bool |
|
464 | - { |
|
465 | - return $this->registered; |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * returns TRUE if: |
|
471 | - * - site is currently NOT in full site maintenance mode |
|
472 | - * - site IS in full site maintenance mode and menu item has a valid maintenance mode parent |
|
473 | - * |
|
474 | - * @return int |
|
475 | - */ |
|
476 | - public function showOnMaintenanceModeMenu(): int |
|
477 | - { |
|
478 | - return ! $this->maintenance_mode || $this->maintenanceModeParent() !== ''; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * @param int $show_on_menu |
|
484 | - * @throws DomainException |
|
485 | - */ |
|
486 | - public function setShowOnMenu(int $show_on_menu): void |
|
487 | - { |
|
488 | - $valid_menu_options = [ |
|
489 | - AdminMenuItem::DISPLAY_NONE, |
|
490 | - AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
491 | - AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
492 | - AdminMenuItem::DISPLAY_NETWORK_ONLY, |
|
493 | - ]; |
|
494 | - if (! in_array($show_on_menu, $valid_menu_options, true)) { |
|
495 | - throw new DomainException( |
|
496 | - sprintf( |
|
497 | - esc_html__( |
|
498 | - 'Invalid "ShowOnMenu" option of "%1$s" supplied. You must use one of the AdminMenuItem::DISPLAY_* constants.', |
|
499 | - 'event_espresso' |
|
500 | - ), |
|
501 | - $show_on_menu |
|
502 | - ) |
|
503 | - ); |
|
504 | - } |
|
505 | - $this->show_on_menu = $show_on_menu; |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * The text to be displayed in the title tags of the page when the menu is selected |
|
511 | - * |
|
512 | - * @return string |
|
513 | - */ |
|
514 | - public function title(): string |
|
515 | - { |
|
516 | - return $this->title; |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * @param string $title |
|
522 | - */ |
|
523 | - public function setTitle(string $title): void |
|
524 | - { |
|
525 | - $this->title = $title; |
|
526 | - } |
|
14 | + public const DISPLAY_NONE = 0; |
|
15 | + |
|
16 | + public const DISPLAY_BLOG_ONLY = 1; |
|
17 | + |
|
18 | + public const DISPLAY_BLOG_AND_NETWORK = 2; |
|
19 | + |
|
20 | + public const DISPLAY_NETWORK_ONLY = 3; |
|
21 | + |
|
22 | + public const TYPE_MENU_TOP = 'top'; |
|
23 | + |
|
24 | + public const TYPE_MENU_GROUP = 'group'; |
|
25 | + |
|
26 | + public const TYPE_MENU_SUB_ITEM = 'sub-item'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * What capability is required to access this page. |
|
31 | + * |
|
32 | + * @since 4.4.0 |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $capability = 'administrator'; |
|
36 | + |
|
37 | + /** |
|
38 | + * set to TRUE if site is currently in maintenance mode level 2 |
|
39 | + * |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | + protected bool $maintenance_mode = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * Menu maps can define a parent slug that gets used instead of the main parent slug for the menu when |
|
46 | + * EE_Maintenance_Mode::STATUS_FULL_SITE is active. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $maintenance_mode_parent = ''; |
|
51 | + |
|
52 | + /** |
|
53 | + * The callback for displaying the page that the menu references. |
|
54 | + * |
|
55 | + * @since 4.4.0 |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + protected $menu_callback; |
|
59 | + |
|
60 | + /** |
|
61 | + * The EE specific group this menu item belongs in (group slug). |
|
62 | + * |
|
63 | + * @since 4.4.0 |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + protected $menu_group; |
|
67 | + |
|
68 | + /** |
|
69 | + * The label for the menu item. (What shows up in the actual menu). |
|
70 | + * |
|
71 | + * @since 4.4.0 |
|
72 | + * @var string |
|
73 | + */ |
|
74 | + protected $menu_label; |
|
75 | + |
|
76 | + /** |
|
77 | + * What order this item should be in the menu. |
|
78 | + * |
|
79 | + * @since 4.4.0 |
|
80 | + * @var int |
|
81 | + */ |
|
82 | + protected $menu_order; |
|
83 | + |
|
84 | + /** |
|
85 | + * What slug should be used to reference this menu item. |
|
86 | + * |
|
87 | + * @since 4.4.0 |
|
88 | + * @var string |
|
89 | + */ |
|
90 | + protected $menu_slug; |
|
91 | + |
|
92 | + /** |
|
93 | + * What menu item is the parent of this menu item. |
|
94 | + * |
|
95 | + * @since 4.4.0 |
|
96 | + * @var string |
|
97 | + */ |
|
98 | + protected $parent_slug; |
|
99 | + |
|
100 | + /** |
|
101 | + * set to TRUE once menu item has been added to generated menu |
|
102 | + * |
|
103 | + * @var bool |
|
104 | + */ |
|
105 | + protected $registered = false; |
|
106 | + |
|
107 | + /** |
|
108 | + * Whether this item is displayed in the menu or not. |
|
109 | + * Sometimes an EE Admin Page needs to register itself but is not accessible via the WordPress |
|
110 | + * admin menu. |
|
111 | + * |
|
112 | + * @since 4.4.0 |
|
113 | + * @var int |
|
114 | + */ |
|
115 | + protected $show_on_menu = self::DISPLAY_BLOG_ONLY; |
|
116 | + |
|
117 | + /** |
|
118 | + * The title for the menu page. (the page the menu links to) |
|
119 | + * |
|
120 | + * @since 4.4.0 |
|
121 | + * @var string |
|
122 | + */ |
|
123 | + protected $title; |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param array $menu_args An array of arguments used to setup the menu properties on construct. |
|
128 | + * @param array $required An array of keys that should be in the $menu_args, |
|
129 | + * this is used to validate that the items that should be defined are present. |
|
130 | + * @return void |
|
131 | + * @throws DomainException |
|
132 | + * @throws InvalidArgumentException |
|
133 | + * @throws OutOfBoundsException |
|
134 | + */ |
|
135 | + public function __construct(array $menu_args, array $required) |
|
136 | + { |
|
137 | + // we don't want this coupling anymore >:( |
|
138 | + unset($menu_args['admin_init_page'], $required['admin_init_page']); |
|
139 | + $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
140 | + |
|
141 | + // filter all args before processing so plugins can manipulate various settings for menus. |
|
142 | + $menu_args = apply_filters( |
|
143 | + 'FHEE__EE_Admin_Page_Menu_Map__construct__menu_args', |
|
144 | + $menu_args, |
|
145 | + $required, |
|
146 | + get_class($this) |
|
147 | + ); |
|
148 | + |
|
149 | + $this->verifyRequired($menu_args, $required); |
|
150 | + $this->setProperties($menu_args); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * This method should define how the menu page gets added for this particular item |
|
156 | + * and go ahead and define it. Note that child classes MUST also return the result of |
|
157 | + * the function used to register the WordPress admin page (the wp_page_slug string) |
|
158 | + * |
|
159 | + * @return string wp_page_slug. |
|
160 | + * @since 4.4.0 |
|
161 | + */ |
|
162 | + abstract protected function registerMenuItem(): string; |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Called by client code to use this menu map for registering a WordPress admin page |
|
167 | + * |
|
168 | + * @param boolean $network_admin whether this is being added to the network admin page or not |
|
169 | + * @since 4.4.0 |
|
170 | + */ |
|
171 | + public function registerAdminMenuItem(bool $network_admin = false): string |
|
172 | + { |
|
173 | + $this->registered = true; |
|
174 | + return $this->displayOnBlogAndNetworkAdmin() |
|
175 | + || $this->displayOnBlogAdmin($network_admin) |
|
176 | + || $this->displayOnNetworkAdmin($network_admin) |
|
177 | + ? $this->registerMenuItem() |
|
178 | + : ''; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param array $menu_args |
|
184 | + * @param array $required |
|
185 | + * @throws DomainException |
|
186 | + */ |
|
187 | + private function verifyRequired(array $menu_args, array $required) |
|
188 | + { |
|
189 | + // verify that required keys are present in the incoming array. |
|
190 | + $missing = array_diff($required, array_keys($menu_args)); |
|
191 | + |
|
192 | + if (! empty($missing)) { |
|
193 | + throw new DomainException( |
|
194 | + sprintf( |
|
195 | + esc_html__( |
|
196 | + '%1$s is missing some expected keys in the argument array. The following keys are missing: %2$s', |
|
197 | + 'event_espresso' |
|
198 | + ), |
|
199 | + get_class($this), |
|
200 | + implode(', ', $missing) |
|
201 | + ) |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + if ( |
|
206 | + in_array('admin_init_page', $required, true) |
|
207 | + && ! (isset($menu_args['admin_init_page']) && $menu_args['admin_init_page'] instanceof EE_Admin_Page_Init) |
|
208 | + ) { |
|
209 | + throw new InvalidArgumentException( |
|
210 | + sprintf( |
|
211 | + esc_html__( |
|
212 | + 'The value for the "admin_init_page" argument must be an instance of an EE_Admin_Page_Init object. Instead %s was given as the value.', |
|
213 | + 'event_espresso' |
|
214 | + ), |
|
215 | + print_r($menu_args['admin_init_page'] ?? null, true) |
|
216 | + ) |
|
217 | + ); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param array $menu_args |
|
224 | + * @throws InvalidArgumentException |
|
225 | + * @throws OutOfBoundsException |
|
226 | + */ |
|
227 | + private function setProperties(array $menu_args) |
|
228 | + { |
|
229 | + $menu_args += [ |
|
230 | + 'capability' => 'ee_read_ee', |
|
231 | + 'maintenance_mode_parent' => '', |
|
232 | + 'menu_callback' => null, |
|
233 | + 'menu_group' => '', |
|
234 | + 'menu_label' => '', |
|
235 | + 'menu_order' => 100, |
|
236 | + 'menu_slug' => '', |
|
237 | + 'parent_slug' => 'espresso_events', |
|
238 | + 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
239 | + 'title' => '', |
|
240 | + ]; |
|
241 | + |
|
242 | + $this->setMenuSlug($menu_args['menu_slug']); |
|
243 | + $this->setCapability($menu_args['capability']); |
|
244 | + $this->setMaintenanceModeParent($menu_args['maintenance_mode_parent']); |
|
245 | + $this->setMenuCallback($menu_args['menu_callback']); |
|
246 | + $this->setMenuGroup($menu_args['menu_group']); |
|
247 | + $this->setMenuLabel($menu_args['menu_label']); |
|
248 | + $this->setMenuOrder($menu_args['menu_order']); |
|
249 | + $this->setParentSlug($menu_args['parent_slug']); |
|
250 | + $this->setShowOnMenu($menu_args['show_on_menu']); |
|
251 | + $this->setTitle($menu_args['title']); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * The capability required for this menu to be displayed to the user. |
|
257 | + * |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public function capability(): string |
|
261 | + { |
|
262 | + return $this->capability; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * @param string $capability |
|
268 | + */ |
|
269 | + public function setCapability(string $capability): void |
|
270 | + { |
|
271 | + $this->capability = $capability; |
|
272 | + // filter capabilities (both static and dynamic) |
|
273 | + $this->capability = apply_filters('FHEE_management_capability', $this->capability, null); |
|
274 | + $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + public function currentUserHasAccess(): bool |
|
279 | + { |
|
280 | + return EE_Capabilities::instance()->current_user_can($this->capability(), $this->menuSlug()); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @param bool $network_admin |
|
286 | + * @return bool |
|
287 | + */ |
|
288 | + public function displayOnBlogAdmin(bool $network_admin): bool |
|
289 | + { |
|
290 | + return ! $network_admin && $this->show_on_menu === AdminMenuItem::DISPLAY_BLOG_ONLY; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @return bool |
|
296 | + */ |
|
297 | + public function displayOnBlogAndNetworkAdmin(): bool |
|
298 | + { |
|
299 | + return $this->show_on_menu === AdminMenuItem::DISPLAY_BLOG_AND_NETWORK; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @param bool $network_admin |
|
305 | + * @return bool |
|
306 | + */ |
|
307 | + public function displayOnNetworkAdmin(bool $network_admin): bool |
|
308 | + { |
|
309 | + return $network_admin && $this->show_on_menu === AdminMenuItem::DISPLAY_NETWORK_ONLY; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * parent slug to use when site is in full maintenance mode |
|
315 | + * |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + public function maintenanceModeParent(): string |
|
319 | + { |
|
320 | + return $this->maintenance_mode_parent; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @param string $maintenance_mode_parent |
|
326 | + */ |
|
327 | + public function setMaintenanceModeParent(string $maintenance_mode_parent): void |
|
328 | + { |
|
329 | + $this->maintenance_mode_parent = $maintenance_mode_parent; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * Optional. The function to be called to output the content for this page. |
|
335 | + * |
|
336 | + * @return callable|null |
|
337 | + */ |
|
338 | + public function menuCallback(): ?callable |
|
339 | + { |
|
340 | + return $this->menu_callback; |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * @param callable|null $menu_callback |
|
346 | + */ |
|
347 | + public function setMenuCallback(?callable $menu_callback): void |
|
348 | + { |
|
349 | + $this->menu_callback = $menu_callback; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * Slug for menu group that this menu item will appear under |
|
355 | + * |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function menuGroup(): string |
|
359 | + { |
|
360 | + return $this->menu_group; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @param string $menu_group |
|
366 | + */ |
|
367 | + public function setMenuGroup(string $menu_group): void |
|
368 | + { |
|
369 | + $this->menu_group = $menu_group; |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * The text to be used for the menu. |
|
375 | + * |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public function menuLabel(): string |
|
379 | + { |
|
380 | + return $this->menu_label; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * @param string $menu_label |
|
386 | + */ |
|
387 | + public function setMenuLabel(string $menu_label): void |
|
388 | + { |
|
389 | + $this->menu_label = $menu_label; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * Optional. The position in the menu order this item should appear. |
|
395 | + * |
|
396 | + * @return int |
|
397 | + */ |
|
398 | + public function menuOrder(): int |
|
399 | + { |
|
400 | + return $this->menu_order; |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * @param int $menu_order |
|
406 | + */ |
|
407 | + public function setMenuOrder(int $menu_order): void |
|
408 | + { |
|
409 | + $this->menu_order = absint($menu_order); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * The slug name to refer to this menu by. Should be unique for this menu |
|
415 | + * |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function menuSlug(): string |
|
419 | + { |
|
420 | + return $this->menu_slug; |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * @param string $menu_slug |
|
426 | + */ |
|
427 | + public function setMenuSlug(string $menu_slug): void |
|
428 | + { |
|
429 | + $this->menu_slug = sanitize_key($menu_slug); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * The slug name for the parent menu (or the file name of a standard WordPress admin page). |
|
435 | + * |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public function parentSlug(): string |
|
439 | + { |
|
440 | + return $this->parent_slug; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * if site is in full maintenance mode, |
|
446 | + * then parent slug will be swapped with the maintenance_mode_parent if that property has been set |
|
447 | + * |
|
448 | + * @param string $parent_slug |
|
449 | + */ |
|
450 | + public function setParentSlug(string $parent_slug): void |
|
451 | + { |
|
452 | + $this->parent_slug = $this->maintenance_mode && $this->maintenance_mode_parent |
|
453 | + ? $this->maintenance_mode_parent |
|
454 | + : $parent_slug; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * returns true if menu item has already been registered with WP core |
|
460 | + * |
|
461 | + * @return bool |
|
462 | + */ |
|
463 | + public function isRegistered(): bool |
|
464 | + { |
|
465 | + return $this->registered; |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * returns TRUE if: |
|
471 | + * - site is currently NOT in full site maintenance mode |
|
472 | + * - site IS in full site maintenance mode and menu item has a valid maintenance mode parent |
|
473 | + * |
|
474 | + * @return int |
|
475 | + */ |
|
476 | + public function showOnMaintenanceModeMenu(): int |
|
477 | + { |
|
478 | + return ! $this->maintenance_mode || $this->maintenanceModeParent() !== ''; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * @param int $show_on_menu |
|
484 | + * @throws DomainException |
|
485 | + */ |
|
486 | + public function setShowOnMenu(int $show_on_menu): void |
|
487 | + { |
|
488 | + $valid_menu_options = [ |
|
489 | + AdminMenuItem::DISPLAY_NONE, |
|
490 | + AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
491 | + AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
492 | + AdminMenuItem::DISPLAY_NETWORK_ONLY, |
|
493 | + ]; |
|
494 | + if (! in_array($show_on_menu, $valid_menu_options, true)) { |
|
495 | + throw new DomainException( |
|
496 | + sprintf( |
|
497 | + esc_html__( |
|
498 | + 'Invalid "ShowOnMenu" option of "%1$s" supplied. You must use one of the AdminMenuItem::DISPLAY_* constants.', |
|
499 | + 'event_espresso' |
|
500 | + ), |
|
501 | + $show_on_menu |
|
502 | + ) |
|
503 | + ); |
|
504 | + } |
|
505 | + $this->show_on_menu = $show_on_menu; |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * The text to be displayed in the title tags of the page when the menu is selected |
|
511 | + * |
|
512 | + * @return string |
|
513 | + */ |
|
514 | + public function title(): string |
|
515 | + { |
|
516 | + return $this->title; |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * @param string $title |
|
522 | + */ |
|
523 | + public function setTitle(string $title): void |
|
524 | + { |
|
525 | + $this->title = $title; |
|
526 | + } |
|
527 | 527 | } |
@@ -4,123 +4,123 @@ |
||
4 | 4 | |
5 | 5 | class AdminMenuTopLevel extends AdminMenuItem |
6 | 6 | { |
7 | - /** |
|
8 | - * The page to a icon used for this menu. |
|
9 | - * |
|
10 | - * @since 4.4.0 |
|
11 | - * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
12 | - * for what can be set for this property. |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $icon_url = ''; |
|
16 | - |
|
17 | - /** |
|
18 | - * What position in the main menu order for the WP admin menu this menu item |
|
19 | - * should show. |
|
20 | - * |
|
21 | - * @since 4.4.0 |
|
22 | - * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
23 | - * for what can be set for this property. |
|
24 | - * @var integer |
|
25 | - */ |
|
26 | - protected $position = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * If included int incoming params, then this class will also register a Sub Menu Admin page with a different |
|
30 | - * subtitle than the main menu item. |
|
31 | - * |
|
32 | - * @since 4.4.0 |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $subtitle = ''; |
|
36 | - |
|
37 | - |
|
38 | - public function __construct(array $menu_args) |
|
39 | - { |
|
40 | - $this->setIconUrl($menu_args['icon_url'] ?? ''); |
|
41 | - $this->setPosition($menu_args['position'] ?? 0); |
|
42 | - $this->setSubtitle($menu_args['subtitle'] ?? ''); |
|
43 | - unset($menu_args['icon_url'], $menu_args['position'], $menu_args['subtitle']); |
|
44 | - parent::__construct( |
|
45 | - $menu_args, |
|
46 | - // required args |
|
47 | - [ |
|
48 | - 'menu_label', |
|
49 | - 'menu_slug', |
|
50 | - 'menu_group', |
|
51 | - 'menu_order', |
|
52 | - ] |
|
53 | - ); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Uses the proper WP utility for registering a menu page for the main WP pages. |
|
59 | - */ |
|
60 | - protected function registerMenuItem(): string |
|
61 | - { |
|
62 | - return add_menu_page( |
|
63 | - $this->title(), |
|
64 | - $this->menuLabel(), |
|
65 | - $this->capability(), |
|
66 | - $this->parentSlug(), |
|
67 | - $this->menuCallback(), |
|
68 | - $this->iconUrl(), |
|
69 | - $this->position() |
|
70 | - ); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function iconUrl(): string |
|
78 | - { |
|
79 | - return $this->icon_url; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @param string $icon_url |
|
85 | - */ |
|
86 | - public function setIconUrl(string $icon_url): void |
|
87 | - { |
|
88 | - $this->icon_url = $icon_url; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return int |
|
94 | - */ |
|
95 | - public function position(): int |
|
96 | - { |
|
97 | - return $this->position; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @param int $position |
|
103 | - */ |
|
104 | - public function setPosition(int $position): void |
|
105 | - { |
|
106 | - $this->position = absint($position); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function subtitle(): string |
|
114 | - { |
|
115 | - return $this->subtitle; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param string $subtitle |
|
121 | - */ |
|
122 | - public function setSubtitle(string $subtitle): void |
|
123 | - { |
|
124 | - $this->subtitle = $subtitle; |
|
125 | - } |
|
7 | + /** |
|
8 | + * The page to a icon used for this menu. |
|
9 | + * |
|
10 | + * @since 4.4.0 |
|
11 | + * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
12 | + * for what can be set for this property. |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $icon_url = ''; |
|
16 | + |
|
17 | + /** |
|
18 | + * What position in the main menu order for the WP admin menu this menu item |
|
19 | + * should show. |
|
20 | + * |
|
21 | + * @since 4.4.0 |
|
22 | + * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
23 | + * for what can be set for this property. |
|
24 | + * @var integer |
|
25 | + */ |
|
26 | + protected $position = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * If included int incoming params, then this class will also register a Sub Menu Admin page with a different |
|
30 | + * subtitle than the main menu item. |
|
31 | + * |
|
32 | + * @since 4.4.0 |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $subtitle = ''; |
|
36 | + |
|
37 | + |
|
38 | + public function __construct(array $menu_args) |
|
39 | + { |
|
40 | + $this->setIconUrl($menu_args['icon_url'] ?? ''); |
|
41 | + $this->setPosition($menu_args['position'] ?? 0); |
|
42 | + $this->setSubtitle($menu_args['subtitle'] ?? ''); |
|
43 | + unset($menu_args['icon_url'], $menu_args['position'], $menu_args['subtitle']); |
|
44 | + parent::__construct( |
|
45 | + $menu_args, |
|
46 | + // required args |
|
47 | + [ |
|
48 | + 'menu_label', |
|
49 | + 'menu_slug', |
|
50 | + 'menu_group', |
|
51 | + 'menu_order', |
|
52 | + ] |
|
53 | + ); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Uses the proper WP utility for registering a menu page for the main WP pages. |
|
59 | + */ |
|
60 | + protected function registerMenuItem(): string |
|
61 | + { |
|
62 | + return add_menu_page( |
|
63 | + $this->title(), |
|
64 | + $this->menuLabel(), |
|
65 | + $this->capability(), |
|
66 | + $this->parentSlug(), |
|
67 | + $this->menuCallback(), |
|
68 | + $this->iconUrl(), |
|
69 | + $this->position() |
|
70 | + ); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function iconUrl(): string |
|
78 | + { |
|
79 | + return $this->icon_url; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @param string $icon_url |
|
85 | + */ |
|
86 | + public function setIconUrl(string $icon_url): void |
|
87 | + { |
|
88 | + $this->icon_url = $icon_url; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return int |
|
94 | + */ |
|
95 | + public function position(): int |
|
96 | + { |
|
97 | + return $this->position; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @param int $position |
|
103 | + */ |
|
104 | + public function setPosition(int $position): void |
|
105 | + { |
|
106 | + $this->position = absint($position); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function subtitle(): string |
|
114 | + { |
|
115 | + return $this->subtitle; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param string $subtitle |
|
121 | + */ |
|
122 | + public function setSubtitle(string $subtitle): void |
|
123 | + { |
|
124 | + $this->subtitle = $subtitle; |
|
125 | + } |
|
126 | 126 | } |
@@ -16,64 +16,64 @@ |
||
16 | 16 | */ |
17 | 17 | class AdminMenuGroup extends AdminMenuItem |
18 | 18 | { |
19 | - /** |
|
20 | - * @var AdminMenuItem[] |
|
21 | - */ |
|
22 | - private $menu_items = []; |
|
19 | + /** |
|
20 | + * @var AdminMenuItem[] |
|
21 | + */ |
|
22 | + private $menu_items = []; |
|
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | - public function __construct(array $menu_args) |
|
27 | - { |
|
28 | - parent::__construct( |
|
29 | - $menu_args, |
|
30 | - // required args |
|
31 | - [ |
|
32 | - 'menu_label', |
|
33 | - 'menu_slug', |
|
34 | - 'menu_order', |
|
35 | - 'parent_slug' |
|
36 | - ] |
|
37 | - ); |
|
38 | - } |
|
26 | + public function __construct(array $menu_args) |
|
27 | + { |
|
28 | + parent::__construct( |
|
29 | + $menu_args, |
|
30 | + // required args |
|
31 | + [ |
|
32 | + 'menu_label', |
|
33 | + 'menu_slug', |
|
34 | + 'menu_order', |
|
35 | + 'parent_slug' |
|
36 | + ] |
|
37 | + ); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - public function addMenuItem(AdminMenuItem $menu_item): void |
|
42 | - { |
|
43 | - $this->menu_items[ $menu_item->menuSlug() ] = $menu_item; |
|
44 | - } |
|
41 | + public function addMenuItem(AdminMenuItem $menu_item): void |
|
42 | + { |
|
43 | + $this->menu_items[ $menu_item->menuSlug() ] = $menu_item; |
|
44 | + } |
|
45 | 45 | |
46 | - public function getMenuItems(): array |
|
47 | - { |
|
48 | - return $this->menu_items; |
|
49 | - } |
|
46 | + public function getMenuItems(): array |
|
47 | + { |
|
48 | + return $this->menu_items; |
|
49 | + } |
|
50 | 50 | |
51 | - public function hasNoMenuItems(): bool |
|
52 | - { |
|
53 | - return empty($this->menu_items); |
|
54 | - } |
|
51 | + public function hasNoMenuItems(): bool |
|
52 | + { |
|
53 | + return empty($this->menu_items); |
|
54 | + } |
|
55 | 55 | |
56 | - public function setMenuItems(array $menu_items): void |
|
57 | - { |
|
58 | - $this->menu_items = $menu_items; |
|
59 | - } |
|
56 | + public function setMenuItems(array $menu_items): void |
|
57 | + { |
|
58 | + $this->menu_items = $menu_items; |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - protected function registerMenuItem(): string |
|
63 | - { |
|
64 | - return add_submenu_page( |
|
65 | - $this->parentSlug(), |
|
66 | - $this->menuLabel(), |
|
67 | - $this->groupLink(), |
|
68 | - $this->capability(), |
|
69 | - $this->menuSlug(), |
|
70 | - '__return_false' |
|
71 | - ); |
|
72 | - } |
|
62 | + protected function registerMenuItem(): string |
|
63 | + { |
|
64 | + return add_submenu_page( |
|
65 | + $this->parentSlug(), |
|
66 | + $this->menuLabel(), |
|
67 | + $this->groupLink(), |
|
68 | + $this->capability(), |
|
69 | + $this->menuSlug(), |
|
70 | + '__return_false' |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - protected function groupLink(): string |
|
76 | - { |
|
77 | - return '<span class="ee_menu_group" onclick="return false;">' . $this->menuLabel() . '</span>'; |
|
78 | - } |
|
75 | + protected function groupLink(): string |
|
76 | + { |
|
77 | + return '<span class="ee_menu_group" onclick="return false;">' . $this->menuLabel() . '</span>'; |
|
78 | + } |
|
79 | 79 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public function addMenuItem(AdminMenuItem $menu_item): void |
42 | 42 | { |
43 | - $this->menu_items[ $menu_item->menuSlug() ] = $menu_item; |
|
43 | + $this->menu_items[$menu_item->menuSlug()] = $menu_item; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | public function getMenuItems(): array |
@@ -74,6 +74,6 @@ discard block |
||
74 | 74 | |
75 | 75 | protected function groupLink(): string |
76 | 76 | { |
77 | - return '<span class="ee_menu_group" onclick="return false;">' . $this->menuLabel() . '</span>'; |
|
77 | + return '<span class="ee_menu_group" onclick="return false;">'.$this->menuLabel().'</span>'; |
|
78 | 78 | } |
79 | 79 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | public function __set(string $property, $value) |
54 | 54 | { |
55 | 55 | // converts a property name like 'menu_slug' into 'setMenuSlug' |
56 | - $setter = 'set' . ucwords($property, '_'); |
|
56 | + $setter = 'set'.ucwords($property, '_'); |
|
57 | 57 | if (method_exists($this, $setter)) { |
58 | 58 | $this->{$setter}($value); |
59 | 59 | } |
@@ -12,49 +12,49 @@ |
||
12 | 12 | */ |
13 | 13 | abstract class EE_Admin_Page_Menu_Map extends AdminMenuItem |
14 | 14 | { |
15 | - const NONE = 0; |
|
16 | - |
|
17 | - const BLOG_ADMIN_ONLY = 1; |
|
18 | - |
|
19 | - const BLOG_AND_NETWORK_ADMIN = 2; |
|
20 | - |
|
21 | - const NETWORK_ADMIN_ONLY = 3; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @return string |
|
26 | - * @deprecated 5.0.0.p |
|
27 | - */ |
|
28 | - protected function _add_menu_page(): string |
|
29 | - { |
|
30 | - return $this->registerMenuItem(); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @param boolean $network_admin whether this is being added to the network admin page or not |
|
36 | - * @deprecated 5.0.0.p |
|
37 | - * @since 4.4.0 |
|
38 | - */ |
|
39 | - public function add_menu_page(bool $network_admin = false) |
|
40 | - { |
|
41 | - $this->registerAdminMenuItem($network_admin); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - public function __get(string $property) |
|
46 | - { |
|
47 | - // converts a property name like 'menu_slug' into 'menuSlug' |
|
48 | - $getter = lcfirst(ucwords($property, '_')); |
|
49 | - return method_exists($this, $getter) ? $this->{$getter}() : null; |
|
50 | - } |
|
51 | - |
|
52 | - public function __set(string $property, $value) |
|
53 | - { |
|
54 | - // converts a property name like 'menu_slug' into 'setMenuSlug' |
|
55 | - $setter = 'set' . ucwords($property, '_'); |
|
56 | - if (method_exists($this, $setter)) { |
|
57 | - $this->{$setter}($value); |
|
58 | - } |
|
59 | - } |
|
15 | + const NONE = 0; |
|
16 | + |
|
17 | + const BLOG_ADMIN_ONLY = 1; |
|
18 | + |
|
19 | + const BLOG_AND_NETWORK_ADMIN = 2; |
|
20 | + |
|
21 | + const NETWORK_ADMIN_ONLY = 3; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @return string |
|
26 | + * @deprecated 5.0.0.p |
|
27 | + */ |
|
28 | + protected function _add_menu_page(): string |
|
29 | + { |
|
30 | + return $this->registerMenuItem(); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @param boolean $network_admin whether this is being added to the network admin page or not |
|
36 | + * @deprecated 5.0.0.p |
|
37 | + * @since 4.4.0 |
|
38 | + */ |
|
39 | + public function add_menu_page(bool $network_admin = false) |
|
40 | + { |
|
41 | + $this->registerAdminMenuItem($network_admin); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + public function __get(string $property) |
|
46 | + { |
|
47 | + // converts a property name like 'menu_slug' into 'menuSlug' |
|
48 | + $getter = lcfirst(ucwords($property, '_')); |
|
49 | + return method_exists($this, $getter) ? $this->{$getter}() : null; |
|
50 | + } |
|
51 | + |
|
52 | + public function __set(string $property, $value) |
|
53 | + { |
|
54 | + // converts a property name like 'menu_slug' into 'setMenuSlug' |
|
55 | + $setter = 'set' . ucwords($property, '_'); |
|
56 | + if (method_exists($this, $setter)) { |
|
57 | + $this->{$setter}($value); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | } |
@@ -14,49 +14,49 @@ |
||
14 | 14 | */ |
15 | 15 | class Tickets_Admin_Page_Init extends EE_Admin_Page_Init |
16 | 16 | { |
17 | - /** |
|
18 | - * constructor |
|
19 | - * |
|
20 | - * @Constructor |
|
21 | - * @access public |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function __construct() |
|
25 | - { |
|
26 | - if (! defined('TICKETS_PG_SLUG')) { |
|
27 | - define('TICKETS_PG_SLUG', 'tickets'); |
|
28 | - define('TICKETS_LABEL', esc_html__('Default Tickets', 'event_espresso')); |
|
29 | - define('TICKETS_ADMIN', EE_CORE_CAF_ADMIN . 'new/' . TICKETS_PG_SLUG . '/'); |
|
30 | - define('TICKETS_ADMIN_URL', admin_url('admin.php?page=' . TICKETS_PG_SLUG)); |
|
31 | - define('TICKETS_ASSETS_PATH', TICKETS_ADMIN . 'assets/'); |
|
32 | - define('TICKETS_ASSETS_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . TICKETS_PG_SLUG . '/assets/'); |
|
33 | - define('TICKETS_TEMPLATE_PATH', TICKETS_ADMIN . 'templates/'); |
|
34 | - define('TICKETS_TEMPLATE_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . TICKETS_PG_SLUG . '/templates/'); |
|
35 | - } |
|
36 | - parent::__construct(); |
|
37 | - $this->_folder_path = EE_CORE_CAF_ADMIN . 'new/' . $this->_folder_name . DS; |
|
38 | - } |
|
17 | + /** |
|
18 | + * constructor |
|
19 | + * |
|
20 | + * @Constructor |
|
21 | + * @access public |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + if (! defined('TICKETS_PG_SLUG')) { |
|
27 | + define('TICKETS_PG_SLUG', 'tickets'); |
|
28 | + define('TICKETS_LABEL', esc_html__('Default Tickets', 'event_espresso')); |
|
29 | + define('TICKETS_ADMIN', EE_CORE_CAF_ADMIN . 'new/' . TICKETS_PG_SLUG . '/'); |
|
30 | + define('TICKETS_ADMIN_URL', admin_url('admin.php?page=' . TICKETS_PG_SLUG)); |
|
31 | + define('TICKETS_ASSETS_PATH', TICKETS_ADMIN . 'assets/'); |
|
32 | + define('TICKETS_ASSETS_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . TICKETS_PG_SLUG . '/assets/'); |
|
33 | + define('TICKETS_TEMPLATE_PATH', TICKETS_ADMIN . 'templates/'); |
|
34 | + define('TICKETS_TEMPLATE_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . TICKETS_PG_SLUG . '/templates/'); |
|
35 | + } |
|
36 | + parent::__construct(); |
|
37 | + $this->_folder_path = EE_CORE_CAF_ADMIN . 'new/' . $this->_folder_name . DS; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - protected function _set_init_properties() |
|
42 | - { |
|
43 | - $this->label = TICKETS_LABEL; |
|
44 | - } |
|
41 | + protected function _set_init_properties() |
|
42 | + { |
|
43 | + $this->label = TICKETS_LABEL; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - protected function _set_menu_map() |
|
48 | - { |
|
49 | - $this->_menu_map = new AdminMenuSubItem( |
|
50 | - array( |
|
51 | - 'menu_group' => 'management', |
|
52 | - 'menu_order' => 15, |
|
53 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
54 | - 'parent_slug' => 'espresso_events', |
|
55 | - 'menu_slug' => TICKETS_PG_SLUG, |
|
56 | - 'menu_label' => TICKETS_LABEL, |
|
57 | - 'capability' => 'ee_read_default_tickets', |
|
58 | - 'admin_init_page' => $this, |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
47 | + protected function _set_menu_map() |
|
48 | + { |
|
49 | + $this->_menu_map = new AdminMenuSubItem( |
|
50 | + array( |
|
51 | + 'menu_group' => 'management', |
|
52 | + 'menu_order' => 15, |
|
53 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
54 | + 'parent_slug' => 'espresso_events', |
|
55 | + 'menu_slug' => TICKETS_PG_SLUG, |
|
56 | + 'menu_label' => TICKETS_LABEL, |
|
57 | + 'capability' => 'ee_read_default_tickets', |
|
58 | + 'admin_init_page' => $this, |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | } |
@@ -23,18 +23,18 @@ |
||
23 | 23 | */ |
24 | 24 | public function __construct() |
25 | 25 | { |
26 | - if (! defined('TICKETS_PG_SLUG')) { |
|
26 | + if ( ! defined('TICKETS_PG_SLUG')) { |
|
27 | 27 | define('TICKETS_PG_SLUG', 'tickets'); |
28 | 28 | define('TICKETS_LABEL', esc_html__('Default Tickets', 'event_espresso')); |
29 | - define('TICKETS_ADMIN', EE_CORE_CAF_ADMIN . 'new/' . TICKETS_PG_SLUG . '/'); |
|
30 | - define('TICKETS_ADMIN_URL', admin_url('admin.php?page=' . TICKETS_PG_SLUG)); |
|
31 | - define('TICKETS_ASSETS_PATH', TICKETS_ADMIN . 'assets/'); |
|
32 | - define('TICKETS_ASSETS_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . TICKETS_PG_SLUG . '/assets/'); |
|
33 | - define('TICKETS_TEMPLATE_PATH', TICKETS_ADMIN . 'templates/'); |
|
34 | - define('TICKETS_TEMPLATE_URL', EE_CORE_CAF_ADMIN_URL . 'new/' . TICKETS_PG_SLUG . '/templates/'); |
|
29 | + define('TICKETS_ADMIN', EE_CORE_CAF_ADMIN.'new/'.TICKETS_PG_SLUG.'/'); |
|
30 | + define('TICKETS_ADMIN_URL', admin_url('admin.php?page='.TICKETS_PG_SLUG)); |
|
31 | + define('TICKETS_ASSETS_PATH', TICKETS_ADMIN.'assets/'); |
|
32 | + define('TICKETS_ASSETS_URL', EE_CORE_CAF_ADMIN_URL.'new/'.TICKETS_PG_SLUG.'/assets/'); |
|
33 | + define('TICKETS_TEMPLATE_PATH', TICKETS_ADMIN.'templates/'); |
|
34 | + define('TICKETS_TEMPLATE_URL', EE_CORE_CAF_ADMIN_URL.'new/'.TICKETS_PG_SLUG.'/templates/'); |
|
35 | 35 | } |
36 | 36 | parent::__construct(); |
37 | - $this->_folder_path = EE_CORE_CAF_ADMIN . 'new/' . $this->_folder_name . DS; |
|
37 | + $this->_folder_path = EE_CORE_CAF_ADMIN.'new/'.$this->_folder_name.DS; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 |