@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | public function previous(); |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns the index of a given object, or false if not found |
|
117 | - * |
|
118 | - * @see http://stackoverflow.com/a/8736013 |
|
119 | - * @param $object |
|
120 | - * @return boolean|int|string |
|
121 | - */ |
|
116 | + * Returns the index of a given object, or false if not found |
|
117 | + * |
|
118 | + * @see http://stackoverflow.com/a/8736013 |
|
119 | + * @param $object |
|
120 | + * @return boolean|int|string |
|
121 | + */ |
|
122 | 122 | public function indexOf( $object ); |
123 | 123 | |
124 | 124 | |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | |
161 | 161 | |
162 | 162 | |
163 | - /** |
|
164 | - * detaches ALL objects from the Collection |
|
165 | - */ |
|
166 | - public function detachAll(); |
|
163 | + /** |
|
164 | + * detaches ALL objects from the Collection |
|
165 | + */ |
|
166 | + public function detachAll(); |
|
167 | 167 | |
168 | 168 | |
169 | 169 | |
170 | - /** |
|
171 | - * unsets and detaches ALL objects from the Collection |
|
172 | - */ |
|
173 | - public function trashAndDetachAll(); |
|
170 | + /** |
|
171 | + * unsets and detaches ALL objects from the Collection |
|
172 | + */ |
|
173 | + public function trashAndDetachAll(); |
|
174 | 174 | |
175 | 175 | } |
176 | 176 | // End of file CollectionInterface.php |
@@ -83,7 +83,6 @@ discard block |
||
83 | 83 | |
84 | 84 | /** |
85 | 85 | * setIdentifier |
86 | - |
|
87 | 86 | * Sets the data associated with an object in the Collection |
88 | 87 | * if no $identifier is supplied, then the spl_object_hash() is used |
89 | 88 | * |
@@ -352,34 +351,34 @@ discard block |
||
352 | 351 | |
353 | 352 | |
354 | 353 | |
355 | - /** |
|
356 | - * detaches ALL objects from the Collection |
|
357 | - */ |
|
358 | - public function detachAll() |
|
359 | - { |
|
360 | - $this->rewind(); |
|
361 | - while ($this->valid()) { |
|
362 | - $object = $this->current(); |
|
363 | - $this->next(); |
|
364 | - $this->detach($object); |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * unsets and detaches ALL objects from the Collection |
|
372 | - */ |
|
373 | - public function trashAndDetachAll() |
|
374 | - { |
|
375 | - $this->rewind(); |
|
376 | - while ($this->valid()) { |
|
377 | - $object = $this->current(); |
|
378 | - $this->next(); |
|
379 | - $this->detach($object); |
|
380 | - unset($object); |
|
381 | - } |
|
382 | - } |
|
354 | + /** |
|
355 | + * detaches ALL objects from the Collection |
|
356 | + */ |
|
357 | + public function detachAll() |
|
358 | + { |
|
359 | + $this->rewind(); |
|
360 | + while ($this->valid()) { |
|
361 | + $object = $this->current(); |
|
362 | + $this->next(); |
|
363 | + $this->detach($object); |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * unsets and detaches ALL objects from the Collection |
|
371 | + */ |
|
372 | + public function trashAndDetachAll() |
|
373 | + { |
|
374 | + $this->rewind(); |
|
375 | + while ($this->valid()) { |
|
376 | + $object = $this->current(); |
|
377 | + $this->next(); |
|
378 | + $this->detach($object); |
|
379 | + unset($object); |
|
380 | + } |
|
381 | + } |
|
383 | 382 | |
384 | 383 | |
385 | 384 |
@@ -79,37 +79,37 @@ |
||
79 | 79 | class LoaderFactory |
80 | 80 | { |
81 | 81 | |
82 | - /** |
|
83 | - * @var LoaderInterface $loader ; |
|
84 | - */ |
|
85 | - private static $loader; |
|
82 | + /** |
|
83 | + * @var LoaderInterface $loader ; |
|
84 | + */ |
|
85 | + private static $loader; |
|
86 | 86 | |
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @param mixed $generator provided during very first instantiation in |
|
91 | - * EE_Load_Espresso_Core::handle_request() |
|
92 | - * otherwise can be left null |
|
93 | - * @return LoaderInterface |
|
94 | - * @throws InvalidArgumentException |
|
95 | - * @throws InvalidInterfaceException |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - */ |
|
98 | - public static function getLoader($generator = null) |
|
99 | - { |
|
100 | - if (! LoaderFactory::$loader instanceof LoaderInterface) { |
|
101 | - $generator = $generator !== null ? $generator : EE_Registry::instance(); |
|
102 | - $core_loader = new CoreLoader($generator); |
|
103 | - LoaderFactory::$loader = new Loader( |
|
104 | - $core_loader, |
|
105 | - new CachingLoader( |
|
106 | - $core_loader, |
|
107 | - new LooseCollection('') |
|
108 | - ) |
|
109 | - ); |
|
110 | - } |
|
111 | - return LoaderFactory::$loader; |
|
112 | - } |
|
89 | + /** |
|
90 | + * @param mixed $generator provided during very first instantiation in |
|
91 | + * EE_Load_Espresso_Core::handle_request() |
|
92 | + * otherwise can be left null |
|
93 | + * @return LoaderInterface |
|
94 | + * @throws InvalidArgumentException |
|
95 | + * @throws InvalidInterfaceException |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + */ |
|
98 | + public static function getLoader($generator = null) |
|
99 | + { |
|
100 | + if (! LoaderFactory::$loader instanceof LoaderInterface) { |
|
101 | + $generator = $generator !== null ? $generator : EE_Registry::instance(); |
|
102 | + $core_loader = new CoreLoader($generator); |
|
103 | + LoaderFactory::$loader = new Loader( |
|
104 | + $core_loader, |
|
105 | + new CachingLoader( |
|
106 | + $core_loader, |
|
107 | + new LooseCollection('') |
|
108 | + ) |
|
109 | + ); |
|
110 | + } |
|
111 | + return LoaderFactory::$loader; |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | 115 | } |
@@ -97,7 +97,7 @@ |
||
97 | 97 | */ |
98 | 98 | public static function getLoader($generator = null) |
99 | 99 | { |
100 | - if (! LoaderFactory::$loader instanceof LoaderInterface) { |
|
100 | + if ( ! LoaderFactory::$loader instanceof LoaderInterface) { |
|
101 | 101 | $generator = $generator !== null ? $generator : EE_Registry::instance(); |
102 | 102 | $core_loader = new CoreLoader($generator); |
103 | 103 | LoaderFactory::$loader = new Loader( |
@@ -32,51 +32,51 @@ discard block |
||
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * get_event |
|
37 | - * attempts to retrieve an EE_Event object any way it can |
|
38 | - * |
|
39 | - * @param int|WP_Post $EVT_ID |
|
40 | - * @return EE_Event|null |
|
41 | - * @throws \EE_Error |
|
42 | - */ |
|
43 | - public static function get_event($EVT_ID = 0) |
|
44 | - { |
|
45 | - // international newspaper? |
|
46 | - global $post; |
|
47 | - $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events' |
|
48 | - ? $EVT_ID->ID |
|
49 | - : absint($EVT_ID); |
|
50 | - // do we already have the Event you are looking for? |
|
51 | - if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
52 | - return EEH_Event_View::$_event; |
|
53 | - } |
|
54 | - //reset property so that the new event is cached. |
|
55 | - EEH_Event_View::$_event = null; |
|
56 | - if (! $EVT_ID && $post instanceof EE_Event) { |
|
57 | - EEH_Event_View::$_event = $post; |
|
58 | - return EEH_Event_View::$_event; |
|
59 | - } |
|
60 | - //if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID |
|
61 | - //then let's just use that cached event on the $post object. |
|
62 | - if ( |
|
63 | - $post instanceof WP_Post |
|
64 | - && $post->post_type === 'espresso_events' |
|
65 | - && isset($post->EE_Event) |
|
66 | - && ( |
|
67 | - $EVT_ID === 0 |
|
68 | - || $EVT_ID === $post->ID |
|
69 | - ) |
|
70 | - ) { |
|
71 | - EEH_Event_View::$_event = $post->EE_Event; |
|
72 | - return EEH_Event_View::$_event; |
|
73 | - } |
|
74 | - //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
|
75 | - if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
76 | - EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
77 | - } |
|
78 | - return EEH_Event_View::$_event; |
|
79 | - } |
|
35 | + /** |
|
36 | + * get_event |
|
37 | + * attempts to retrieve an EE_Event object any way it can |
|
38 | + * |
|
39 | + * @param int|WP_Post $EVT_ID |
|
40 | + * @return EE_Event|null |
|
41 | + * @throws \EE_Error |
|
42 | + */ |
|
43 | + public static function get_event($EVT_ID = 0) |
|
44 | + { |
|
45 | + // international newspaper? |
|
46 | + global $post; |
|
47 | + $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events' |
|
48 | + ? $EVT_ID->ID |
|
49 | + : absint($EVT_ID); |
|
50 | + // do we already have the Event you are looking for? |
|
51 | + if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
52 | + return EEH_Event_View::$_event; |
|
53 | + } |
|
54 | + //reset property so that the new event is cached. |
|
55 | + EEH_Event_View::$_event = null; |
|
56 | + if (! $EVT_ID && $post instanceof EE_Event) { |
|
57 | + EEH_Event_View::$_event = $post; |
|
58 | + return EEH_Event_View::$_event; |
|
59 | + } |
|
60 | + //if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID |
|
61 | + //then let's just use that cached event on the $post object. |
|
62 | + if ( |
|
63 | + $post instanceof WP_Post |
|
64 | + && $post->post_type === 'espresso_events' |
|
65 | + && isset($post->EE_Event) |
|
66 | + && ( |
|
67 | + $EVT_ID === 0 |
|
68 | + || $EVT_ID === $post->ID |
|
69 | + ) |
|
70 | + ) { |
|
71 | + EEH_Event_View::$_event = $post->EE_Event; |
|
72 | + return EEH_Event_View::$_event; |
|
73 | + } |
|
74 | + //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
|
75 | + if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
76 | + EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
77 | + } |
|
78 | + return EEH_Event_View::$_event; |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | 82 | |
@@ -152,58 +152,58 @@ discard block |
||
152 | 152 | * @return string |
153 | 153 | */ |
154 | 154 | public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) { |
155 | - global $post; |
|
155 | + global $post; |
|
156 | 156 | ob_start(); |
157 | 157 | if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) { |
158 | 158 | // admin has chosen "full description" |
159 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
159 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
160 | 160 | the_content(); |
161 | 161 | } else if (( is_archive() && espresso_display_excerpt_in_event_list() ) ) { |
162 | - if ( has_excerpt( $post->ID )) { |
|
163 | - // admin has chosen "excerpt (short desc)" |
|
164 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
165 | - // AND an excerpt actually exists |
|
166 | - the_excerpt(); |
|
167 | - } else { |
|
168 | - // admin has chosen "excerpt (short desc)" |
|
169 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
170 | - // but NO excerpt actually exists, so we need to create one |
|
171 | - if ( ! empty( $num_words )) { |
|
172 | - if ( empty( $more )) { |
|
173 | - $more_link_text = __( '(more…)' ); |
|
174 | - $more = ' <a href="' . get_permalink() . '"'; |
|
175 | - $more .= ' class="more-link"'; |
|
176 | - $more .= \EED_Events_Archive::link_target(); |
|
177 | - $more .= '>' . $more_link_text . '</a>'; |
|
178 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
179 | - } |
|
180 | - $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
|
181 | - |
|
182 | - $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
|
183 | - } else { |
|
184 | - $content = get_the_content(); |
|
185 | - } |
|
186 | - global $allowedtags; |
|
187 | - // make sure links are allowed |
|
188 | - $allowedtags['a'] = isset($allowedtags['a']) |
|
189 | - ? $allowedtags['a'] |
|
190 | - : array(); |
|
191 | - // as well as target attribute |
|
192 | - $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
193 | - ? $allowedtags['a']['target'] |
|
194 | - : false; |
|
195 | - // but get previous value so we can reset it |
|
196 | - $prev_value = $allowedtags['a']['target']; |
|
197 | - $allowedtags['a']['target'] = true; |
|
198 | - $content = wp_kses( $content, $allowedtags ); |
|
199 | - $content = strip_shortcodes( $content ); |
|
200 | - echo apply_filters( 'the_content', $content ); |
|
201 | - $allowedtags['a']['target'] = $prev_value; |
|
202 | - } |
|
203 | - } else { |
|
204 | - // admin has chosen "none" |
|
205 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
206 | - echo apply_filters( 'the_content', '' ); |
|
162 | + if ( has_excerpt( $post->ID )) { |
|
163 | + // admin has chosen "excerpt (short desc)" |
|
164 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
165 | + // AND an excerpt actually exists |
|
166 | + the_excerpt(); |
|
167 | + } else { |
|
168 | + // admin has chosen "excerpt (short desc)" |
|
169 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
170 | + // but NO excerpt actually exists, so we need to create one |
|
171 | + if ( ! empty( $num_words )) { |
|
172 | + if ( empty( $more )) { |
|
173 | + $more_link_text = __( '(more…)' ); |
|
174 | + $more = ' <a href="' . get_permalink() . '"'; |
|
175 | + $more .= ' class="more-link"'; |
|
176 | + $more .= \EED_Events_Archive::link_target(); |
|
177 | + $more .= '>' . $more_link_text . '</a>'; |
|
178 | + $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
179 | + } |
|
180 | + $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
|
181 | + |
|
182 | + $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
|
183 | + } else { |
|
184 | + $content = get_the_content(); |
|
185 | + } |
|
186 | + global $allowedtags; |
|
187 | + // make sure links are allowed |
|
188 | + $allowedtags['a'] = isset($allowedtags['a']) |
|
189 | + ? $allowedtags['a'] |
|
190 | + : array(); |
|
191 | + // as well as target attribute |
|
192 | + $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
193 | + ? $allowedtags['a']['target'] |
|
194 | + : false; |
|
195 | + // but get previous value so we can reset it |
|
196 | + $prev_value = $allowedtags['a']['target']; |
|
197 | + $allowedtags['a']['target'] = true; |
|
198 | + $content = wp_kses( $content, $allowedtags ); |
|
199 | + $content = strip_shortcodes( $content ); |
|
200 | + echo apply_filters( 'the_content', $content ); |
|
201 | + $allowedtags['a']['target'] = $prev_value; |
|
202 | + } |
|
203 | + } else { |
|
204 | + // admin has chosen "none" |
|
205 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
206 | + echo apply_filters( 'the_content', '' ); |
|
207 | 207 | } |
208 | 208 | return ob_get_clean(); |
209 | 209 | } |
@@ -250,11 +250,11 @@ discard block |
||
250 | 250 | $url = get_term_link( $term, 'espresso_venue_categories' ); |
251 | 251 | if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
252 | 252 | $category_links[] = '<a href="' . esc_url( $url ) |
253 | - . '" rel="tag"' |
|
254 | - . \EED_Events_Archive::link_target() |
|
255 | - .'>' |
|
256 | - . $term->name |
|
257 | - . '</a>'; |
|
253 | + . '" rel="tag"' |
|
254 | + . \EED_Events_Archive::link_target() |
|
255 | + .'>' |
|
256 | + . $term->name |
|
257 | + . '</a>'; |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | } |
54 | 54 | //reset property so that the new event is cached. |
55 | 55 | EEH_Event_View::$_event = null; |
56 | - if (! $EVT_ID && $post instanceof EE_Event) { |
|
56 | + if ( ! $EVT_ID && $post instanceof EE_Event) { |
|
57 | 57 | EEH_Event_View::$_event = $post; |
58 | 58 | return EEH_Event_View::$_event; |
59 | 59 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | return EEH_Event_View::$_event; |
73 | 73 | } |
74 | 74 | //If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
75 | - if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
75 | + if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
76 | 76 | EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
77 | 77 | } |
78 | 78 | return EEH_Event_View::$_event; |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @param int $EVT_ID |
88 | 88 | * @return boolean |
89 | 89 | */ |
90 | - public static function display_ticket_selector( $EVT_ID = 0 ) { |
|
91 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
90 | + public static function display_ticket_selector($EVT_ID = 0) { |
|
91 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
92 | 92 | return $event instanceof EE_Event ? $event->display_ticket_selector() : FALSE; |
93 | 93 | } |
94 | 94 | |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param int $EVT_ID |
102 | 102 | * @return string |
103 | 103 | */ |
104 | - public static function event_status( $EVT_ID = 0 ) { |
|
105 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
106 | - return $event instanceof EE_Event ? $event->pretty_active_status( FALSE ) : ''; |
|
104 | + public static function event_status($EVT_ID = 0) { |
|
105 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
106 | + return $event instanceof EE_Event ? $event->pretty_active_status(FALSE) : ''; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * @param int $EVT_ID |
116 | 116 | * @return string |
117 | 117 | */ |
118 | - public static function event_active_status( $EVT_ID = 0 ) { |
|
119 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
118 | + public static function event_active_status($EVT_ID = 0) { |
|
119 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
120 | 120 | return $event instanceof EE_Event ? $event->pretty_active_status() : 'inactive'; |
121 | 121 | } |
122 | 122 | |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | * @param int $EVT_ID |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public static function event_has_content_or_excerpt( $EVT_ID = 0 ) { |
|
133 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
132 | + public static function event_has_content_or_excerpt($EVT_ID = 0) { |
|
133 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
134 | 134 | $has_content_or_excerpt = FALSE; |
135 | - if ( $event instanceof EE_Event ) { |
|
136 | - $has_content_or_excerpt = $event->description() != '' || $event->short_description( NULL, NULL, TRUE ) != '' ? TRUE : FALSE; |
|
135 | + if ($event instanceof EE_Event) { |
|
136 | + $has_content_or_excerpt = $event->description() != '' || $event->short_description(NULL, NULL, TRUE) != '' ? TRUE : FALSE; |
|
137 | 137 | } |
138 | - if ( is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) { |
|
138 | + if (is_archive() && ! (espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list())) { |
|
139 | 139 | $has_content_or_excerpt = FALSE; |
140 | 140 | } |
141 | 141 | return $has_content_or_excerpt; |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | * @param null $more |
152 | 152 | * @return string |
153 | 153 | */ |
154 | - public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) { |
|
154 | + public static function event_content_or_excerpt($num_words = NULL, $more = NULL) { |
|
155 | 155 | global $post; |
156 | 156 | ob_start(); |
157 | - if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) { |
|
157 | + if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) { |
|
158 | 158 | // admin has chosen "full description" |
159 | 159 | // for the "Event Espresso - Events > Templates > Display Description" option |
160 | 160 | the_content(); |
161 | - } else if (( is_archive() && espresso_display_excerpt_in_event_list() ) ) { |
|
162 | - if ( has_excerpt( $post->ID )) { |
|
161 | + } else if ((is_archive() && espresso_display_excerpt_in_event_list())) { |
|
162 | + if (has_excerpt($post->ID)) { |
|
163 | 163 | // admin has chosen "excerpt (short desc)" |
164 | 164 | // for the "Event Espresso - Events > Templates > Display Description" option |
165 | 165 | // AND an excerpt actually exists |
@@ -168,20 +168,20 @@ discard block |
||
168 | 168 | // admin has chosen "excerpt (short desc)" |
169 | 169 | // for the "Event Espresso - Events > Templates > Display Description" option |
170 | 170 | // but NO excerpt actually exists, so we need to create one |
171 | - if ( ! empty( $num_words )) { |
|
172 | - if ( empty( $more )) { |
|
173 | - $more_link_text = __( '(more…)' ); |
|
174 | - $more = ' <a href="' . get_permalink() . '"'; |
|
171 | + if ( ! empty($num_words)) { |
|
172 | + if (empty($more)) { |
|
173 | + $more_link_text = __('(more…)'); |
|
174 | + $more = ' <a href="'.get_permalink().'"'; |
|
175 | 175 | $more .= ' class="more-link"'; |
176 | 176 | $more .= \EED_Events_Archive::link_target(); |
177 | - $more .= '>' . $more_link_text . '</a>'; |
|
178 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
177 | + $more .= '>'.$more_link_text.'</a>'; |
|
178 | + $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
179 | 179 | } |
180 | - $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
|
180 | + $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
|
181 | 181 | |
182 | - $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
|
182 | + $content = wp_trim_words($content, $num_words, ' ').$more; |
|
183 | 183 | } else { |
184 | - $content = get_the_content(); |
|
184 | + $content = get_the_content(); |
|
185 | 185 | } |
186 | 186 | global $allowedtags; |
187 | 187 | // make sure links are allowed |
@@ -195,15 +195,15 @@ discard block |
||
195 | 195 | // but get previous value so we can reset it |
196 | 196 | $prev_value = $allowedtags['a']['target']; |
197 | 197 | $allowedtags['a']['target'] = true; |
198 | - $content = wp_kses( $content, $allowedtags ); |
|
199 | - $content = strip_shortcodes( $content ); |
|
200 | - echo apply_filters( 'the_content', $content ); |
|
198 | + $content = wp_kses($content, $allowedtags); |
|
199 | + $content = strip_shortcodes($content); |
|
200 | + echo apply_filters('the_content', $content); |
|
201 | 201 | $allowedtags['a']['target'] = $prev_value; |
202 | 202 | } |
203 | 203 | } else { |
204 | 204 | // admin has chosen "none" |
205 | 205 | // for the "Event Espresso - Events > Templates > Display Description" option |
206 | - echo apply_filters( 'the_content', '' ); |
|
206 | + echo apply_filters('the_content', ''); |
|
207 | 207 | } |
208 | 208 | return ob_get_clean(); |
209 | 209 | } |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | * @param int $EVT_ID |
218 | 218 | * @return EE_Ticket[] |
219 | 219 | */ |
220 | - public static function event_tickets_available( $EVT_ID = 0 ) { |
|
221 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
220 | + public static function event_tickets_available($EVT_ID = 0) { |
|
221 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
222 | 222 | $tickets_available_for_purchase = array(); |
223 | - if( $event instanceof EE_Event ) { |
|
224 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, FALSE ); |
|
225 | - foreach( $datetimes as $datetime ) { |
|
226 | - $tickets_available_for_purchase = array_merge( $tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase() ); |
|
223 | + if ($event instanceof EE_Event) { |
|
224 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, FALSE); |
|
225 | + foreach ($datetimes as $datetime) { |
|
226 | + $tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase()); |
|
227 | 227 | } |
228 | 228 | } |
229 | 229 | return $tickets_available_for_purchase; |
@@ -239,17 +239,17 @@ discard block |
||
239 | 239 | * @param bool $hide_uncategorized |
240 | 240 | * @return string |
241 | 241 | */ |
242 | - public static function event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE ) { |
|
242 | + public static function event_categories($EVT_ID = 0, $hide_uncategorized = TRUE) { |
|
243 | 243 | $category_links = array(); |
244 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
245 | - if ( $event instanceof EE_Event ) { |
|
246 | - $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' ); |
|
247 | - if ( $event_categories ) { |
|
244 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
245 | + if ($event instanceof EE_Event) { |
|
246 | + $event_categories = get_the_terms($event->ID(), 'espresso_event_categories'); |
|
247 | + if ($event_categories) { |
|
248 | 248 | // loop thru terms and create links |
249 | - foreach ( $event_categories as $term ) { |
|
250 | - $url = get_term_link( $term, 'espresso_venue_categories' ); |
|
251 | - if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
|
252 | - $category_links[] = '<a href="' . esc_url( $url ) |
|
249 | + foreach ($event_categories as $term) { |
|
250 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
251 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
252 | + $category_links[] = '<a href="'.esc_url($url) |
|
253 | 253 | . '" rel="tag"' |
254 | 254 | . \EED_Events_Archive::link_target() |
255 | 255 | .'>' |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
262 | - return implode( ', ', $category_links ); |
|
262 | + return implode(', ', $category_links); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | |
@@ -273,10 +273,10 @@ discard block |
||
273 | 273 | * @param int $EVT_ID |
274 | 274 | * @return string |
275 | 275 | */ |
276 | - public static function the_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
277 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
278 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
279 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
276 | + public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
277 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
278 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
279 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -290,10 +290,10 @@ discard block |
||
290 | 290 | * @param int $EVT_ID |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - public static function the_event_end_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
294 | - $datetime = EEH_Event_View::get_last_date_obj( $EVT_ID ); |
|
295 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
296 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
293 | + public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
294 | + $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
295 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
296 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | |
@@ -307,10 +307,10 @@ discard block |
||
307 | 307 | * @param int $EVT_ID |
308 | 308 | * @return string |
309 | 309 | */ |
310 | - public static function the_earliest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
311 | - $datetime = EEH_Event_View::get_earliest_date_obj( $EVT_ID ); |
|
312 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
313 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
310 | + public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
311 | + $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
|
312 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
313 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param int $EVT_ID |
325 | 325 | * @return string |
326 | 326 | */ |
327 | - public static function the_latest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
328 | - $datetime = EEH_Event_View::get_latest_date_obj( $EVT_ID ); |
|
329 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
330 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
327 | + public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
328 | + $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID); |
|
329 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
330 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
@@ -339,13 +339,13 @@ discard block |
||
339 | 339 | * @param int $EVT_ID |
340 | 340 | * @return string |
341 | 341 | */ |
342 | - public static function event_date_as_calendar_page( $EVT_ID = 0 ) { |
|
343 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
344 | - if ( $datetime instanceof EE_Datetime ) { |
|
342 | + public static function event_date_as_calendar_page($EVT_ID = 0) { |
|
343 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
344 | + if ($datetime instanceof EE_Datetime) { |
|
345 | 345 | ?> |
346 | 346 | <div class="event-date-calendar-page-dv"> |
347 | - <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime( 'DTT_EVT_start', 'M' );?></div> |
|
348 | - <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date( 'd' );?></div> |
|
347 | + <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M'); ?></div> |
|
348 | + <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d'); ?></div> |
|
349 | 349 | </div> |
350 | 350 | <?php |
351 | 351 | } |
@@ -360,17 +360,17 @@ discard block |
||
360 | 360 | * @param int $EVT_ID |
361 | 361 | * @return string |
362 | 362 | */ |
363 | - public static function get_primary_date_obj( $EVT_ID = 0 ) { |
|
364 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
365 | - if ( $event instanceof EE_Event ) { |
|
363 | + public static function get_primary_date_obj($EVT_ID = 0) { |
|
364 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
365 | + if ($event instanceof EE_Event) { |
|
366 | 366 | $datetimes = $event->get_many_related( |
367 | 367 | 'Datetime', |
368 | 368 | array( |
369 | 369 | 'limit' => 1, |
370 | - 'order_by' => array( 'DTT_order' => 'ASC' ) |
|
370 | + 'order_by' => array('DTT_order' => 'ASC') |
|
371 | 371 | ) |
372 | 372 | ); |
373 | - return reset( $datetimes ); |
|
373 | + return reset($datetimes); |
|
374 | 374 | } else { |
375 | 375 | return FALSE; |
376 | 376 | } |
@@ -385,17 +385,17 @@ discard block |
||
385 | 385 | * @param int $EVT_ID |
386 | 386 | * @return string |
387 | 387 | */ |
388 | - public static function get_last_date_obj( $EVT_ID = 0 ) { |
|
389 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
390 | - if ( $event instanceof EE_Event ) { |
|
388 | + public static function get_last_date_obj($EVT_ID = 0) { |
|
389 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
390 | + if ($event instanceof EE_Event) { |
|
391 | 391 | $datetimes = $event->get_many_related( |
392 | 392 | 'Datetime', |
393 | 393 | array( |
394 | 394 | 'limit' => 1, |
395 | - 'order_by' => array( 'DTT_order' => 'DESC' ) |
|
395 | + 'order_by' => array('DTT_order' => 'DESC') |
|
396 | 396 | ) |
397 | 397 | ); |
398 | - return end( $datetimes ); |
|
398 | + return end($datetimes); |
|
399 | 399 | } else { |
400 | 400 | return FALSE; |
401 | 401 | } |
@@ -410,17 +410,17 @@ discard block |
||
410 | 410 | * @param int $EVT_ID |
411 | 411 | * @return string |
412 | 412 | */ |
413 | - public static function get_earliest_date_obj( $EVT_ID = 0 ) { |
|
414 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
415 | - if ( $event instanceof EE_Event ) { |
|
413 | + public static function get_earliest_date_obj($EVT_ID = 0) { |
|
414 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
415 | + if ($event instanceof EE_Event) { |
|
416 | 416 | $datetimes = $event->get_many_related( |
417 | 417 | 'Datetime', |
418 | 418 | array( |
419 | 419 | 'limit' => 1, |
420 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
420 | + 'order_by' => array('DTT_EVT_start' => 'ASC') |
|
421 | 421 | ) |
422 | 422 | ); |
423 | - return reset( $datetimes ); |
|
423 | + return reset($datetimes); |
|
424 | 424 | } else { |
425 | 425 | return FALSE; |
426 | 426 | } |
@@ -435,17 +435,17 @@ discard block |
||
435 | 435 | * @param int $EVT_ID |
436 | 436 | * @return string |
437 | 437 | */ |
438 | - public static function get_latest_date_obj( $EVT_ID = 0 ) { |
|
439 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
440 | - if ( $event instanceof EE_Event ) { |
|
438 | + public static function get_latest_date_obj($EVT_ID = 0) { |
|
439 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
440 | + if ($event instanceof EE_Event) { |
|
441 | 441 | $datetimes = $event->get_many_related( |
442 | 442 | 'Datetime', |
443 | 443 | array( |
444 | 444 | 'limit' => 1, |
445 | - 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
445 | + 'order_by' => array('DTT_EVT_start' => 'DESC') |
|
446 | 446 | ) |
447 | 447 | ); |
448 | - return end( $datetimes ); |
|
448 | + return end($datetimes); |
|
449 | 449 | } else { |
450 | 450 | return FALSE; |
451 | 451 | } |
@@ -463,17 +463,17 @@ discard block |
||
463 | 463 | * @param null $limit |
464 | 464 | * @return EE_Datetime[] |
465 | 465 | */ |
466 | - public static function get_all_date_obj( $EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL ) { |
|
467 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
468 | - if($include_expired === null){ |
|
469 | - if($event instanceof EE_Event && $event->is_expired()){ |
|
466 | + public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL) { |
|
467 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
468 | + if ($include_expired === null) { |
|
469 | + if ($event instanceof EE_Event && $event->is_expired()) { |
|
470 | 470 | $include_expired = true; |
471 | - }else{ |
|
471 | + } else { |
|
472 | 472 | $include_expired = false; |
473 | 473 | } |
474 | 474 | } |
475 | 475 | |
476 | - if ( $event instanceof EE_Event ) { |
|
476 | + if ($event instanceof EE_Event) { |
|
477 | 477 | return $event->datetimes_ordered($include_expired, $include_deleted, $limit); |
478 | 478 | } else { |
479 | 479 | return array(); |
@@ -489,11 +489,11 @@ discard block |
||
489 | 489 | * @param int $EVT_ID |
490 | 490 | * @return string |
491 | 491 | */ |
492 | - public static function event_link_url( $EVT_ID = 0 ) { |
|
493 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
494 | - if ( $event instanceof EE_Event ) { |
|
495 | - $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink( $event->ID() ); |
|
496 | - return preg_match( "~^(?:f|ht)tps?://~i", $url ) ? $url : 'http://' . $url; |
|
492 | + public static function event_link_url($EVT_ID = 0) { |
|
493 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
494 | + if ($event instanceof EE_Event) { |
|
495 | + $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID()); |
|
496 | + return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://'.$url; |
|
497 | 497 | } |
498 | 498 | return NULL; |
499 | 499 | } |
@@ -507,10 +507,10 @@ discard block |
||
507 | 507 | * @param int $EVT_ID |
508 | 508 | * @return string |
509 | 509 | */ |
510 | - public static function event_phone( $EVT_ID = 0 ) { |
|
511 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
512 | - if ( $event instanceof EE_Event ) { |
|
513 | - return EEH_Schema::telephone( $event->phone() ); |
|
510 | + public static function event_phone($EVT_ID = 0) { |
|
511 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
512 | + if ($event instanceof EE_Event) { |
|
513 | + return EEH_Schema::telephone($event->phone()); |
|
514 | 514 | } |
515 | 515 | return NULL; |
516 | 516 | } |
@@ -527,26 +527,26 @@ discard block |
||
527 | 527 | * @param string $after |
528 | 528 | * @return string |
529 | 529 | */ |
530 | - public static function edit_event_link( $EVT_ID = 0, $link = '', $before = '', $after = '' ) { |
|
531 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
532 | - if ( $event instanceof EE_Event ) { |
|
530 | + public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') { |
|
531 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
532 | + if ($event instanceof EE_Event) { |
|
533 | 533 | // can the user edit this post ? |
534 | - if ( current_user_can( 'edit_post', $event->ID() )) { |
|
534 | + if (current_user_can('edit_post', $event->ID())) { |
|
535 | 535 | // set link text |
536 | - $link_text = ! empty( $link ) ? $link : __('edit this event'); |
|
536 | + $link_text = ! empty($link) ? $link : __('edit this event'); |
|
537 | 537 | // generate nonce |
538 | - $nonce = wp_create_nonce( 'edit_nonce' ); |
|
538 | + $nonce = wp_create_nonce('edit_nonce'); |
|
539 | 539 | // generate url to event editor for this event |
540 | - $url = add_query_arg( array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url() ); |
|
540 | + $url = add_query_arg(array('page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce), admin_url()); |
|
541 | 541 | // get edit CPT text |
542 | - $post_type_obj = get_post_type_object( 'espresso_events' ); |
|
542 | + $post_type_obj = get_post_type_object('espresso_events'); |
|
543 | 543 | // build final link html |
544 | - $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
545 | - $link .= ' title="' . esc_attr( $post_type_obj->labels->edit_item ) . '"'; |
|
544 | + $link = '<a class="post-edit-link" href="'.$url.'" '; |
|
545 | + $link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"'; |
|
546 | 546 | $link .= \EED_Events_Archive::link_target(); |
547 | - $link .='>' . $link_text . '</a>'; |
|
547 | + $link .= '>'.$link_text.'</a>'; |
|
548 | 548 | // put it all together |
549 | - return $before . apply_filters( 'edit_post_link', $link, $event->ID() ) . $after; |
|
549 | + return $before.apply_filters('edit_post_link', $link, $event->ID()).$after; |
|
550 | 550 | } |
551 | 551 | } |
552 | 552 | return ''; |
@@ -206,7 +206,7 @@ |
||
206 | 206 | function espresso_ticket_selector( $event = NULL ) { |
207 | 207 | if ( ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) { |
208 | 208 | espresso_load_ticket_selector(); |
209 | - \EED_Ticket_Selector::set_definitions(); |
|
209 | + \EED_Ticket_Selector::set_definitions(); |
|
210 | 210 | echo EED_Ticket_Selector::display_ticket_selector( $event ); |
211 | 211 | } |
212 | 212 | } |
@@ -14,12 +14,12 @@ discard block |
||
14 | 14 | * @param int | \EE_Event $event |
15 | 15 | * @return bool |
16 | 16 | */ |
17 | -function is_espresso_event( $event = NULL ) { |
|
18 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
17 | +function is_espresso_event($event = NULL) { |
|
18 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
19 | 19 | // extract EE_Event object from passed param regardless of what it is (within reason of course) |
20 | - $event = EEH_Event_View::get_event( $event ); |
|
20 | + $event = EEH_Event_View::get_event($event); |
|
21 | 21 | // do we have a valid event ? |
22 | - return $event instanceof EE_Event ? TRUE : FALSE; |
|
22 | + return $event instanceof EE_Event ? TRUE : FALSE; |
|
23 | 23 | } |
24 | 24 | return FALSE; |
25 | 25 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @return bool |
32 | 32 | */ |
33 | 33 | function is_espresso_event_single() { |
34 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
34 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
35 | 35 | global $wp_query; |
36 | 36 | // return conditionals set by CPTs |
37 | 37 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : FALSE; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return bool |
47 | 47 | */ |
48 | 48 | function is_espresso_event_archive() { |
49 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
49 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
50 | 50 | global $wp_query; |
51 | 51 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : FALSE; |
52 | 52 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return bool |
61 | 61 | */ |
62 | 62 | function is_espresso_event_taxonomy() { |
63 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
63 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
64 | 64 | global $wp_query; |
65 | 65 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : FALSE; |
66 | 66 | } |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | * @param int | \EE_Venue $venue |
75 | 75 | * @return bool |
76 | 76 | */ |
77 | -function is_espresso_venue( $venue = NULL ) { |
|
78 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
77 | +function is_espresso_venue($venue = NULL) { |
|
78 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
79 | 79 | // extract EE_Venue object from passed param regardless of what it is (within reason of course) |
80 | - $venue = EEH_Venue_View::get_venue( $venue, FALSE ); |
|
80 | + $venue = EEH_Venue_View::get_venue($venue, FALSE); |
|
81 | 81 | // do we have a valid event ? |
82 | 82 | return $venue instanceof EE_Venue ? TRUE : FALSE; |
83 | 83 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return bool |
92 | 92 | */ |
93 | 93 | function is_espresso_venue_single() { |
94 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
94 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
95 | 95 | global $wp_query; |
96 | 96 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : FALSE; |
97 | 97 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @return bool |
106 | 106 | */ |
107 | 107 | function is_espresso_venue_archive() { |
108 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
108 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
109 | 109 | global $wp_query; |
110 | 110 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : FALSE; |
111 | 111 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return bool |
120 | 120 | */ |
121 | 121 | function is_espresso_venue_taxonomy() { |
122 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
122 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
123 | 123 | global $wp_query; |
124 | 124 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : FALSE; |
125 | 125 | } |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | * @param $conditional_tag |
134 | 134 | * @return bool |
135 | 135 | */ |
136 | -function can_use_espresso_conditionals( $conditional_tag ) { |
|
137 | - if ( ! did_action( 'AHEE__EE_System__initialize' )) { |
|
136 | +function can_use_espresso_conditionals($conditional_tag) { |
|
137 | + if ( ! did_action('AHEE__EE_System__initialize')) { |
|
138 | 138 | EE_Error::doing_it_wrong( |
139 | 139 | __FUNCTION__, |
140 | 140 | sprintf( |
141 | - __( 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.','event_espresso'), |
|
141 | + __('The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', 'event_espresso'), |
|
142 | 142 | $conditional_tag |
143 | 143 | ), |
144 | 144 | '4.4.0' |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | |
154 | 154 | /*************************** Event Queries ***************************/ |
155 | 155 | |
156 | -if ( ! function_exists( 'espresso_get_events' )) { |
|
156 | +if ( ! function_exists('espresso_get_events')) { |
|
157 | 157 | /** |
158 | 158 | * espresso_get_events |
159 | 159 | * @param array $params |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - function espresso_get_events( $params = array() ) { |
|
162 | + function espresso_get_events($params = array()) { |
|
163 | 163 | //set default params |
164 | 164 | $default_espresso_events_params = array( |
165 | 165 | 'limit' => 10, |
@@ -170,18 +170,18 @@ discard block |
||
170 | 170 | 'sort' => 'ASC' |
171 | 171 | ); |
172 | 172 | // allow the defaults to be filtered |
173 | - $default_espresso_events_params = apply_filters( 'espresso_get_events__default_espresso_events_params', $default_espresso_events_params ); |
|
173 | + $default_espresso_events_params = apply_filters('espresso_get_events__default_espresso_events_params', $default_espresso_events_params); |
|
174 | 174 | // grab params and merge with defaults, then extract |
175 | - $params = array_merge( $default_espresso_events_params, $params ); |
|
175 | + $params = array_merge($default_espresso_events_params, $params); |
|
176 | 176 | // run the query |
177 | - $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $params ); |
|
177 | + $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params); |
|
178 | 178 | // assign results to a variable so we can return it |
179 | 179 | $events = $events_query->have_posts() ? $events_query->posts : array(); |
180 | 180 | // but first reset the query and postdata |
181 | 181 | wp_reset_query(); |
182 | 182 | wp_reset_postdata(); |
183 | 183 | EED_Events_Archive::remove_all_events_archive_filters(); |
184 | - unset( $events_query ); |
|
184 | + unset($events_query); |
|
185 | 185 | return $events; |
186 | 186 | } |
187 | 187 | } |
@@ -195,33 +195,33 @@ discard block |
||
195 | 195 | * espresso_load_ticket_selector |
196 | 196 | */ |
197 | 197 | function espresso_load_ticket_selector() { |
198 | - EE_Registry::instance()->load_file( EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module' ); |
|
198 | + EE_Registry::instance()->load_file(EE_MODULES.'ticket_selector', 'EED_Ticket_Selector', 'module'); |
|
199 | 199 | } |
200 | 200 | |
201 | -if ( ! function_exists( 'espresso_ticket_selector' )) { |
|
201 | +if ( ! function_exists('espresso_ticket_selector')) { |
|
202 | 202 | /** |
203 | 203 | * espresso_ticket_selector |
204 | 204 | * @param null $event |
205 | 205 | */ |
206 | - function espresso_ticket_selector( $event = NULL ) { |
|
207 | - if ( ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) { |
|
206 | + function espresso_ticket_selector($event = NULL) { |
|
207 | + if ( ! apply_filters('FHEE_disable_espresso_ticket_selector', FALSE)) { |
|
208 | 208 | espresso_load_ticket_selector(); |
209 | 209 | \EED_Ticket_Selector::set_definitions(); |
210 | - echo EED_Ticket_Selector::display_ticket_selector( $event ); |
|
210 | + echo EED_Ticket_Selector::display_ticket_selector($event); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | 215 | |
216 | - if ( ! function_exists( 'espresso_view_details_btn' )) { |
|
216 | + if ( ! function_exists('espresso_view_details_btn')) { |
|
217 | 217 | /** |
218 | 218 | * espresso_view_details_btn |
219 | 219 | * @param null $event |
220 | 220 | */ |
221 | - function espresso_view_details_btn( $event = NULL ) { |
|
222 | - if ( ! apply_filters( 'FHEE_disable_espresso_view_details_btn', FALSE ) ) { |
|
221 | + function espresso_view_details_btn($event = NULL) { |
|
222 | + if ( ! apply_filters('FHEE_disable_espresso_view_details_btn', FALSE)) { |
|
223 | 223 | espresso_load_ticket_selector(); |
224 | - echo EED_Ticket_Selector::display_ticket_selector( $event, TRUE ); |
|
224 | + echo EED_Ticket_Selector::display_ticket_selector($event, TRUE); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | |
232 | 232 | /*************************** EEH_Event_View ***************************/ |
233 | 233 | |
234 | -if ( ! function_exists( 'espresso_load_event_list_assets' )) { |
|
234 | +if ( ! function_exists('espresso_load_event_list_assets')) { |
|
235 | 235 | /** |
236 | 236 | * espresso_load_event_list_assets |
237 | 237 | * ensures that event list styles and scripts are loaded |
@@ -240,13 +240,13 @@ discard block |
||
240 | 240 | */ |
241 | 241 | function espresso_load_event_list_assets() { |
242 | 242 | $event_list = EED_Events_Archive::instance(); |
243 | - add_action( 'AHEE__EE_System__initialize_last', array( $event_list, 'load_event_list_assets' ), 10 ); |
|
244 | - add_filter( 'FHEE_enable_default_espresso_css', '__return_true' ); |
|
243 | + add_action('AHEE__EE_System__initialize_last', array($event_list, 'load_event_list_assets'), 10); |
|
244 | + add_filter('FHEE_enable_default_espresso_css', '__return_true'); |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | 248 | |
249 | -if ( ! function_exists( 'espresso_event_reg_button' )) { |
|
249 | +if ( ! function_exists('espresso_event_reg_button')) { |
|
250 | 250 | /** |
251 | 251 | * espresso_event_reg_button |
252 | 252 | * returns the "Register Now" button if event is active, |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | * @param bool $EVT_ID |
259 | 259 | * @return string |
260 | 260 | */ |
261 | - function espresso_event_reg_button( $btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE ) { |
|
262 | - $event_status = EEH_Event_View::event_active_status( $EVT_ID ); |
|
263 | - switch ( $event_status ) { |
|
261 | + function espresso_event_reg_button($btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE) { |
|
262 | + $event_status = EEH_Event_View::event_active_status($EVT_ID); |
|
263 | + switch ($event_status) { |
|
264 | 264 | case EE_Datetime::sold_out : |
265 | 265 | $btn_text = __('Sold Out', 'event_espresso'); |
266 | 266 | $class = 'ee-pink'; |
@@ -276,10 +276,10 @@ discard block |
||
276 | 276 | case EE_Datetime::upcoming : |
277 | 277 | case EE_Datetime::active : |
278 | 278 | default : |
279 | - $btn_text =! empty( $btn_text_if_active ) ? $btn_text_if_active : __( 'Register Now', 'event_espresso' ); |
|
279 | + $btn_text = ! empty($btn_text_if_active) ? $btn_text_if_active : __('Register Now', 'event_espresso'); |
|
280 | 280 | $class = 'ee-green'; |
281 | 281 | } |
282 | - if ( $event_status < 1 && ! empty( $btn_text_if_inactive )) { |
|
282 | + if ($event_status < 1 && ! empty($btn_text_if_inactive)) { |
|
283 | 283 | $btn_text = $btn_text_if_inactive; |
284 | 284 | $class = 'ee-grey'; |
285 | 285 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | |
294 | 294 | |
295 | 295 | |
296 | -if ( ! function_exists( 'espresso_display_ticket_selector' )) { |
|
296 | +if ( ! function_exists('espresso_display_ticket_selector')) { |
|
297 | 297 | /** |
298 | 298 | * espresso_display_ticket_selector |
299 | 299 | * whether or not to display the Ticket Selector for an event |
@@ -301,14 +301,14 @@ discard block |
||
301 | 301 | * @param bool $EVT_ID |
302 | 302 | * @return boolean |
303 | 303 | */ |
304 | - function espresso_display_ticket_selector( $EVT_ID = FALSE ) { |
|
305 | - return EEH_Event_View::display_ticket_selector( $EVT_ID ); |
|
304 | + function espresso_display_ticket_selector($EVT_ID = FALSE) { |
|
305 | + return EEH_Event_View::display_ticket_selector($EVT_ID); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | 309 | |
310 | 310 | |
311 | -if ( ! function_exists( 'espresso_event_status_banner' )) { |
|
311 | +if ( ! function_exists('espresso_event_status_banner')) { |
|
312 | 312 | /** |
313 | 313 | * espresso_event_status |
314 | 314 | * returns a banner showing the event status if it is sold out, expired, or inactive |
@@ -316,13 +316,13 @@ discard block |
||
316 | 316 | * @param bool $EVT_ID |
317 | 317 | * @return string |
318 | 318 | */ |
319 | - function espresso_event_status_banner( $EVT_ID = FALSE ) { |
|
320 | - return EEH_Event_View::event_status( $EVT_ID ); |
|
319 | + function espresso_event_status_banner($EVT_ID = FALSE) { |
|
320 | + return EEH_Event_View::event_status($EVT_ID); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
324 | 324 | |
325 | -if ( ! function_exists( 'espresso_event_status' )) { |
|
325 | +if ( ! function_exists('espresso_event_status')) { |
|
326 | 326 | /** |
327 | 327 | * espresso_event_status |
328 | 328 | * returns the event status if it is sold out, expired, or inactive |
@@ -331,17 +331,17 @@ discard block |
||
331 | 331 | * @param bool $echo |
332 | 332 | * @return string |
333 | 333 | */ |
334 | - function espresso_event_status( $EVT_ID = 0, $echo = TRUE ) { |
|
335 | - if ( $echo ) { |
|
336 | - echo EEH_Event_View::event_active_status( $EVT_ID ); |
|
334 | + function espresso_event_status($EVT_ID = 0, $echo = TRUE) { |
|
335 | + if ($echo) { |
|
336 | + echo EEH_Event_View::event_active_status($EVT_ID); |
|
337 | 337 | return ''; |
338 | 338 | } |
339 | - return EEH_Event_View::event_active_status( $EVT_ID ); |
|
339 | + return EEH_Event_View::event_active_status($EVT_ID); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
343 | 343 | |
344 | -if ( ! function_exists( 'espresso_event_categories' )) { |
|
344 | +if ( ! function_exists('espresso_event_categories')) { |
|
345 | 345 | /** |
346 | 346 | * espresso_event_categories |
347 | 347 | * returns the terms associated with an event |
@@ -351,17 +351,17 @@ discard block |
||
351 | 351 | * @param bool $echo |
352 | 352 | * @return string |
353 | 353 | */ |
354 | - function espresso_event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
355 | - if ( $echo ) { |
|
356 | - echo EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
354 | + function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
355 | + if ($echo) { |
|
356 | + echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
357 | 357 | return ''; |
358 | 358 | } |
359 | - return EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
359 | + return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
360 | 360 | } |
361 | 361 | } |
362 | 362 | |
363 | 363 | |
364 | -if ( ! function_exists( 'espresso_event_tickets_available' )) { |
|
364 | +if ( ! function_exists('espresso_event_tickets_available')) { |
|
365 | 365 | /** |
366 | 366 | * espresso_event_tickets_available |
367 | 367 | * returns the ticket types available for purchase for an event |
@@ -371,26 +371,26 @@ discard block |
||
371 | 371 | * @param bool $format |
372 | 372 | * @return string |
373 | 373 | */ |
374 | - function espresso_event_tickets_available( $EVT_ID = 0, $echo = TRUE, $format = TRUE ) { |
|
375 | - $tickets = EEH_Event_View::event_tickets_available( $EVT_ID ); |
|
376 | - if ( is_array( $tickets ) && ! empty( $tickets )) { |
|
374 | + function espresso_event_tickets_available($EVT_ID = 0, $echo = TRUE, $format = TRUE) { |
|
375 | + $tickets = EEH_Event_View::event_tickets_available($EVT_ID); |
|
376 | + if (is_array($tickets) && ! empty($tickets)) { |
|
377 | 377 | // if formatting then $html will be a string, else it will be an array of ticket objects |
378 | - $html = $format ? '<ul id="ee-event-tickets-ul-' . $EVT_ID . '" class="ee-event-tickets-ul">' : array(); |
|
379 | - foreach ( $tickets as $ticket ) { |
|
380 | - if ( $ticket instanceof EE_Ticket ) { |
|
381 | - if ( $format ) { |
|
382 | - $html .= '<li id="ee-event-tickets-li-' . $ticket->ID() . '" class="ee-event-tickets-li">'; |
|
383 | - $html .= $ticket->name() . ' ' . EEH_Template::format_currency( $ticket->get_ticket_total_with_taxes() ); |
|
378 | + $html = $format ? '<ul id="ee-event-tickets-ul-'.$EVT_ID.'" class="ee-event-tickets-ul">' : array(); |
|
379 | + foreach ($tickets as $ticket) { |
|
380 | + if ($ticket instanceof EE_Ticket) { |
|
381 | + if ($format) { |
|
382 | + $html .= '<li id="ee-event-tickets-li-'.$ticket->ID().'" class="ee-event-tickets-li">'; |
|
383 | + $html .= $ticket->name().' '.EEH_Template::format_currency($ticket->get_ticket_total_with_taxes()); |
|
384 | 384 | $html .= '</li>'; |
385 | 385 | } else { |
386 | 386 | $html[] = $ticket; |
387 | 387 | } |
388 | 388 | } |
389 | 389 | } |
390 | - if ( $format ) { |
|
390 | + if ($format) { |
|
391 | 391 | $html .= '</ul>'; |
392 | 392 | } |
393 | - if ( $echo && ! $format ) { |
|
393 | + if ($echo && ! $format) { |
|
394 | 394 | echo $html; |
395 | 395 | return ''; |
396 | 396 | } |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | -if ( ! function_exists( 'espresso_event_date_obj' )) { |
|
403 | +if ( ! function_exists('espresso_event_date_obj')) { |
|
404 | 404 | /** |
405 | 405 | * espresso_event_date_obj |
406 | 406 | * returns the primary date object for an event |
@@ -408,13 +408,13 @@ discard block |
||
408 | 408 | * @param bool $EVT_ID |
409 | 409 | * @return object |
410 | 410 | */ |
411 | - function espresso_event_date_obj( $EVT_ID = FALSE ) { |
|
412 | - return EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
411 | + function espresso_event_date_obj($EVT_ID = FALSE) { |
|
412 | + return EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | 416 | |
417 | -if ( ! function_exists( 'espresso_event_date' )) { |
|
417 | +if ( ! function_exists('espresso_event_date')) { |
|
418 | 418 | /** |
419 | 419 | * espresso_event_date |
420 | 420 | * returns the primary date for an event |
@@ -425,22 +425,22 @@ discard block |
||
425 | 425 | * @param bool $echo |
426 | 426 | * @return string |
427 | 427 | */ |
428 | - function espresso_event_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
429 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
430 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
431 | - $date_format = apply_filters( 'FHEE__espresso_event_date__date_format', $date_format ); |
|
432 | - $time_format = apply_filters( 'FHEE__espresso_event_date__time_format', $time_format ); |
|
433 | - if($echo){ |
|
434 | - echo EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
428 | + function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
429 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
430 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
431 | + $date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format); |
|
432 | + $time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format); |
|
433 | + if ($echo) { |
|
434 | + echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
435 | 435 | return ''; |
436 | 436 | } |
437 | - return EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
437 | + return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
438 | 438 | |
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | 442 | |
443 | -if ( ! function_exists( 'espresso_list_of_event_dates' )) { |
|
443 | +if ( ! function_exists('espresso_list_of_event_dates')) { |
|
444 | 444 | /** |
445 | 445 | * espresso_list_of_event_dates |
446 | 446 | * returns a unordered list of dates for an event |
@@ -455,40 +455,40 @@ discard block |
||
455 | 455 | * @param null $limit |
456 | 456 | * @return string |
457 | 457 | */ |
458 | - function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) { |
|
459 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
460 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
461 | - $date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format ); |
|
462 | - $time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format ); |
|
463 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit ); |
|
464 | - if ( ! $format ) { |
|
465 | - return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes ); |
|
458 | + function espresso_list_of_event_dates($EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL) { |
|
459 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
460 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
461 | + $date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format); |
|
462 | + $time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format); |
|
463 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, FALSE, $limit); |
|
464 | + if ( ! $format) { |
|
465 | + return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes); |
|
466 | 466 | } |
467 | 467 | //d( $datetimes ); |
468 | - if ( is_array( $datetimes ) && ! empty( $datetimes )) { |
|
468 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
469 | 469 | global $post; |
470 | - $html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
471 | - foreach ( $datetimes as $datetime ) { |
|
472 | - if ( $datetime instanceof EE_Datetime ) { |
|
473 | - $html .= '<li id="ee-event-datetimes-li-' . $datetime->ID(); |
|
474 | - $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-' . $datetime->get_active_status() . '">'; |
|
470 | + $html = $format ? '<ul id="ee-event-datetimes-ul-'.$post->ID.'" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
471 | + foreach ($datetimes as $datetime) { |
|
472 | + if ($datetime instanceof EE_Datetime) { |
|
473 | + $html .= '<li id="ee-event-datetimes-li-'.$datetime->ID(); |
|
474 | + $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-'.$datetime->get_active_status().'">'; |
|
475 | 475 | $datetime_name = $datetime->name(); |
476 | - $html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : ''; |
|
477 | - $html .= ! empty( $datetime_name ) && $add_breaks ? '<br />' : ''; |
|
478 | - $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">' . $datetime->date_range( $date_format ) . '</span><br/>'; |
|
479 | - $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">' . $datetime->time_range( $time_format ) . '</span>'; |
|
476 | + $html .= ! empty($datetime_name) ? '<strong>'.$datetime_name.'</strong>' : ''; |
|
477 | + $html .= ! empty($datetime_name) && $add_breaks ? '<br />' : ''; |
|
478 | + $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">'.$datetime->date_range($date_format).'</span><br/>'; |
|
479 | + $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">'.$datetime->time_range($time_format).'</span>'; |
|
480 | 480 | $datetime_description = $datetime->description(); |
481 | - $html .= ! empty( $datetime_description ) && $add_breaks ? '<br />' : ''; |
|
482 | - $html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : ''; |
|
483 | - $html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime ); |
|
481 | + $html .= ! empty($datetime_description) && $add_breaks ? '<br />' : ''; |
|
482 | + $html .= ! empty($datetime_description) ? ' - '.$datetime_description : ''; |
|
483 | + $html = apply_filters('FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime); |
|
484 | 484 | $html .= '</li>'; |
485 | 485 | } |
486 | 486 | } |
487 | 487 | $html .= $format ? '</ul>' : ''; |
488 | 488 | } else { |
489 | - $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : ''; |
|
489 | + $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>'.__('There are no upcoming dates for this event.', 'event_espresso').'</p><br/>' : ''; |
|
490 | 490 | } |
491 | - if ( $echo ) { |
|
491 | + if ($echo) { |
|
492 | 492 | echo $html; |
493 | 493 | return ''; |
494 | 494 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | |
500 | -if ( ! function_exists( 'espresso_event_end_date' )) { |
|
500 | +if ( ! function_exists('espresso_event_end_date')) { |
|
501 | 501 | /** |
502 | 502 | * espresso_event_end_date |
503 | 503 | * returns the last date for an event |
@@ -508,20 +508,20 @@ discard block |
||
508 | 508 | * @param bool $echo |
509 | 509 | * @return string |
510 | 510 | */ |
511 | - function espresso_event_end_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
512 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
513 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
514 | - $date_format = apply_filters( 'FHEE__espresso_event_end_date__date_format', $date_format ); |
|
515 | - $time_format = apply_filters( 'FHEE__espresso_event_end_date__time_format', $time_format ); |
|
516 | - if($echo){ |
|
517 | - echo EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
511 | + function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
512 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
513 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
514 | + $date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format); |
|
515 | + $time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format); |
|
516 | + if ($echo) { |
|
517 | + echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
518 | 518 | return ''; |
519 | 519 | } |
520 | - return EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
520 | + return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
521 | 521 | } |
522 | 522 | } |
523 | 523 | |
524 | -if ( ! function_exists( 'espresso_event_date_range' )) { |
|
524 | +if ( ! function_exists('espresso_event_date_range')) { |
|
525 | 525 | /** |
526 | 526 | * espresso_event_date_range |
527 | 527 | * returns the first and last chronologically ordered dates for an event (if different) |
@@ -534,31 +534,31 @@ discard block |
||
534 | 534 | * @param bool $echo |
535 | 535 | * @return string |
536 | 536 | */ |
537 | - function espresso_event_date_range( $date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
537 | + function espresso_event_date_range($date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
538 | 538 | // set and filter date and time formats when a range is returned |
539 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
540 | - $date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', $date_format ); |
|
539 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
540 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format); |
|
541 | 541 | // get the start and end date with NO time portion |
542 | - $the_event_date = EEH_Event_View::the_earliest_event_date( $date_format, '', $EVT_ID ); |
|
543 | - $the_event_end_date = EEH_Event_View::the_latest_event_date( $date_format, '', $EVT_ID ); |
|
542 | + $the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID); |
|
543 | + $the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID); |
|
544 | 544 | // now we can determine if date range spans more than one day |
545 | - if ( $the_event_date != $the_event_end_date ) { |
|
546 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
547 | - $time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', $time_format ); |
|
545 | + if ($the_event_date != $the_event_end_date) { |
|
546 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
547 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format); |
|
548 | 548 | $html = sprintf( |
549 | - __( '%1$s - %2$s', 'event_espresso' ), |
|
550 | - EEH_Event_View::the_earliest_event_date( $date_format, $time_format, $EVT_ID ), |
|
551 | - EEH_Event_View::the_latest_event_date( $date_format, $time_format, $EVT_ID ) |
|
549 | + __('%1$s - %2$s', 'event_espresso'), |
|
550 | + EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID), |
|
551 | + EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID) |
|
552 | 552 | ); |
553 | 553 | } else { |
554 | 554 | // set and filter date and time formats when only a single datetime is returned |
555 | - $single_date_format = ! empty( $single_date_format ) ? $single_date_format : get_option( 'date_format' ); |
|
556 | - $single_time_format = ! empty( $single_time_format ) ? $single_time_format : get_option( 'time_format' ); |
|
557 | - $single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', $single_date_format ); |
|
558 | - $single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', $single_time_format ); |
|
559 | - $html = EEH_Event_View::the_earliest_event_date( $single_date_format, $single_time_format, $EVT_ID ); |
|
555 | + $single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format'); |
|
556 | + $single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format'); |
|
557 | + $single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format); |
|
558 | + $single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format); |
|
559 | + $html = EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID); |
|
560 | 560 | } |
561 | - if ( $echo ) { |
|
561 | + if ($echo) { |
|
562 | 562 | echo $html; |
563 | 563 | return ''; |
564 | 564 | } |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | } |
568 | 568 | |
569 | 569 | |
570 | -if ( ! function_exists( 'espresso_event_date_as_calendar_page' )) { |
|
570 | +if ( ! function_exists('espresso_event_date_as_calendar_page')) { |
|
571 | 571 | /** |
572 | 572 | * espresso_event_date_as_calendar_page |
573 | 573 | * returns the primary date for an event, stylized to appear as the page of a calendar |
@@ -575,15 +575,15 @@ discard block |
||
575 | 575 | * @param bool $EVT_ID |
576 | 576 | * @return string |
577 | 577 | */ |
578 | - function espresso_event_date_as_calendar_page( $EVT_ID = FALSE ) { |
|
579 | - EEH_Event_View::event_date_as_calendar_page( $EVT_ID ); |
|
578 | + function espresso_event_date_as_calendar_page($EVT_ID = FALSE) { |
|
579 | + EEH_Event_View::event_date_as_calendar_page($EVT_ID); |
|
580 | 580 | } |
581 | 581 | } |
582 | 582 | |
583 | 583 | |
584 | 584 | |
585 | 585 | |
586 | -if ( ! function_exists( 'espresso_event_link_url' )) { |
|
586 | +if ( ! function_exists('espresso_event_link_url')) { |
|
587 | 587 | /** |
588 | 588 | * espresso_event_link_url |
589 | 589 | * |
@@ -591,18 +591,18 @@ discard block |
||
591 | 591 | * @param bool $echo |
592 | 592 | * @return string |
593 | 593 | */ |
594 | - function espresso_event_link_url( $EVT_ID = 0, $echo = TRUE ) { |
|
595 | - if ( $echo ) { |
|
596 | - echo EEH_Event_View::event_link_url( $EVT_ID ); |
|
594 | + function espresso_event_link_url($EVT_ID = 0, $echo = TRUE) { |
|
595 | + if ($echo) { |
|
596 | + echo EEH_Event_View::event_link_url($EVT_ID); |
|
597 | 597 | return ''; |
598 | 598 | } |
599 | - return EEH_Event_View::event_link_url( $EVT_ID ); |
|
599 | + return EEH_Event_View::event_link_url($EVT_ID); |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | |
603 | 603 | |
604 | 604 | |
605 | -if ( ! function_exists( 'espresso_event_has_content_or_excerpt' )) { |
|
605 | +if ( ! function_exists('espresso_event_has_content_or_excerpt')) { |
|
606 | 606 | /** |
607 | 607 | * espresso_event_has_content_or_excerpt |
608 | 608 | * |
@@ -610,15 +610,15 @@ discard block |
||
610 | 610 | * @param bool $EVT_ID |
611 | 611 | * @return boolean |
612 | 612 | */ |
613 | - function espresso_event_has_content_or_excerpt( $EVT_ID = FALSE ) { |
|
614 | - return EEH_Event_View::event_has_content_or_excerpt( $EVT_ID ); |
|
613 | + function espresso_event_has_content_or_excerpt($EVT_ID = FALSE) { |
|
614 | + return EEH_Event_View::event_has_content_or_excerpt($EVT_ID); |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 | |
618 | 618 | |
619 | 619 | |
620 | 620 | |
621 | -if ( ! function_exists( 'espresso_event_content_or_excerpt' )) { |
|
621 | +if ( ! function_exists('espresso_event_content_or_excerpt')) { |
|
622 | 622 | /** |
623 | 623 | * espresso_event_content_or_excerpt |
624 | 624 | * |
@@ -627,18 +627,18 @@ discard block |
||
627 | 627 | * @param bool $echo |
628 | 628 | * @return string |
629 | 629 | */ |
630 | - function espresso_event_content_or_excerpt( $num_words = 55, $more = NULL, $echo = TRUE ) { |
|
631 | - if ( $echo ) { |
|
632 | - echo EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
630 | + function espresso_event_content_or_excerpt($num_words = 55, $more = NULL, $echo = TRUE) { |
|
631 | + if ($echo) { |
|
632 | + echo EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
633 | 633 | return ''; |
634 | 634 | } |
635 | - return EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
635 | + return EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | |
639 | 639 | |
640 | 640 | |
641 | -if ( ! function_exists( 'espresso_event_phone' )) { |
|
641 | +if ( ! function_exists('espresso_event_phone')) { |
|
642 | 642 | /** |
643 | 643 | * espresso_event_phone |
644 | 644 | * |
@@ -646,18 +646,18 @@ discard block |
||
646 | 646 | * @param bool $echo |
647 | 647 | * @return string |
648 | 648 | */ |
649 | - function espresso_event_phone( $EVT_ID = 0, $echo = TRUE ) { |
|
650 | - if ( $echo ) { |
|
651 | - echo EEH_Event_View::event_phone( $EVT_ID ); |
|
649 | + function espresso_event_phone($EVT_ID = 0, $echo = TRUE) { |
|
650 | + if ($echo) { |
|
651 | + echo EEH_Event_View::event_phone($EVT_ID); |
|
652 | 652 | return ''; |
653 | 653 | } |
654 | - return EEH_Event_View::event_phone( $EVT_ID ); |
|
654 | + return EEH_Event_View::event_phone($EVT_ID); |
|
655 | 655 | } |
656 | 656 | } |
657 | 657 | |
658 | 658 | |
659 | 659 | |
660 | -if ( ! function_exists( 'espresso_edit_event_link' )) { |
|
660 | +if ( ! function_exists('espresso_edit_event_link')) { |
|
661 | 661 | /** |
662 | 662 | * espresso_edit_event_link |
663 | 663 | * returns a link to edit an event |
@@ -666,39 +666,39 @@ discard block |
||
666 | 666 | * @param bool $echo |
667 | 667 | * @return string |
668 | 668 | */ |
669 | - function espresso_edit_event_link( $EVT_ID = 0, $echo = TRUE ) { |
|
670 | - if ( $echo ) { |
|
671 | - echo EEH_Event_View::edit_event_link( $EVT_ID ); |
|
669 | + function espresso_edit_event_link($EVT_ID = 0, $echo = TRUE) { |
|
670 | + if ($echo) { |
|
671 | + echo EEH_Event_View::edit_event_link($EVT_ID); |
|
672 | 672 | return ''; |
673 | 673 | } |
674 | - return EEH_Event_View::edit_event_link( $EVT_ID ); |
|
674 | + return EEH_Event_View::edit_event_link($EVT_ID); |
|
675 | 675 | } |
676 | 676 | } |
677 | 677 | |
678 | 678 | |
679 | -if ( ! function_exists( 'espresso_organization_name' )) { |
|
679 | +if ( ! function_exists('espresso_organization_name')) { |
|
680 | 680 | /** |
681 | 681 | * espresso_organization_name |
682 | 682 | * @param bool $echo |
683 | 683 | * @return string |
684 | 684 | */ |
685 | 685 | function espresso_organization_name($echo = TRUE) { |
686 | - if($echo){ |
|
687 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
686 | + if ($echo) { |
|
687 | + echo EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
688 | 688 | return ''; |
689 | 689 | } |
690 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
690 | + return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | |
694 | -if ( ! function_exists( 'espresso_organization_address' )) { |
|
694 | +if ( ! function_exists('espresso_organization_address')) { |
|
695 | 695 | /** |
696 | 696 | * espresso_organization_address |
697 | 697 | * @param string $type |
698 | 698 | * @return string |
699 | 699 | */ |
700 | - function espresso_organization_address( $type = 'inline' ) { |
|
701 | - if ( EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config ) { |
|
700 | + function espresso_organization_address($type = 'inline') { |
|
701 | + if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) { |
|
702 | 702 | $address = new EventEspresso\core\domain\entities\GenericAddress( |
703 | 703 | EE_Registry::instance()->CFG->organization->address_1, |
704 | 704 | EE_Registry::instance()->CFG->organization->address_2, |
@@ -707,129 +707,129 @@ discard block |
||
707 | 707 | EE_Registry::instance()->CFG->organization->zip, |
708 | 708 | EE_Registry::instance()->CFG->organization->CNT_ISO |
709 | 709 | ); |
710 | - return EEH_Address::format( $address, $type ); |
|
710 | + return EEH_Address::format($address, $type); |
|
711 | 711 | } |
712 | 712 | return ''; |
713 | 713 | } |
714 | 714 | } |
715 | 715 | |
716 | -if ( ! function_exists( 'espresso_organization_email' )) { |
|
716 | +if ( ! function_exists('espresso_organization_email')) { |
|
717 | 717 | /** |
718 | 718 | * espresso_organization_email |
719 | 719 | * @param bool $echo |
720 | 720 | * @return string |
721 | 721 | */ |
722 | - function espresso_organization_email( $echo = TRUE ) { |
|
723 | - if($echo){ |
|
724 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
722 | + function espresso_organization_email($echo = TRUE) { |
|
723 | + if ($echo) { |
|
724 | + echo EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
725 | 725 | return ''; |
726 | 726 | } |
727 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
727 | + return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
728 | 728 | } |
729 | 729 | } |
730 | 730 | |
731 | -if ( ! function_exists( 'espresso_organization_logo_url' )) { |
|
731 | +if ( ! function_exists('espresso_organization_logo_url')) { |
|
732 | 732 | /** |
733 | 733 | * espresso_organization_logo_url |
734 | 734 | * @param bool $echo |
735 | 735 | * @return string |
736 | 736 | */ |
737 | - function espresso_organization_logo_url( $echo = TRUE ) { |
|
738 | - if($echo){ |
|
739 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
737 | + function espresso_organization_logo_url($echo = TRUE) { |
|
738 | + if ($echo) { |
|
739 | + echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
740 | 740 | return ''; |
741 | 741 | } |
742 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
742 | + return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
743 | 743 | } |
744 | 744 | } |
745 | 745 | |
746 | -if ( ! function_exists( 'espresso_organization_facebook' )) { |
|
746 | +if ( ! function_exists('espresso_organization_facebook')) { |
|
747 | 747 | /** |
748 | 748 | * espresso_organization_facebook |
749 | 749 | * @param bool $echo |
750 | 750 | * @return string |
751 | 751 | */ |
752 | - function espresso_organization_facebook( $echo = TRUE ) { |
|
753 | - if($echo){ |
|
754 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
752 | + function espresso_organization_facebook($echo = TRUE) { |
|
753 | + if ($echo) { |
|
754 | + echo EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
755 | 755 | return ''; |
756 | 756 | } |
757 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
757 | + return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
758 | 758 | } |
759 | 759 | } |
760 | 760 | |
761 | -if ( ! function_exists( 'espresso_organization_twitter' )) { |
|
761 | +if ( ! function_exists('espresso_organization_twitter')) { |
|
762 | 762 | /** |
763 | 763 | * espresso_organization_twitter |
764 | 764 | * @param bool $echo |
765 | 765 | * @return string |
766 | 766 | */ |
767 | - function espresso_organization_twitter( $echo = TRUE ) { |
|
768 | - if($echo){ |
|
769 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
767 | + function espresso_organization_twitter($echo = TRUE) { |
|
768 | + if ($echo) { |
|
769 | + echo EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
770 | 770 | return ''; |
771 | 771 | } |
772 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
772 | + return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
773 | 773 | } |
774 | 774 | } |
775 | 775 | |
776 | -if ( ! function_exists( 'espresso_organization_linkedin' )) { |
|
776 | +if ( ! function_exists('espresso_organization_linkedin')) { |
|
777 | 777 | /** |
778 | 778 | * espresso_organization_linkedin |
779 | 779 | * @param bool $echo |
780 | 780 | * @return string |
781 | 781 | */ |
782 | - function espresso_organization_linkedin( $echo = TRUE ) { |
|
783 | - if($echo){ |
|
784 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
782 | + function espresso_organization_linkedin($echo = TRUE) { |
|
783 | + if ($echo) { |
|
784 | + echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
785 | 785 | return ''; |
786 | 786 | } |
787 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
787 | + return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
788 | 788 | } |
789 | 789 | } |
790 | 790 | |
791 | -if ( ! function_exists( 'espresso_organization_pinterest' )) { |
|
791 | +if ( ! function_exists('espresso_organization_pinterest')) { |
|
792 | 792 | /** |
793 | 793 | * espresso_organization_pinterest |
794 | 794 | * @param bool $echo |
795 | 795 | * @return string |
796 | 796 | */ |
797 | - function espresso_organization_pinterest( $echo = TRUE ) { |
|
798 | - if($echo){ |
|
799 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
797 | + function espresso_organization_pinterest($echo = TRUE) { |
|
798 | + if ($echo) { |
|
799 | + echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
800 | 800 | return ''; |
801 | 801 | } |
802 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
802 | + return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
803 | 803 | } |
804 | 804 | } |
805 | 805 | |
806 | -if ( ! function_exists( 'espresso_organization_google' )) { |
|
806 | +if ( ! function_exists('espresso_organization_google')) { |
|
807 | 807 | /** |
808 | 808 | * espresso_organization_google |
809 | 809 | * @param bool $echo |
810 | 810 | * @return string |
811 | 811 | */ |
812 | - function espresso_organization_google( $echo = TRUE ) { |
|
813 | - if($echo){ |
|
814 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
812 | + function espresso_organization_google($echo = TRUE) { |
|
813 | + if ($echo) { |
|
814 | + echo EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
815 | 815 | return ''; |
816 | 816 | } |
817 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
817 | + return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
818 | 818 | } |
819 | 819 | } |
820 | 820 | |
821 | -if ( ! function_exists( 'espresso_organization_instagram' )) { |
|
821 | +if ( ! function_exists('espresso_organization_instagram')) { |
|
822 | 822 | /** |
823 | 823 | * espresso_organization_instagram |
824 | 824 | * @param bool $echo |
825 | 825 | * @return string |
826 | 826 | */ |
827 | - function espresso_organization_instagram( $echo = TRUE ) { |
|
828 | - if($echo){ |
|
829 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
827 | + function espresso_organization_instagram($echo = TRUE) { |
|
828 | + if ($echo) { |
|
829 | + echo EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
830 | 830 | return ''; |
831 | 831 | } |
832 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
832 | + return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
833 | 833 | } |
834 | 834 | } |
835 | 835 | |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | |
840 | 840 | |
841 | 841 | |
842 | -if ( ! function_exists( 'espresso_event_venues' )) { |
|
842 | +if ( ! function_exists('espresso_event_venues')) { |
|
843 | 843 | /** |
844 | 844 | * espresso_event_venues |
845 | 845 | * |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | |
854 | 854 | |
855 | 855 | |
856 | -if ( ! function_exists( 'espresso_venue_id' )) { |
|
856 | +if ( ! function_exists('espresso_venue_id')) { |
|
857 | 857 | /** |
858 | 858 | * espresso_venue_name |
859 | 859 | * |
@@ -861,15 +861,15 @@ discard block |
||
861 | 861 | * @param int $EVT_ID |
862 | 862 | * @return string |
863 | 863 | */ |
864 | - function espresso_venue_id( $EVT_ID = 0 ) { |
|
865 | - $venue = EEH_Venue_View::get_venue( $EVT_ID ); |
|
864 | + function espresso_venue_id($EVT_ID = 0) { |
|
865 | + $venue = EEH_Venue_View::get_venue($EVT_ID); |
|
866 | 866 | return $venue instanceof EE_Venue ? $venue->ID() : 0; |
867 | 867 | } |
868 | 868 | } |
869 | 869 | |
870 | 870 | |
871 | 871 | |
872 | -if ( ! function_exists( 'espresso_is_venue_private' ) ) { |
|
872 | +if ( ! function_exists('espresso_is_venue_private')) { |
|
873 | 873 | /** |
874 | 874 | * Return whether a venue is private or not. |
875 | 875 | * @see EEH_Venue_View::get_venue() for more info on expected return results. |
@@ -878,45 +878,45 @@ discard block |
||
878 | 878 | * |
879 | 879 | * @return bool | null |
880 | 880 | */ |
881 | - function espresso_is_venue_private( $VNU_ID = 0 ) { |
|
882 | - return EEH_Venue_View::is_venue_private( $VNU_ID ); |
|
881 | + function espresso_is_venue_private($VNU_ID = 0) { |
|
882 | + return EEH_Venue_View::is_venue_private($VNU_ID); |
|
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
886 | 886 | |
887 | 887 | |
888 | -if ( ! function_exists( 'espresso_venue_is_password_protected' ) ) { |
|
888 | +if ( ! function_exists('espresso_venue_is_password_protected')) { |
|
889 | 889 | /** |
890 | 890 | * returns true or false if a venue is password protected or not |
891 | 891 | * |
892 | 892 | * @param int $VNU_ID optional, the venue id to check. |
893 | 893 | * @return string |
894 | 894 | */ |
895 | - function espresso_venue_is_password_protected( $VNU_ID = 0 ) { |
|
896 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
897 | - return EEH_Venue_View::is_venue_password_protected( $VNU_ID ); |
|
895 | + function espresso_venue_is_password_protected($VNU_ID = 0) { |
|
896 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
897 | + return EEH_Venue_View::is_venue_password_protected($VNU_ID); |
|
898 | 898 | } |
899 | 899 | } |
900 | 900 | |
901 | 901 | |
902 | 902 | |
903 | -if ( ! function_exists( 'espresso_password_protected_venue_form' ) ) { |
|
903 | +if ( ! function_exists('espresso_password_protected_venue_form')) { |
|
904 | 904 | /** |
905 | 905 | * Returns a password form if venue is password protected. |
906 | 906 | * |
907 | 907 | * @param int $VNU_ID optional, the venue id to check. |
908 | 908 | * @return string |
909 | 909 | */ |
910 | - function espresso_password_protected_venue_form( $VNU_ID = 0 ) { |
|
911 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
912 | - return EEH_Venue_View::password_protected_venue_form( $VNU_ID ); |
|
910 | + function espresso_password_protected_venue_form($VNU_ID = 0) { |
|
911 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
912 | + return EEH_Venue_View::password_protected_venue_form($VNU_ID); |
|
913 | 913 | } |
914 | 914 | } |
915 | 915 | |
916 | 916 | |
917 | 917 | |
918 | 918 | |
919 | -if ( ! function_exists( 'espresso_venue_name' )) { |
|
919 | +if ( ! function_exists('espresso_venue_name')) { |
|
920 | 920 | /** |
921 | 921 | * espresso_venue_name |
922 | 922 | * |
@@ -926,19 +926,19 @@ discard block |
||
926 | 926 | * @param bool $echo |
927 | 927 | * @return string |
928 | 928 | */ |
929 | - function espresso_venue_name( $VNU_ID = 0, $link_to = 'details', $echo = TRUE ) { |
|
930 | - if($echo){ |
|
931 | - echo EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
929 | + function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = TRUE) { |
|
930 | + if ($echo) { |
|
931 | + echo EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
932 | 932 | return ''; |
933 | 933 | } |
934 | - return EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
934 | + return EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
935 | 935 | } |
936 | 936 | } |
937 | 937 | |
938 | 938 | |
939 | 939 | |
940 | 940 | |
941 | -if ( ! function_exists( 'espresso_venue_link' )) { |
|
941 | +if ( ! function_exists('espresso_venue_link')) { |
|
942 | 942 | /** |
943 | 943 | * espresso_venue_link |
944 | 944 | * |
@@ -947,14 +947,14 @@ discard block |
||
947 | 947 | * @param string $text |
948 | 948 | * @return string |
949 | 949 | */ |
950 | - function espresso_venue_link( $VNU_ID = 0, $text = '' ) { |
|
951 | - return EEH_Venue_View::venue_details_link( $VNU_ID, $text ); |
|
950 | + function espresso_venue_link($VNU_ID = 0, $text = '') { |
|
951 | + return EEH_Venue_View::venue_details_link($VNU_ID, $text); |
|
952 | 952 | } |
953 | 953 | } |
954 | 954 | |
955 | 955 | |
956 | 956 | |
957 | -if ( ! function_exists( 'espresso_venue_description' )) { |
|
957 | +if ( ! function_exists('espresso_venue_description')) { |
|
958 | 958 | /** |
959 | 959 | * espresso_venue_description |
960 | 960 | * |
@@ -963,17 +963,17 @@ discard block |
||
963 | 963 | * @param bool $echo |
964 | 964 | * @return string |
965 | 965 | */ |
966 | - function espresso_venue_description( $VNU_ID = FALSE, $echo = TRUE ) { |
|
967 | - if($echo){ |
|
968 | - echo EEH_Venue_View::venue_description( $VNU_ID ); |
|
966 | + function espresso_venue_description($VNU_ID = FALSE, $echo = TRUE) { |
|
967 | + if ($echo) { |
|
968 | + echo EEH_Venue_View::venue_description($VNU_ID); |
|
969 | 969 | return ''; |
970 | 970 | } |
971 | - return EEH_Venue_View::venue_description( $VNU_ID ); |
|
971 | + return EEH_Venue_View::venue_description($VNU_ID); |
|
972 | 972 | } |
973 | 973 | } |
974 | 974 | |
975 | 975 | |
976 | -if ( ! function_exists( 'espresso_venue_excerpt' )) { |
|
976 | +if ( ! function_exists('espresso_venue_excerpt')) { |
|
977 | 977 | /** |
978 | 978 | * espresso_venue_excerpt |
979 | 979 | * |
@@ -982,18 +982,18 @@ discard block |
||
982 | 982 | * @param bool $echo |
983 | 983 | * @return string |
984 | 984 | */ |
985 | - function espresso_venue_excerpt( $VNU_ID = 0, $echo = TRUE ) { |
|
986 | - if ( $echo ) { |
|
987 | - echo EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
985 | + function espresso_venue_excerpt($VNU_ID = 0, $echo = TRUE) { |
|
986 | + if ($echo) { |
|
987 | + echo EEH_Venue_View::venue_excerpt($VNU_ID); |
|
988 | 988 | return ''; |
989 | 989 | } |
990 | - return EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
990 | + return EEH_Venue_View::venue_excerpt($VNU_ID); |
|
991 | 991 | } |
992 | 992 | } |
993 | 993 | |
994 | 994 | |
995 | 995 | |
996 | -if ( ! function_exists( 'espresso_venue_categories' )) { |
|
996 | +if ( ! function_exists('espresso_venue_categories')) { |
|
997 | 997 | /** |
998 | 998 | * espresso_venue_categories |
999 | 999 | * returns the terms associated with a venue |
@@ -1003,17 +1003,17 @@ discard block |
||
1003 | 1003 | * @param bool $echo |
1004 | 1004 | * @return string |
1005 | 1005 | */ |
1006 | - function espresso_venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
1007 | - if ( $echo ) { |
|
1008 | - echo EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
1006 | + function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
1007 | + if ($echo) { |
|
1008 | + echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1009 | 1009 | return ''; |
1010 | 1010 | } |
1011 | - return EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
1011 | + return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1012 | 1012 | } |
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | |
1016 | -if ( ! function_exists( 'espresso_venue_address' )) { |
|
1016 | +if ( ! function_exists('espresso_venue_address')) { |
|
1017 | 1017 | /** |
1018 | 1018 | * espresso_venue_address |
1019 | 1019 | * returns a formatted block of html for displaying a venue's address |
@@ -1023,17 +1023,17 @@ discard block |
||
1023 | 1023 | * @param bool $echo |
1024 | 1024 | * @return string |
1025 | 1025 | */ |
1026 | - function espresso_venue_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
1027 | - if ( $echo ) { |
|
1028 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
1026 | + function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
1027 | + if ($echo) { |
|
1028 | + echo EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1029 | 1029 | return ''; |
1030 | 1030 | } |
1031 | - return EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
1031 | + return EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1032 | 1032 | } |
1033 | 1033 | } |
1034 | 1034 | |
1035 | 1035 | |
1036 | -if ( ! function_exists( 'espresso_venue_raw_address' )) { |
|
1036 | +if ( ! function_exists('espresso_venue_raw_address')) { |
|
1037 | 1037 | /** |
1038 | 1038 | * espresso_venue_address |
1039 | 1039 | * returns an UN-formatted string containing a venue's address |
@@ -1043,17 +1043,17 @@ discard block |
||
1043 | 1043 | * @param bool $echo |
1044 | 1044 | * @return string |
1045 | 1045 | */ |
1046 | - function espresso_venue_raw_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
1047 | - if ( $echo ) { |
|
1048 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
1046 | + function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
1047 | + if ($echo) { |
|
1048 | + echo EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
1049 | 1049 | return ''; |
1050 | 1050 | } |
1051 | - return EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
1051 | + return EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
1052 | 1052 | } |
1053 | 1053 | } |
1054 | 1054 | |
1055 | 1055 | |
1056 | -if ( ! function_exists( 'espresso_venue_has_address' )) { |
|
1056 | +if ( ! function_exists('espresso_venue_has_address')) { |
|
1057 | 1057 | /** |
1058 | 1058 | * espresso_venue_has_address |
1059 | 1059 | * returns TRUE or FALSE if a Venue has address information |
@@ -1061,13 +1061,13 @@ discard block |
||
1061 | 1061 | * @param int $VNU_ID |
1062 | 1062 | * @return bool |
1063 | 1063 | */ |
1064 | - function espresso_venue_has_address( $VNU_ID = 0 ) { |
|
1065 | - return EEH_Venue_View::venue_has_address( $VNU_ID ); |
|
1064 | + function espresso_venue_has_address($VNU_ID = 0) { |
|
1065 | + return EEH_Venue_View::venue_has_address($VNU_ID); |
|
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | |
1069 | 1069 | |
1070 | -if ( ! function_exists( 'espresso_venue_gmap' )) { |
|
1070 | +if ( ! function_exists('espresso_venue_gmap')) { |
|
1071 | 1071 | /** |
1072 | 1072 | * espresso_venue_gmap |
1073 | 1073 | * returns a google map for the venue address |
@@ -1078,17 +1078,17 @@ discard block |
||
1078 | 1078 | * @param bool $echo |
1079 | 1079 | * @return string |
1080 | 1080 | */ |
1081 | - function espresso_venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE ) { |
|
1082 | - if ( $echo ) { |
|
1083 | - echo EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
1081 | + function espresso_venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE) { |
|
1082 | + if ($echo) { |
|
1083 | + echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1084 | 1084 | return ''; |
1085 | 1085 | } |
1086 | - return EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
1086 | + return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1087 | 1087 | } |
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | |
1091 | -if ( ! function_exists( 'espresso_venue_phone' )) { |
|
1091 | +if ( ! function_exists('espresso_venue_phone')) { |
|
1092 | 1092 | /** |
1093 | 1093 | * espresso_venue_phone |
1094 | 1094 | * |
@@ -1096,18 +1096,18 @@ discard block |
||
1096 | 1096 | * @param bool $echo |
1097 | 1097 | * @return string |
1098 | 1098 | */ |
1099 | - function espresso_venue_phone( $VNU_ID = 0, $echo = TRUE ) { |
|
1100 | - if ( $echo ) { |
|
1101 | - echo EEH_Venue_View::venue_phone( $VNU_ID ); |
|
1099 | + function espresso_venue_phone($VNU_ID = 0, $echo = TRUE) { |
|
1100 | + if ($echo) { |
|
1101 | + echo EEH_Venue_View::venue_phone($VNU_ID); |
|
1102 | 1102 | return ''; |
1103 | 1103 | } |
1104 | - return EEH_Venue_View::venue_phone( $VNU_ID ); |
|
1104 | + return EEH_Venue_View::venue_phone($VNU_ID); |
|
1105 | 1105 | } |
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | |
1109 | 1109 | |
1110 | -if ( ! function_exists( 'espresso_venue_website' )) { |
|
1110 | +if ( ! function_exists('espresso_venue_website')) { |
|
1111 | 1111 | /** |
1112 | 1112 | * espresso_venue_website |
1113 | 1113 | * |
@@ -1115,18 +1115,18 @@ discard block |
||
1115 | 1115 | * @param bool $echo |
1116 | 1116 | * @return string |
1117 | 1117 | */ |
1118 | - function espresso_venue_website( $VNU_ID = 0, $echo = TRUE ) { |
|
1119 | - if ( $echo ) { |
|
1120 | - echo EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
1118 | + function espresso_venue_website($VNU_ID = 0, $echo = TRUE) { |
|
1119 | + if ($echo) { |
|
1120 | + echo EEH_Venue_View::venue_website_link($VNU_ID); |
|
1121 | 1121 | return ''; |
1122 | 1122 | } |
1123 | - return EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
1123 | + return EEH_Venue_View::venue_website_link($VNU_ID); |
|
1124 | 1124 | } |
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | |
1128 | 1128 | |
1129 | -if ( ! function_exists( 'espresso_edit_venue_link' )) { |
|
1129 | +if ( ! function_exists('espresso_edit_venue_link')) { |
|
1130 | 1130 | /** |
1131 | 1131 | * espresso_edit_venue_link |
1132 | 1132 | * |
@@ -1134,12 +1134,12 @@ discard block |
||
1134 | 1134 | * @param bool $echo |
1135 | 1135 | * @return string |
1136 | 1136 | */ |
1137 | - function espresso_edit_venue_link( $VNU_ID = 0, $echo = TRUE ) { |
|
1138 | - if($echo){ |
|
1139 | - echo EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
1137 | + function espresso_edit_venue_link($VNU_ID = 0, $echo = TRUE) { |
|
1138 | + if ($echo) { |
|
1139 | + echo EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1140 | 1140 | return ''; |
1141 | 1141 | } |
1142 | - return EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
1142 | + return EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1143 | 1143 | } |
1144 | 1144 | } |
1145 | 1145 |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class EED_Ticket_Selector extends EED_Module { |
24 | 24 | |
25 | - /** |
|
26 | - * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector |
|
27 | - */ |
|
28 | - private static $ticket_selector; |
|
25 | + /** |
|
26 | + * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector |
|
27 | + */ |
|
28 | + private static $ticket_selector; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button |
|
32 | - */ |
|
33 | - private static $iframe_embed_button; |
|
30 | + /** |
|
31 | + * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button |
|
32 | + */ |
|
33 | + private static $iframe_embed_button; |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | // routing |
62 | 62 | EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' ); |
63 | 63 | EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' ); |
64 | - EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections'); |
|
65 | - add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 ); |
|
64 | + EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections'); |
|
65 | + add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 ); |
|
66 | 66 | add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 ); |
67 | - add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 ); |
|
68 | - add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 ); |
|
69 | - EED_Ticket_Selector::loadIframeAssets(); |
|
70 | - } |
|
67 | + add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 ); |
|
68 | + add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 ); |
|
69 | + EED_Ticket_Selector::loadIframeAssets(); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | 73 | |
@@ -86,16 +86,16 @@ discard block |
||
86 | 86 | 10 |
87 | 87 | ); |
88 | 88 | |
89 | - /** |
|
90 | - * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
91 | - * registrations work. |
|
92 | - */ |
|
89 | + /** |
|
90 | + * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
91 | + * registrations work. |
|
92 | + */ |
|
93 | 93 | add_action( |
94 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
95 | - array('EED_Ticket_Selector', 'set_definitions'), |
|
96 | - 10 |
|
97 | - ); |
|
98 | - } |
|
94 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
95 | + array('EED_Ticket_Selector', 'set_definitions'), |
|
96 | + 10 |
|
97 | + ); |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | 101 | |
@@ -106,34 +106,34 @@ discard block |
||
106 | 106 | * @return void |
107 | 107 | */ |
108 | 108 | public static function set_definitions() { |
109 | - // don't do this twice |
|
110 | - if(defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
111 | - return; |
|
112 | - } |
|
109 | + // don't do this twice |
|
110 | + if(defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
111 | + return; |
|
112 | + } |
|
113 | 113 | define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
114 | 114 | define( |
115 | - 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
116 | - str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS |
|
117 | - ); |
|
115 | + 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
116 | + str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS |
|
117 | + ); |
|
118 | 118 | //if config is not set, initialize |
119 | 119 | if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) { |
120 | - \EED_Ticket_Selector::instance()->set_config(); |
|
121 | - \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config(); |
|
120 | + \EED_Ticket_Selector::instance()->set_config(); |
|
121 | + \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config(); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | |
126 | 126 | |
127 | 127 | /** |
128 | - * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector |
|
129 | - */ |
|
130 | - public static function ticketSelector() |
|
131 | - { |
|
132 | - if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
133 | - EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(); |
|
134 | - } |
|
135 | - return EED_Ticket_Selector::$ticket_selector; |
|
136 | - } |
|
128 | + * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector |
|
129 | + */ |
|
130 | + public static function ticketSelector() |
|
131 | + { |
|
132 | + if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
133 | + EED_Ticket_Selector::$ticket_selector = new DisplayTicketSelector(); |
|
134 | + } |
|
135 | + return EED_Ticket_Selector::$ticket_selector; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | 139 | /** |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | |
187 | 187 | |
188 | 188 | |
189 | - /** |
|
190 | - * creates buttons for selecting number of attendees for an event |
|
191 | - * |
|
192 | - * @access public |
|
193 | - * @param WP_Post|int $event |
|
194 | - * @param bool $view_details |
|
195 | - * @return string |
|
196 | - * @throws \EE_Error |
|
197 | - */ |
|
189 | + /** |
|
190 | + * creates buttons for selecting number of attendees for an event |
|
191 | + * |
|
192 | + * @access public |
|
193 | + * @param WP_Post|int $event |
|
194 | + * @param bool $view_details |
|
195 | + * @return string |
|
196 | + * @throws \EE_Error |
|
197 | + */ |
|
198 | 198 | public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) { |
199 | 199 | return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details ); |
200 | 200 | } |
@@ -215,244 +215,244 @@ discard block |
||
215 | 215 | |
216 | 216 | |
217 | 217 | |
218 | - /** |
|
219 | - * cancel_ticket_selections |
|
220 | - * |
|
221 | - * @access public |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - public static function cancel_ticket_selections() |
|
225 | - { |
|
226 | - $form = new ProcessTicketSelector(); |
|
227 | - return $form->cancelTicketSelections(); |
|
228 | - } |
|
218 | + /** |
|
219 | + * cancel_ticket_selections |
|
220 | + * |
|
221 | + * @access public |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + public static function cancel_ticket_selections() |
|
225 | + { |
|
226 | + $form = new ProcessTicketSelector(); |
|
227 | + return $form->cancelTicketSelections(); |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | 231 | |
232 | 232 | /** |
233 | - * @return void |
|
234 | - */ |
|
233 | + * @return void |
|
234 | + */ |
|
235 | 235 | public static function translate_js_strings() { |
236 | - EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
237 | - 'please select a datetime', 'event_espresso' |
|
238 | - ); |
|
239 | - } |
|
236 | + EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
237 | + 'please select a datetime', 'event_espresso' |
|
238 | + ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | |
242 | 242 | |
243 | 243 | /** |
244 | - * load js |
|
245 | - * |
|
246 | - * @access public |
|
247 | - * @return void |
|
248 | - */ |
|
244 | + * load js |
|
245 | + * |
|
246 | + * @access public |
|
247 | + * @return void |
|
248 | + */ |
|
249 | 249 | public static function load_tckt_slctr_assets() { |
250 | 250 | if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) { |
251 | - // add some style |
|
252 | - wp_register_style( |
|
253 | - 'ticket_selector', |
|
254 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
255 | - array(), |
|
256 | - EVENT_ESPRESSO_VERSION |
|
257 | - ); |
|
258 | - wp_enqueue_style('ticket_selector'); |
|
259 | - // make it dance |
|
260 | - wp_register_script( |
|
261 | - 'ticket_selector', |
|
262 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
263 | - array('espresso_core'), |
|
264 | - EVENT_ESPRESSO_VERSION, |
|
265 | - TRUE |
|
266 | - ); |
|
251 | + // add some style |
|
252 | + wp_register_style( |
|
253 | + 'ticket_selector', |
|
254 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
255 | + array(), |
|
256 | + EVENT_ESPRESSO_VERSION |
|
257 | + ); |
|
258 | + wp_enqueue_style('ticket_selector'); |
|
259 | + // make it dance |
|
260 | + wp_register_script( |
|
261 | + 'ticket_selector', |
|
262 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
263 | + array('espresso_core'), |
|
264 | + EVENT_ESPRESSO_VERSION, |
|
265 | + TRUE |
|
266 | + ); |
|
267 | 267 | wp_enqueue_script('ticket_selector'); |
268 | - require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'); |
|
269 | - \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
270 | - } |
|
268 | + require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'); |
|
269 | + \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @return void |
|
277 | + */ |
|
278 | + public static function loadIframeAssets() |
|
279 | + { |
|
280 | + // for event lists |
|
281 | + add_filter( |
|
282 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
283 | + array('EED_Ticket_Selector', 'iframeCss') |
|
284 | + ); |
|
285 | + add_filter( |
|
286 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
287 | + array('EED_Ticket_Selector', 'iframeJs') |
|
288 | + ); |
|
289 | + // for ticket selectors |
|
290 | + add_filter( |
|
291 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
292 | + array('EED_Ticket_Selector', 'iframeCss') |
|
293 | + ); |
|
294 | + add_filter( |
|
295 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
296 | + array('EED_Ticket_Selector', 'iframeJs') |
|
297 | + ); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
304 | + * |
|
305 | + * @param array $iframe_css |
|
306 | + * @return array |
|
307 | + */ |
|
308 | + public static function iframeCss(array $iframe_css) |
|
309 | + { |
|
310 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
311 | + return $iframe_css; |
|
271 | 312 | } |
272 | 313 | |
273 | 314 | |
274 | 315 | |
275 | - /** |
|
276 | - * @return void |
|
277 | - */ |
|
278 | - public static function loadIframeAssets() |
|
279 | - { |
|
280 | - // for event lists |
|
281 | - add_filter( |
|
282 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
283 | - array('EED_Ticket_Selector', 'iframeCss') |
|
284 | - ); |
|
285 | - add_filter( |
|
286 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
287 | - array('EED_Ticket_Selector', 'iframeJs') |
|
288 | - ); |
|
289 | - // for ticket selectors |
|
290 | - add_filter( |
|
291 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
292 | - array('EED_Ticket_Selector', 'iframeCss') |
|
293 | - ); |
|
294 | - add_filter( |
|
295 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
296 | - array('EED_Ticket_Selector', 'iframeJs') |
|
297 | - ); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
304 | - * |
|
305 | - * @param array $iframe_css |
|
306 | - * @return array |
|
307 | - */ |
|
308 | - public static function iframeCss(array $iframe_css) |
|
309 | - { |
|
310 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
311 | - return $iframe_css; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
318 | - * |
|
319 | - * @param array $iframe_js |
|
320 | - * @return array |
|
321 | - */ |
|
322 | - public static function iframeJs(array $iframe_js) |
|
323 | - { |
|
324 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
325 | - return $iframe_js; |
|
326 | - } |
|
316 | + /** |
|
317 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
318 | + * |
|
319 | + * @param array $iframe_js |
|
320 | + * @return array |
|
321 | + */ |
|
322 | + public static function iframeJs(array $iframe_js) |
|
323 | + { |
|
324 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
325 | + return $iframe_js; |
|
326 | + } |
|
327 | 327 | |
328 | 328 | |
329 | 329 | /****************************** DEPRECATED ******************************/ |
330 | 330 | |
331 | 331 | |
332 | 332 | |
333 | - /** |
|
334 | - * @deprecated |
|
335 | - * @return string |
|
336 | - * @throws \EE_Error |
|
337 | - */ |
|
338 | - public static function display_view_details_btn() |
|
339 | - { |
|
340 | - // todo add doing_it_wrong() notice during next major version |
|
341 | - return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @deprecated |
|
348 | - * @return string |
|
349 | - * @throws \EE_Error |
|
350 | - */ |
|
351 | - public static function display_ticket_selector_submit() |
|
352 | - { |
|
353 | - // todo add doing_it_wrong() notice during next major version |
|
354 | - return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @deprecated |
|
361 | - * @param string $permalink_string |
|
362 | - * @param int $id |
|
363 | - * @param string $new_title |
|
364 | - * @param string $new_slug |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
368 | - { |
|
369 | - // todo add doing_it_wrong() notice during next major version |
|
370 | - if ( |
|
371 | - \EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
372 | - && \EE_Registry::instance()->REQ->get('action') === 'edit' |
|
373 | - ) { |
|
374 | - $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
|
375 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
376 | - } |
|
377 | - return ''; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * @deprecated |
|
384 | - * @param int $ID |
|
385 | - * @param string $external_url |
|
386 | - * @return string |
|
387 | - */ |
|
388 | - public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
389 | - { |
|
390 | - // todo add doing_it_wrong() notice during next major version |
|
391 | - return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * @deprecated |
|
398 | - * @return string |
|
399 | - */ |
|
400 | - public static function ticket_selector_form_close() |
|
401 | - { |
|
402 | - // todo add doing_it_wrong() notice during next major version |
|
403 | - return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * @deprecated |
|
410 | - * @return string |
|
411 | - */ |
|
412 | - public static function no_tkt_slctr_end_dv() |
|
413 | - { |
|
414 | - // todo add doing_it_wrong() notice during next major version |
|
415 | - return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * @deprecated 4.9.13 |
|
422 | - * @return string |
|
423 | - */ |
|
424 | - public static function tkt_slctr_end_dv() |
|
425 | - { |
|
426 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * @deprecated |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - public static function clear_tkt_slctr() |
|
436 | - { |
|
437 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * @deprecated |
|
444 | - */ |
|
445 | - public static function load_tckt_slctr_assets_admin() |
|
446 | - { |
|
447 | - // todo add doing_it_wrong() notice during next major version |
|
448 | - if ( |
|
449 | - \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events' |
|
450 | - && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit' |
|
451 | - ) { |
|
452 | - $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
|
453 | - $iframe_embed_button->embedButtonAssets(); |
|
454 | - } |
|
455 | - } |
|
333 | + /** |
|
334 | + * @deprecated |
|
335 | + * @return string |
|
336 | + * @throws \EE_Error |
|
337 | + */ |
|
338 | + public static function display_view_details_btn() |
|
339 | + { |
|
340 | + // todo add doing_it_wrong() notice during next major version |
|
341 | + return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @deprecated |
|
348 | + * @return string |
|
349 | + * @throws \EE_Error |
|
350 | + */ |
|
351 | + public static function display_ticket_selector_submit() |
|
352 | + { |
|
353 | + // todo add doing_it_wrong() notice during next major version |
|
354 | + return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @deprecated |
|
361 | + * @param string $permalink_string |
|
362 | + * @param int $id |
|
363 | + * @param string $new_title |
|
364 | + * @param string $new_slug |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
368 | + { |
|
369 | + // todo add doing_it_wrong() notice during next major version |
|
370 | + if ( |
|
371 | + \EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
372 | + && \EE_Registry::instance()->REQ->get('action') === 'edit' |
|
373 | + ) { |
|
374 | + $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
|
375 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
376 | + } |
|
377 | + return ''; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * @deprecated |
|
384 | + * @param int $ID |
|
385 | + * @param string $external_url |
|
386 | + * @return string |
|
387 | + */ |
|
388 | + public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
389 | + { |
|
390 | + // todo add doing_it_wrong() notice during next major version |
|
391 | + return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * @deprecated |
|
398 | + * @return string |
|
399 | + */ |
|
400 | + public static function ticket_selector_form_close() |
|
401 | + { |
|
402 | + // todo add doing_it_wrong() notice during next major version |
|
403 | + return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * @deprecated |
|
410 | + * @return string |
|
411 | + */ |
|
412 | + public static function no_tkt_slctr_end_dv() |
|
413 | + { |
|
414 | + // todo add doing_it_wrong() notice during next major version |
|
415 | + return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * @deprecated 4.9.13 |
|
422 | + * @return string |
|
423 | + */ |
|
424 | + public static function tkt_slctr_end_dv() |
|
425 | + { |
|
426 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * @deprecated |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + public static function clear_tkt_slctr() |
|
436 | + { |
|
437 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * @deprecated |
|
444 | + */ |
|
445 | + public static function load_tckt_slctr_assets_admin() |
|
446 | + { |
|
447 | + // todo add doing_it_wrong() notice during next major version |
|
448 | + if ( |
|
449 | + \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events' |
|
450 | + && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit' |
|
451 | + ) { |
|
452 | + $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
|
453 | + $iframe_embed_button->embedButtonAssets(); |
|
454 | + } |
|
455 | + } |
|
456 | 456 | |
457 | 457 | |
458 | 458 | } |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | use EventEspresso\modules\ticket_selector\TicketSelectorIframe; |
4 | 4 | use EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
7 | - exit( 'No direct script access allowed' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @return EED_Ticket_Selector |
39 | 39 | */ |
40 | 40 | public static function instance() { |
41 | - return parent::get_instance( __CLASS__ ); |
|
41 | + return parent::get_instance(__CLASS__); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - protected function set_config(){ |
|
47 | - $this->set_config_section( 'template_settings' ); |
|
48 | - $this->set_config_class( 'EE_Ticket_Selector_Config' ); |
|
49 | - $this->set_config_name( 'EED_Ticket_Selector' ); |
|
46 | + protected function set_config() { |
|
47 | + $this->set_config_section('template_settings'); |
|
48 | + $this->set_config_class('EE_Ticket_Selector_Config'); |
|
49 | + $this->set_config_name('EED_Ticket_Selector'); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public static function set_hooks() { |
61 | 61 | // routing |
62 | - EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' ); |
|
63 | - EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' ); |
|
62 | + EE_Config::register_route('iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector'); |
|
63 | + EE_Config::register_route('process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections'); |
|
64 | 64 | EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections'); |
65 | - add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 ); |
|
66 | - add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 ); |
|
67 | - add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 ); |
|
68 | - add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 ); |
|
65 | + add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2); |
|
66 | + add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1); |
|
67 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'translate_js_strings'), 0); |
|
68 | + add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10); |
|
69 | 69 | EED_Ticket_Selector::loadIframeAssets(); |
70 | 70 | } |
71 | 71 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | // to load assets for "espresso_events" page on the "edit" route (action) |
83 | 83 | add_action( |
84 | 84 | 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit', |
85 | - array( 'EED_Ticket_Selector', 'ticket_selector_iframe_embed_button' ), |
|
85 | + array('EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'), |
|
86 | 86 | 10 |
87 | 87 | ); |
88 | 88 | |
@@ -107,16 +107,16 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public static function set_definitions() { |
109 | 109 | // don't do this twice |
110 | - if(defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
110 | + if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | - define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
|
113 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
114 | 114 | define( |
115 | 115 | 'TICKET_SELECTOR_TEMPLATES_PATH', |
116 | - str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS |
|
116 | + str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS |
|
117 | 117 | ); |
118 | 118 | //if config is not set, initialize |
119 | - if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) { |
|
119 | + if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) { |
|
120 | 120 | \EED_Ticket_Selector::instance()->set_config(); |
121 | 121 | \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config(); |
122 | 122 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param WP $WP |
144 | 144 | * @return void |
145 | 145 | */ |
146 | - public function run( $WP ) {} |
|
146 | + public function run($WP) {} |
|
147 | 147 | |
148 | 148 | |
149 | 149 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @return \EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton |
152 | 152 | */ |
153 | 153 | public static function getIframeEmbedButton() { |
154 | - if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton ) { |
|
154 | + if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
155 | 155 | self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
156 | 156 | } |
157 | 157 | return self::$iframe_embed_button; |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | * @return string |
196 | 196 | * @throws \EE_Error |
197 | 197 | */ |
198 | - public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) { |
|
199 | - return EED_Ticket_Selector::ticketSelector()->display( $event, $view_details ); |
|
198 | + public static function display_ticket_selector($event = NULL, $view_details = FALSE) { |
|
199 | + return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | |
@@ -247,11 +247,11 @@ discard block |
||
247 | 247 | * @return void |
248 | 248 | */ |
249 | 249 | public static function load_tckt_slctr_assets() { |
250 | - if ( apply_filters( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE ) ) { |
|
250 | + if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', FALSE)) { |
|
251 | 251 | // add some style |
252 | 252 | wp_register_style( |
253 | 253 | 'ticket_selector', |
254 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
254 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css', |
|
255 | 255 | array(), |
256 | 256 | EVENT_ESPRESSO_VERSION |
257 | 257 | ); |
@@ -259,13 +259,13 @@ discard block |
||
259 | 259 | // make it dance |
260 | 260 | wp_register_script( |
261 | 261 | 'ticket_selector', |
262 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
262 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js', |
|
263 | 263 | array('espresso_core'), |
264 | 264 | EVENT_ESPRESSO_VERSION, |
265 | 265 | TRUE |
266 | 266 | ); |
267 | 267 | wp_enqueue_script('ticket_selector'); |
268 | - require_once( EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'); |
|
268 | + require_once(EE_LIBRARIES.'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'); |
|
269 | 269 | \EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
270 | 270 | } |
271 | 271 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | */ |
308 | 308 | public static function iframeCss(array $iframe_css) |
309 | 309 | { |
310 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
310 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css'; |
|
311 | 311 | return $iframe_css; |
312 | 312 | } |
313 | 313 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public static function iframeJs(array $iframe_js) |
323 | 323 | { |
324 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
324 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js'; |
|
325 | 325 | return $iframe_js; |
326 | 326 | } |
327 | 327 | |
@@ -446,8 +446,8 @@ discard block |
||
446 | 446 | { |
447 | 447 | // todo add doing_it_wrong() notice during next major version |
448 | 448 | if ( |
449 | - \EE_Registry::instance()->REQ->get( 'page' ) === 'espresso_events' |
|
450 | - && \EE_Registry::instance()->REQ->get( 'action' ) === 'edit' |
|
449 | + \EE_Registry::instance()->REQ->get('page') === 'espresso_events' |
|
450 | + && \EE_Registry::instance()->REQ->get('action') === 'edit' |
|
451 | 451 | ) { |
452 | 452 | $iframe_embed_button = \EED_Ticket_Selector::getIframeEmbedButton(); |
453 | 453 | $iframe_embed_button->embedButtonAssets(); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -24,470 +24,470 @@ discard block |
||
24 | 24 | { |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * This gets set in _setup_cpt |
|
29 | - * It will contain the object for the custom post type. |
|
30 | - * |
|
31 | - * @var EE_CPT_Base |
|
32 | - */ |
|
33 | - protected $_cpt_object; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * a boolean flag to set whether the current route is a cpt route or not. |
|
39 | - * |
|
40 | - * @var bool |
|
41 | - */ |
|
42 | - protected $_cpt_route = false; |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
48 | - * //in this array we define what the custom post type for this route is. |
|
49 | - * array( |
|
50 | - * 'route_name' => 'custom_post_type_slug' |
|
51 | - * ) |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - protected $_cpt_routes = array(); |
|
56 | - |
|
27 | + /** |
|
28 | + * This gets set in _setup_cpt |
|
29 | + * It will contain the object for the custom post type. |
|
30 | + * |
|
31 | + * @var EE_CPT_Base |
|
32 | + */ |
|
33 | + protected $_cpt_object; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * a boolean flag to set whether the current route is a cpt route or not. |
|
39 | + * |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | + protected $_cpt_route = false; |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
48 | + * //in this array we define what the custom post type for this route is. |
|
49 | + * array( |
|
50 | + * 'route_name' => 'custom_post_type_slug' |
|
51 | + * ) |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + protected $_cpt_routes = array(); |
|
56 | + |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
61 | - * in this format: |
|
62 | - * array( |
|
63 | - * 'post_type_slug' => 'edit_route' |
|
64 | - * ) |
|
65 | - * |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $_cpt_edit_routes = array(); |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
74 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
75 | - * _cpt_model_names property should be in the following format: array( |
|
76 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
77 | - * |
|
78 | - * @var array $_cpt_model_names |
|
79 | - */ |
|
80 | - protected $_cpt_model_names = array(); |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @var EE_CPT_Base |
|
85 | - */ |
|
86 | - protected $_cpt_model_obj = false; |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
92 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
93 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
94 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
95 | - * |
|
96 | - * @var array() |
|
97 | - */ |
|
98 | - protected $_autosave_containers = array(); |
|
99 | - protected $_autosave_fields = array(); |
|
100 | - |
|
101 | - /** |
|
102 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
103 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
104 | - * |
|
105 | - * @var array |
|
106 | - */ |
|
107 | - protected $_pagenow_map; |
|
108 | - |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
113 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
114 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
115 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
116 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
117 | - * |
|
118 | - * @access protected |
|
119 | - * @abstract |
|
120 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
121 | - * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
130 | - * |
|
131 | - * @abstract |
|
132 | - * @access public |
|
133 | - * @param string $post_id The ID of the cpt that was trashed |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - abstract public function trash_cpt_item($post_id); |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
142 | - * |
|
143 | - * @param string $post_id theID of the cpt that was untrashed |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - abstract public function restore_cpt_item($post_id); |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
152 | - * from the db |
|
153 | - * |
|
154 | - * @param string $post_id the ID of the cpt that was deleted |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - abstract public function delete_cpt_item($post_id); |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
163 | - * |
|
164 | - * @access protected |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - protected function _before_page_setup() |
|
168 | - { |
|
169 | - $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
170 | - $this->_cpt_routes = array_merge(array( |
|
171 | - 'create_new' => $this->page_slug, |
|
172 | - 'edit' => $this->page_slug, |
|
173 | - 'trash' => $this->page_slug, |
|
174 | - ), $this->_cpt_routes); |
|
175 | - //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
176 | - $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
177 | - ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
178 | - : get_post_type_object($page); |
|
179 | - //tweak pagenow for page loading. |
|
180 | - if ( ! $this->_pagenow_map) { |
|
181 | - $this->_pagenow_map = array( |
|
182 | - 'create_new' => 'post-new.php', |
|
183 | - 'edit' => 'post.php', |
|
184 | - 'trash' => 'post.php', |
|
185 | - ); |
|
186 | - } |
|
187 | - add_action('current_screen', array($this, 'modify_pagenow')); |
|
188 | - //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
189 | - //get current page from autosave |
|
190 | - $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
191 | - ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
192 | - : null; |
|
193 | - $this->_current_page = isset($this->_req_data['current_page']) |
|
194 | - ? $this->_req_data['current_page'] |
|
195 | - : $current_page; |
|
196 | - //autosave... make sure its only for the correct page |
|
197 | - //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
198 | - //setup autosave ajax hook |
|
199 | - //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
200 | - //} |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
207 | - * |
|
208 | - * @param WP_Screen $current_screen |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function modify_pagenow($current_screen) |
|
212 | - { |
|
213 | - global $pagenow, $hook_suffix; |
|
214 | - //possibly reset pagenow. |
|
215 | - if ( ! empty($this->_req_data['page']) |
|
216 | - && $this->_req_data['page'] == $this->page_slug |
|
217 | - && ! empty($this->_req_data['action']) |
|
218 | - && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
219 | - ) { |
|
220 | - $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
221 | - $hook_suffix = $pagenow; |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
229 | - * |
|
230 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
231 | - * automatically register the id for the post metabox as a container. |
|
232 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
233 | - * you would send along the id of a metabox container. |
|
234 | - * @return void |
|
235 | - */ |
|
236 | - protected function _register_autosave_containers($ids) |
|
237 | - { |
|
238 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
245 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
246 | - */ |
|
247 | - protected function _set_autosave_containers() |
|
248 | - { |
|
249 | - global $wp_meta_boxes; |
|
250 | - $containers = array(); |
|
251 | - if (empty($wp_meta_boxes)) { |
|
252 | - return; |
|
253 | - } |
|
254 | - $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
255 | - foreach ($current_metaboxes as $box_context) { |
|
256 | - foreach ($box_context as $box_details) { |
|
257 | - foreach ($box_details as $box) { |
|
258 | - if ( |
|
259 | - is_array($box['callback']) |
|
260 | - && ( |
|
261 | - $box['callback'][0] instanceof EE_Admin_Page |
|
262 | - || $box['callback'][0] instanceof EE_Admin_Hooks |
|
263 | - ) |
|
264 | - ) { |
|
265 | - $containers[] = $box['id']; |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - } |
|
270 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
271 | - //add hidden inputs container |
|
272 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - protected function _load_autosave_scripts_styles() |
|
278 | - { |
|
279 | - /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
59 | + /** |
|
60 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
61 | + * in this format: |
|
62 | + * array( |
|
63 | + * 'post_type_slug' => 'edit_route' |
|
64 | + * ) |
|
65 | + * |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $_cpt_edit_routes = array(); |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
74 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
75 | + * _cpt_model_names property should be in the following format: array( |
|
76 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
77 | + * |
|
78 | + * @var array $_cpt_model_names |
|
79 | + */ |
|
80 | + protected $_cpt_model_names = array(); |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @var EE_CPT_Base |
|
85 | + */ |
|
86 | + protected $_cpt_model_obj = false; |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
92 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
93 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
94 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
95 | + * |
|
96 | + * @var array() |
|
97 | + */ |
|
98 | + protected $_autosave_containers = array(); |
|
99 | + protected $_autosave_fields = array(); |
|
100 | + |
|
101 | + /** |
|
102 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
103 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
104 | + * |
|
105 | + * @var array |
|
106 | + */ |
|
107 | + protected $_pagenow_map; |
|
108 | + |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
113 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
114 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
115 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
116 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
117 | + * |
|
118 | + * @access protected |
|
119 | + * @abstract |
|
120 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
121 | + * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
130 | + * |
|
131 | + * @abstract |
|
132 | + * @access public |
|
133 | + * @param string $post_id The ID of the cpt that was trashed |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + abstract public function trash_cpt_item($post_id); |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
142 | + * |
|
143 | + * @param string $post_id theID of the cpt that was untrashed |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + abstract public function restore_cpt_item($post_id); |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
152 | + * from the db |
|
153 | + * |
|
154 | + * @param string $post_id the ID of the cpt that was deleted |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + abstract public function delete_cpt_item($post_id); |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
163 | + * |
|
164 | + * @access protected |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + protected function _before_page_setup() |
|
168 | + { |
|
169 | + $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
170 | + $this->_cpt_routes = array_merge(array( |
|
171 | + 'create_new' => $this->page_slug, |
|
172 | + 'edit' => $this->page_slug, |
|
173 | + 'trash' => $this->page_slug, |
|
174 | + ), $this->_cpt_routes); |
|
175 | + //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
176 | + $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
177 | + ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
178 | + : get_post_type_object($page); |
|
179 | + //tweak pagenow for page loading. |
|
180 | + if ( ! $this->_pagenow_map) { |
|
181 | + $this->_pagenow_map = array( |
|
182 | + 'create_new' => 'post-new.php', |
|
183 | + 'edit' => 'post.php', |
|
184 | + 'trash' => 'post.php', |
|
185 | + ); |
|
186 | + } |
|
187 | + add_action('current_screen', array($this, 'modify_pagenow')); |
|
188 | + //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
189 | + //get current page from autosave |
|
190 | + $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
191 | + ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
192 | + : null; |
|
193 | + $this->_current_page = isset($this->_req_data['current_page']) |
|
194 | + ? $this->_req_data['current_page'] |
|
195 | + : $current_page; |
|
196 | + //autosave... make sure its only for the correct page |
|
197 | + //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
198 | + //setup autosave ajax hook |
|
199 | + //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
200 | + //} |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
207 | + * |
|
208 | + * @param WP_Screen $current_screen |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function modify_pagenow($current_screen) |
|
212 | + { |
|
213 | + global $pagenow, $hook_suffix; |
|
214 | + //possibly reset pagenow. |
|
215 | + if ( ! empty($this->_req_data['page']) |
|
216 | + && $this->_req_data['page'] == $this->page_slug |
|
217 | + && ! empty($this->_req_data['action']) |
|
218 | + && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
219 | + ) { |
|
220 | + $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
221 | + $hook_suffix = $pagenow; |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
229 | + * |
|
230 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
231 | + * automatically register the id for the post metabox as a container. |
|
232 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
233 | + * you would send along the id of a metabox container. |
|
234 | + * @return void |
|
235 | + */ |
|
236 | + protected function _register_autosave_containers($ids) |
|
237 | + { |
|
238 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
245 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
246 | + */ |
|
247 | + protected function _set_autosave_containers() |
|
248 | + { |
|
249 | + global $wp_meta_boxes; |
|
250 | + $containers = array(); |
|
251 | + if (empty($wp_meta_boxes)) { |
|
252 | + return; |
|
253 | + } |
|
254 | + $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
255 | + foreach ($current_metaboxes as $box_context) { |
|
256 | + foreach ($box_context as $box_details) { |
|
257 | + foreach ($box_details as $box) { |
|
258 | + if ( |
|
259 | + is_array($box['callback']) |
|
260 | + && ( |
|
261 | + $box['callback'][0] instanceof EE_Admin_Page |
|
262 | + || $box['callback'][0] instanceof EE_Admin_Hooks |
|
263 | + ) |
|
264 | + ) { |
|
265 | + $containers[] = $box['id']; |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + } |
|
270 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
271 | + //add hidden inputs container |
|
272 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + protected function _load_autosave_scripts_styles() |
|
278 | + { |
|
279 | + /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
280 | 280 | wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2 |
281 | 281 | |
282 | - //filter _autosave_containers |
|
283 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
284 | - $this->_autosave_containers, $this); |
|
285 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
286 | - $containers, $this); |
|
287 | - |
|
288 | - wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
289 | - $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
290 | - |
|
291 | - $unsaved_data_msg = array( |
|
292 | - 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
293 | - 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
294 | - 'inputChanged' => 0, |
|
295 | - ); |
|
296 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - public function load_page_dependencies() |
|
302 | - { |
|
303 | - try { |
|
304 | - $this->_load_page_dependencies(); |
|
305 | - } catch (EE_Error $e) { |
|
306 | - $e->get_error(); |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
314 | - * |
|
315 | - * @access protected |
|
316 | - * @return void |
|
317 | - */ |
|
318 | - protected function _load_page_dependencies() |
|
319 | - { |
|
320 | - //we only add stuff if this is a cpt_route! |
|
321 | - if ( ! $this->_cpt_route) { |
|
322 | - parent::_load_page_dependencies(); |
|
323 | - return; |
|
324 | - } |
|
325 | - // now let's do some automatic filters into the wp_system |
|
326 | - // and we'll check to make sure the CHILD class |
|
327 | - // automatically has the required methods in place. |
|
328 | - // the following filters are for setting all the redirects |
|
329 | - // on DEFAULT WP custom post type actions |
|
330 | - // let's add a hidden input to the post-edit form |
|
331 | - // so we know when we have to trigger our custom redirects! |
|
332 | - // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
333 | - add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
334 | - // inject our Admin page nav tabs... |
|
335 | - // let's make sure the nav tabs are set if they aren't already |
|
336 | - // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
337 | - add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
338 | - // modify the post_updated messages array |
|
339 | - add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
340 | - // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
341 | - // cpts use the same format for shortlinks as posts! |
|
342 | - add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
343 | - // This basically allows us to change the title of the "publish" metabox area |
|
344 | - // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
345 | - if ( ! empty($this->_labels['publishbox'])) { |
|
346 | - $box_label = is_array($this->_labels['publishbox']) |
|
347 | - && isset($this->_labels['publishbox'][$this->_req_action]) |
|
348 | - ? $this->_labels['publishbox'][$this->_req_action] |
|
349 | - : $this->_labels['publishbox']; |
|
350 | - add_meta_box( |
|
351 | - 'submitdiv', |
|
352 | - $box_label, |
|
353 | - 'post_submit_meta_box', |
|
354 | - $this->_cpt_routes[$this->_req_action], |
|
355 | - 'side', |
|
356 | - 'core' |
|
357 | - ); |
|
358 | - } |
|
359 | - //let's add page_templates metabox if this cpt added support for it. |
|
360 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
361 | - add_meta_box( |
|
362 | - 'page_templates', |
|
363 | - __('Page Template', 'event_espresso'), |
|
364 | - array($this, 'page_template_meta_box'), |
|
365 | - $this->_cpt_routes[$this->_req_action], |
|
366 | - 'side', |
|
367 | - 'default' |
|
368 | - ); |
|
369 | - } |
|
370 | - //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
371 | - if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
372 | - add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
373 | - } |
|
374 | - //add preview button |
|
375 | - add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
376 | - //insert our own post_stati dropdown |
|
377 | - add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
378 | - //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
379 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
380 | - add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
381 | - } |
|
382 | - // This allows for adding additional stuff after the title field on the wp post edit form. |
|
383 | - // This is also before the wp_editor for post description field. |
|
384 | - if (method_exists($this, 'edit_form_after_title')) { |
|
385 | - add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
386 | - } |
|
387 | - /** |
|
388 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
389 | - */ |
|
390 | - add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
391 | - parent::_load_page_dependencies(); |
|
392 | - // notice we are ALSO going to load the pagenow hook set for this route |
|
393 | - // (see _before_page_setup for the reset of the pagenow global ). |
|
394 | - // This is for any plugins that are doing things properly |
|
395 | - // and hooking into the load page hook for core wp cpt routes. |
|
396 | - global $pagenow; |
|
397 | - do_action('load-' . $pagenow); |
|
398 | - $this->modify_current_screen(); |
|
399 | - add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
400 | - //we route REALLY early. |
|
401 | - try { |
|
402 | - $this->_route_admin_request(); |
|
403 | - } catch (EE_Error $e) { |
|
404 | - $e->get_error(); |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
412 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
413 | - * route instead. |
|
414 | - * |
|
415 | - * @param string $good_protocol_url The escaped url. |
|
416 | - * @param string $original_url The original url. |
|
417 | - * @param string $_context The context sent to the esc_url method. |
|
418 | - * @return string possibly a new url for our route. |
|
419 | - */ |
|
420 | - public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
421 | - { |
|
422 | - $routes_to_match = array( |
|
423 | - 0 => array( |
|
424 | - 'edit.php?post_type=espresso_attendees', |
|
425 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
426 | - ), |
|
427 | - 1 => array( |
|
428 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
429 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
430 | - ), |
|
431 | - ); |
|
432 | - foreach ($routes_to_match as $route_matches) { |
|
433 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
434 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
435 | - } |
|
436 | - } |
|
437 | - return $good_protocol_url; |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * Determine whether the current cpt supports page templates or not. |
|
444 | - * |
|
445 | - * @since %VER% |
|
446 | - * @param string $cpt_name The cpt slug we're checking on. |
|
447 | - * @return bool True supported, false not. |
|
448 | - */ |
|
449 | - private function _supports_page_templates($cpt_name) |
|
450 | - { |
|
451 | - |
|
452 | - $cpt_args = EE_Register_CPTs::get_CPTs(); |
|
453 | - $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
454 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
455 | - |
|
456 | - //if the installed version of WP is > 4.7 we do some additional checks. |
|
457 | - if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
458 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
459 | - //if there are $post_templates for this cpt, then we return false for this method because |
|
460 | - //that means we aren't going to load our page template manager and leave that up to the native |
|
461 | - //cpt template manager. |
|
462 | - $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
463 | - } |
|
464 | - |
|
465 | - return $cpt_has_support; |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * Callback for the page_templates metabox selector. |
|
471 | - * |
|
472 | - * @since %VER% |
|
473 | - * @return void |
|
474 | - */ |
|
475 | - public function page_template_meta_box() |
|
476 | - { |
|
477 | - global $post; |
|
478 | - $template = ''; |
|
479 | - |
|
480 | - if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
481 | - $page_template_count = count(get_page_templates()); |
|
482 | - } else { |
|
483 | - $page_template_count = count(get_page_templates($post)); |
|
484 | - }; |
|
485 | - |
|
486 | - if ($page_template_count) { |
|
487 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
488 | - $template = ! empty($page_template) ? $page_template : ''; |
|
489 | - } |
|
490 | - ?> |
|
282 | + //filter _autosave_containers |
|
283 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
284 | + $this->_autosave_containers, $this); |
|
285 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
286 | + $containers, $this); |
|
287 | + |
|
288 | + wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
289 | + $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
290 | + |
|
291 | + $unsaved_data_msg = array( |
|
292 | + 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
293 | + 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
294 | + 'inputChanged' => 0, |
|
295 | + ); |
|
296 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + public function load_page_dependencies() |
|
302 | + { |
|
303 | + try { |
|
304 | + $this->_load_page_dependencies(); |
|
305 | + } catch (EE_Error $e) { |
|
306 | + $e->get_error(); |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
314 | + * |
|
315 | + * @access protected |
|
316 | + * @return void |
|
317 | + */ |
|
318 | + protected function _load_page_dependencies() |
|
319 | + { |
|
320 | + //we only add stuff if this is a cpt_route! |
|
321 | + if ( ! $this->_cpt_route) { |
|
322 | + parent::_load_page_dependencies(); |
|
323 | + return; |
|
324 | + } |
|
325 | + // now let's do some automatic filters into the wp_system |
|
326 | + // and we'll check to make sure the CHILD class |
|
327 | + // automatically has the required methods in place. |
|
328 | + // the following filters are for setting all the redirects |
|
329 | + // on DEFAULT WP custom post type actions |
|
330 | + // let's add a hidden input to the post-edit form |
|
331 | + // so we know when we have to trigger our custom redirects! |
|
332 | + // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
333 | + add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
334 | + // inject our Admin page nav tabs... |
|
335 | + // let's make sure the nav tabs are set if they aren't already |
|
336 | + // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
337 | + add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
338 | + // modify the post_updated messages array |
|
339 | + add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
340 | + // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
341 | + // cpts use the same format for shortlinks as posts! |
|
342 | + add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
343 | + // This basically allows us to change the title of the "publish" metabox area |
|
344 | + // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
345 | + if ( ! empty($this->_labels['publishbox'])) { |
|
346 | + $box_label = is_array($this->_labels['publishbox']) |
|
347 | + && isset($this->_labels['publishbox'][$this->_req_action]) |
|
348 | + ? $this->_labels['publishbox'][$this->_req_action] |
|
349 | + : $this->_labels['publishbox']; |
|
350 | + add_meta_box( |
|
351 | + 'submitdiv', |
|
352 | + $box_label, |
|
353 | + 'post_submit_meta_box', |
|
354 | + $this->_cpt_routes[$this->_req_action], |
|
355 | + 'side', |
|
356 | + 'core' |
|
357 | + ); |
|
358 | + } |
|
359 | + //let's add page_templates metabox if this cpt added support for it. |
|
360 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
361 | + add_meta_box( |
|
362 | + 'page_templates', |
|
363 | + __('Page Template', 'event_espresso'), |
|
364 | + array($this, 'page_template_meta_box'), |
|
365 | + $this->_cpt_routes[$this->_req_action], |
|
366 | + 'side', |
|
367 | + 'default' |
|
368 | + ); |
|
369 | + } |
|
370 | + //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
371 | + if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
372 | + add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
373 | + } |
|
374 | + //add preview button |
|
375 | + add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
376 | + //insert our own post_stati dropdown |
|
377 | + add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
378 | + //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
379 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
380 | + add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
381 | + } |
|
382 | + // This allows for adding additional stuff after the title field on the wp post edit form. |
|
383 | + // This is also before the wp_editor for post description field. |
|
384 | + if (method_exists($this, 'edit_form_after_title')) { |
|
385 | + add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
386 | + } |
|
387 | + /** |
|
388 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
389 | + */ |
|
390 | + add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
391 | + parent::_load_page_dependencies(); |
|
392 | + // notice we are ALSO going to load the pagenow hook set for this route |
|
393 | + // (see _before_page_setup for the reset of the pagenow global ). |
|
394 | + // This is for any plugins that are doing things properly |
|
395 | + // and hooking into the load page hook for core wp cpt routes. |
|
396 | + global $pagenow; |
|
397 | + do_action('load-' . $pagenow); |
|
398 | + $this->modify_current_screen(); |
|
399 | + add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
400 | + //we route REALLY early. |
|
401 | + try { |
|
402 | + $this->_route_admin_request(); |
|
403 | + } catch (EE_Error $e) { |
|
404 | + $e->get_error(); |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
412 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
413 | + * route instead. |
|
414 | + * |
|
415 | + * @param string $good_protocol_url The escaped url. |
|
416 | + * @param string $original_url The original url. |
|
417 | + * @param string $_context The context sent to the esc_url method. |
|
418 | + * @return string possibly a new url for our route. |
|
419 | + */ |
|
420 | + public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
421 | + { |
|
422 | + $routes_to_match = array( |
|
423 | + 0 => array( |
|
424 | + 'edit.php?post_type=espresso_attendees', |
|
425 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
426 | + ), |
|
427 | + 1 => array( |
|
428 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
429 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
430 | + ), |
|
431 | + ); |
|
432 | + foreach ($routes_to_match as $route_matches) { |
|
433 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
434 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
435 | + } |
|
436 | + } |
|
437 | + return $good_protocol_url; |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * Determine whether the current cpt supports page templates or not. |
|
444 | + * |
|
445 | + * @since %VER% |
|
446 | + * @param string $cpt_name The cpt slug we're checking on. |
|
447 | + * @return bool True supported, false not. |
|
448 | + */ |
|
449 | + private function _supports_page_templates($cpt_name) |
|
450 | + { |
|
451 | + |
|
452 | + $cpt_args = EE_Register_CPTs::get_CPTs(); |
|
453 | + $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
454 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
455 | + |
|
456 | + //if the installed version of WP is > 4.7 we do some additional checks. |
|
457 | + if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
458 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
459 | + //if there are $post_templates for this cpt, then we return false for this method because |
|
460 | + //that means we aren't going to load our page template manager and leave that up to the native |
|
461 | + //cpt template manager. |
|
462 | + $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
463 | + } |
|
464 | + |
|
465 | + return $cpt_has_support; |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * Callback for the page_templates metabox selector. |
|
471 | + * |
|
472 | + * @since %VER% |
|
473 | + * @return void |
|
474 | + */ |
|
475 | + public function page_template_meta_box() |
|
476 | + { |
|
477 | + global $post; |
|
478 | + $template = ''; |
|
479 | + |
|
480 | + if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
481 | + $page_template_count = count(get_page_templates()); |
|
482 | + } else { |
|
483 | + $page_template_count = count(get_page_templates($post)); |
|
484 | + }; |
|
485 | + |
|
486 | + if ($page_template_count) { |
|
487 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
488 | + $template = ! empty($page_template) ? $page_template : ''; |
|
489 | + } |
|
490 | + ?> |
|
491 | 491 | <p><strong><?php _e('Template') ?></strong></p> |
492 | 492 | <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select |
493 | 493 | name="page_template" id="page_template"> |
@@ -495,450 +495,450 @@ discard block |
||
495 | 495 | <?php page_template_dropdown($template); ?> |
496 | 496 | </select> |
497 | 497 | <?php |
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
504 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
505 | - * |
|
506 | - * @param string $return the current html |
|
507 | - * @param int $id the post id for the page |
|
508 | - * @param string $new_title What the title is |
|
509 | - * @param string $new_slug what the slug is |
|
510 | - * @return string The new html string for the permalink area |
|
511 | - */ |
|
512 | - public function preview_button_html($return, $id, $new_title, $new_slug) |
|
513 | - { |
|
514 | - $post = get_post($id); |
|
515 | - if ('publish' !== get_post_status($post)) { |
|
516 | - //include shims for the `get_preview_post_link` function |
|
517 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
518 | - $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
519 | - . get_preview_post_link($id) |
|
520 | - . '" class="button button-small">' |
|
521 | - . __('Preview', 'event_espresso') |
|
522 | - . '</a></span>' |
|
523 | - . "\n"; |
|
524 | - } |
|
525 | - return $return; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * add our custom post stati dropdown on the wp post page for this cpt |
|
532 | - * |
|
533 | - * @return void |
|
534 | - */ |
|
535 | - public function custom_post_stati_dropdown() |
|
536 | - { |
|
537 | - |
|
538 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
539 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
540 | - ? $statuses[$this->_cpt_model_obj->status()] |
|
541 | - : ''; |
|
542 | - $template_args = array( |
|
543 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
544 | - 'statuses' => $statuses, |
|
545 | - 'cur_status_label' => $cur_status_label, |
|
546 | - 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
547 | - ); |
|
548 | - //we'll add a trash post status (WP doesn't add one for some reason) |
|
549 | - if ($this->_cpt_model_obj->status() === 'trash') { |
|
550 | - $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
551 | - $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
552 | - $template_args['statuses'] = $statuses; |
|
553 | - } |
|
554 | - |
|
555 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
556 | - EEH_Template::display_template($template, $template_args); |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - |
|
561 | - public function setup_autosave_hooks() |
|
562 | - { |
|
563 | - $this->_set_autosave_containers(); |
|
564 | - $this->_load_autosave_scripts_styles(); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
571 | - * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
572 | - * for the nonce in here, but then this method looks for two things: |
|
573 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
574 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
575 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
576 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
577 | - * template args. |
|
578 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
579 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
580 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
581 | - * $this->_template_args['data']['items'] = array( |
|
582 | - * 'event-datetime-ids' => '1,2,3'; |
|
583 | - * ); |
|
584 | - * Keep in mind the following things: |
|
585 | - * - "where" index is for the input with the id as that string. |
|
586 | - * - "what" index is what will be used for the value of that input. |
|
587 | - * |
|
588 | - * @return void |
|
589 | - */ |
|
590 | - public function do_extra_autosave_stuff() |
|
591 | - { |
|
592 | - //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
593 | - $nonce = isset($this->_req_data['autosavenonce']) |
|
594 | - ? $this->_req_data['autosavenonce'] |
|
595 | - : null; |
|
596 | - $this->_verify_nonce($nonce, 'autosave'); |
|
597 | - //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
598 | - if ( ! defined('DOING_AUTOSAVE')) { |
|
599 | - define('DOING_AUTOSAVE', true); |
|
600 | - } |
|
601 | - //if we made it here then the nonce checked out. Let's run our methods and actions |
|
602 | - $autosave = "_ee_autosave_{$this->_current_view}"; |
|
603 | - if (method_exists($this, $autosave)) { |
|
604 | - $this->$autosave(); |
|
605 | - } else { |
|
606 | - $this->_template_args['success'] = true; |
|
607 | - } |
|
608 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
609 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
610 | - //now let's return json |
|
611 | - $this->_return_json(); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
618 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
619 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
620 | - * |
|
621 | - * @access protected |
|
622 | - * @throws EE_Error |
|
623 | - * @return void |
|
624 | - */ |
|
625 | - protected function _extend_page_config_for_cpt() |
|
626 | - { |
|
627 | - //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
628 | - if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
629 | - return; |
|
630 | - } |
|
631 | - //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
632 | - if ( ! empty($this->_cpt_object)) { |
|
633 | - $this->_page_routes = array_merge(array( |
|
634 | - 'create_new' => '_create_new_cpt_item', |
|
635 | - 'edit' => '_edit_cpt_item', |
|
636 | - ), $this->_page_routes); |
|
637 | - $this->_page_config = array_merge(array( |
|
638 | - 'create_new' => array( |
|
639 | - 'nav' => array( |
|
640 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
641 | - 'order' => 5, |
|
642 | - ), |
|
643 | - 'require_nonce' => false, |
|
644 | - ), |
|
645 | - 'edit' => array( |
|
646 | - 'nav' => array( |
|
647 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
648 | - 'order' => 5, |
|
649 | - 'persistent' => false, |
|
650 | - 'url' => '', |
|
651 | - ), |
|
652 | - 'require_nonce' => false, |
|
653 | - ), |
|
654 | - ), |
|
655 | - $this->_page_config |
|
656 | - ); |
|
657 | - } |
|
658 | - //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
659 | - if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
660 | - return; |
|
661 | - } |
|
662 | - $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
663 | - //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
664 | - if (empty($this->_cpt_object)) { |
|
665 | - $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'), |
|
666 | - $this->page_slug, $this->_req_action, get_class($this)); |
|
667 | - throw new EE_Error($msg); |
|
668 | - } |
|
669 | - if ($this->_cpt_route) { |
|
670 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
671 | - $this->_set_model_object($id); |
|
672 | - } |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - |
|
677 | - /** |
|
678 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
679 | - * |
|
680 | - * @access protected |
|
681 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
682 | - * @param bool $ignore_route_check |
|
683 | - * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
684 | - * @throws EE_Error |
|
685 | - */ |
|
686 | - protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
687 | - { |
|
688 | - $model = null; |
|
689 | - if ( |
|
690 | - empty($this->_cpt_model_names) |
|
691 | - || ( |
|
692 | - ! $ignore_route_check |
|
693 | - && ! isset($this->_cpt_routes[$this->_req_action]) |
|
694 | - ) || ( |
|
695 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
696 | - && $this->_cpt_model_obj->ID() === $id |
|
697 | - ) |
|
698 | - ) { |
|
699 | - //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
700 | - return; |
|
701 | - } |
|
702 | - //if ignore_route_check is true, then get the model name via EE_Register_CPTs |
|
703 | - if ($ignore_route_check) { |
|
704 | - $model_names = EE_Register_CPTs::get_cpt_model_names(); |
|
705 | - $post_type = get_post_type($id); |
|
706 | - if (isset($model_names[$post_type])) { |
|
707 | - $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
708 | - } |
|
709 | - } else { |
|
710 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
711 | - } |
|
712 | - if ($model instanceof EEM_Base) { |
|
713 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
714 | - } |
|
715 | - do_action( |
|
716 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
717 | - $this->_cpt_model_obj, |
|
718 | - $req_type |
|
719 | - ); |
|
720 | - } |
|
721 | - |
|
722 | - |
|
723 | - |
|
724 | - /** |
|
725 | - * admin_init_global |
|
726 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
727 | - * This method executes for ALL EE Admin pages. |
|
728 | - * |
|
729 | - * @access public |
|
730 | - * @return void |
|
731 | - */ |
|
732 | - public function admin_init_global() |
|
733 | - { |
|
734 | - $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
735 | - //its possible this is a new save so let's catch that instead |
|
736 | - $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
737 | - $post_type = $post ? $post->post_type : false; |
|
738 | - $current_route = isset($this->_req_data['current_route']) |
|
739 | - ? $this->_req_data['current_route'] |
|
740 | - : 'shouldneverwork'; |
|
741 | - $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
742 | - ? $this->_cpt_routes[$current_route] |
|
743 | - : ''; |
|
744 | - add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
745 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
746 | - if ($post_type === $route_to_check) { |
|
747 | - add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
748 | - } |
|
749 | - //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
750 | - $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
751 | - if ( ! empty($revision)) { |
|
752 | - $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
753 | - //doing a restore? |
|
754 | - if ( ! empty($action) && $action === 'restore') { |
|
755 | - //get post for revision |
|
756 | - $rev_post = get_post($revision); |
|
757 | - $rev_parent = get_post($rev_post->post_parent); |
|
758 | - //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
759 | - if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
760 | - add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
761 | - //restores of revisions |
|
762 | - add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
763 | - } |
|
764 | - } |
|
765 | - } |
|
766 | - //NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
767 | - if ($post_type && $post_type === $route_to_check) { |
|
768 | - //$post_id, $post |
|
769 | - add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
770 | - //$post_id |
|
771 | - add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
772 | - add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
773 | - add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
774 | - add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
775 | - } |
|
776 | - } |
|
777 | - |
|
778 | - |
|
779 | - |
|
780 | - /** |
|
781 | - * Callback for the WordPress trashed_post hook. |
|
782 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
783 | - * |
|
784 | - * @param int $post_id |
|
785 | - * @throws \EE_Error |
|
786 | - */ |
|
787 | - public function before_trash_cpt_item($post_id) |
|
788 | - { |
|
789 | - $this->_set_model_object($post_id, true, 'trash'); |
|
790 | - //if our cpt object isn't existent then get out immediately. |
|
791 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
792 | - return; |
|
793 | - } |
|
794 | - $this->trash_cpt_item($post_id); |
|
795 | - } |
|
796 | - |
|
797 | - |
|
798 | - |
|
799 | - /** |
|
800 | - * Callback for the WordPress untrashed_post hook. |
|
801 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
802 | - * |
|
803 | - * @param $post_id |
|
804 | - * @throws \EE_Error |
|
805 | - */ |
|
806 | - public function before_restore_cpt_item($post_id) |
|
807 | - { |
|
808 | - $this->_set_model_object($post_id, true, 'restore'); |
|
809 | - //if our cpt object isn't existent then get out immediately. |
|
810 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
811 | - return; |
|
812 | - } |
|
813 | - $this->restore_cpt_item($post_id); |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - |
|
818 | - /** |
|
819 | - * Callback for the WordPress after_delete_post hook. |
|
820 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
821 | - * |
|
822 | - * @param $post_id |
|
823 | - * @throws \EE_Error |
|
824 | - */ |
|
825 | - public function before_delete_cpt_item($post_id) |
|
826 | - { |
|
827 | - $this->_set_model_object($post_id, true, 'delete'); |
|
828 | - //if our cpt object isn't existent then get out immediately. |
|
829 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
830 | - return; |
|
831 | - } |
|
832 | - $this->delete_cpt_item($post_id); |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - |
|
837 | - /** |
|
838 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
839 | - * accordingly. |
|
840 | - * |
|
841 | - * @access public |
|
842 | - * @throws EE_Error |
|
843 | - * @return void |
|
844 | - */ |
|
845 | - public function verify_cpt_object() |
|
846 | - { |
|
847 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
848 | - // verify event object |
|
849 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
850 | - throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
851 | - 'event_espresso'), $label)); |
|
852 | - } |
|
853 | - //if auto-draft then throw an error |
|
854 | - if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
855 | - EE_Error::overwrite_errors(); |
|
856 | - EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'), |
|
857 | - $label), __FILE__, __FUNCTION__, __LINE__); |
|
858 | - } |
|
859 | - } |
|
860 | - |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * admin_footer_scripts_global |
|
865 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
866 | - * will apply on ALL EE_Admin pages. |
|
867 | - * |
|
868 | - * @access public |
|
869 | - * @return void |
|
870 | - */ |
|
871 | - public function admin_footer_scripts_global() |
|
872 | - { |
|
873 | - $this->_add_admin_page_ajax_loading_img(); |
|
874 | - $this->_add_admin_page_overlay(); |
|
875 | - } |
|
876 | - |
|
877 | - |
|
878 | - |
|
879 | - /** |
|
880 | - * add in any global scripts for cpt routes |
|
881 | - * |
|
882 | - * @return void |
|
883 | - */ |
|
884 | - public function load_global_scripts_styles() |
|
885 | - { |
|
886 | - parent::load_global_scripts_styles(); |
|
887 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
888 | - //setup custom post status object for localize script but only if we've got a cpt object |
|
889 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
890 | - if ( ! empty($statuses)) { |
|
891 | - //get ALL statuses! |
|
892 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
893 | - //setup object |
|
894 | - $ee_cpt_statuses = array(); |
|
895 | - foreach ($statuses as $status => $label) { |
|
896 | - $ee_cpt_statuses[$status] = array( |
|
897 | - 'label' => $label, |
|
898 | - 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
899 | - ); |
|
900 | - } |
|
901 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
902 | - } |
|
903 | - } |
|
904 | - } |
|
905 | - |
|
906 | - |
|
907 | - |
|
908 | - /** |
|
909 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
910 | - * insert/updates |
|
911 | - * |
|
912 | - * @param int $post_id ID of post being updated |
|
913 | - * @param WP_Post $post Post object from WP |
|
914 | - * @param bool $update Whether this is an update or a new save. |
|
915 | - * @return void |
|
916 | - * @throws \EE_Error |
|
917 | - */ |
|
918 | - public function insert_update($post_id, $post, $update) |
|
919 | - { |
|
920 | - //make sure that if this is a revision OR trash action that we don't do any updates! |
|
921 | - if ( |
|
922 | - isset($this->_req_data['action']) |
|
923 | - && ( |
|
924 | - $this->_req_data['action'] === 'restore' |
|
925 | - || $this->_req_data['action'] === 'trash' |
|
926 | - ) |
|
927 | - ) { |
|
928 | - return; |
|
929 | - } |
|
930 | - $this->_set_model_object($post_id, true, 'insert_update'); |
|
931 | - //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
932 | - if ($update |
|
933 | - && ( |
|
934 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
935 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
936 | - ) |
|
937 | - ) { |
|
938 | - return; |
|
939 | - } |
|
940 | - //check for autosave and update our req_data property accordingly. |
|
941 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
504 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
505 | + * |
|
506 | + * @param string $return the current html |
|
507 | + * @param int $id the post id for the page |
|
508 | + * @param string $new_title What the title is |
|
509 | + * @param string $new_slug what the slug is |
|
510 | + * @return string The new html string for the permalink area |
|
511 | + */ |
|
512 | + public function preview_button_html($return, $id, $new_title, $new_slug) |
|
513 | + { |
|
514 | + $post = get_post($id); |
|
515 | + if ('publish' !== get_post_status($post)) { |
|
516 | + //include shims for the `get_preview_post_link` function |
|
517 | + require_once( EE_CORE . 'wordpress-shims.php' ); |
|
518 | + $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
519 | + . get_preview_post_link($id) |
|
520 | + . '" class="button button-small">' |
|
521 | + . __('Preview', 'event_espresso') |
|
522 | + . '</a></span>' |
|
523 | + . "\n"; |
|
524 | + } |
|
525 | + return $return; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * add our custom post stati dropdown on the wp post page for this cpt |
|
532 | + * |
|
533 | + * @return void |
|
534 | + */ |
|
535 | + public function custom_post_stati_dropdown() |
|
536 | + { |
|
537 | + |
|
538 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
539 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
540 | + ? $statuses[$this->_cpt_model_obj->status()] |
|
541 | + : ''; |
|
542 | + $template_args = array( |
|
543 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
544 | + 'statuses' => $statuses, |
|
545 | + 'cur_status_label' => $cur_status_label, |
|
546 | + 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
547 | + ); |
|
548 | + //we'll add a trash post status (WP doesn't add one for some reason) |
|
549 | + if ($this->_cpt_model_obj->status() === 'trash') { |
|
550 | + $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
551 | + $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
552 | + $template_args['statuses'] = $statuses; |
|
553 | + } |
|
554 | + |
|
555 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
556 | + EEH_Template::display_template($template, $template_args); |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + |
|
561 | + public function setup_autosave_hooks() |
|
562 | + { |
|
563 | + $this->_set_autosave_containers(); |
|
564 | + $this->_load_autosave_scripts_styles(); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
571 | + * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
572 | + * for the nonce in here, but then this method looks for two things: |
|
573 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
574 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
575 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
576 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
577 | + * template args. |
|
578 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
579 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
580 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
581 | + * $this->_template_args['data']['items'] = array( |
|
582 | + * 'event-datetime-ids' => '1,2,3'; |
|
583 | + * ); |
|
584 | + * Keep in mind the following things: |
|
585 | + * - "where" index is for the input with the id as that string. |
|
586 | + * - "what" index is what will be used for the value of that input. |
|
587 | + * |
|
588 | + * @return void |
|
589 | + */ |
|
590 | + public function do_extra_autosave_stuff() |
|
591 | + { |
|
592 | + //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
593 | + $nonce = isset($this->_req_data['autosavenonce']) |
|
594 | + ? $this->_req_data['autosavenonce'] |
|
595 | + : null; |
|
596 | + $this->_verify_nonce($nonce, 'autosave'); |
|
597 | + //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
598 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
599 | + define('DOING_AUTOSAVE', true); |
|
600 | + } |
|
601 | + //if we made it here then the nonce checked out. Let's run our methods and actions |
|
602 | + $autosave = "_ee_autosave_{$this->_current_view}"; |
|
603 | + if (method_exists($this, $autosave)) { |
|
604 | + $this->$autosave(); |
|
605 | + } else { |
|
606 | + $this->_template_args['success'] = true; |
|
607 | + } |
|
608 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
609 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
610 | + //now let's return json |
|
611 | + $this->_return_json(); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
618 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
619 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
620 | + * |
|
621 | + * @access protected |
|
622 | + * @throws EE_Error |
|
623 | + * @return void |
|
624 | + */ |
|
625 | + protected function _extend_page_config_for_cpt() |
|
626 | + { |
|
627 | + //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
628 | + if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
629 | + return; |
|
630 | + } |
|
631 | + //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
632 | + if ( ! empty($this->_cpt_object)) { |
|
633 | + $this->_page_routes = array_merge(array( |
|
634 | + 'create_new' => '_create_new_cpt_item', |
|
635 | + 'edit' => '_edit_cpt_item', |
|
636 | + ), $this->_page_routes); |
|
637 | + $this->_page_config = array_merge(array( |
|
638 | + 'create_new' => array( |
|
639 | + 'nav' => array( |
|
640 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
641 | + 'order' => 5, |
|
642 | + ), |
|
643 | + 'require_nonce' => false, |
|
644 | + ), |
|
645 | + 'edit' => array( |
|
646 | + 'nav' => array( |
|
647 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
648 | + 'order' => 5, |
|
649 | + 'persistent' => false, |
|
650 | + 'url' => '', |
|
651 | + ), |
|
652 | + 'require_nonce' => false, |
|
653 | + ), |
|
654 | + ), |
|
655 | + $this->_page_config |
|
656 | + ); |
|
657 | + } |
|
658 | + //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
659 | + if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
660 | + return; |
|
661 | + } |
|
662 | + $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
663 | + //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
664 | + if (empty($this->_cpt_object)) { |
|
665 | + $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'), |
|
666 | + $this->page_slug, $this->_req_action, get_class($this)); |
|
667 | + throw new EE_Error($msg); |
|
668 | + } |
|
669 | + if ($this->_cpt_route) { |
|
670 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
671 | + $this->_set_model_object($id); |
|
672 | + } |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + |
|
677 | + /** |
|
678 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
679 | + * |
|
680 | + * @access protected |
|
681 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
682 | + * @param bool $ignore_route_check |
|
683 | + * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
684 | + * @throws EE_Error |
|
685 | + */ |
|
686 | + protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
687 | + { |
|
688 | + $model = null; |
|
689 | + if ( |
|
690 | + empty($this->_cpt_model_names) |
|
691 | + || ( |
|
692 | + ! $ignore_route_check |
|
693 | + && ! isset($this->_cpt_routes[$this->_req_action]) |
|
694 | + ) || ( |
|
695 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
696 | + && $this->_cpt_model_obj->ID() === $id |
|
697 | + ) |
|
698 | + ) { |
|
699 | + //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
700 | + return; |
|
701 | + } |
|
702 | + //if ignore_route_check is true, then get the model name via EE_Register_CPTs |
|
703 | + if ($ignore_route_check) { |
|
704 | + $model_names = EE_Register_CPTs::get_cpt_model_names(); |
|
705 | + $post_type = get_post_type($id); |
|
706 | + if (isset($model_names[$post_type])) { |
|
707 | + $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
708 | + } |
|
709 | + } else { |
|
710 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
711 | + } |
|
712 | + if ($model instanceof EEM_Base) { |
|
713 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
714 | + } |
|
715 | + do_action( |
|
716 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
717 | + $this->_cpt_model_obj, |
|
718 | + $req_type |
|
719 | + ); |
|
720 | + } |
|
721 | + |
|
722 | + |
|
723 | + |
|
724 | + /** |
|
725 | + * admin_init_global |
|
726 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
727 | + * This method executes for ALL EE Admin pages. |
|
728 | + * |
|
729 | + * @access public |
|
730 | + * @return void |
|
731 | + */ |
|
732 | + public function admin_init_global() |
|
733 | + { |
|
734 | + $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
735 | + //its possible this is a new save so let's catch that instead |
|
736 | + $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
737 | + $post_type = $post ? $post->post_type : false; |
|
738 | + $current_route = isset($this->_req_data['current_route']) |
|
739 | + ? $this->_req_data['current_route'] |
|
740 | + : 'shouldneverwork'; |
|
741 | + $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
742 | + ? $this->_cpt_routes[$current_route] |
|
743 | + : ''; |
|
744 | + add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
745 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
746 | + if ($post_type === $route_to_check) { |
|
747 | + add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
748 | + } |
|
749 | + //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
750 | + $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
751 | + if ( ! empty($revision)) { |
|
752 | + $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
753 | + //doing a restore? |
|
754 | + if ( ! empty($action) && $action === 'restore') { |
|
755 | + //get post for revision |
|
756 | + $rev_post = get_post($revision); |
|
757 | + $rev_parent = get_post($rev_post->post_parent); |
|
758 | + //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
759 | + if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
760 | + add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
761 | + //restores of revisions |
|
762 | + add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
763 | + } |
|
764 | + } |
|
765 | + } |
|
766 | + //NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
767 | + if ($post_type && $post_type === $route_to_check) { |
|
768 | + //$post_id, $post |
|
769 | + add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
770 | + //$post_id |
|
771 | + add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
772 | + add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
773 | + add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
774 | + add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
775 | + } |
|
776 | + } |
|
777 | + |
|
778 | + |
|
779 | + |
|
780 | + /** |
|
781 | + * Callback for the WordPress trashed_post hook. |
|
782 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
783 | + * |
|
784 | + * @param int $post_id |
|
785 | + * @throws \EE_Error |
|
786 | + */ |
|
787 | + public function before_trash_cpt_item($post_id) |
|
788 | + { |
|
789 | + $this->_set_model_object($post_id, true, 'trash'); |
|
790 | + //if our cpt object isn't existent then get out immediately. |
|
791 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
792 | + return; |
|
793 | + } |
|
794 | + $this->trash_cpt_item($post_id); |
|
795 | + } |
|
796 | + |
|
797 | + |
|
798 | + |
|
799 | + /** |
|
800 | + * Callback for the WordPress untrashed_post hook. |
|
801 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
802 | + * |
|
803 | + * @param $post_id |
|
804 | + * @throws \EE_Error |
|
805 | + */ |
|
806 | + public function before_restore_cpt_item($post_id) |
|
807 | + { |
|
808 | + $this->_set_model_object($post_id, true, 'restore'); |
|
809 | + //if our cpt object isn't existent then get out immediately. |
|
810 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
811 | + return; |
|
812 | + } |
|
813 | + $this->restore_cpt_item($post_id); |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + |
|
818 | + /** |
|
819 | + * Callback for the WordPress after_delete_post hook. |
|
820 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
821 | + * |
|
822 | + * @param $post_id |
|
823 | + * @throws \EE_Error |
|
824 | + */ |
|
825 | + public function before_delete_cpt_item($post_id) |
|
826 | + { |
|
827 | + $this->_set_model_object($post_id, true, 'delete'); |
|
828 | + //if our cpt object isn't existent then get out immediately. |
|
829 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
830 | + return; |
|
831 | + } |
|
832 | + $this->delete_cpt_item($post_id); |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + |
|
837 | + /** |
|
838 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
839 | + * accordingly. |
|
840 | + * |
|
841 | + * @access public |
|
842 | + * @throws EE_Error |
|
843 | + * @return void |
|
844 | + */ |
|
845 | + public function verify_cpt_object() |
|
846 | + { |
|
847 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
848 | + // verify event object |
|
849 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
850 | + throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
851 | + 'event_espresso'), $label)); |
|
852 | + } |
|
853 | + //if auto-draft then throw an error |
|
854 | + if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
855 | + EE_Error::overwrite_errors(); |
|
856 | + EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'), |
|
857 | + $label), __FILE__, __FUNCTION__, __LINE__); |
|
858 | + } |
|
859 | + } |
|
860 | + |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * admin_footer_scripts_global |
|
865 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
866 | + * will apply on ALL EE_Admin pages. |
|
867 | + * |
|
868 | + * @access public |
|
869 | + * @return void |
|
870 | + */ |
|
871 | + public function admin_footer_scripts_global() |
|
872 | + { |
|
873 | + $this->_add_admin_page_ajax_loading_img(); |
|
874 | + $this->_add_admin_page_overlay(); |
|
875 | + } |
|
876 | + |
|
877 | + |
|
878 | + |
|
879 | + /** |
|
880 | + * add in any global scripts for cpt routes |
|
881 | + * |
|
882 | + * @return void |
|
883 | + */ |
|
884 | + public function load_global_scripts_styles() |
|
885 | + { |
|
886 | + parent::load_global_scripts_styles(); |
|
887 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
888 | + //setup custom post status object for localize script but only if we've got a cpt object |
|
889 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
890 | + if ( ! empty($statuses)) { |
|
891 | + //get ALL statuses! |
|
892 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
893 | + //setup object |
|
894 | + $ee_cpt_statuses = array(); |
|
895 | + foreach ($statuses as $status => $label) { |
|
896 | + $ee_cpt_statuses[$status] = array( |
|
897 | + 'label' => $label, |
|
898 | + 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
899 | + ); |
|
900 | + } |
|
901 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
902 | + } |
|
903 | + } |
|
904 | + } |
|
905 | + |
|
906 | + |
|
907 | + |
|
908 | + /** |
|
909 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
910 | + * insert/updates |
|
911 | + * |
|
912 | + * @param int $post_id ID of post being updated |
|
913 | + * @param WP_Post $post Post object from WP |
|
914 | + * @param bool $update Whether this is an update or a new save. |
|
915 | + * @return void |
|
916 | + * @throws \EE_Error |
|
917 | + */ |
|
918 | + public function insert_update($post_id, $post, $update) |
|
919 | + { |
|
920 | + //make sure that if this is a revision OR trash action that we don't do any updates! |
|
921 | + if ( |
|
922 | + isset($this->_req_data['action']) |
|
923 | + && ( |
|
924 | + $this->_req_data['action'] === 'restore' |
|
925 | + || $this->_req_data['action'] === 'trash' |
|
926 | + ) |
|
927 | + ) { |
|
928 | + return; |
|
929 | + } |
|
930 | + $this->_set_model_object($post_id, true, 'insert_update'); |
|
931 | + //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
932 | + if ($update |
|
933 | + && ( |
|
934 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
935 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
936 | + ) |
|
937 | + ) { |
|
938 | + return; |
|
939 | + } |
|
940 | + //check for autosave and update our req_data property accordingly. |
|
941 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
942 | 942 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
943 | 943 | |
944 | 944 | foreach ( (array) $values as $key => $value ) { |
@@ -948,527 +948,527 @@ discard block |
||
948 | 948 | |
949 | 949 | }/**/ //TODO reactivate after autosave is implemented in 4.2 |
950 | 950 | |
951 | - //take care of updating any selected page_template IF this cpt supports it. |
|
952 | - if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
953 | - //wp version aware. |
|
954 | - if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) { |
|
955 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
956 | - } else { |
|
957 | - $post->page_template = $this->_req_data['page_template']; |
|
958 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
959 | - } |
|
960 | - if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
961 | - EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
962 | - } else { |
|
963 | - update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
964 | - } |
|
965 | - } |
|
966 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
967 | - return; |
|
968 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
969 | - $this->_insert_update_cpt_item($post_id, $post); |
|
970 | - } |
|
971 | - |
|
972 | - |
|
973 | - |
|
974 | - /** |
|
975 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
976 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
977 | - * so we don't have to check for our CPT. |
|
978 | - * |
|
979 | - * @param int $post_id ID of the post |
|
980 | - * @return void |
|
981 | - */ |
|
982 | - public function dont_permanently_delete_ee_cpts($post_id) |
|
983 | - { |
|
984 | - //only do this if we're actually processing one of our CPTs |
|
985 | - //if our cpt object isn't existent then get out immediately. |
|
986 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
987 | - return; |
|
988 | - } |
|
989 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
990 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
991 | - //our cpts may have comments so let's take care of that too |
|
992 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
993 | - } |
|
994 | - |
|
995 | - |
|
996 | - |
|
997 | - /** |
|
998 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
999 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1000 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1001 | - * |
|
1002 | - * @param int $post_id ID of cpt item |
|
1003 | - * @param int $revision_id ID of revision being restored |
|
1004 | - * @return void |
|
1005 | - */ |
|
1006 | - public function restore_revision($post_id, $revision_id) |
|
1007 | - { |
|
1008 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
1009 | - //global action |
|
1010 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1011 | - //class specific action so you can limit hooking into a specific page. |
|
1012 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1013 | - } |
|
1014 | - |
|
1015 | - |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * @see restore_revision() for details |
|
1019 | - * @param int $post_id ID of cpt item |
|
1020 | - * @param int $revision_id ID of revision for item |
|
1021 | - * @return void |
|
1022 | - */ |
|
1023 | - abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1024 | - |
|
1025 | - |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1029 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1030 | - * To fix we have to reset the current_screen using the page_slug |
|
1031 | - * (which is identical - or should be - to our registered_post_type id.) |
|
1032 | - * Also, since the core WP file loads the admin_header.php for WP |
|
1033 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1034 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1035 | - * |
|
1036 | - * @return void |
|
1037 | - */ |
|
1038 | - public function modify_current_screen() |
|
1039 | - { |
|
1040 | - //ONLY do this if the current page_route IS a cpt route |
|
1041 | - if ( ! $this->_cpt_route) { |
|
1042 | - return; |
|
1043 | - } |
|
1044 | - //routing things REALLY early b/c this is a cpt admin page |
|
1045 | - set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1046 | - $this->_current_screen = get_current_screen(); |
|
1047 | - $this->_current_screen->base = 'event-espresso'; |
|
1048 | - $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
1049 | - /*try { |
|
951 | + //take care of updating any selected page_template IF this cpt supports it. |
|
952 | + if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
953 | + //wp version aware. |
|
954 | + if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) { |
|
955 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
956 | + } else { |
|
957 | + $post->page_template = $this->_req_data['page_template']; |
|
958 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
959 | + } |
|
960 | + if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
961 | + EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
962 | + } else { |
|
963 | + update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
964 | + } |
|
965 | + } |
|
966 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
967 | + return; |
|
968 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
969 | + $this->_insert_update_cpt_item($post_id, $post); |
|
970 | + } |
|
971 | + |
|
972 | + |
|
973 | + |
|
974 | + /** |
|
975 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
976 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
977 | + * so we don't have to check for our CPT. |
|
978 | + * |
|
979 | + * @param int $post_id ID of the post |
|
980 | + * @return void |
|
981 | + */ |
|
982 | + public function dont_permanently_delete_ee_cpts($post_id) |
|
983 | + { |
|
984 | + //only do this if we're actually processing one of our CPTs |
|
985 | + //if our cpt object isn't existent then get out immediately. |
|
986 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
987 | + return; |
|
988 | + } |
|
989 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
990 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
991 | + //our cpts may have comments so let's take care of that too |
|
992 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
993 | + } |
|
994 | + |
|
995 | + |
|
996 | + |
|
997 | + /** |
|
998 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
999 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1000 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1001 | + * |
|
1002 | + * @param int $post_id ID of cpt item |
|
1003 | + * @param int $revision_id ID of revision being restored |
|
1004 | + * @return void |
|
1005 | + */ |
|
1006 | + public function restore_revision($post_id, $revision_id) |
|
1007 | + { |
|
1008 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
1009 | + //global action |
|
1010 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1011 | + //class specific action so you can limit hooking into a specific page. |
|
1012 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1013 | + } |
|
1014 | + |
|
1015 | + |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * @see restore_revision() for details |
|
1019 | + * @param int $post_id ID of cpt item |
|
1020 | + * @param int $revision_id ID of revision for item |
|
1021 | + * @return void |
|
1022 | + */ |
|
1023 | + abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1024 | + |
|
1025 | + |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1029 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1030 | + * To fix we have to reset the current_screen using the page_slug |
|
1031 | + * (which is identical - or should be - to our registered_post_type id.) |
|
1032 | + * Also, since the core WP file loads the admin_header.php for WP |
|
1033 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1034 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1035 | + * |
|
1036 | + * @return void |
|
1037 | + */ |
|
1038 | + public function modify_current_screen() |
|
1039 | + { |
|
1040 | + //ONLY do this if the current page_route IS a cpt route |
|
1041 | + if ( ! $this->_cpt_route) { |
|
1042 | + return; |
|
1043 | + } |
|
1044 | + //routing things REALLY early b/c this is a cpt admin page |
|
1045 | + set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1046 | + $this->_current_screen = get_current_screen(); |
|
1047 | + $this->_current_screen->base = 'event-espresso'; |
|
1048 | + $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
1049 | + /*try { |
|
1050 | 1050 | $this->_route_admin_request(); |
1051 | 1051 | } catch ( EE_Error $e ) { |
1052 | 1052 | $e->get_error(); |
1053 | 1053 | }/**/ |
1054 | - } |
|
1055 | - |
|
1056 | - |
|
1057 | - |
|
1058 | - /** |
|
1059 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1060 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1061 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1062 | - * default to be. |
|
1063 | - * |
|
1064 | - * @param string $title The new title (or existing if there is no editor_title defined) |
|
1065 | - * @return string |
|
1066 | - */ |
|
1067 | - public function add_custom_editor_default_title($title) |
|
1068 | - { |
|
1069 | - return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1070 | - ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1071 | - : $title; |
|
1072 | - } |
|
1073 | - |
|
1074 | - |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1078 | - * |
|
1079 | - * @param string $shortlink The already generated shortlink |
|
1080 | - * @param int $id Post ID for this item |
|
1081 | - * @param string $context The context for the link |
|
1082 | - * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1083 | - * @return string |
|
1084 | - */ |
|
1085 | - public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1086 | - { |
|
1087 | - if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1088 | - $post = get_post($id); |
|
1089 | - if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1090 | - $shortlink = home_url('?p=' . $post->ID); |
|
1091 | - } |
|
1092 | - } |
|
1093 | - return $shortlink; |
|
1094 | - } |
|
1095 | - |
|
1096 | - |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1100 | - * already run in modify_current_screen()) |
|
1101 | - * |
|
1102 | - * @return void |
|
1103 | - */ |
|
1104 | - public function route_admin_request() |
|
1105 | - { |
|
1106 | - if ($this->_cpt_route) { |
|
1107 | - return; |
|
1108 | - } |
|
1109 | - try { |
|
1110 | - $this->_route_admin_request(); |
|
1111 | - } catch (EE_Error $e) { |
|
1112 | - $e->get_error(); |
|
1113 | - } |
|
1114 | - } |
|
1115 | - |
|
1116 | - |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1120 | - * |
|
1121 | - * @return void |
|
1122 | - */ |
|
1123 | - public function cpt_post_form_hidden_input() |
|
1124 | - { |
|
1125 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1126 | - //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1127 | - echo '<div id="ee-cpt-hidden-inputs">'; |
|
1128 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1129 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1130 | - echo '</div>'; |
|
1131 | - } |
|
1132 | - |
|
1133 | - |
|
1134 | - |
|
1135 | - /** |
|
1136 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1137 | - * |
|
1138 | - * @param string $location Original location url |
|
1139 | - * @param int $status Status for http header |
|
1140 | - * @return string new (or original) url to redirect to. |
|
1141 | - */ |
|
1142 | - public function revision_redirect($location, $status) |
|
1143 | - { |
|
1144 | - //get revision |
|
1145 | - $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1146 | - //can't do anything without revision so let's get out if not present |
|
1147 | - if (empty($rev_id)) { |
|
1148 | - return $location; |
|
1149 | - } |
|
1150 | - //get rev_post_data |
|
1151 | - $rev = get_post($rev_id); |
|
1152 | - $admin_url = $this->_admin_base_url; |
|
1153 | - $query_args = array( |
|
1154 | - 'action' => 'edit', |
|
1155 | - 'post' => $rev->post_parent, |
|
1156 | - 'revision' => $rev_id, |
|
1157 | - 'message' => 5, |
|
1158 | - ); |
|
1159 | - $this->_process_notices($query_args, true); |
|
1160 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1161 | - } |
|
1162 | - |
|
1163 | - |
|
1164 | - |
|
1165 | - /** |
|
1166 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1167 | - * |
|
1168 | - * @param string $link the original generated link |
|
1169 | - * @param int $id post id |
|
1170 | - * @param string $context optional, defaults to display. How to write the '&' |
|
1171 | - * @return string the link |
|
1172 | - */ |
|
1173 | - public function modify_edit_post_link($link, $id, $context) |
|
1174 | - { |
|
1175 | - $post = get_post($id); |
|
1176 | - if ( ! isset($this->_req_data['action']) |
|
1177 | - || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1178 | - || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1179 | - ) { |
|
1180 | - return $link; |
|
1181 | - } |
|
1182 | - $query_args = array( |
|
1183 | - 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1184 | - ? $this->_cpt_edit_routes[$post->post_type] |
|
1185 | - : 'edit', |
|
1186 | - 'post' => $id, |
|
1187 | - ); |
|
1188 | - return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1189 | - } |
|
1190 | - |
|
1191 | - |
|
1192 | - /** |
|
1193 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1194 | - * our routes. |
|
1195 | - * |
|
1196 | - * @param string $delete_link original delete link |
|
1197 | - * @param int $post_id id of cpt object |
|
1198 | - * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1199 | - * @return string new delete link |
|
1200 | - * @throws EE_Error |
|
1201 | - */ |
|
1202 | - public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1203 | - { |
|
1204 | - $post = get_post($post_id); |
|
1205 | - |
|
1206 | - if (empty($this->_req_data['action']) |
|
1207 | - || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1208 | - || ! $post instanceof WP_Post |
|
1209 | - || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1210 | - ) { |
|
1211 | - return $delete_link; |
|
1212 | - } |
|
1213 | - $this->_set_model_object($post->ID, true); |
|
1214 | - |
|
1215 | - //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1216 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1217 | - |
|
1218 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
1219 | - array( |
|
1220 | - 'page' => $this->_req_data['page'], |
|
1221 | - 'action' => $action, |
|
1222 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1223 | - => $post->ID |
|
1224 | - ), |
|
1225 | - admin_url() |
|
1226 | - ); |
|
1227 | - } |
|
1228 | - |
|
1229 | - |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1233 | - * so that we can hijack the default redirect locations for wp custom post types |
|
1234 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1235 | - * |
|
1236 | - * @param string $location This is the incoming currently set redirect location |
|
1237 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1238 | - * @return string the new location to redirect to |
|
1239 | - */ |
|
1240 | - public function cpt_post_location_redirect($location, $post_id) |
|
1241 | - { |
|
1242 | - //we DO have a match so let's setup the url |
|
1243 | - //we have to get the post to determine our route |
|
1244 | - $post = get_post($post_id); |
|
1245 | - $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1246 | - //shared query_args |
|
1247 | - $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1248 | - $admin_url = $this->_admin_base_url; |
|
1249 | - if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1250 | - $status = get_post_status($post_id); |
|
1251 | - if (isset($this->_req_data['publish'])) { |
|
1252 | - switch ($status) { |
|
1253 | - case 'pending': |
|
1254 | - $message = 8; |
|
1255 | - break; |
|
1256 | - case 'future': |
|
1257 | - $message = 9; |
|
1258 | - break; |
|
1259 | - default: |
|
1260 | - $message = 6; |
|
1261 | - } |
|
1262 | - } else { |
|
1263 | - $message = 'draft' === $status ? 10 : 1; |
|
1264 | - } |
|
1265 | - } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1266 | - $message = 2; |
|
1267 | - // $append = '#postcustom'; |
|
1268 | - } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1269 | - $message = 3; |
|
1270 | - // $append = '#postcustom'; |
|
1271 | - } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1272 | - $message = 7; |
|
1273 | - } else { |
|
1274 | - $message = 4; |
|
1275 | - } |
|
1276 | - //change the message if the post type is not viewable on the frontend |
|
1277 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
1278 | - $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1279 | - $query_args = array_merge(array('message' => $message), $query_args); |
|
1280 | - $this->_process_notices($query_args, true); |
|
1281 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1282 | - } |
|
1283 | - |
|
1284 | - |
|
1285 | - |
|
1286 | - /** |
|
1287 | - * This method is called to inject nav tabs on core WP cpt pages |
|
1288 | - * |
|
1289 | - * @access public |
|
1290 | - * @return void |
|
1291 | - */ |
|
1292 | - public function inject_nav_tabs() |
|
1293 | - { |
|
1294 | - //can we hijack and insert the nav_tabs? |
|
1295 | - $nav_tabs = $this->_get_main_nav_tabs(); |
|
1296 | - //first close off existing form tag |
|
1297 | - $html = '>'; |
|
1298 | - $html .= $nav_tabs; |
|
1299 | - //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1300 | - $html .= '<span></span'; |
|
1301 | - echo $html; |
|
1302 | - } |
|
1303 | - |
|
1304 | - |
|
1305 | - |
|
1306 | - /** |
|
1307 | - * This just sets up the post update messages when an update form is loaded |
|
1308 | - * |
|
1309 | - * @access public |
|
1310 | - * @param array $messages the original messages array |
|
1311 | - * @return array the new messages array |
|
1312 | - */ |
|
1313 | - public function post_update_messages($messages) |
|
1314 | - { |
|
1315 | - global $post; |
|
1316 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1317 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1318 | - // $post_type = $post ? $post->post_type : false; |
|
1319 | - /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1054 | + } |
|
1055 | + |
|
1056 | + |
|
1057 | + |
|
1058 | + /** |
|
1059 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1060 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1061 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1062 | + * default to be. |
|
1063 | + * |
|
1064 | + * @param string $title The new title (or existing if there is no editor_title defined) |
|
1065 | + * @return string |
|
1066 | + */ |
|
1067 | + public function add_custom_editor_default_title($title) |
|
1068 | + { |
|
1069 | + return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1070 | + ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1071 | + : $title; |
|
1072 | + } |
|
1073 | + |
|
1074 | + |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1078 | + * |
|
1079 | + * @param string $shortlink The already generated shortlink |
|
1080 | + * @param int $id Post ID for this item |
|
1081 | + * @param string $context The context for the link |
|
1082 | + * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1083 | + * @return string |
|
1084 | + */ |
|
1085 | + public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1086 | + { |
|
1087 | + if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1088 | + $post = get_post($id); |
|
1089 | + if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1090 | + $shortlink = home_url('?p=' . $post->ID); |
|
1091 | + } |
|
1092 | + } |
|
1093 | + return $shortlink; |
|
1094 | + } |
|
1095 | + |
|
1096 | + |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1100 | + * already run in modify_current_screen()) |
|
1101 | + * |
|
1102 | + * @return void |
|
1103 | + */ |
|
1104 | + public function route_admin_request() |
|
1105 | + { |
|
1106 | + if ($this->_cpt_route) { |
|
1107 | + return; |
|
1108 | + } |
|
1109 | + try { |
|
1110 | + $this->_route_admin_request(); |
|
1111 | + } catch (EE_Error $e) { |
|
1112 | + $e->get_error(); |
|
1113 | + } |
|
1114 | + } |
|
1115 | + |
|
1116 | + |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1120 | + * |
|
1121 | + * @return void |
|
1122 | + */ |
|
1123 | + public function cpt_post_form_hidden_input() |
|
1124 | + { |
|
1125 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1126 | + //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1127 | + echo '<div id="ee-cpt-hidden-inputs">'; |
|
1128 | + echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1129 | + echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1130 | + echo '</div>'; |
|
1131 | + } |
|
1132 | + |
|
1133 | + |
|
1134 | + |
|
1135 | + /** |
|
1136 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1137 | + * |
|
1138 | + * @param string $location Original location url |
|
1139 | + * @param int $status Status for http header |
|
1140 | + * @return string new (or original) url to redirect to. |
|
1141 | + */ |
|
1142 | + public function revision_redirect($location, $status) |
|
1143 | + { |
|
1144 | + //get revision |
|
1145 | + $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1146 | + //can't do anything without revision so let's get out if not present |
|
1147 | + if (empty($rev_id)) { |
|
1148 | + return $location; |
|
1149 | + } |
|
1150 | + //get rev_post_data |
|
1151 | + $rev = get_post($rev_id); |
|
1152 | + $admin_url = $this->_admin_base_url; |
|
1153 | + $query_args = array( |
|
1154 | + 'action' => 'edit', |
|
1155 | + 'post' => $rev->post_parent, |
|
1156 | + 'revision' => $rev_id, |
|
1157 | + 'message' => 5, |
|
1158 | + ); |
|
1159 | + $this->_process_notices($query_args, true); |
|
1160 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1161 | + } |
|
1162 | + |
|
1163 | + |
|
1164 | + |
|
1165 | + /** |
|
1166 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1167 | + * |
|
1168 | + * @param string $link the original generated link |
|
1169 | + * @param int $id post id |
|
1170 | + * @param string $context optional, defaults to display. How to write the '&' |
|
1171 | + * @return string the link |
|
1172 | + */ |
|
1173 | + public function modify_edit_post_link($link, $id, $context) |
|
1174 | + { |
|
1175 | + $post = get_post($id); |
|
1176 | + if ( ! isset($this->_req_data['action']) |
|
1177 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1178 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1179 | + ) { |
|
1180 | + return $link; |
|
1181 | + } |
|
1182 | + $query_args = array( |
|
1183 | + 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1184 | + ? $this->_cpt_edit_routes[$post->post_type] |
|
1185 | + : 'edit', |
|
1186 | + 'post' => $id, |
|
1187 | + ); |
|
1188 | + return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1189 | + } |
|
1190 | + |
|
1191 | + |
|
1192 | + /** |
|
1193 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1194 | + * our routes. |
|
1195 | + * |
|
1196 | + * @param string $delete_link original delete link |
|
1197 | + * @param int $post_id id of cpt object |
|
1198 | + * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1199 | + * @return string new delete link |
|
1200 | + * @throws EE_Error |
|
1201 | + */ |
|
1202 | + public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1203 | + { |
|
1204 | + $post = get_post($post_id); |
|
1205 | + |
|
1206 | + if (empty($this->_req_data['action']) |
|
1207 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1208 | + || ! $post instanceof WP_Post |
|
1209 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1210 | + ) { |
|
1211 | + return $delete_link; |
|
1212 | + } |
|
1213 | + $this->_set_model_object($post->ID, true); |
|
1214 | + |
|
1215 | + //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1216 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1217 | + |
|
1218 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
1219 | + array( |
|
1220 | + 'page' => $this->_req_data['page'], |
|
1221 | + 'action' => $action, |
|
1222 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1223 | + => $post->ID |
|
1224 | + ), |
|
1225 | + admin_url() |
|
1226 | + ); |
|
1227 | + } |
|
1228 | + |
|
1229 | + |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1233 | + * so that we can hijack the default redirect locations for wp custom post types |
|
1234 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1235 | + * |
|
1236 | + * @param string $location This is the incoming currently set redirect location |
|
1237 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1238 | + * @return string the new location to redirect to |
|
1239 | + */ |
|
1240 | + public function cpt_post_location_redirect($location, $post_id) |
|
1241 | + { |
|
1242 | + //we DO have a match so let's setup the url |
|
1243 | + //we have to get the post to determine our route |
|
1244 | + $post = get_post($post_id); |
|
1245 | + $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1246 | + //shared query_args |
|
1247 | + $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1248 | + $admin_url = $this->_admin_base_url; |
|
1249 | + if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1250 | + $status = get_post_status($post_id); |
|
1251 | + if (isset($this->_req_data['publish'])) { |
|
1252 | + switch ($status) { |
|
1253 | + case 'pending': |
|
1254 | + $message = 8; |
|
1255 | + break; |
|
1256 | + case 'future': |
|
1257 | + $message = 9; |
|
1258 | + break; |
|
1259 | + default: |
|
1260 | + $message = 6; |
|
1261 | + } |
|
1262 | + } else { |
|
1263 | + $message = 'draft' === $status ? 10 : 1; |
|
1264 | + } |
|
1265 | + } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1266 | + $message = 2; |
|
1267 | + // $append = '#postcustom'; |
|
1268 | + } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1269 | + $message = 3; |
|
1270 | + // $append = '#postcustom'; |
|
1271 | + } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1272 | + $message = 7; |
|
1273 | + } else { |
|
1274 | + $message = 4; |
|
1275 | + } |
|
1276 | + //change the message if the post type is not viewable on the frontend |
|
1277 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
1278 | + $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1279 | + $query_args = array_merge(array('message' => $message), $query_args); |
|
1280 | + $this->_process_notices($query_args, true); |
|
1281 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1282 | + } |
|
1283 | + |
|
1284 | + |
|
1285 | + |
|
1286 | + /** |
|
1287 | + * This method is called to inject nav tabs on core WP cpt pages |
|
1288 | + * |
|
1289 | + * @access public |
|
1290 | + * @return void |
|
1291 | + */ |
|
1292 | + public function inject_nav_tabs() |
|
1293 | + { |
|
1294 | + //can we hijack and insert the nav_tabs? |
|
1295 | + $nav_tabs = $this->_get_main_nav_tabs(); |
|
1296 | + //first close off existing form tag |
|
1297 | + $html = '>'; |
|
1298 | + $html .= $nav_tabs; |
|
1299 | + //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1300 | + $html .= '<span></span'; |
|
1301 | + echo $html; |
|
1302 | + } |
|
1303 | + |
|
1304 | + |
|
1305 | + |
|
1306 | + /** |
|
1307 | + * This just sets up the post update messages when an update form is loaded |
|
1308 | + * |
|
1309 | + * @access public |
|
1310 | + * @param array $messages the original messages array |
|
1311 | + * @return array the new messages array |
|
1312 | + */ |
|
1313 | + public function post_update_messages($messages) |
|
1314 | + { |
|
1315 | + global $post; |
|
1316 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1317 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1318 | + // $post_type = $post ? $post->post_type : false; |
|
1319 | + /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1320 | 1320 | |
1321 | 1321 | $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/ |
1322 | - $messages[$post->post_type] = array( |
|
1323 | - 0 => '', //Unused. Messages start at index 1. |
|
1324 | - 1 => sprintf( |
|
1325 | - __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1326 | - $this->_cpt_object->labels->singular_name, |
|
1327 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1328 | - '</a>' |
|
1329 | - ), |
|
1330 | - 2 => __('Custom field updated'), |
|
1331 | - 3 => __('Custom field deleted.'), |
|
1332 | - 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1333 | - 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
1334 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1335 | - : false, |
|
1336 | - 6 => sprintf( |
|
1337 | - __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1338 | - $this->_cpt_object->labels->singular_name, |
|
1339 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1340 | - '</a>' |
|
1341 | - ), |
|
1342 | - 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1343 | - 8 => sprintf( |
|
1344 | - __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1345 | - $this->_cpt_object->labels->singular_name, |
|
1346 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1347 | - '</a>' |
|
1348 | - ), |
|
1349 | - 9 => sprintf( |
|
1350 | - __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1351 | - $this->_cpt_object->labels->singular_name, |
|
1352 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1353 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1354 | - '</a>' |
|
1355 | - ), |
|
1356 | - 10 => sprintf( |
|
1357 | - __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1358 | - $this->_cpt_object->labels->singular_name, |
|
1359 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1360 | - '</a>' |
|
1361 | - ), |
|
1362 | - ); |
|
1363 | - return $messages; |
|
1364 | - } |
|
1365 | - |
|
1366 | - |
|
1367 | - |
|
1368 | - /** |
|
1369 | - * default method for the 'create_new' route for cpt admin pages. |
|
1370 | - * For reference what to include in here, see wp-admin/post-new.php |
|
1371 | - * |
|
1372 | - * @access protected |
|
1373 | - * @return void |
|
1374 | - */ |
|
1375 | - protected function _create_new_cpt_item() |
|
1376 | - { |
|
1377 | - // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1378 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1379 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1380 | - $post_type_object = $this->_cpt_object; |
|
1381 | - $title = $post_type_object->labels->add_new_item; |
|
1382 | - $editing = true; |
|
1383 | - wp_enqueue_script('autosave'); |
|
1384 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1385 | - $post_ID = $post->ID; |
|
1386 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1387 | - //modify the default editor title field with default title. |
|
1388 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1389 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1390 | - } |
|
1391 | - |
|
1392 | - |
|
1393 | - |
|
1394 | - public function add_new_admin_page_global() |
|
1395 | - { |
|
1396 | - $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1397 | - ?> |
|
1322 | + $messages[$post->post_type] = array( |
|
1323 | + 0 => '', //Unused. Messages start at index 1. |
|
1324 | + 1 => sprintf( |
|
1325 | + __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1326 | + $this->_cpt_object->labels->singular_name, |
|
1327 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1328 | + '</a>' |
|
1329 | + ), |
|
1330 | + 2 => __('Custom field updated'), |
|
1331 | + 3 => __('Custom field deleted.'), |
|
1332 | + 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1333 | + 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
1334 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1335 | + : false, |
|
1336 | + 6 => sprintf( |
|
1337 | + __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1338 | + $this->_cpt_object->labels->singular_name, |
|
1339 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1340 | + '</a>' |
|
1341 | + ), |
|
1342 | + 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1343 | + 8 => sprintf( |
|
1344 | + __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1345 | + $this->_cpt_object->labels->singular_name, |
|
1346 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1347 | + '</a>' |
|
1348 | + ), |
|
1349 | + 9 => sprintf( |
|
1350 | + __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1351 | + $this->_cpt_object->labels->singular_name, |
|
1352 | + '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1353 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1354 | + '</a>' |
|
1355 | + ), |
|
1356 | + 10 => sprintf( |
|
1357 | + __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1358 | + $this->_cpt_object->labels->singular_name, |
|
1359 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1360 | + '</a>' |
|
1361 | + ), |
|
1362 | + ); |
|
1363 | + return $messages; |
|
1364 | + } |
|
1365 | + |
|
1366 | + |
|
1367 | + |
|
1368 | + /** |
|
1369 | + * default method for the 'create_new' route for cpt admin pages. |
|
1370 | + * For reference what to include in here, see wp-admin/post-new.php |
|
1371 | + * |
|
1372 | + * @access protected |
|
1373 | + * @return void |
|
1374 | + */ |
|
1375 | + protected function _create_new_cpt_item() |
|
1376 | + { |
|
1377 | + // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1378 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1379 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1380 | + $post_type_object = $this->_cpt_object; |
|
1381 | + $title = $post_type_object->labels->add_new_item; |
|
1382 | + $editing = true; |
|
1383 | + wp_enqueue_script('autosave'); |
|
1384 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1385 | + $post_ID = $post->ID; |
|
1386 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1387 | + //modify the default editor title field with default title. |
|
1388 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1389 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1390 | + } |
|
1391 | + |
|
1392 | + |
|
1393 | + |
|
1394 | + public function add_new_admin_page_global() |
|
1395 | + { |
|
1396 | + $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1397 | + ?> |
|
1398 | 1398 | <script type="text/javascript"> |
1399 | 1399 | adminpage = '<?php echo $admin_page; ?>'; |
1400 | 1400 | </script> |
1401 | 1401 | <?php |
1402 | - } |
|
1403 | - |
|
1404 | - |
|
1405 | - |
|
1406 | - /** |
|
1407 | - * default method for the 'edit' route for cpt admin pages |
|
1408 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
1409 | - * |
|
1410 | - * @access protected |
|
1411 | - * @return string template for edit cpt form |
|
1412 | - */ |
|
1413 | - protected function _edit_cpt_item() |
|
1414 | - { |
|
1415 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1416 | - $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1417 | - $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1418 | - if (empty ($post)) { |
|
1419 | - wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
1420 | - } |
|
1421 | - if ( ! empty($_GET['get-post-lock'])) { |
|
1422 | - wp_set_post_lock($post_id); |
|
1423 | - wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1424 | - exit(); |
|
1425 | - } |
|
1426 | - |
|
1427 | - // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1428 | - $editing = true; |
|
1429 | - $post_ID = $post_id; |
|
1430 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1431 | - $post_type_object = $this->_cpt_object; |
|
1432 | - |
|
1433 | - if ( ! wp_check_post_lock($post->ID)) { |
|
1434 | - $active_post_lock = wp_set_post_lock($post->ID); |
|
1435 | - //wp_enqueue_script('autosave'); |
|
1436 | - } |
|
1437 | - $title = $this->_cpt_object->labels->edit_item; |
|
1438 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
1439 | - if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1440 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1441 | - ) { |
|
1442 | - $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1443 | - 'create_new', $this); |
|
1444 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1445 | - 'action' => $create_new_action, |
|
1446 | - 'page' => $this->page_slug, |
|
1447 | - ), 'admin.php'); |
|
1448 | - } |
|
1449 | - if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1450 | - wp_enqueue_script('admin-comments'); |
|
1451 | - enqueue_comment_hotkeys_js(); |
|
1452 | - } |
|
1453 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1454 | - //modify the default editor title field with default title. |
|
1455 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1456 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1457 | - } |
|
1458 | - |
|
1459 | - |
|
1460 | - |
|
1461 | - /** |
|
1462 | - * some getters |
|
1463 | - */ |
|
1464 | - /** |
|
1465 | - * This returns the protected _cpt_model_obj property |
|
1466 | - * |
|
1467 | - * @return EE_CPT_Base |
|
1468 | - */ |
|
1469 | - public function get_cpt_model_obj() |
|
1470 | - { |
|
1471 | - return $this->_cpt_model_obj; |
|
1472 | - } |
|
1402 | + } |
|
1403 | + |
|
1404 | + |
|
1405 | + |
|
1406 | + /** |
|
1407 | + * default method for the 'edit' route for cpt admin pages |
|
1408 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
1409 | + * |
|
1410 | + * @access protected |
|
1411 | + * @return string template for edit cpt form |
|
1412 | + */ |
|
1413 | + protected function _edit_cpt_item() |
|
1414 | + { |
|
1415 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1416 | + $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1417 | + $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1418 | + if (empty ($post)) { |
|
1419 | + wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
1420 | + } |
|
1421 | + if ( ! empty($_GET['get-post-lock'])) { |
|
1422 | + wp_set_post_lock($post_id); |
|
1423 | + wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1424 | + exit(); |
|
1425 | + } |
|
1426 | + |
|
1427 | + // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1428 | + $editing = true; |
|
1429 | + $post_ID = $post_id; |
|
1430 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1431 | + $post_type_object = $this->_cpt_object; |
|
1432 | + |
|
1433 | + if ( ! wp_check_post_lock($post->ID)) { |
|
1434 | + $active_post_lock = wp_set_post_lock($post->ID); |
|
1435 | + //wp_enqueue_script('autosave'); |
|
1436 | + } |
|
1437 | + $title = $this->_cpt_object->labels->edit_item; |
|
1438 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
1439 | + if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1440 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1441 | + ) { |
|
1442 | + $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1443 | + 'create_new', $this); |
|
1444 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1445 | + 'action' => $create_new_action, |
|
1446 | + 'page' => $this->page_slug, |
|
1447 | + ), 'admin.php'); |
|
1448 | + } |
|
1449 | + if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1450 | + wp_enqueue_script('admin-comments'); |
|
1451 | + enqueue_comment_hotkeys_js(); |
|
1452 | + } |
|
1453 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1454 | + //modify the default editor title field with default title. |
|
1455 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1456 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1457 | + } |
|
1458 | + |
|
1459 | + |
|
1460 | + |
|
1461 | + /** |
|
1462 | + * some getters |
|
1463 | + */ |
|
1464 | + /** |
|
1465 | + * This returns the protected _cpt_model_obj property |
|
1466 | + * |
|
1467 | + * @return EE_CPT_Base |
|
1468 | + */ |
|
1469 | + public function get_cpt_model_obj() |
|
1470 | + { |
|
1471 | + return $this->_cpt_model_obj; |
|
1472 | + } |
|
1473 | 1473 | |
1474 | 1474 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | */ |
236 | 236 | protected function _register_autosave_containers($ids) |
237 | 237 | { |
238 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
238 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | //filter _autosave_containers |
283 | 283 | $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
284 | 284 | $this->_autosave_containers, $this); |
285 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
285 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers', |
|
286 | 286 | $containers, $this); |
287 | 287 | |
288 | 288 | wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | // This is for any plugins that are doing things properly |
395 | 395 | // and hooking into the load page hook for core wp cpt routes. |
396 | 396 | global $pagenow; |
397 | - do_action('load-' . $pagenow); |
|
397 | + do_action('load-'.$pagenow); |
|
398 | 398 | $this->modify_current_screen(); |
399 | 399 | add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
400 | 400 | //we route REALLY early. |
@@ -425,8 +425,8 @@ discard block |
||
425 | 425 | 'admin.php?page=espresso_registrations&action=contact_list', |
426 | 426 | ), |
427 | 427 | 1 => array( |
428 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
429 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
428 | + 'edit.php?post_type='.$this->_cpt_object->name, |
|
429 | + 'admin.php?page='.$this->_cpt_object->name, |
|
430 | 430 | ), |
431 | 431 | ); |
432 | 432 | foreach ($routes_to_match as $route_matches) { |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | $cpt_has_support = ! empty($cpt_args['page_templates']); |
455 | 455 | |
456 | 456 | //if the installed version of WP is > 4.7 we do some additional checks. |
457 | - if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
457 | + if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) { |
|
458 | 458 | $post_templates = wp_get_theme()->get_post_templates(); |
459 | 459 | //if there are $post_templates for this cpt, then we return false for this method because |
460 | 460 | //that means we aren't going to load our page template manager and leave that up to the native |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | global $post; |
478 | 478 | $template = ''; |
479 | 479 | |
480 | - if (EE_Recommended_Versions::check_wp_version('4.7','>=')) { |
|
480 | + if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) { |
|
481 | 481 | $page_template_count = count(get_page_templates()); |
482 | 482 | } else { |
483 | 483 | $page_template_count = count(get_page_templates($post)); |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | $post = get_post($id); |
515 | 515 | if ('publish' !== get_post_status($post)) { |
516 | 516 | //include shims for the `get_preview_post_link` function |
517 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
517 | + require_once(EE_CORE.'wordpress-shims.php'); |
|
518 | 518 | $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
519 | 519 | . get_preview_post_link($id) |
520 | 520 | . '" class="button button-small">' |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | $template_args['statuses'] = $statuses; |
553 | 553 | } |
554 | 554 | |
555 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
555 | + $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php'; |
|
556 | 556 | EEH_Template::display_template($template, $template_args); |
557 | 557 | } |
558 | 558 | |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | $this->_template_args['success'] = true; |
607 | 607 | } |
608 | 608 | do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
609 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
609 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this); |
|
610 | 610 | //now let's return json |
611 | 611 | $this->_return_json(); |
612 | 612 | } |
@@ -1009,7 +1009,7 @@ discard block |
||
1009 | 1009 | //global action |
1010 | 1010 | do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
1011 | 1011 | //class specific action so you can limit hooking into a specific page. |
1012 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1012 | + do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | if ( ! empty($id) && get_option('permalink_structure') !== '') { |
1088 | 1088 | $post = get_post($id); |
1089 | 1089 | if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
1090 | - $shortlink = home_url('?p=' . $post->ID); |
|
1090 | + $shortlink = home_url('?p='.$post->ID); |
|
1091 | 1091 | } |
1092 | 1092 | } |
1093 | 1093 | return $shortlink; |
@@ -1122,11 +1122,11 @@ discard block |
||
1122 | 1122 | */ |
1123 | 1123 | public function cpt_post_form_hidden_input() |
1124 | 1124 | { |
1125 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1125 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />'; |
|
1126 | 1126 | //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
1127 | 1127 | echo '<div id="ee-cpt-hidden-inputs">'; |
1128 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1129 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1128 | + echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />'; |
|
1129 | + echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />'; |
|
1130 | 1130 | echo '</div>'; |
1131 | 1131 | } |
1132 | 1132 | |
@@ -1213,7 +1213,7 @@ discard block |
||
1213 | 1213 | $this->_set_model_object($post->ID, true); |
1214 | 1214 | |
1215 | 1215 | //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
1216 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1216 | + $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1217 | 1217 | |
1218 | 1218 | return EE_Admin_Page::add_query_args_and_nonce( |
1219 | 1219 | array( |
@@ -1324,39 +1324,39 @@ discard block |
||
1324 | 1324 | 1 => sprintf( |
1325 | 1325 | __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
1326 | 1326 | $this->_cpt_object->labels->singular_name, |
1327 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1327 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1328 | 1328 | '</a>' |
1329 | 1329 | ), |
1330 | 1330 | 2 => __('Custom field updated'), |
1331 | 1331 | 3 => __('Custom field deleted.'), |
1332 | 1332 | 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1333 | 1333 | 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
1334 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1334 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false)) |
|
1335 | 1335 | : false, |
1336 | 1336 | 6 => sprintf( |
1337 | 1337 | __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
1338 | 1338 | $this->_cpt_object->labels->singular_name, |
1339 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1339 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1340 | 1340 | '</a>' |
1341 | 1341 | ), |
1342 | 1342 | 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1343 | 1343 | 8 => sprintf( |
1344 | 1344 | __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
1345 | 1345 | $this->_cpt_object->labels->singular_name, |
1346 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1346 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">', |
|
1347 | 1347 | '</a>' |
1348 | 1348 | ), |
1349 | 1349 | 9 => sprintf( |
1350 | 1350 | __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
1351 | 1351 | $this->_cpt_object->labels->singular_name, |
1352 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1353 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1352 | + '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>', |
|
1353 | + '<a target="_blank" href="'.esc_url(get_permalink($id)), |
|
1354 | 1354 | '</a>' |
1355 | 1355 | ), |
1356 | 1356 | 10 => sprintf( |
1357 | 1357 | __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
1358 | 1358 | $this->_cpt_object->labels->singular_name, |
1359 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1359 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1360 | 1360 | '</a>' |
1361 | 1361 | ), |
1362 | 1362 | ); |
@@ -1386,7 +1386,7 @@ discard block |
||
1386 | 1386 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
1387 | 1387 | //modify the default editor title field with default title. |
1388 | 1388 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
1389 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1389 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
1390 | 1390 | } |
1391 | 1391 | |
1392 | 1392 | |
@@ -1453,7 +1453,7 @@ discard block |
||
1453 | 1453 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
1454 | 1454 | //modify the default editor title field with default title. |
1455 | 1455 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
1456 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1456 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
1457 | 1457 | } |
1458 | 1458 | |
1459 | 1459 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -25,1093 +25,1093 @@ discard block |
||
25 | 25 | { |
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @Constructor |
|
30 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
31 | - * @access public |
|
32 | - */ |
|
33 | - public function __construct($routing = true) |
|
34 | - { |
|
35 | - define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
36 | - define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
37 | - define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
38 | - define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
39 | - define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
40 | - parent::__construct($routing); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - protected function _extend_page_config() |
|
45 | - { |
|
46 | - $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
47 | - $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
48 | - $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
|
49 | - |
|
50 | - $new_page_routes = array( |
|
51 | - 'question_groups' => array( |
|
52 | - 'func' => '_question_groups_overview_list_table', |
|
53 | - 'capability' => 'ee_read_question_groups', |
|
54 | - ), |
|
55 | - 'add_question' => array( |
|
56 | - 'func' => '_edit_question', |
|
57 | - 'capability' => 'ee_edit_questions', |
|
58 | - ), |
|
59 | - 'insert_question' => array( |
|
60 | - 'func' => '_insert_or_update_question', |
|
61 | - 'args' => array('new_question' => true), |
|
62 | - 'capability' => 'ee_edit_questions', |
|
63 | - 'noheader' => true, |
|
64 | - ), |
|
65 | - 'duplicate_question' => array( |
|
66 | - 'func' => '_duplicate_question', |
|
67 | - 'capability' => 'ee_edit_questions', |
|
68 | - 'noheader' => true, |
|
69 | - ), |
|
70 | - 'trash_question' => array( |
|
71 | - 'func' => '_trash_question', |
|
72 | - 'capability' => 'ee_delete_question', |
|
73 | - 'obj_id' => $qst_id, |
|
74 | - 'noheader' => true, |
|
75 | - ), |
|
76 | - |
|
77 | - 'restore_question' => array( |
|
78 | - 'func' => '_trash_or_restore_questions', |
|
79 | - 'capability' => 'ee_delete_question', |
|
80 | - 'obj_id' => $qst_id, |
|
81 | - 'args' => array('trash' => false), |
|
82 | - 'noheader' => true, |
|
83 | - ), |
|
84 | - |
|
85 | - 'delete_question' => array( |
|
86 | - 'func' => '_delete_question', |
|
87 | - 'capability' => 'ee_delete_question', |
|
88 | - 'obj_id' => $qst_id, |
|
89 | - 'noheader' => true, |
|
90 | - ), |
|
91 | - |
|
92 | - 'trash_questions' => array( |
|
93 | - 'func' => '_trash_or_restore_questions', |
|
94 | - 'capability' => 'ee_delete_questions', |
|
95 | - 'args' => array('trash' => true), |
|
96 | - 'noheader' => true, |
|
97 | - ), |
|
98 | - |
|
99 | - 'restore_questions' => array( |
|
100 | - 'func' => '_trash_or_restore_questions', |
|
101 | - 'capability' => 'ee_delete_questions', |
|
102 | - 'args' => array('trash' => false), |
|
103 | - 'noheader' => true, |
|
104 | - ), |
|
105 | - |
|
106 | - 'delete_questions' => array( |
|
107 | - 'func' => '_delete_questions', |
|
108 | - 'args' => array(), |
|
109 | - 'capability' => 'ee_delete_questions', |
|
110 | - 'noheader' => true, |
|
111 | - ), |
|
112 | - |
|
113 | - 'add_question_group' => array( |
|
114 | - 'func' => '_edit_question_group', |
|
115 | - 'capability' => 'ee_edit_question_groups', |
|
116 | - ), |
|
117 | - |
|
118 | - 'edit_question_group' => array( |
|
119 | - 'func' => '_edit_question_group', |
|
120 | - 'capability' => 'ee_edit_question_group', |
|
121 | - 'obj_id' => $qsg_id, |
|
122 | - 'args' => array('edit'), |
|
123 | - ), |
|
124 | - |
|
125 | - 'delete_question_groups' => array( |
|
126 | - 'func' => '_delete_question_groups', |
|
127 | - 'capability' => 'ee_delete_question_groups', |
|
128 | - 'noheader' => true, |
|
129 | - ), |
|
130 | - |
|
131 | - 'delete_question_group' => array( |
|
132 | - 'func' => '_delete_question_groups', |
|
133 | - 'capability' => 'ee_delete_question_group', |
|
134 | - 'obj_id' => $qsg_id, |
|
135 | - 'noheader' => true, |
|
136 | - ), |
|
137 | - |
|
138 | - 'trash_question_group' => array( |
|
139 | - 'func' => '_trash_or_restore_question_groups', |
|
140 | - 'args' => array('trash' => true), |
|
141 | - 'capability' => 'ee_delete_question_group', |
|
142 | - 'obj_id' => $qsg_id, |
|
143 | - 'noheader' => true, |
|
144 | - ), |
|
145 | - |
|
146 | - 'restore_question_group' => array( |
|
147 | - 'func' => '_trash_or_restore_question_groups', |
|
148 | - 'args' => array('trash' => false), |
|
149 | - 'capability' => 'ee_delete_question_group', |
|
150 | - 'obj_id' => $qsg_id, |
|
151 | - 'noheader' => true, |
|
152 | - ), |
|
153 | - |
|
154 | - 'insert_question_group' => array( |
|
155 | - 'func' => '_insert_or_update_question_group', |
|
156 | - 'args' => array('new_question_group' => true), |
|
157 | - 'capability' => 'ee_edit_question_groups', |
|
158 | - 'noheader' => true, |
|
159 | - ), |
|
160 | - |
|
161 | - 'update_question_group' => array( |
|
162 | - 'func' => '_insert_or_update_question_group', |
|
163 | - 'args' => array('new_question_group' => false), |
|
164 | - 'capability' => 'ee_edit_question_group', |
|
165 | - 'obj_id' => $qsg_id, |
|
166 | - 'noheader' => true, |
|
167 | - ), |
|
168 | - |
|
169 | - 'trash_question_groups' => array( |
|
170 | - 'func' => '_trash_or_restore_question_groups', |
|
171 | - 'args' => array('trash' => true), |
|
172 | - 'capability' => 'ee_delete_question_groups', |
|
173 | - 'noheader' => array('trash' => false), |
|
174 | - ), |
|
175 | - |
|
176 | - 'restore_question_groups' => array( |
|
177 | - 'func' => '_trash_or_restore_question_groups', |
|
178 | - 'args' => array('trash' => false), |
|
179 | - 'capability' => 'ee_delete_question_groups', |
|
180 | - 'noheader' => true, |
|
181 | - ), |
|
182 | - |
|
183 | - |
|
184 | - 'espresso_update_question_group_order' => array( |
|
185 | - 'func' => 'update_question_group_order', |
|
186 | - 'capability' => 'ee_edit_question_groups', |
|
187 | - 'noheader' => true, |
|
188 | - ), |
|
189 | - |
|
190 | - 'view_reg_form_settings' => array( |
|
191 | - 'func' => '_reg_form_settings', |
|
192 | - 'capability' => 'manage_options', |
|
193 | - ), |
|
194 | - |
|
195 | - 'update_reg_form_settings' => array( |
|
196 | - 'func' => '_update_reg_form_settings', |
|
197 | - 'capability' => 'manage_options', |
|
198 | - 'noheader' => true, |
|
199 | - ), |
|
200 | - ); |
|
201 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
202 | - |
|
203 | - $new_page_config = array( |
|
204 | - |
|
205 | - 'question_groups' => array( |
|
206 | - 'nav' => array( |
|
207 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
208 | - 'order' => 20, |
|
209 | - ), |
|
210 | - 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
211 | - 'help_tabs' => array( |
|
212 | - 'registration_form_question_groups_help_tab' => array( |
|
213 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
214 | - 'filename' => 'registration_form_question_groups', |
|
215 | - ), |
|
216 | - 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
217 | - 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
218 | - 'filename' => 'registration_form_question_groups_table_column_headings', |
|
219 | - ), |
|
220 | - 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
221 | - 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
222 | - 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
223 | - ), |
|
224 | - ), |
|
225 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
226 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
227 | - 'require_nonce' => false, |
|
228 | - 'qtips' => array( |
|
229 | - 'EE_Registration_Form_Tips', |
|
230 | - ), |
|
231 | - ), |
|
232 | - |
|
233 | - 'add_question' => array( |
|
234 | - 'nav' => array( |
|
235 | - 'label' => esc_html__('Add Question', 'event_espresso'), |
|
236 | - 'order' => 5, |
|
237 | - 'persistent' => false, |
|
238 | - ), |
|
239 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
240 | - 'help_tabs' => array( |
|
241 | - 'registration_form_add_question_help_tab' => array( |
|
242 | - 'title' => esc_html__('Add Question', 'event_espresso'), |
|
243 | - 'filename' => 'registration_form_add_question', |
|
244 | - ), |
|
245 | - ), |
|
246 | - 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
247 | - 'require_nonce' => false, |
|
248 | - ), |
|
249 | - |
|
250 | - 'add_question_group' => array( |
|
251 | - 'nav' => array( |
|
252 | - 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
253 | - 'order' => 5, |
|
254 | - 'persistent' => false, |
|
255 | - ), |
|
256 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
257 | - 'help_tabs' => array( |
|
258 | - 'registration_form_add_question_group_help_tab' => array( |
|
259 | - 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
260 | - 'filename' => 'registration_form_add_question_group', |
|
261 | - ), |
|
262 | - ), |
|
263 | - 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
264 | - 'require_nonce' => false, |
|
265 | - ), |
|
266 | - |
|
267 | - 'edit_question_group' => array( |
|
268 | - 'nav' => array( |
|
269 | - 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
270 | - 'order' => 5, |
|
271 | - 'persistent' => false, |
|
272 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']), |
|
273 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
274 | - ), |
|
275 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
276 | - 'help_tabs' => array( |
|
277 | - 'registration_form_edit_question_group_help_tab' => array( |
|
278 | - 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
279 | - 'filename' => 'registration_form_edit_question_group', |
|
280 | - ), |
|
281 | - ), |
|
282 | - 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
283 | - 'require_nonce' => false, |
|
284 | - ), |
|
285 | - |
|
286 | - 'view_reg_form_settings' => array( |
|
287 | - 'nav' => array( |
|
288 | - 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
289 | - 'order' => 40, |
|
290 | - ), |
|
291 | - 'labels' => array( |
|
292 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
293 | - ), |
|
294 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
295 | - 'help_tabs' => array( |
|
296 | - 'registration_form_reg_form_settings_help_tab' => array( |
|
297 | - 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
298 | - 'filename' => 'registration_form_reg_form_settings', |
|
299 | - ), |
|
300 | - ), |
|
301 | - 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
302 | - 'require_nonce' => false, |
|
303 | - ), |
|
304 | - |
|
305 | - ); |
|
306 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
307 | - |
|
308 | - //change the list table we're going to use so it's the NEW list table! |
|
309 | - $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
310 | - |
|
311 | - |
|
312 | - //additional labels |
|
313 | - $new_labels = array( |
|
314 | - 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
315 | - 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
316 | - 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
317 | - 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
318 | - 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
319 | - ); |
|
320 | - $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - protected function _ajax_hooks() |
|
326 | - { |
|
327 | - add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - public function load_scripts_styles_question_groups() |
|
332 | - { |
|
333 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - public function load_scripts_styles_add_question_group() |
|
338 | - { |
|
339 | - $this->load_scripts_styles_forms(); |
|
340 | - $this->load_sortable_question_script(); |
|
341 | - } |
|
342 | - |
|
343 | - public function load_scripts_styles_edit_question_group() |
|
344 | - { |
|
345 | - $this->load_scripts_styles_forms(); |
|
346 | - $this->load_sortable_question_script(); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * registers and enqueues script for questions |
|
352 | - * |
|
353 | - * @return void |
|
354 | - */ |
|
355 | - public function load_sortable_question_script() |
|
356 | - { |
|
357 | - wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
358 | - array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
359 | - wp_enqueue_script('ee-question-sortable'); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - protected function _set_list_table_views_default() |
|
364 | - { |
|
365 | - $this->_views = array( |
|
366 | - 'all' => array( |
|
367 | - 'slug' => 'all', |
|
368 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
369 | - 'count' => 0, |
|
370 | - 'bulk_action' => array( |
|
371 | - 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
372 | - ), |
|
373 | - ), |
|
374 | - ); |
|
375 | - |
|
376 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
377 | - 'espresso_registration_form_trash_questions') |
|
378 | - ) { |
|
379 | - $this->_views['trash'] = array( |
|
380 | - 'slug' => 'trash', |
|
381 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
382 | - 'count' => 0, |
|
383 | - 'bulk_action' => array( |
|
384 | - 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
385 | - 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
386 | - ), |
|
387 | - ); |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - protected function _set_list_table_views_question_groups() |
|
393 | - { |
|
394 | - $this->_views = array( |
|
395 | - 'all' => array( |
|
396 | - 'slug' => 'all', |
|
397 | - 'label' => esc_html__('All', 'event_espresso'), |
|
398 | - 'count' => 0, |
|
399 | - 'bulk_action' => array( |
|
400 | - 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
401 | - ), |
|
402 | - ), |
|
403 | - ); |
|
404 | - |
|
405 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups', |
|
406 | - 'espresso_registration_form_trash_question_groups') |
|
407 | - ) { |
|
408 | - $this->_views['trash'] = array( |
|
409 | - 'slug' => 'trash', |
|
410 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
411 | - 'count' => 0, |
|
412 | - 'bulk_action' => array( |
|
413 | - 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
414 | - 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
415 | - ), |
|
416 | - ); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - protected function _questions_overview_list_table() |
|
422 | - { |
|
423 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
424 | - 'add_question', |
|
425 | - 'add_question', |
|
426 | - array(), |
|
427 | - 'add-new-h2' |
|
428 | - ); |
|
429 | - parent::_questions_overview_list_table(); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - protected function _question_groups_overview_list_table() |
|
434 | - { |
|
435 | - $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
436 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
437 | - 'add_question_group', |
|
438 | - 'add_question_group', |
|
439 | - array(), |
|
440 | - 'add-new-h2' |
|
441 | - ); |
|
442 | - $this->display_admin_list_table_page_with_sidebar(); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - protected function _delete_question() |
|
447 | - { |
|
448 | - $success = $this->_delete_items($this->_question_model); |
|
449 | - $this->_redirect_after_action( |
|
450 | - $success, |
|
451 | - $this->_question_model->item_name($success), |
|
452 | - 'deleted', |
|
453 | - array('action' => 'default', 'status' => 'all') |
|
454 | - ); |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - protected function _delete_questions() |
|
459 | - { |
|
460 | - $success = $this->_delete_items($this->_question_model); |
|
461 | - $this->_redirect_after_action( |
|
462 | - $success, |
|
463 | - $this->_question_model->item_name($success), |
|
464 | - 'deleted permanently', |
|
465 | - array('action' => 'default', 'status' => 'trash') |
|
466 | - ); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Performs the deletion of a single or multiple questions or question groups. |
|
472 | - * |
|
473 | - * @param EEM_Soft_Delete_Base $model |
|
474 | - * @return int number of items deleted permanently |
|
475 | - */ |
|
476 | - private function _delete_items(EEM_Soft_Delete_Base $model) |
|
477 | - { |
|
478 | - $success = 0; |
|
479 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
480 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
481 | - // if array has more than one element than success message should be plural |
|
482 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
483 | - // cycle thru bulk action checkboxes |
|
484 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
485 | - if (! $this->_delete_item($ID, $model)) { |
|
486 | - $success = 0; |
|
487 | - } |
|
488 | - } |
|
489 | - |
|
490 | - } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
491 | - $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
492 | - |
|
493 | - } elseif (! empty($this->_req_data['QST_ID'])) { |
|
494 | - $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
495 | - } else { |
|
496 | - EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
497 | - "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
498 | - } |
|
499 | - return $success; |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Deletes the specified question (and its associated question options) or question group |
|
504 | - * |
|
505 | - * @param int $id |
|
506 | - * @param EEM_Soft_Delete_Base $model |
|
507 | - * @return boolean |
|
508 | - */ |
|
509 | - protected function _delete_item($id, $model) |
|
510 | - { |
|
511 | - if ($model instanceof EEM_Question) { |
|
512 | - EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
513 | - } |
|
514 | - return $model->delete_permanently_by_ID(absint($id)); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /****************************** QUESTION GROUPS ******************************/ |
|
519 | - |
|
520 | - |
|
521 | - protected function _edit_question_group($type = 'add') |
|
522 | - { |
|
523 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
524 | - $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : false; |
|
525 | - |
|
526 | - switch ($this->_req_action) { |
|
527 | - case 'add_question_group' : |
|
528 | - $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
529 | - break; |
|
530 | - case 'edit_question_group' : |
|
531 | - $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
532 | - break; |
|
533 | - default : |
|
534 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
535 | - } |
|
536 | - // add ID to title if editing |
|
537 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
538 | - if ($ID) { |
|
539 | - /** @var EE_Question_Group $questionGroup */ |
|
540 | - $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
541 | - $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
542 | - $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
543 | - } else { |
|
544 | - /** @var EE_Question_Group $questionGroup */ |
|
545 | - $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
546 | - $questionGroup->set_order_to_latest(); |
|
547 | - $this->_set_add_edit_form_tags('insert_question_group'); |
|
548 | - } |
|
549 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
550 | - $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
551 | - $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
552 | - $this->_template_args['question_group'] = $questionGroup; |
|
553 | - |
|
554 | - $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
555 | - $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
556 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
557 | - $this->_template_args, true); |
|
558 | - |
|
559 | - // the details template wrapper |
|
560 | - $this->display_admin_page_with_sidebar(); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - protected function _delete_question_groups() |
|
565 | - { |
|
566 | - $success = $this->_delete_items($this->_question_group_model); |
|
567 | - $this->_redirect_after_action($success, $this->_question_group_model->item_name($success), |
|
568 | - 'deleted permanently', array('action' => 'question_groups', 'status' => 'trash')); |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * @param bool $new_question_group |
|
574 | - */ |
|
575 | - protected function _insert_or_update_question_group($new_question_group = true) |
|
576 | - { |
|
577 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
578 | - $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
579 | - if ($new_question_group) { |
|
580 | - $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
581 | - $success = $QSG_ID ? 1 : 0; |
|
582 | - } else { |
|
583 | - $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
584 | - unset($set_column_values['QSG_ID']); |
|
585 | - $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
586 | - } |
|
587 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone); |
|
588 | - // update the existing related questions |
|
589 | - // BUT FIRST... delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group) |
|
590 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
591 | - // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
592 | - EEM_Question_Group_Question::instance()->delete(array( |
|
593 | - array( |
|
594 | - 'QST_ID' => $phone_question_id, |
|
595 | - 'QSG_ID' => array('!=', $QSG_ID), |
|
596 | - ), |
|
597 | - )); |
|
598 | - } |
|
599 | - /** @type EE_Question_Group $question_group */ |
|
600 | - $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
601 | - $questions = $question_group->questions(); |
|
602 | - // make sure system phone question is added to list of questions for this group |
|
603 | - if (! isset($questions[$phone_question_id])) { |
|
604 | - $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
605 | - } |
|
606 | - |
|
607 | - foreach ($questions as $question_ID => $question) { |
|
608 | - // first we always check for order. |
|
609 | - if (! empty($this->_req_data['question_orders'][$question_ID])) { |
|
610 | - //update question order |
|
611 | - $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
|
612 | - } |
|
613 | - |
|
614 | - // then we always check if adding or removing. |
|
615 | - if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
616 | - $question_group->add_question($question_ID); |
|
617 | - } else { |
|
618 | - // not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it) |
|
619 | - if ( |
|
620 | - in_array( |
|
621 | - $question->system_ID(), |
|
622 | - EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group()) |
|
623 | - ) |
|
624 | - ) { |
|
625 | - continue; |
|
626 | - } else { |
|
627 | - $question_group->remove_question($question_ID); |
|
628 | - } |
|
629 | - } |
|
630 | - } |
|
631 | - // save new related questions |
|
632 | - if (isset($this->_req_data['questions'])) { |
|
633 | - foreach ($this->_req_data['questions'] as $QST_ID) { |
|
634 | - $question_group->add_question($QST_ID); |
|
635 | - if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
636 | - $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
637 | - } |
|
638 | - } |
|
639 | - } |
|
640 | - |
|
641 | - if ($success !== false) { |
|
642 | - $msg = $new_question_group ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
643 | - $this->_question_group_model->item_name()) : sprintf(esc_html__('The %s has been updated', |
|
644 | - 'event_espresso'), $this->_question_group_model->item_name()); |
|
645 | - EE_Error::add_success($msg); |
|
646 | - } |
|
647 | - $this->_redirect_after_action(false, '', '', array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
648 | - true); |
|
649 | - |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * duplicates a question and all its question options and redirects to the new question. |
|
654 | - */ |
|
655 | - public function _duplicate_question() |
|
656 | - { |
|
657 | - $question_ID = (int)$this->_req_data['QST_ID']; |
|
658 | - $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
659 | - if ($question instanceof EE_Question) { |
|
660 | - $new_question = $question->duplicate(); |
|
661 | - if ($new_question instanceof EE_Question) { |
|
662 | - $this->_redirect_after_action(true, esc_html__('Question', 'event_espresso'), |
|
663 | - esc_html__('Duplicated', 'event_espresso'), |
|
664 | - array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), true); |
|
665 | - } else { |
|
666 | - global $wpdb; |
|
667 | - EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %1$d because: %2$s', |
|
668 | - 'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__); |
|
669 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
670 | - } |
|
671 | - } else { |
|
672 | - EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %d because it didn\'t exist!', |
|
673 | - 'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__); |
|
674 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
675 | - } |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * @param bool $trash |
|
681 | - */ |
|
682 | - protected function _trash_or_restore_question_groups($trash = true) |
|
683 | - { |
|
684 | - $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - *_trash_question |
|
690 | - */ |
|
691 | - protected function _trash_question() |
|
692 | - { |
|
693 | - $success = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']); |
|
694 | - $query_args = array('action' => 'default', 'status' => 'all'); |
|
695 | - $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * @param bool $trash |
|
701 | - */ |
|
702 | - protected function _trash_or_restore_questions($trash = true) |
|
703 | - { |
|
704 | - $this->_trash_or_restore_items($this->_question_model, $trash); |
|
705 | - } |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * Internally used to delete or restore items, using the request data. Meant to be |
|
710 | - * flexible between question or question groups |
|
711 | - * |
|
712 | - * @param EEM_Soft_Delete_Base $model |
|
713 | - * @param boolean $trash whether to trash or restore |
|
714 | - */ |
|
715 | - private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
716 | - { |
|
717 | - |
|
718 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
719 | - |
|
720 | - $success = 1; |
|
721 | - //Checkboxes |
|
722 | - //echo "trash $trash"; |
|
723 | - //var_dump($this->_req_data['checkbox']);die; |
|
724 | - if (isset($this->_req_data['checkbox'])) { |
|
725 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
726 | - // if array has more than one element than success message should be plural |
|
727 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
728 | - // cycle thru bulk action checkboxes |
|
729 | - while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
730 | - if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
731 | - $success = 0; |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - } else { |
|
736 | - // grab single id and delete |
|
737 | - $ID = absint($this->_req_data['checkbox']); |
|
738 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
739 | - $success = 0; |
|
740 | - } |
|
741 | - } |
|
742 | - |
|
743 | - } else { |
|
744 | - // delete via trash link |
|
745 | - // grab single id and delete |
|
746 | - $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
747 | - if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
748 | - $success = 0; |
|
749 | - } |
|
750 | - |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
755 | - //echo "action :$action"; |
|
756 | - //$action = 'questions' ? 'default' : $action; |
|
757 | - if ($trash) { |
|
758 | - $action_desc = 'trashed'; |
|
759 | - $status = 'trash'; |
|
760 | - } else { |
|
761 | - $action_desc = 'restored'; |
|
762 | - $status = 'all'; |
|
763 | - } |
|
764 | - $this->_redirect_after_action($success, $model->item_name($success), $action_desc, |
|
765 | - array('action' => $action, 'status' => $status)); |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * @param $per_page |
|
771 | - * @param int $current_page |
|
772 | - * @param bool|false $count |
|
773 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
774 | - */ |
|
775 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
776 | - { |
|
777 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
778 | - |
|
779 | - if ($count) { |
|
780 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
781 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
782 | - $results = $this->_question_model->count_deleted($where); |
|
783 | - } else { |
|
784 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
785 | - $results = $this->_question_model->get_all_deleted($query_params); |
|
786 | - } |
|
787 | - return $results; |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - /** |
|
792 | - * @param $per_page |
|
793 | - * @param int $current_page |
|
794 | - * @param bool|false $count |
|
795 | - * @return \EE_Soft_Delete_Base_Class[] |
|
796 | - */ |
|
797 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
798 | - { |
|
799 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
800 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
801 | - if ($count) { |
|
802 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
803 | - $results = $questionGroupModel->count($where); |
|
804 | - } else { |
|
805 | - $results = $questionGroupModel->get_all($query_params); |
|
806 | - } |
|
807 | - return $results; |
|
808 | - } |
|
809 | - |
|
810 | - |
|
811 | - /** |
|
812 | - * @param $per_page |
|
813 | - * @param int $current_page |
|
814 | - * @param bool $count |
|
815 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
816 | - */ |
|
817 | - public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
818 | - { |
|
819 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
820 | - $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
821 | - if ($count) { |
|
822 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
823 | - $query_params['limit'] = null; |
|
824 | - $results = $questionGroupModel->count_deleted($where); |
|
825 | - } else { |
|
826 | - $results = $questionGroupModel->get_all_deleted($query_params); |
|
827 | - } |
|
828 | - return $results; |
|
829 | - } |
|
830 | - |
|
831 | - |
|
832 | - /** |
|
833 | - * method for performing updates to question order |
|
834 | - * |
|
835 | - * @return array results array |
|
836 | - */ |
|
837 | - public function update_question_group_order() |
|
838 | - { |
|
839 | - |
|
840 | - $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
841 | - |
|
842 | - // grab our row IDs |
|
843 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
844 | - ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
845 | - : array(); |
|
846 | - |
|
847 | - $perpage = ! empty($this->_req_data['perpage']) |
|
848 | - ? (int)$this->_req_data['perpage'] |
|
849 | - : null; |
|
850 | - $curpage = ! empty($this->_req_data['curpage']) |
|
851 | - ? (int)$this->_req_data['curpage'] |
|
852 | - : null; |
|
853 | - |
|
854 | - if (! empty($row_ids)) { |
|
855 | - //figure out where we start the row_id count at for the current page. |
|
856 | - $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
857 | - |
|
858 | - $row_count = count($row_ids); |
|
859 | - for ($i = 0; $i < $row_count; $i++) { |
|
860 | - //Update the questions when re-ordering |
|
861 | - $updated = EEM_Question_Group::instance()->update( |
|
862 | - array('QSG_order' => $qsgcount), |
|
863 | - array(array('QSG_ID' => $row_ids[$i])) |
|
864 | - ); |
|
865 | - if ($updated === false) { |
|
866 | - $success = false; |
|
867 | - } |
|
868 | - $qsgcount++; |
|
869 | - } |
|
870 | - } else { |
|
871 | - $success = false; |
|
872 | - } |
|
873 | - |
|
874 | - $errors = ! $success |
|
875 | - ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
876 | - : false; |
|
877 | - |
|
878 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
879 | - die(); |
|
880 | - |
|
881 | - } |
|
882 | - |
|
883 | - |
|
884 | - |
|
885 | - /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
886 | - |
|
887 | - |
|
888 | - /** |
|
889 | - * _reg_form_settings |
|
890 | - * |
|
891 | - * @throws \EE_Error |
|
892 | - */ |
|
893 | - protected function _reg_form_settings() |
|
894 | - { |
|
895 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
896 | - add_action( |
|
897 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
898 | - array($this, 'email_validation_settings_form'), |
|
899 | - 2 |
|
900 | - ); |
|
901 | - $this->_template_args = (array)apply_filters( |
|
902 | - 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
903 | - $this->_template_args |
|
904 | - ); |
|
905 | - $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
906 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
907 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
908 | - REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
909 | - $this->_template_args, |
|
910 | - true |
|
911 | - ); |
|
912 | - $this->display_admin_page_with_sidebar(); |
|
913 | - } |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * _update_reg_form_settings |
|
918 | - */ |
|
919 | - protected function _update_reg_form_settings() |
|
920 | - { |
|
921 | - EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
922 | - EE_Registry::instance()->CFG->registration |
|
923 | - ); |
|
924 | - EE_Registry::instance()->CFG->registration = apply_filters( |
|
925 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
926 | - EE_Registry::instance()->CFG->registration |
|
927 | - ); |
|
928 | - $success = $this->_update_espresso_configuration( |
|
929 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
930 | - EE_Registry::instance()->CFG, |
|
931 | - __FILE__, __FUNCTION__, __LINE__ |
|
932 | - ); |
|
933 | - $this->_redirect_after_action($success, esc_html__('Registration Form Options', 'event_espresso'), 'updated', |
|
934 | - array('action' => 'view_reg_form_settings')); |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * email_validation_settings_form |
|
940 | - * |
|
941 | - * @access public |
|
942 | - * @return void |
|
943 | - * @throws \EE_Error |
|
944 | - */ |
|
945 | - public function email_validation_settings_form() |
|
946 | - { |
|
947 | - echo $this->_email_validation_settings_form()->get_html(); |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - /** |
|
952 | - * _email_validation_settings_form |
|
953 | - * |
|
954 | - * @access protected |
|
955 | - * @return EE_Form_Section_Proper |
|
956 | - * @throws \EE_Error |
|
957 | - */ |
|
958 | - protected function _email_validation_settings_form() |
|
959 | - { |
|
960 | - return new EE_Form_Section_Proper( |
|
961 | - array( |
|
962 | - 'name' => 'email_validation_settings', |
|
963 | - 'html_id' => 'email_validation_settings', |
|
964 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
965 | - 'subsections' => apply_filters( |
|
966 | - 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
967 | - array( |
|
968 | - 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
969 | - EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
970 | - ), |
|
971 | - 'email_validation_level' => new EE_Select_Input( |
|
972 | - array( |
|
973 | - 'basic' => esc_html__('Basic', 'event_espresso'), |
|
974 | - 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
975 | - 'i18n' => esc_html__('International', 'event_espresso'), |
|
976 | - 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
977 | - ), |
|
978 | - array( |
|
979 | - 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
980 | - . EEH_Template::get_help_tab_link('email_validation_info'), |
|
981 | - 'html_help_text' => esc_html__('These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
982 | - 'event_espresso'), |
|
983 | - 'default' => isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
984 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
985 | - : 'wp_default', |
|
986 | - 'required' => false, |
|
987 | - ) |
|
988 | - ), |
|
989 | - ) |
|
990 | - ), |
|
991 | - ) |
|
992 | - ); |
|
993 | - } |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * update_email_validation_settings_form |
|
998 | - * |
|
999 | - * @access public |
|
1000 | - * @param \EE_Registration_Config $EE_Registration_Config |
|
1001 | - * @return \EE_Registration_Config |
|
1002 | - */ |
|
1003 | - public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1004 | - { |
|
1005 | - $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
1006 | - try { |
|
1007 | - $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
1008 | - // if not displaying a form, then check for form submission |
|
1009 | - if ($email_validation_settings_form->was_submitted()) { |
|
1010 | - // capture form data |
|
1011 | - $email_validation_settings_form->receive_form_submission(); |
|
1012 | - // validate form data |
|
1013 | - if ($email_validation_settings_form->is_valid()) { |
|
1014 | - // grab validated data from form |
|
1015 | - $valid_data = $email_validation_settings_form->valid_data(); |
|
1016 | - if (isset($valid_data['email_validation_level'])) { |
|
1017 | - $email_validation_level = $valid_data['email_validation_level']; |
|
1018 | - // now if they want to use international email addresses |
|
1019 | - if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
1020 | - // in case we need to reset their email validation level, |
|
1021 | - // make sure that the previous value wasn't already set to one of the i18n options. |
|
1022 | - if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
1023 | - // if so, then reset it back to "basic" since that is the only other option that, |
|
1024 | - // despite offering poor validation, supports i18n email addresses |
|
1025 | - $prev_email_validation_level = 'basic'; |
|
1026 | - } |
|
1027 | - // confirm our i18n email validation will work on the server |
|
1028 | - if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1029 | - // or reset email validation level to previous value |
|
1030 | - $email_validation_level = $prev_email_validation_level; |
|
1031 | - } |
|
1032 | - } |
|
1033 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1034 | - } else { |
|
1035 | - EE_Error::add_error( |
|
1036 | - esc_html__( |
|
1037 | - 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
1038 | - 'event_espresso' |
|
1039 | - ), |
|
1040 | - __FILE__, __FUNCTION__, __LINE__ |
|
1041 | - ); |
|
1042 | - } |
|
1043 | - } else { |
|
1044 | - if ($email_validation_settings_form->submission_error_message() !== '') { |
|
1045 | - EE_Error::add_error( |
|
1046 | - $email_validation_settings_form->submission_error_message(), |
|
1047 | - __FILE__, __FUNCTION__, __LINE__ |
|
1048 | - ); |
|
1049 | - } |
|
1050 | - } |
|
1051 | - } |
|
1052 | - } catch (EE_Error $e) { |
|
1053 | - $e->get_error(); |
|
1054 | - } |
|
1055 | - return $EE_Registration_Config; |
|
1056 | - } |
|
1057 | - |
|
1058 | - |
|
1059 | - /** |
|
1060 | - * confirms that the server's PHP version has the PCRE module enabled, |
|
1061 | - * and that the PCRE version works with our i18n email validation |
|
1062 | - * |
|
1063 | - * @param \EE_Registration_Config $EE_Registration_Config |
|
1064 | - * @param string $email_validation_level |
|
1065 | - * @return bool |
|
1066 | - */ |
|
1067 | - private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
1068 | - { |
|
1069 | - // first check that PCRE is enabled |
|
1070 | - if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1071 | - EE_Error::add_error( |
|
1072 | - sprintf( |
|
1073 | - esc_html__( |
|
1074 | - 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
1075 | - 'event_espresso' |
|
1076 | - ), |
|
1077 | - '<br />' |
|
1078 | - ), |
|
1079 | - __FILE__, |
|
1080 | - __FUNCTION__, |
|
1081 | - __LINE__ |
|
1082 | - ); |
|
1083 | - return false; |
|
1084 | - } else { |
|
1085 | - // PCRE support is enabled, but let's still |
|
1086 | - // perform a test to see if the server will support it. |
|
1087 | - // but first, save the updated validation level to the config, |
|
1088 | - // so that the validation strategy picks it up. |
|
1089 | - // this will get bumped back down if it doesn't work |
|
1090 | - $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1091 | - try { |
|
1092 | - $email_validator = new EE_Email_Validation_Strategy(); |
|
1093 | - $i18n_email_address = apply_filters( |
|
1094 | - 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
1095 | - 'jägerjü[email protected]' |
|
1096 | - ); |
|
1097 | - $email_validator->validate($i18n_email_address); |
|
1098 | - } catch (Exception $e) { |
|
1099 | - EE_Error::add_error( |
|
1100 | - sprintf( |
|
1101 | - esc_html__( |
|
1102 | - 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
1103 | - 'event_espresso' |
|
1104 | - ), |
|
1105 | - '<br />', |
|
1106 | - '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>' |
|
1107 | - ), |
|
1108 | - __FILE__, __FUNCTION__, __LINE__ |
|
1109 | - ); |
|
1110 | - return false; |
|
1111 | - } |
|
1112 | - } |
|
1113 | - return true; |
|
1114 | - } |
|
28 | + /** |
|
29 | + * @Constructor |
|
30 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
31 | + * @access public |
|
32 | + */ |
|
33 | + public function __construct($routing = true) |
|
34 | + { |
|
35 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS); |
|
36 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS); |
|
37 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/'); |
|
38 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS); |
|
39 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/'); |
|
40 | + parent::__construct($routing); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + protected function _extend_page_config() |
|
45 | + { |
|
46 | + $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
|
47 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
48 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
|
49 | + |
|
50 | + $new_page_routes = array( |
|
51 | + 'question_groups' => array( |
|
52 | + 'func' => '_question_groups_overview_list_table', |
|
53 | + 'capability' => 'ee_read_question_groups', |
|
54 | + ), |
|
55 | + 'add_question' => array( |
|
56 | + 'func' => '_edit_question', |
|
57 | + 'capability' => 'ee_edit_questions', |
|
58 | + ), |
|
59 | + 'insert_question' => array( |
|
60 | + 'func' => '_insert_or_update_question', |
|
61 | + 'args' => array('new_question' => true), |
|
62 | + 'capability' => 'ee_edit_questions', |
|
63 | + 'noheader' => true, |
|
64 | + ), |
|
65 | + 'duplicate_question' => array( |
|
66 | + 'func' => '_duplicate_question', |
|
67 | + 'capability' => 'ee_edit_questions', |
|
68 | + 'noheader' => true, |
|
69 | + ), |
|
70 | + 'trash_question' => array( |
|
71 | + 'func' => '_trash_question', |
|
72 | + 'capability' => 'ee_delete_question', |
|
73 | + 'obj_id' => $qst_id, |
|
74 | + 'noheader' => true, |
|
75 | + ), |
|
76 | + |
|
77 | + 'restore_question' => array( |
|
78 | + 'func' => '_trash_or_restore_questions', |
|
79 | + 'capability' => 'ee_delete_question', |
|
80 | + 'obj_id' => $qst_id, |
|
81 | + 'args' => array('trash' => false), |
|
82 | + 'noheader' => true, |
|
83 | + ), |
|
84 | + |
|
85 | + 'delete_question' => array( |
|
86 | + 'func' => '_delete_question', |
|
87 | + 'capability' => 'ee_delete_question', |
|
88 | + 'obj_id' => $qst_id, |
|
89 | + 'noheader' => true, |
|
90 | + ), |
|
91 | + |
|
92 | + 'trash_questions' => array( |
|
93 | + 'func' => '_trash_or_restore_questions', |
|
94 | + 'capability' => 'ee_delete_questions', |
|
95 | + 'args' => array('trash' => true), |
|
96 | + 'noheader' => true, |
|
97 | + ), |
|
98 | + |
|
99 | + 'restore_questions' => array( |
|
100 | + 'func' => '_trash_or_restore_questions', |
|
101 | + 'capability' => 'ee_delete_questions', |
|
102 | + 'args' => array('trash' => false), |
|
103 | + 'noheader' => true, |
|
104 | + ), |
|
105 | + |
|
106 | + 'delete_questions' => array( |
|
107 | + 'func' => '_delete_questions', |
|
108 | + 'args' => array(), |
|
109 | + 'capability' => 'ee_delete_questions', |
|
110 | + 'noheader' => true, |
|
111 | + ), |
|
112 | + |
|
113 | + 'add_question_group' => array( |
|
114 | + 'func' => '_edit_question_group', |
|
115 | + 'capability' => 'ee_edit_question_groups', |
|
116 | + ), |
|
117 | + |
|
118 | + 'edit_question_group' => array( |
|
119 | + 'func' => '_edit_question_group', |
|
120 | + 'capability' => 'ee_edit_question_group', |
|
121 | + 'obj_id' => $qsg_id, |
|
122 | + 'args' => array('edit'), |
|
123 | + ), |
|
124 | + |
|
125 | + 'delete_question_groups' => array( |
|
126 | + 'func' => '_delete_question_groups', |
|
127 | + 'capability' => 'ee_delete_question_groups', |
|
128 | + 'noheader' => true, |
|
129 | + ), |
|
130 | + |
|
131 | + 'delete_question_group' => array( |
|
132 | + 'func' => '_delete_question_groups', |
|
133 | + 'capability' => 'ee_delete_question_group', |
|
134 | + 'obj_id' => $qsg_id, |
|
135 | + 'noheader' => true, |
|
136 | + ), |
|
137 | + |
|
138 | + 'trash_question_group' => array( |
|
139 | + 'func' => '_trash_or_restore_question_groups', |
|
140 | + 'args' => array('trash' => true), |
|
141 | + 'capability' => 'ee_delete_question_group', |
|
142 | + 'obj_id' => $qsg_id, |
|
143 | + 'noheader' => true, |
|
144 | + ), |
|
145 | + |
|
146 | + 'restore_question_group' => array( |
|
147 | + 'func' => '_trash_or_restore_question_groups', |
|
148 | + 'args' => array('trash' => false), |
|
149 | + 'capability' => 'ee_delete_question_group', |
|
150 | + 'obj_id' => $qsg_id, |
|
151 | + 'noheader' => true, |
|
152 | + ), |
|
153 | + |
|
154 | + 'insert_question_group' => array( |
|
155 | + 'func' => '_insert_or_update_question_group', |
|
156 | + 'args' => array('new_question_group' => true), |
|
157 | + 'capability' => 'ee_edit_question_groups', |
|
158 | + 'noheader' => true, |
|
159 | + ), |
|
160 | + |
|
161 | + 'update_question_group' => array( |
|
162 | + 'func' => '_insert_or_update_question_group', |
|
163 | + 'args' => array('new_question_group' => false), |
|
164 | + 'capability' => 'ee_edit_question_group', |
|
165 | + 'obj_id' => $qsg_id, |
|
166 | + 'noheader' => true, |
|
167 | + ), |
|
168 | + |
|
169 | + 'trash_question_groups' => array( |
|
170 | + 'func' => '_trash_or_restore_question_groups', |
|
171 | + 'args' => array('trash' => true), |
|
172 | + 'capability' => 'ee_delete_question_groups', |
|
173 | + 'noheader' => array('trash' => false), |
|
174 | + ), |
|
175 | + |
|
176 | + 'restore_question_groups' => array( |
|
177 | + 'func' => '_trash_or_restore_question_groups', |
|
178 | + 'args' => array('trash' => false), |
|
179 | + 'capability' => 'ee_delete_question_groups', |
|
180 | + 'noheader' => true, |
|
181 | + ), |
|
182 | + |
|
183 | + |
|
184 | + 'espresso_update_question_group_order' => array( |
|
185 | + 'func' => 'update_question_group_order', |
|
186 | + 'capability' => 'ee_edit_question_groups', |
|
187 | + 'noheader' => true, |
|
188 | + ), |
|
189 | + |
|
190 | + 'view_reg_form_settings' => array( |
|
191 | + 'func' => '_reg_form_settings', |
|
192 | + 'capability' => 'manage_options', |
|
193 | + ), |
|
194 | + |
|
195 | + 'update_reg_form_settings' => array( |
|
196 | + 'func' => '_update_reg_form_settings', |
|
197 | + 'capability' => 'manage_options', |
|
198 | + 'noheader' => true, |
|
199 | + ), |
|
200 | + ); |
|
201 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
202 | + |
|
203 | + $new_page_config = array( |
|
204 | + |
|
205 | + 'question_groups' => array( |
|
206 | + 'nav' => array( |
|
207 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
208 | + 'order' => 20, |
|
209 | + ), |
|
210 | + 'list_table' => 'Registration_Form_Question_Groups_Admin_List_Table', |
|
211 | + 'help_tabs' => array( |
|
212 | + 'registration_form_question_groups_help_tab' => array( |
|
213 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
214 | + 'filename' => 'registration_form_question_groups', |
|
215 | + ), |
|
216 | + 'registration_form_question_groups_table_column_headings_help_tab' => array( |
|
217 | + 'title' => esc_html__('Question Groups Table Column Headings', 'event_espresso'), |
|
218 | + 'filename' => 'registration_form_question_groups_table_column_headings', |
|
219 | + ), |
|
220 | + 'registration_form_question_groups_views_bulk_actions_search_help_tab' => array( |
|
221 | + 'title' => esc_html__('Question Groups Views & Bulk Actions & Search', 'event_espresso'), |
|
222 | + 'filename' => 'registration_form_question_groups_views_bulk_actions_search', |
|
223 | + ), |
|
224 | + ), |
|
225 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
226 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
227 | + 'require_nonce' => false, |
|
228 | + 'qtips' => array( |
|
229 | + 'EE_Registration_Form_Tips', |
|
230 | + ), |
|
231 | + ), |
|
232 | + |
|
233 | + 'add_question' => array( |
|
234 | + 'nav' => array( |
|
235 | + 'label' => esc_html__('Add Question', 'event_espresso'), |
|
236 | + 'order' => 5, |
|
237 | + 'persistent' => false, |
|
238 | + ), |
|
239 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
240 | + 'help_tabs' => array( |
|
241 | + 'registration_form_add_question_help_tab' => array( |
|
242 | + 'title' => esc_html__('Add Question', 'event_espresso'), |
|
243 | + 'filename' => 'registration_form_add_question', |
|
244 | + ), |
|
245 | + ), |
|
246 | + 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
247 | + 'require_nonce' => false, |
|
248 | + ), |
|
249 | + |
|
250 | + 'add_question_group' => array( |
|
251 | + 'nav' => array( |
|
252 | + 'label' => esc_html__('Add Question Group', 'event_espresso'), |
|
253 | + 'order' => 5, |
|
254 | + 'persistent' => false, |
|
255 | + ), |
|
256 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
257 | + 'help_tabs' => array( |
|
258 | + 'registration_form_add_question_group_help_tab' => array( |
|
259 | + 'title' => esc_html__('Add Question Group', 'event_espresso'), |
|
260 | + 'filename' => 'registration_form_add_question_group', |
|
261 | + ), |
|
262 | + ), |
|
263 | + 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
264 | + 'require_nonce' => false, |
|
265 | + ), |
|
266 | + |
|
267 | + 'edit_question_group' => array( |
|
268 | + 'nav' => array( |
|
269 | + 'label' => esc_html__('Edit Question Group', 'event_espresso'), |
|
270 | + 'order' => 5, |
|
271 | + 'persistent' => false, |
|
272 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']), |
|
273 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
274 | + ), |
|
275 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
276 | + 'help_tabs' => array( |
|
277 | + 'registration_form_edit_question_group_help_tab' => array( |
|
278 | + 'title' => esc_html__('Edit Question Group', 'event_espresso'), |
|
279 | + 'filename' => 'registration_form_edit_question_group', |
|
280 | + ), |
|
281 | + ), |
|
282 | + 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
283 | + 'require_nonce' => false, |
|
284 | + ), |
|
285 | + |
|
286 | + 'view_reg_form_settings' => array( |
|
287 | + 'nav' => array( |
|
288 | + 'label' => esc_html__('Reg Form Settings', 'event_espresso'), |
|
289 | + 'order' => 40, |
|
290 | + ), |
|
291 | + 'labels' => array( |
|
292 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
293 | + ), |
|
294 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
295 | + 'help_tabs' => array( |
|
296 | + 'registration_form_reg_form_settings_help_tab' => array( |
|
297 | + 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
298 | + 'filename' => 'registration_form_reg_form_settings', |
|
299 | + ), |
|
300 | + ), |
|
301 | + 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
302 | + 'require_nonce' => false, |
|
303 | + ), |
|
304 | + |
|
305 | + ); |
|
306 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
307 | + |
|
308 | + //change the list table we're going to use so it's the NEW list table! |
|
309 | + $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
|
310 | + |
|
311 | + |
|
312 | + //additional labels |
|
313 | + $new_labels = array( |
|
314 | + 'add_question' => esc_html__('Add New Question', 'event_espresso'), |
|
315 | + 'delete_question' => esc_html__('Delete Question', 'event_espresso'), |
|
316 | + 'add_question_group' => esc_html__('Add New Question Group', 'event_espresso'), |
|
317 | + 'edit_question_group' => esc_html__('Edit Question Group', 'event_espresso'), |
|
318 | + 'delete_question_group' => esc_html__('Delete Question Group', 'event_espresso'), |
|
319 | + ); |
|
320 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + protected function _ajax_hooks() |
|
326 | + { |
|
327 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + public function load_scripts_styles_question_groups() |
|
332 | + { |
|
333 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + public function load_scripts_styles_add_question_group() |
|
338 | + { |
|
339 | + $this->load_scripts_styles_forms(); |
|
340 | + $this->load_sortable_question_script(); |
|
341 | + } |
|
342 | + |
|
343 | + public function load_scripts_styles_edit_question_group() |
|
344 | + { |
|
345 | + $this->load_scripts_styles_forms(); |
|
346 | + $this->load_sortable_question_script(); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * registers and enqueues script for questions |
|
352 | + * |
|
353 | + * @return void |
|
354 | + */ |
|
355 | + public function load_sortable_question_script() |
|
356 | + { |
|
357 | + wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', |
|
358 | + array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
359 | + wp_enqueue_script('ee-question-sortable'); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + protected function _set_list_table_views_default() |
|
364 | + { |
|
365 | + $this->_views = array( |
|
366 | + 'all' => array( |
|
367 | + 'slug' => 'all', |
|
368 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
369 | + 'count' => 0, |
|
370 | + 'bulk_action' => array( |
|
371 | + 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
|
372 | + ), |
|
373 | + ), |
|
374 | + ); |
|
375 | + |
|
376 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
377 | + 'espresso_registration_form_trash_questions') |
|
378 | + ) { |
|
379 | + $this->_views['trash'] = array( |
|
380 | + 'slug' => 'trash', |
|
381 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
382 | + 'count' => 0, |
|
383 | + 'bulk_action' => array( |
|
384 | + 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
|
385 | + 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
|
386 | + ), |
|
387 | + ); |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + protected function _set_list_table_views_question_groups() |
|
393 | + { |
|
394 | + $this->_views = array( |
|
395 | + 'all' => array( |
|
396 | + 'slug' => 'all', |
|
397 | + 'label' => esc_html__('All', 'event_espresso'), |
|
398 | + 'count' => 0, |
|
399 | + 'bulk_action' => array( |
|
400 | + 'trash_question_groups' => esc_html__('Trash', 'event_espresso'), |
|
401 | + ), |
|
402 | + ), |
|
403 | + ); |
|
404 | + |
|
405 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups', |
|
406 | + 'espresso_registration_form_trash_question_groups') |
|
407 | + ) { |
|
408 | + $this->_views['trash'] = array( |
|
409 | + 'slug' => 'trash', |
|
410 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
411 | + 'count' => 0, |
|
412 | + 'bulk_action' => array( |
|
413 | + 'delete_question_groups' => esc_html__('Delete Permanently', 'event_espresso'), |
|
414 | + 'restore_question_groups' => esc_html__('Restore', 'event_espresso'), |
|
415 | + ), |
|
416 | + ); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + protected function _questions_overview_list_table() |
|
422 | + { |
|
423 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
424 | + 'add_question', |
|
425 | + 'add_question', |
|
426 | + array(), |
|
427 | + 'add-new-h2' |
|
428 | + ); |
|
429 | + parent::_questions_overview_list_table(); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + protected function _question_groups_overview_list_table() |
|
434 | + { |
|
435 | + $this->_search_btn_label = esc_html__('Question Groups', 'event_espresso'); |
|
436 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
437 | + 'add_question_group', |
|
438 | + 'add_question_group', |
|
439 | + array(), |
|
440 | + 'add-new-h2' |
|
441 | + ); |
|
442 | + $this->display_admin_list_table_page_with_sidebar(); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + protected function _delete_question() |
|
447 | + { |
|
448 | + $success = $this->_delete_items($this->_question_model); |
|
449 | + $this->_redirect_after_action( |
|
450 | + $success, |
|
451 | + $this->_question_model->item_name($success), |
|
452 | + 'deleted', |
|
453 | + array('action' => 'default', 'status' => 'all') |
|
454 | + ); |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + protected function _delete_questions() |
|
459 | + { |
|
460 | + $success = $this->_delete_items($this->_question_model); |
|
461 | + $this->_redirect_after_action( |
|
462 | + $success, |
|
463 | + $this->_question_model->item_name($success), |
|
464 | + 'deleted permanently', |
|
465 | + array('action' => 'default', 'status' => 'trash') |
|
466 | + ); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Performs the deletion of a single or multiple questions or question groups. |
|
472 | + * |
|
473 | + * @param EEM_Soft_Delete_Base $model |
|
474 | + * @return int number of items deleted permanently |
|
475 | + */ |
|
476 | + private function _delete_items(EEM_Soft_Delete_Base $model) |
|
477 | + { |
|
478 | + $success = 0; |
|
479 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
480 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
481 | + // if array has more than one element than success message should be plural |
|
482 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
483 | + // cycle thru bulk action checkboxes |
|
484 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
485 | + if (! $this->_delete_item($ID, $model)) { |
|
486 | + $success = 0; |
|
487 | + } |
|
488 | + } |
|
489 | + |
|
490 | + } elseif (! empty($this->_req_data['QSG_ID'])) { |
|
491 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
492 | + |
|
493 | + } elseif (! empty($this->_req_data['QST_ID'])) { |
|
494 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
495 | + } else { |
|
496 | + EE_Error::add_error(sprintf(esc_html__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", |
|
497 | + "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
498 | + } |
|
499 | + return $success; |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Deletes the specified question (and its associated question options) or question group |
|
504 | + * |
|
505 | + * @param int $id |
|
506 | + * @param EEM_Soft_Delete_Base $model |
|
507 | + * @return boolean |
|
508 | + */ |
|
509 | + protected function _delete_item($id, $model) |
|
510 | + { |
|
511 | + if ($model instanceof EEM_Question) { |
|
512 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
513 | + } |
|
514 | + return $model->delete_permanently_by_ID(absint($id)); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /****************************** QUESTION GROUPS ******************************/ |
|
519 | + |
|
520 | + |
|
521 | + protected function _edit_question_group($type = 'add') |
|
522 | + { |
|
523 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
524 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : false; |
|
525 | + |
|
526 | + switch ($this->_req_action) { |
|
527 | + case 'add_question_group' : |
|
528 | + $this->_admin_page_title = esc_html__('Add Question Group', 'event_espresso'); |
|
529 | + break; |
|
530 | + case 'edit_question_group' : |
|
531 | + $this->_admin_page_title = esc_html__('Edit Question Group', 'event_espresso'); |
|
532 | + break; |
|
533 | + default : |
|
534 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
535 | + } |
|
536 | + // add ID to title if editing |
|
537 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
538 | + if ($ID) { |
|
539 | + /** @var EE_Question_Group $questionGroup */ |
|
540 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
541 | + $additional_hidden_fields = array('QSG_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
542 | + $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
|
543 | + } else { |
|
544 | + /** @var EE_Question_Group $questionGroup */ |
|
545 | + $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
|
546 | + $questionGroup->set_order_to_latest(); |
|
547 | + $this->_set_add_edit_form_tags('insert_question_group'); |
|
548 | + } |
|
549 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
550 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
551 | + $this->_template_args['QSG_ID'] = $ID ? $ID : true; |
|
552 | + $this->_template_args['question_group'] = $questionGroup; |
|
553 | + |
|
554 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
555 | + $this->_set_publish_post_box_vars('id', $ID, false, $redirect_URL); |
|
556 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', |
|
557 | + $this->_template_args, true); |
|
558 | + |
|
559 | + // the details template wrapper |
|
560 | + $this->display_admin_page_with_sidebar(); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + protected function _delete_question_groups() |
|
565 | + { |
|
566 | + $success = $this->_delete_items($this->_question_group_model); |
|
567 | + $this->_redirect_after_action($success, $this->_question_group_model->item_name($success), |
|
568 | + 'deleted permanently', array('action' => 'question_groups', 'status' => 'trash')); |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * @param bool $new_question_group |
|
574 | + */ |
|
575 | + protected function _insert_or_update_question_group($new_question_group = true) |
|
576 | + { |
|
577 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
578 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
579 | + if ($new_question_group) { |
|
580 | + $QSG_ID = $this->_question_group_model->insert($set_column_values); |
|
581 | + $success = $QSG_ID ? 1 : 0; |
|
582 | + } else { |
|
583 | + $QSG_ID = absint($this->_req_data['QSG_ID']); |
|
584 | + unset($set_column_values['QSG_ID']); |
|
585 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
586 | + } |
|
587 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone); |
|
588 | + // update the existing related questions |
|
589 | + // BUT FIRST... delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group) |
|
590 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
591 | + // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
|
592 | + EEM_Question_Group_Question::instance()->delete(array( |
|
593 | + array( |
|
594 | + 'QST_ID' => $phone_question_id, |
|
595 | + 'QSG_ID' => array('!=', $QSG_ID), |
|
596 | + ), |
|
597 | + )); |
|
598 | + } |
|
599 | + /** @type EE_Question_Group $question_group */ |
|
600 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
601 | + $questions = $question_group->questions(); |
|
602 | + // make sure system phone question is added to list of questions for this group |
|
603 | + if (! isset($questions[$phone_question_id])) { |
|
604 | + $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
605 | + } |
|
606 | + |
|
607 | + foreach ($questions as $question_ID => $question) { |
|
608 | + // first we always check for order. |
|
609 | + if (! empty($this->_req_data['question_orders'][$question_ID])) { |
|
610 | + //update question order |
|
611 | + $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
|
612 | + } |
|
613 | + |
|
614 | + // then we always check if adding or removing. |
|
615 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
616 | + $question_group->add_question($question_ID); |
|
617 | + } else { |
|
618 | + // not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it) |
|
619 | + if ( |
|
620 | + in_array( |
|
621 | + $question->system_ID(), |
|
622 | + EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group()) |
|
623 | + ) |
|
624 | + ) { |
|
625 | + continue; |
|
626 | + } else { |
|
627 | + $question_group->remove_question($question_ID); |
|
628 | + } |
|
629 | + } |
|
630 | + } |
|
631 | + // save new related questions |
|
632 | + if (isset($this->_req_data['questions'])) { |
|
633 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
634 | + $question_group->add_question($QST_ID); |
|
635 | + if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
636 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
637 | + } |
|
638 | + } |
|
639 | + } |
|
640 | + |
|
641 | + if ($success !== false) { |
|
642 | + $msg = $new_question_group ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
643 | + $this->_question_group_model->item_name()) : sprintf(esc_html__('The %s has been updated', |
|
644 | + 'event_espresso'), $this->_question_group_model->item_name()); |
|
645 | + EE_Error::add_success($msg); |
|
646 | + } |
|
647 | + $this->_redirect_after_action(false, '', '', array('action' => 'edit_question_group', 'QSG_ID' => $QSG_ID), |
|
648 | + true); |
|
649 | + |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * duplicates a question and all its question options and redirects to the new question. |
|
654 | + */ |
|
655 | + public function _duplicate_question() |
|
656 | + { |
|
657 | + $question_ID = (int)$this->_req_data['QST_ID']; |
|
658 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
659 | + if ($question instanceof EE_Question) { |
|
660 | + $new_question = $question->duplicate(); |
|
661 | + if ($new_question instanceof EE_Question) { |
|
662 | + $this->_redirect_after_action(true, esc_html__('Question', 'event_espresso'), |
|
663 | + esc_html__('Duplicated', 'event_espresso'), |
|
664 | + array('action' => 'edit_question', 'QST_ID' => $new_question->ID()), true); |
|
665 | + } else { |
|
666 | + global $wpdb; |
|
667 | + EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %1$d because: %2$s', |
|
668 | + 'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__); |
|
669 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
670 | + } |
|
671 | + } else { |
|
672 | + EE_Error::add_error(sprintf(esc_html__('Could not duplicate question with ID %d because it didn\'t exist!', |
|
673 | + 'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__); |
|
674 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
675 | + } |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * @param bool $trash |
|
681 | + */ |
|
682 | + protected function _trash_or_restore_question_groups($trash = true) |
|
683 | + { |
|
684 | + $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + *_trash_question |
|
690 | + */ |
|
691 | + protected function _trash_question() |
|
692 | + { |
|
693 | + $success = $this->_question_model->delete_by_ID((int)$this->_req_data['QST_ID']); |
|
694 | + $query_args = array('action' => 'default', 'status' => 'all'); |
|
695 | + $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * @param bool $trash |
|
701 | + */ |
|
702 | + protected function _trash_or_restore_questions($trash = true) |
|
703 | + { |
|
704 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
705 | + } |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * Internally used to delete or restore items, using the request data. Meant to be |
|
710 | + * flexible between question or question groups |
|
711 | + * |
|
712 | + * @param EEM_Soft_Delete_Base $model |
|
713 | + * @param boolean $trash whether to trash or restore |
|
714 | + */ |
|
715 | + private function _trash_or_restore_items(EEM_Soft_Delete_Base $model, $trash = true) |
|
716 | + { |
|
717 | + |
|
718 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
719 | + |
|
720 | + $success = 1; |
|
721 | + //Checkboxes |
|
722 | + //echo "trash $trash"; |
|
723 | + //var_dump($this->_req_data['checkbox']);die; |
|
724 | + if (isset($this->_req_data['checkbox'])) { |
|
725 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
726 | + // if array has more than one element than success message should be plural |
|
727 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
728 | + // cycle thru bulk action checkboxes |
|
729 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
730 | + if (! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
731 | + $success = 0; |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + } else { |
|
736 | + // grab single id and delete |
|
737 | + $ID = absint($this->_req_data['checkbox']); |
|
738 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
739 | + $success = 0; |
|
740 | + } |
|
741 | + } |
|
742 | + |
|
743 | + } else { |
|
744 | + // delete via trash link |
|
745 | + // grab single id and delete |
|
746 | + $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
747 | + if (! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
748 | + $success = 0; |
|
749 | + } |
|
750 | + |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
755 | + //echo "action :$action"; |
|
756 | + //$action = 'questions' ? 'default' : $action; |
|
757 | + if ($trash) { |
|
758 | + $action_desc = 'trashed'; |
|
759 | + $status = 'trash'; |
|
760 | + } else { |
|
761 | + $action_desc = 'restored'; |
|
762 | + $status = 'all'; |
|
763 | + } |
|
764 | + $this->_redirect_after_action($success, $model->item_name($success), $action_desc, |
|
765 | + array('action' => $action, 'status' => $status)); |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * @param $per_page |
|
771 | + * @param int $current_page |
|
772 | + * @param bool|false $count |
|
773 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
774 | + */ |
|
775 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
776 | + { |
|
777 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
778 | + |
|
779 | + if ($count) { |
|
780 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
781 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
782 | + $results = $this->_question_model->count_deleted($where); |
|
783 | + } else { |
|
784 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
785 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
786 | + } |
|
787 | + return $results; |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + /** |
|
792 | + * @param $per_page |
|
793 | + * @param int $current_page |
|
794 | + * @param bool|false $count |
|
795 | + * @return \EE_Soft_Delete_Base_Class[] |
|
796 | + */ |
|
797 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
798 | + { |
|
799 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
800 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
801 | + if ($count) { |
|
802 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
803 | + $results = $questionGroupModel->count($where); |
|
804 | + } else { |
|
805 | + $results = $questionGroupModel->get_all($query_params); |
|
806 | + } |
|
807 | + return $results; |
|
808 | + } |
|
809 | + |
|
810 | + |
|
811 | + /** |
|
812 | + * @param $per_page |
|
813 | + * @param int $current_page |
|
814 | + * @param bool $count |
|
815 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
816 | + */ |
|
817 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = false) |
|
818 | + { |
|
819 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
820 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
821 | + if ($count) { |
|
822 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
823 | + $query_params['limit'] = null; |
|
824 | + $results = $questionGroupModel->count_deleted($where); |
|
825 | + } else { |
|
826 | + $results = $questionGroupModel->get_all_deleted($query_params); |
|
827 | + } |
|
828 | + return $results; |
|
829 | + } |
|
830 | + |
|
831 | + |
|
832 | + /** |
|
833 | + * method for performing updates to question order |
|
834 | + * |
|
835 | + * @return array results array |
|
836 | + */ |
|
837 | + public function update_question_group_order() |
|
838 | + { |
|
839 | + |
|
840 | + $success = esc_html__('Question group order was updated successfully.', 'event_espresso'); |
|
841 | + |
|
842 | + // grab our row IDs |
|
843 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) |
|
844 | + ? explode(',', rtrim($this->_req_data['row_ids'], ',')) |
|
845 | + : array(); |
|
846 | + |
|
847 | + $perpage = ! empty($this->_req_data['perpage']) |
|
848 | + ? (int)$this->_req_data['perpage'] |
|
849 | + : null; |
|
850 | + $curpage = ! empty($this->_req_data['curpage']) |
|
851 | + ? (int)$this->_req_data['curpage'] |
|
852 | + : null; |
|
853 | + |
|
854 | + if (! empty($row_ids)) { |
|
855 | + //figure out where we start the row_id count at for the current page. |
|
856 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
857 | + |
|
858 | + $row_count = count($row_ids); |
|
859 | + for ($i = 0; $i < $row_count; $i++) { |
|
860 | + //Update the questions when re-ordering |
|
861 | + $updated = EEM_Question_Group::instance()->update( |
|
862 | + array('QSG_order' => $qsgcount), |
|
863 | + array(array('QSG_ID' => $row_ids[$i])) |
|
864 | + ); |
|
865 | + if ($updated === false) { |
|
866 | + $success = false; |
|
867 | + } |
|
868 | + $qsgcount++; |
|
869 | + } |
|
870 | + } else { |
|
871 | + $success = false; |
|
872 | + } |
|
873 | + |
|
874 | + $errors = ! $success |
|
875 | + ? esc_html__('An error occurred. The question group order was not updated.', 'event_espresso') |
|
876 | + : false; |
|
877 | + |
|
878 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
879 | + die(); |
|
880 | + |
|
881 | + } |
|
882 | + |
|
883 | + |
|
884 | + |
|
885 | + /*************************************** REGISTRATION SETTINGS ***************************************/ |
|
886 | + |
|
887 | + |
|
888 | + /** |
|
889 | + * _reg_form_settings |
|
890 | + * |
|
891 | + * @throws \EE_Error |
|
892 | + */ |
|
893 | + protected function _reg_form_settings() |
|
894 | + { |
|
895 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
896 | + add_action( |
|
897 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
898 | + array($this, 'email_validation_settings_form'), |
|
899 | + 2 |
|
900 | + ); |
|
901 | + $this->_template_args = (array)apply_filters( |
|
902 | + 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', |
|
903 | + $this->_template_args |
|
904 | + ); |
|
905 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
906 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
907 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
908 | + REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', |
|
909 | + $this->_template_args, |
|
910 | + true |
|
911 | + ); |
|
912 | + $this->display_admin_page_with_sidebar(); |
|
913 | + } |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * _update_reg_form_settings |
|
918 | + */ |
|
919 | + protected function _update_reg_form_settings() |
|
920 | + { |
|
921 | + EE_Registry::instance()->CFG->registration = $this->update_email_validation_settings_form( |
|
922 | + EE_Registry::instance()->CFG->registration |
|
923 | + ); |
|
924 | + EE_Registry::instance()->CFG->registration = apply_filters( |
|
925 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
926 | + EE_Registry::instance()->CFG->registration |
|
927 | + ); |
|
928 | + $success = $this->_update_espresso_configuration( |
|
929 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
930 | + EE_Registry::instance()->CFG, |
|
931 | + __FILE__, __FUNCTION__, __LINE__ |
|
932 | + ); |
|
933 | + $this->_redirect_after_action($success, esc_html__('Registration Form Options', 'event_espresso'), 'updated', |
|
934 | + array('action' => 'view_reg_form_settings')); |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * email_validation_settings_form |
|
940 | + * |
|
941 | + * @access public |
|
942 | + * @return void |
|
943 | + * @throws \EE_Error |
|
944 | + */ |
|
945 | + public function email_validation_settings_form() |
|
946 | + { |
|
947 | + echo $this->_email_validation_settings_form()->get_html(); |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + /** |
|
952 | + * _email_validation_settings_form |
|
953 | + * |
|
954 | + * @access protected |
|
955 | + * @return EE_Form_Section_Proper |
|
956 | + * @throws \EE_Error |
|
957 | + */ |
|
958 | + protected function _email_validation_settings_form() |
|
959 | + { |
|
960 | + return new EE_Form_Section_Proper( |
|
961 | + array( |
|
962 | + 'name' => 'email_validation_settings', |
|
963 | + 'html_id' => 'email_validation_settings', |
|
964 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
965 | + 'subsections' => apply_filters( |
|
966 | + 'FHEE__Extend_Registration_Form_Admin_Page___email_validation_settings_form__form_subsections', |
|
967 | + array( |
|
968 | + 'email_validation_hdr' => new EE_Form_Section_HTML( |
|
969 | + EEH_HTML::h2(esc_html__('Email Validation Settings', 'event_espresso')) |
|
970 | + ), |
|
971 | + 'email_validation_level' => new EE_Select_Input( |
|
972 | + array( |
|
973 | + 'basic' => esc_html__('Basic', 'event_espresso'), |
|
974 | + 'wp_default' => esc_html__('WordPress Default', 'event_espresso'), |
|
975 | + 'i18n' => esc_html__('International', 'event_espresso'), |
|
976 | + 'i18n_dns' => esc_html__('International + DNS Check', 'event_espresso'), |
|
977 | + ), |
|
978 | + array( |
|
979 | + 'html_label_text' => esc_html__('Email Validation Level', 'event_espresso') |
|
980 | + . EEH_Template::get_help_tab_link('email_validation_info'), |
|
981 | + 'html_help_text' => esc_html__('These levels range from basic validation ( ie: [email protected] ) to more advanced checks against international email addresses (ie: üñîçøðé@example.com ) with additional MX and A record checks to confirm the domain actually exists. More information on on each level can be found within the help section.', |
|
982 | + 'event_espresso'), |
|
983 | + 'default' => isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
984 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
985 | + : 'wp_default', |
|
986 | + 'required' => false, |
|
987 | + ) |
|
988 | + ), |
|
989 | + ) |
|
990 | + ), |
|
991 | + ) |
|
992 | + ); |
|
993 | + } |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * update_email_validation_settings_form |
|
998 | + * |
|
999 | + * @access public |
|
1000 | + * @param \EE_Registration_Config $EE_Registration_Config |
|
1001 | + * @return \EE_Registration_Config |
|
1002 | + */ |
|
1003 | + public function update_email_validation_settings_form(EE_Registration_Config $EE_Registration_Config) |
|
1004 | + { |
|
1005 | + $prev_email_validation_level = $EE_Registration_Config->email_validation_level; |
|
1006 | + try { |
|
1007 | + $email_validation_settings_form = $this->_email_validation_settings_form(); |
|
1008 | + // if not displaying a form, then check for form submission |
|
1009 | + if ($email_validation_settings_form->was_submitted()) { |
|
1010 | + // capture form data |
|
1011 | + $email_validation_settings_form->receive_form_submission(); |
|
1012 | + // validate form data |
|
1013 | + if ($email_validation_settings_form->is_valid()) { |
|
1014 | + // grab validated data from form |
|
1015 | + $valid_data = $email_validation_settings_form->valid_data(); |
|
1016 | + if (isset($valid_data['email_validation_level'])) { |
|
1017 | + $email_validation_level = $valid_data['email_validation_level']; |
|
1018 | + // now if they want to use international email addresses |
|
1019 | + if ($email_validation_level === 'i18n' || $email_validation_level === 'i18n_dns') { |
|
1020 | + // in case we need to reset their email validation level, |
|
1021 | + // make sure that the previous value wasn't already set to one of the i18n options. |
|
1022 | + if ($prev_email_validation_level === 'i18n' || $prev_email_validation_level === 'i18n_dns') { |
|
1023 | + // if so, then reset it back to "basic" since that is the only other option that, |
|
1024 | + // despite offering poor validation, supports i18n email addresses |
|
1025 | + $prev_email_validation_level = 'basic'; |
|
1026 | + } |
|
1027 | + // confirm our i18n email validation will work on the server |
|
1028 | + if (! $this->_verify_pcre_support($EE_Registration_Config, $email_validation_level)) { |
|
1029 | + // or reset email validation level to previous value |
|
1030 | + $email_validation_level = $prev_email_validation_level; |
|
1031 | + } |
|
1032 | + } |
|
1033 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1034 | + } else { |
|
1035 | + EE_Error::add_error( |
|
1036 | + esc_html__( |
|
1037 | + 'Invalid or missing Email Validation settings. Please refresh the form and try again.', |
|
1038 | + 'event_espresso' |
|
1039 | + ), |
|
1040 | + __FILE__, __FUNCTION__, __LINE__ |
|
1041 | + ); |
|
1042 | + } |
|
1043 | + } else { |
|
1044 | + if ($email_validation_settings_form->submission_error_message() !== '') { |
|
1045 | + EE_Error::add_error( |
|
1046 | + $email_validation_settings_form->submission_error_message(), |
|
1047 | + __FILE__, __FUNCTION__, __LINE__ |
|
1048 | + ); |
|
1049 | + } |
|
1050 | + } |
|
1051 | + } |
|
1052 | + } catch (EE_Error $e) { |
|
1053 | + $e->get_error(); |
|
1054 | + } |
|
1055 | + return $EE_Registration_Config; |
|
1056 | + } |
|
1057 | + |
|
1058 | + |
|
1059 | + /** |
|
1060 | + * confirms that the server's PHP version has the PCRE module enabled, |
|
1061 | + * and that the PCRE version works with our i18n email validation |
|
1062 | + * |
|
1063 | + * @param \EE_Registration_Config $EE_Registration_Config |
|
1064 | + * @param string $email_validation_level |
|
1065 | + * @return bool |
|
1066 | + */ |
|
1067 | + private function _verify_pcre_support(EE_Registration_Config $EE_Registration_Config, $email_validation_level) |
|
1068 | + { |
|
1069 | + // first check that PCRE is enabled |
|
1070 | + if (! defined('PREG_BAD_UTF8_ERROR')) { |
|
1071 | + EE_Error::add_error( |
|
1072 | + sprintf( |
|
1073 | + esc_html__( |
|
1074 | + 'We\'re sorry, but it appears that your server\'s version of PHP was not compiled with PCRE unicode support.%1$sPlease contact your hosting company and ask them whether the PCRE compiled with your version of PHP on your server can be been built with the "--enable-unicode-properties" and "--enable-utf8" configuration switches to enable more complex regex expressions.%1$sIf they are unable, or unwilling to do so, then your server will not support international email addresses using UTF-8 unicode characters. This means you will either have to lower your email validation level to "Basic" or "WordPress Default", or switch to a hosting company that has/can enable PCRE unicode support on the server.', |
|
1075 | + 'event_espresso' |
|
1076 | + ), |
|
1077 | + '<br />' |
|
1078 | + ), |
|
1079 | + __FILE__, |
|
1080 | + __FUNCTION__, |
|
1081 | + __LINE__ |
|
1082 | + ); |
|
1083 | + return false; |
|
1084 | + } else { |
|
1085 | + // PCRE support is enabled, but let's still |
|
1086 | + // perform a test to see if the server will support it. |
|
1087 | + // but first, save the updated validation level to the config, |
|
1088 | + // so that the validation strategy picks it up. |
|
1089 | + // this will get bumped back down if it doesn't work |
|
1090 | + $EE_Registration_Config->email_validation_level = $email_validation_level; |
|
1091 | + try { |
|
1092 | + $email_validator = new EE_Email_Validation_Strategy(); |
|
1093 | + $i18n_email_address = apply_filters( |
|
1094 | + 'FHEE__Extend_Registration_Form_Admin_Page__update_email_validation_settings_form__i18n_email_address', |
|
1095 | + 'jägerjü[email protected]' |
|
1096 | + ); |
|
1097 | + $email_validator->validate($i18n_email_address); |
|
1098 | + } catch (Exception $e) { |
|
1099 | + EE_Error::add_error( |
|
1100 | + sprintf( |
|
1101 | + esc_html__( |
|
1102 | + 'We\'re sorry, but it appears that your server\'s configuration will not support the "International" or "International + DNS Check" email validation levels.%1$sTo correct this issue, please consult with your hosting company regarding your server\'s PCRE settings.%1$sIt is recommended that your PHP version be configured to use PCRE 8.10 or newer.%1$sMore information regarding PCRE versions and installation can be found here: %2$s', |
|
1103 | + 'event_espresso' |
|
1104 | + ), |
|
1105 | + '<br />', |
|
1106 | + '<a href="http://php.net/manual/en/pcre.installation.php" target="_blank">http://php.net/manual/en/pcre.installation.php</a>' |
|
1107 | + ), |
|
1108 | + __FILE__, __FUNCTION__, __LINE__ |
|
1109 | + ); |
|
1110 | + return false; |
|
1111 | + } |
|
1112 | + } |
|
1113 | + return true; |
|
1114 | + } |
|
1115 | 1115 | |
1116 | 1116 | |
1117 | 1117 | } |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | */ |
37 | 37 | protected $_feature_image = array(); |
38 | 38 | |
39 | - /** |
|
40 | - * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
41 | + */ |
|
42 | 42 | protected $_wp_post; |
43 | 43 | |
44 | 44 | |
@@ -46,75 +46,75 @@ discard block |
||
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
51 | - * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
52 | - * @return WP_Post |
|
53 | - */ |
|
54 | - public function wp_post(){ |
|
55 | - global $wpdb; |
|
56 | - if (! $this->_wp_post instanceof WP_Post) { |
|
57 | - if ($this->ID()) { |
|
58 | - $this->_wp_post = get_post($this->ID()); |
|
59 | - } else { |
|
60 | - $simulated_db_result = new stdClass(); |
|
61 | - foreach($this->get_model()->field_settings(true) as $field_name => $field_obj){ |
|
62 | - if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts){ |
|
63 | - $column = $field_obj->get_table_column(); |
|
64 | - |
|
65 | - if($field_obj instanceof EE_Datetime_Field){ |
|
66 | - $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
67 | - } elseif( $field_obj->is_db_only_field()){ |
|
68 | - $value_on_model_obj = $field_obj->get_default_value(); |
|
69 | - } else { |
|
70 | - $value_on_model_obj = $this->get_raw($field_name); |
|
71 | - } |
|
72 | - $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
73 | - } |
|
74 | - } |
|
75 | - $this->_wp_post = new WP_Post($simulated_db_result); |
|
76 | - } |
|
77 | - //and let's make retrieving the EE CPT object easy too |
|
78 | - $classname = get_class($this); |
|
79 | - if (! isset($this->_wp_post->{$classname})) { |
|
80 | - $this->_wp_post->{$classname} = $this; |
|
81 | - } |
|
82 | - } |
|
83 | - return $this->_wp_post; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * When fetching a new value for a post field that uses the global $post for rendering, |
|
88 | - * set the global $post temporarily to be this model object; and afterwards restore it |
|
89 | - * @param string $fieldname |
|
90 | - * @param bool $pretty |
|
91 | - * @param string $extra_cache_ref |
|
92 | - * @return mixed |
|
93 | - */ |
|
94 | - protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
95 | - { |
|
96 | - global $post; |
|
97 | - |
|
98 | - if ( $pretty |
|
99 | - && ( |
|
100 | - ! ( |
|
101 | - $post instanceof WP_Post |
|
102 | - && $post->ID |
|
103 | - ) |
|
104 | - || (int)$post->ID !== $this->ID() |
|
105 | - ) |
|
106 | - && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field ) { |
|
107 | - $old_post = $post; |
|
108 | - $post = $this->wp_post(); |
|
109 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
110 | - $post = $old_post; |
|
111 | - } else { |
|
112 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
113 | - } |
|
114 | - return $return_value; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
49 | + /** |
|
50 | + * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
51 | + * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
52 | + * @return WP_Post |
|
53 | + */ |
|
54 | + public function wp_post(){ |
|
55 | + global $wpdb; |
|
56 | + if (! $this->_wp_post instanceof WP_Post) { |
|
57 | + if ($this->ID()) { |
|
58 | + $this->_wp_post = get_post($this->ID()); |
|
59 | + } else { |
|
60 | + $simulated_db_result = new stdClass(); |
|
61 | + foreach($this->get_model()->field_settings(true) as $field_name => $field_obj){ |
|
62 | + if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts){ |
|
63 | + $column = $field_obj->get_table_column(); |
|
64 | + |
|
65 | + if($field_obj instanceof EE_Datetime_Field){ |
|
66 | + $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
67 | + } elseif( $field_obj->is_db_only_field()){ |
|
68 | + $value_on_model_obj = $field_obj->get_default_value(); |
|
69 | + } else { |
|
70 | + $value_on_model_obj = $this->get_raw($field_name); |
|
71 | + } |
|
72 | + $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
73 | + } |
|
74 | + } |
|
75 | + $this->_wp_post = new WP_Post($simulated_db_result); |
|
76 | + } |
|
77 | + //and let's make retrieving the EE CPT object easy too |
|
78 | + $classname = get_class($this); |
|
79 | + if (! isset($this->_wp_post->{$classname})) { |
|
80 | + $this->_wp_post->{$classname} = $this; |
|
81 | + } |
|
82 | + } |
|
83 | + return $this->_wp_post; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * When fetching a new value for a post field that uses the global $post for rendering, |
|
88 | + * set the global $post temporarily to be this model object; and afterwards restore it |
|
89 | + * @param string $fieldname |
|
90 | + * @param bool $pretty |
|
91 | + * @param string $extra_cache_ref |
|
92 | + * @return mixed |
|
93 | + */ |
|
94 | + protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
95 | + { |
|
96 | + global $post; |
|
97 | + |
|
98 | + if ( $pretty |
|
99 | + && ( |
|
100 | + ! ( |
|
101 | + $post instanceof WP_Post |
|
102 | + && $post->ID |
|
103 | + ) |
|
104 | + || (int)$post->ID !== $this->ID() |
|
105 | + ) |
|
106 | + && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field ) { |
|
107 | + $old_post = $post; |
|
108 | + $post = $this->wp_post(); |
|
109 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
110 | + $post = $old_post; |
|
111 | + } else { |
|
112 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
113 | + } |
|
114 | + return $return_value; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | 118 | * Adds to the specified event category. If it category doesn't exist, creates it. |
119 | 119 | * @param string $category_name |
120 | 120 | * @param string $category_description optional |
@@ -399,14 +399,14 @@ discard block |
||
399 | 399 | |
400 | 400 | |
401 | 401 | |
402 | - /** |
|
403 | - * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
404 | - * @return array |
|
405 | - */ |
|
406 | - public function __sleep() |
|
407 | - { |
|
408 | - $properties_to_serialize = parent::__sleep(); |
|
409 | - $properties_to_serialize = array_diff( $properties_to_serialize, array('_wp_post')); |
|
410 | - return $properties_to_serialize; |
|
411 | - } |
|
402 | + /** |
|
403 | + * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
404 | + * @return array |
|
405 | + */ |
|
406 | + public function __sleep() |
|
407 | + { |
|
408 | + $properties_to_serialize = parent::__sleep(); |
|
409 | + $properties_to_serialize = array_diff( $properties_to_serialize, array('_wp_post')); |
|
410 | + return $properties_to_serialize; |
|
411 | + } |
|
412 | 412 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -51,20 +51,20 @@ discard block |
||
51 | 51 | * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
52 | 52 | * @return WP_Post |
53 | 53 | */ |
54 | - public function wp_post(){ |
|
54 | + public function wp_post() { |
|
55 | 55 | global $wpdb; |
56 | - if (! $this->_wp_post instanceof WP_Post) { |
|
56 | + if ( ! $this->_wp_post instanceof WP_Post) { |
|
57 | 57 | if ($this->ID()) { |
58 | 58 | $this->_wp_post = get_post($this->ID()); |
59 | 59 | } else { |
60 | 60 | $simulated_db_result = new stdClass(); |
61 | - foreach($this->get_model()->field_settings(true) as $field_name => $field_obj){ |
|
62 | - if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts){ |
|
61 | + foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) { |
|
62 | + if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts) { |
|
63 | 63 | $column = $field_obj->get_table_column(); |
64 | 64 | |
65 | - if($field_obj instanceof EE_Datetime_Field){ |
|
65 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
66 | 66 | $value_on_model_obj = $this->get_DateTime_object($field_name); |
67 | - } elseif( $field_obj->is_db_only_field()){ |
|
67 | + } elseif ($field_obj->is_db_only_field()) { |
|
68 | 68 | $value_on_model_obj = $field_obj->get_default_value(); |
69 | 69 | } else { |
70 | 70 | $value_on_model_obj = $this->get_raw($field_name); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | } |
77 | 77 | //and let's make retrieving the EE CPT object easy too |
78 | 78 | $classname = get_class($this); |
79 | - if (! isset($this->_wp_post->{$classname})) { |
|
79 | + if ( ! isset($this->_wp_post->{$classname})) { |
|
80 | 80 | $this->_wp_post->{$classname} = $this; |
81 | 81 | } |
82 | 82 | } |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | { |
96 | 96 | global $post; |
97 | 97 | |
98 | - if ( $pretty |
|
98 | + if ($pretty |
|
99 | 99 | && ( |
100 | 100 | ! ( |
101 | 101 | $post instanceof WP_Post |
102 | 102 | && $post->ID |
103 | 103 | ) |
104 | - || (int)$post->ID !== $this->ID() |
|
104 | + || (int) $post->ID !== $this->ID() |
|
105 | 105 | ) |
106 | - && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field ) { |
|
106 | + && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field) { |
|
107 | 107 | $old_post = $post; |
108 | 108 | $post = $this->wp_post(); |
109 | 109 | $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * @param int $parent_term_taxonomy_id optional |
122 | 122 | * @return EE_Term_Taxonomy |
123 | 123 | */ |
124 | - function add_event_category( $category_name, $category_description = NULL, $parent_term_taxonomy_id = NULL ) { |
|
125 | - return $this->get_model()->add_event_category( $this, $category_name, $category_description, $parent_term_taxonomy_id ); |
|
124 | + function add_event_category($category_name, $category_description = NULL, $parent_term_taxonomy_id = NULL) { |
|
125 | + return $this->get_model()->add_event_category($this, $category_name, $category_description, $parent_term_taxonomy_id); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @param string $category_name |
133 | 133 | * @return bool |
134 | 134 | */ |
135 | - function remove_event_category( $category_name ) { |
|
136 | - return $this->get_model()->remove_event_category( $this, $category_name ); |
|
135 | + function remove_event_category($category_name) { |
|
136 | + return $this->get_model()->remove_event_category($this, $category_name); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | * @param EE_Term_Taxonomy $term_taxonomy |
145 | 145 | * @return EE_Base_Class the relation was removed from |
146 | 146 | */ |
147 | - function remove_relation_to_term_taxonomy( $term_taxonomy ) { |
|
148 | - if ( !$term_taxonomy ) { |
|
149 | - EE_Error::add_error( sprintf( __( "No Term_Taxonomy provided which to remove from model object of type %s and id %d", "event_espresso" ), get_class( $this ), $this->ID() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
147 | + function remove_relation_to_term_taxonomy($term_taxonomy) { |
|
148 | + if ( ! $term_taxonomy) { |
|
149 | + EE_Error::add_error(sprintf(__("No Term_Taxonomy provided which to remove from model object of type %s and id %d", "event_espresso"), get_class($this), $this->ID()), __FILE__, __FUNCTION__, __LINE__); |
|
150 | 150 | return NULL; |
151 | 151 | } |
152 | - $term_taxonomy->set_count( $term_taxonomy->count() - 1 ); |
|
152 | + $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
153 | 153 | $term_taxonomy->save(); |
154 | - return $this->_remove_relation_to( $term_taxonomy, 'Term_Taxonomy' ); |
|
154 | + return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @return int |
176 | 176 | */ |
177 | 177 | public function parent() { |
178 | - return $this->get( 'parent' ); |
|
178 | + return $this->get('parent'); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @return string |
186 | 186 | */ |
187 | 187 | public function status() { |
188 | - return $this->get( 'status' ); |
|
188 | + return $this->get('status'); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | /** |
194 | 194 | * @param string $status |
195 | 195 | */ |
196 | - public function set_status( $status ) { |
|
197 | - $this->set( 'status', $status ); |
|
196 | + public function set_status($status) { |
|
197 | + $this->set('status', $status); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | * @param string|array $attr Optional. Query string or array of attributes. |
209 | 209 | * @return string HTML image element |
210 | 210 | */ |
211 | - protected function _get_feature_image( $size, $attr ) { |
|
211 | + protected function _get_feature_image($size, $attr) { |
|
212 | 212 | //first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
213 | - $attr_key = is_array( $attr ) ? implode( '_', $attr ) : $attr; |
|
214 | - $cache_key = is_array( $size ) ? implode( '_', $size ) . $attr_key : $size . $attr_key; |
|
215 | - $this->_feature_image[ $cache_key ] = isset( $this->_feature_image[ $cache_key ] ) ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image( $this->ID(), $size, $attr ); |
|
216 | - return $this->_feature_image[ $cache_key ]; |
|
213 | + $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
|
214 | + $cache_key = is_array($size) ? implode('_', $size).$attr_key : $size.$attr_key; |
|
215 | + $this->_feature_image[$cache_key] = isset($this->_feature_image[$cache_key]) ? $this->_feature_image[$cache_key] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
216 | + return $this->_feature_image[$cache_key]; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * @param string|array $attr |
225 | 225 | * @return string of html |
226 | 226 | */ |
227 | - public function feature_image( $size = 'thumbnail', $attr = '' ) { |
|
228 | - return $this->_get_feature_image( $size, $attr ); |
|
227 | + public function feature_image($size = 'thumbnail', $attr = '') { |
|
228 | + return $this->_get_feature_image($size, $attr); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | * @param string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array representing width and height in pixels eg. array(32,32). |
236 | 236 | * @return string|boolean the url of the image or false if not found |
237 | 237 | */ |
238 | - public function feature_image_url( $size = 'thumbnail' ) { |
|
239 | - $attachment = wp_get_attachment_image_src( get_post_thumbnail_id( $this->ID() ), $size ); |
|
240 | - return !empty( $attachment ) ? $attachment[ 0 ] : FALSE; |
|
238 | + public function feature_image_url($size = 'thumbnail') { |
|
239 | + $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size); |
|
240 | + return ! empty($attachment) ? $attachment[0] : FALSE; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | |
@@ -259,36 +259,36 @@ discard block |
||
259 | 259 | * This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names sent); |
260 | 260 | * @return void |
261 | 261 | */ |
262 | - public function restore_revision( $revision_id, $related_obj_names = array(), $where_query = array() ) { |
|
262 | + public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array()) { |
|
263 | 263 | //get revision object |
264 | - $revision_obj = $this->get_model()->get_one_by_ID( $revision_id ); |
|
265 | - if ( $revision_obj instanceof EE_CPT_Base ) { |
|
264 | + $revision_obj = $this->get_model()->get_one_by_ID($revision_id); |
|
265 | + if ($revision_obj instanceof EE_CPT_Base) { |
|
266 | 266 | //no related_obj_name so we assume we're saving a revision on this object. |
267 | - if ( empty( $related_obj_names ) ) { |
|
267 | + if (empty($related_obj_names)) { |
|
268 | 268 | $fields = $this->get_model()->get_meta_table_fields(); |
269 | - foreach ( $fields as $field ) { |
|
270 | - $this->set( $field, $revision_obj->get( $field ) ); |
|
269 | + foreach ($fields as $field) { |
|
270 | + $this->set($field, $revision_obj->get($field)); |
|
271 | 271 | } |
272 | 272 | $this->save(); |
273 | 273 | } |
274 | - $related_obj_names = (array)$related_obj_names; |
|
275 | - foreach ( $related_obj_names as $related_name ) { |
|
274 | + $related_obj_names = (array) $related_obj_names; |
|
275 | + foreach ($related_obj_names as $related_name) { |
|
276 | 276 | //related_obj_name so we're saving a revision on an object related to this object |
277 | 277 | //do we have $where_query params for this related object? If we do then we include that. |
278 | - $cols_n_values = isset( $where_query[ $related_name ] ) ? $where_query[ $related_name ] : array(); |
|
279 | - $where_params = !empty( $cols_n_values ) ? array( $cols_n_values ) : array(); |
|
280 | - $related_objs = $this->get_many_related( $related_name, $where_params ); |
|
281 | - $revision_related_objs = $revision_obj->get_many_related( $related_name, $where_params ); |
|
278 | + $cols_n_values = isset($where_query[$related_name]) ? $where_query[$related_name] : array(); |
|
279 | + $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
|
280 | + $related_objs = $this->get_many_related($related_name, $where_params); |
|
281 | + $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
|
282 | 282 | //load helper |
283 | 283 | //remove related objs from this object that are not in revision |
284 | 284 | //array_diff *should* work cause I think objects are indexed by ID? |
285 | - $related_to_remove = EEH_Array::object_array_diff( $related_objs, $revision_related_objs ); |
|
286 | - foreach ( $related_to_remove as $rr ) { |
|
287 | - $this->_remove_relation_to( $rr, $related_name, $cols_n_values ); |
|
285 | + $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs); |
|
286 | + foreach ($related_to_remove as $rr) { |
|
287 | + $this->_remove_relation_to($rr, $related_name, $cols_n_values); |
|
288 | 288 | } |
289 | 289 | //add all related objs attached to revision to this object |
290 | - foreach ( $revision_related_objs as $r_obj ) { |
|
291 | - $this->_add_relation_to( $r_obj, $related_name, $cols_n_values ); |
|
290 | + foreach ($revision_related_objs as $r_obj) { |
|
291 | + $this->_add_relation_to($r_obj, $related_name, $cols_n_values); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | } |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | * <li>If $single is set to false, or left blank, the function returns an array containing all values of the specified key.</li> |
305 | 305 | * <li>If $single is set to true, the function returns the first value of the specified key (not in an array</li></ul> |
306 | 306 | */ |
307 | - public function get_post_meta( $meta_key = NULL, $single = FALSE ) { |
|
308 | - return get_post_meta( $this->ID(), $meta_key, $single ); |
|
307 | + public function get_post_meta($meta_key = NULL, $single = FALSE) { |
|
308 | + return get_post_meta($this->ID(), $meta_key, $single); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -317,11 +317,11 @@ discard block |
||
317 | 317 | * @param mixed $prev_value |
318 | 318 | * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. NOTE: If the meta_value passed to this function is the same as the value that is already in the database, this function returns false. |
319 | 319 | */ |
320 | - public function update_post_meta( $meta_key, $meta_value, $prev_value = NULL ) { |
|
321 | - if ( ! $this->ID() ) { |
|
320 | + public function update_post_meta($meta_key, $meta_value, $prev_value = NULL) { |
|
321 | + if ( ! $this->ID()) { |
|
322 | 322 | $this->save(); |
323 | 323 | } |
324 | - return update_post_meta( $this->ID(), $meta_key, $meta_value, $prev_value ); |
|
324 | + return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | |
@@ -333,11 +333,11 @@ discard block |
||
333 | 333 | * @param bool $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not |
334 | 334 | * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given key already exists, in which case false is returned. |
335 | 335 | */ |
336 | - public function add_post_meta( $meta_key, $meta_value, $unique = FALSE ) { |
|
337 | - if ( $this->ID() ) { |
|
336 | + public function add_post_meta($meta_key, $meta_value, $unique = FALSE) { |
|
337 | + if ($this->ID()) { |
|
338 | 338 | $this->save(); |
339 | 339 | } |
340 | - return add_post_meta( $this->ID(), $meta_key, $meta_value, $unique ); |
|
340 | + return add_post_meta($this->ID(), $meta_key, $meta_value, $unique); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | * @param mixed $meta_value |
350 | 350 | * @return boolean False for failure. True for success. |
351 | 351 | */ |
352 | - public function delete_post_meta( $meta_key, $meta_value = '' ) { |
|
353 | - if ( ! $this->ID() ) { |
|
352 | + public function delete_post_meta($meta_key, $meta_value = '') { |
|
353 | + if ( ! $this->ID()) { |
|
354 | 354 | //there are obviously no postmetas for this if it's not saved |
355 | 355 | //so let's just report this as a success |
356 | 356 | return true; |
357 | 357 | } |
358 | - return delete_post_meta( $this->ID(), $meta_key, $meta_value ); |
|
358 | + return delete_post_meta($this->ID(), $meta_key, $meta_value); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * @return string |
366 | 366 | */ |
367 | 367 | public function get_permalink() { |
368 | - return get_permalink( $this->ID() ); |
|
368 | + return get_permalink($this->ID()); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | |
@@ -375,8 +375,8 @@ discard block |
||
375 | 375 | * @param array $query_params |
376 | 376 | * @return EE_Term_Taxonomy |
377 | 377 | */ |
378 | - public function term_taxonomies( $query_params = array() ) { |
|
379 | - return $this->get_many_related( 'Term_Taxonomy', $query_params ); |
|
378 | + public function term_taxonomies($query_params = array()) { |
|
379 | + return $this->get_many_related('Term_Taxonomy', $query_params); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | public function __sleep() |
407 | 407 | { |
408 | 408 | $properties_to_serialize = parent::__sleep(); |
409 | - $properties_to_serialize = array_diff( $properties_to_serialize, array('_wp_post')); |
|
409 | + $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post')); |
|
410 | 410 | return $properties_to_serialize; |
411 | 411 | } |
412 | 412 | } |