@@ -22,171 +22,171 @@ |
||
22 | 22 | class CachingLoader extends CachingLoaderDecorator |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionInterface $cache |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $identifier |
|
32 | - */ |
|
33 | - protected $identifier; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * CachingLoader constructor. |
|
39 | - * |
|
40 | - * @param LoaderDecoratorInterface $loader |
|
41 | - * @param CollectionInterface $cache |
|
42 | - * @param string $identifier |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - LoaderDecoratorInterface $loader, |
|
47 | - CollectionInterface $cache, |
|
48 | - $identifier = '' |
|
49 | - ) { |
|
50 | - parent::__construct($loader); |
|
51 | - $this->cache = $cache; |
|
52 | - $this->setIdentifier($identifier); |
|
53 | - if ($this->identifier !== '') { |
|
54 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
55 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
56 | - // where "IDENTIFIER" = the string that was set during construction |
|
57 | - add_action( |
|
58 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
59 | - array($this, 'reset') |
|
60 | - ); |
|
61 | - } |
|
62 | - // to clear ALL caches, simply do the following: |
|
63 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
64 | - add_action( |
|
65 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
66 | - array($this, 'reset') |
|
67 | - ); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function identifier() |
|
76 | - { |
|
77 | - return $this->identifier; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $identifier |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - */ |
|
86 | - private function setIdentifier($identifier) |
|
87 | - { |
|
88 | - if (! is_string($identifier)) { |
|
89 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | - } |
|
91 | - $this->identifier = $identifier; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param string $fqcn |
|
97 | - * @param mixed $object |
|
98 | - * @return bool |
|
99 | - * @throws InvalidArgumentException |
|
100 | - */ |
|
101 | - public function share($fqcn, $object) |
|
102 | - { |
|
103 | - if ($object instanceof $fqcn) { |
|
104 | - return $this->cache->add($object, md5($fqcn)); |
|
105 | - } |
|
106 | - throw new InvalidArgumentException( |
|
107 | - sprintf( |
|
108 | - esc_html__( |
|
109 | - 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
110 | - 'event_espresso' |
|
111 | - ), |
|
112 | - $fqcn |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @param string $fqcn |
|
120 | - * @param array $arguments |
|
121 | - * @param bool $shared |
|
122 | - * @return mixed |
|
123 | - */ |
|
124 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
125 | - { |
|
126 | - $fqcn = ltrim($fqcn, '\\'); |
|
127 | - // caching can be turned off via the following code: |
|
128 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
129 | - if( |
|
130 | - apply_filters( |
|
131 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
132 | - false, |
|
133 | - $this |
|
134 | - ) |
|
135 | - ){ |
|
136 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
137 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
138 | - return $this->loader->load($fqcn, $arguments, false); |
|
139 | - } |
|
140 | - $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments)); |
|
141 | - if ($this->cache->has($identifier)) { |
|
142 | - return $this->cache->get($identifier); |
|
143 | - } |
|
144 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
145 | - if ($object instanceof $fqcn) { |
|
146 | - $this->cache->add($object, $identifier); |
|
147 | - } |
|
148 | - return $object; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * empties cache and calls reset() on loader if method exists |
|
155 | - */ |
|
156 | - public function reset() |
|
157 | - { |
|
158 | - $this->cache->trashAndDetachAll(); |
|
159 | - $this->loader->reset(); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * build a string representation of a class' arguments |
|
166 | - * (mostly because Closures can't be serialized) |
|
167 | - * |
|
168 | - * @param array $arguments |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - private function getIdentifierForArgument(array $arguments) |
|
172 | - { |
|
173 | - $identifier = ''; |
|
174 | - foreach ($arguments as $argument) { |
|
175 | - switch (true) { |
|
176 | - case is_object($argument) : |
|
177 | - case $argument instanceof Closure : |
|
178 | - $identifier .= spl_object_hash($argument); |
|
179 | - break; |
|
180 | - case is_array($argument) : |
|
181 | - $identifier .= $this->getIdentifierForArgument($argument); |
|
182 | - break; |
|
183 | - default : |
|
184 | - $identifier .= $argument; |
|
185 | - break; |
|
186 | - } |
|
187 | - } |
|
188 | - return $identifier; |
|
189 | - } |
|
25 | + /** |
|
26 | + * @var CollectionInterface $cache |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $identifier |
|
32 | + */ |
|
33 | + protected $identifier; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * CachingLoader constructor. |
|
39 | + * |
|
40 | + * @param LoaderDecoratorInterface $loader |
|
41 | + * @param CollectionInterface $cache |
|
42 | + * @param string $identifier |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + LoaderDecoratorInterface $loader, |
|
47 | + CollectionInterface $cache, |
|
48 | + $identifier = '' |
|
49 | + ) { |
|
50 | + parent::__construct($loader); |
|
51 | + $this->cache = $cache; |
|
52 | + $this->setIdentifier($identifier); |
|
53 | + if ($this->identifier !== '') { |
|
54 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
55 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
56 | + // where "IDENTIFIER" = the string that was set during construction |
|
57 | + add_action( |
|
58 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
59 | + array($this, 'reset') |
|
60 | + ); |
|
61 | + } |
|
62 | + // to clear ALL caches, simply do the following: |
|
63 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
64 | + add_action( |
|
65 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
66 | + array($this, 'reset') |
|
67 | + ); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function identifier() |
|
76 | + { |
|
77 | + return $this->identifier; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $identifier |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + */ |
|
86 | + private function setIdentifier($identifier) |
|
87 | + { |
|
88 | + if (! is_string($identifier)) { |
|
89 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | + } |
|
91 | + $this->identifier = $identifier; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param string $fqcn |
|
97 | + * @param mixed $object |
|
98 | + * @return bool |
|
99 | + * @throws InvalidArgumentException |
|
100 | + */ |
|
101 | + public function share($fqcn, $object) |
|
102 | + { |
|
103 | + if ($object instanceof $fqcn) { |
|
104 | + return $this->cache->add($object, md5($fqcn)); |
|
105 | + } |
|
106 | + throw new InvalidArgumentException( |
|
107 | + sprintf( |
|
108 | + esc_html__( |
|
109 | + 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
110 | + 'event_espresso' |
|
111 | + ), |
|
112 | + $fqcn |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @param string $fqcn |
|
120 | + * @param array $arguments |
|
121 | + * @param bool $shared |
|
122 | + * @return mixed |
|
123 | + */ |
|
124 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
125 | + { |
|
126 | + $fqcn = ltrim($fqcn, '\\'); |
|
127 | + // caching can be turned off via the following code: |
|
128 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
129 | + if( |
|
130 | + apply_filters( |
|
131 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
132 | + false, |
|
133 | + $this |
|
134 | + ) |
|
135 | + ){ |
|
136 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
137 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
138 | + return $this->loader->load($fqcn, $arguments, false); |
|
139 | + } |
|
140 | + $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments)); |
|
141 | + if ($this->cache->has($identifier)) { |
|
142 | + return $this->cache->get($identifier); |
|
143 | + } |
|
144 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
145 | + if ($object instanceof $fqcn) { |
|
146 | + $this->cache->add($object, $identifier); |
|
147 | + } |
|
148 | + return $object; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * empties cache and calls reset() on loader if method exists |
|
155 | + */ |
|
156 | + public function reset() |
|
157 | + { |
|
158 | + $this->cache->trashAndDetachAll(); |
|
159 | + $this->loader->reset(); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * build a string representation of a class' arguments |
|
166 | + * (mostly because Closures can't be serialized) |
|
167 | + * |
|
168 | + * @param array $arguments |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + private function getIdentifierForArgument(array $arguments) |
|
172 | + { |
|
173 | + $identifier = ''; |
|
174 | + foreach ($arguments as $argument) { |
|
175 | + switch (true) { |
|
176 | + case is_object($argument) : |
|
177 | + case $argument instanceof Closure : |
|
178 | + $identifier .= spl_object_hash($argument); |
|
179 | + break; |
|
180 | + case is_array($argument) : |
|
181 | + $identifier .= $this->getIdentifierForArgument($argument); |
|
182 | + break; |
|
183 | + default : |
|
184 | + $identifier .= $argument; |
|
185 | + break; |
|
186 | + } |
|
187 | + } |
|
188 | + return $identifier; |
|
189 | + } |
|
190 | 190 | |
191 | 191 | |
192 | 192 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | private function setIdentifier($identifier) |
87 | 87 | { |
88 | - if (! is_string($identifier)) { |
|
88 | + if ( ! is_string($identifier)) { |
|
89 | 89 | throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
90 | 90 | } |
91 | 91 | $this->identifier = $identifier; |
@@ -126,18 +126,18 @@ discard block |
||
126 | 126 | $fqcn = ltrim($fqcn, '\\'); |
127 | 127 | // caching can be turned off via the following code: |
128 | 128 | // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
129 | - if( |
|
129 | + if ( |
|
130 | 130 | apply_filters( |
131 | 131 | 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
132 | 132 | false, |
133 | 133 | $this |
134 | 134 | ) |
135 | - ){ |
|
135 | + ) { |
|
136 | 136 | // even though $shared might be true, caching could be bypassed for whatever reason, |
137 | 137 | // so we don't want the core loader to cache anything, therefore caching is turned off |
138 | 138 | return $this->loader->load($fqcn, $arguments, false); |
139 | 139 | } |
140 | - $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments)); |
|
140 | + $identifier = md5($fqcn.$this->getIdentifierForArgument($arguments)); |
|
141 | 141 | if ($this->cache->has($identifier)) { |
142 | 142 | return $this->cache->get($identifier); |
143 | 143 | } |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct() { |
33 | 33 | parent::__construct( |
34 | - __( 'Event Espresso Upcoming Events', 'event_espresso' ), |
|
35 | - array( 'description' => __( 'A widget to display your upcoming events.', 'event_espresso' )) |
|
34 | + __('Event Espresso Upcoming Events', 'event_espresso'), |
|
35 | + array('description' => __('A widget to display your upcoming events.', 'event_espresso')) |
|
36 | 36 | ); |
37 | 37 | } |
38 | 38 | |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @param array $instance Previously saved values from database. |
46 | 46 | * @return string|void |
47 | 47 | */ |
48 | - public function form( $instance ) { |
|
48 | + public function form($instance) { |
|
49 | 49 | |
50 | - EE_Registry::instance()->load_class( 'Question_Option', array(), FALSE, FALSE, TRUE ); |
|
50 | + EE_Registry::instance()->load_class('Question_Option', array(), FALSE, FALSE, TRUE); |
|
51 | 51 | // Set up some default widget settings. |
52 | 52 | $defaults = array( |
53 | 53 | 'title' => __('Upcoming Events', 'event_espresso'), |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | 'image_size' => 'medium' |
64 | 64 | ); |
65 | 65 | |
66 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
66 | + $instance = wp_parse_args((array) $instance, $defaults); |
|
67 | 67 | // don't add HTML labels for EE_Form_Fields generated inputs |
68 | - add_filter( 'FHEE__EEH_Form_Fields__label_html', '__return_empty_string' ); |
|
68 | + add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string'); |
|
69 | 69 | $yes_no_values = array( |
70 | - EE_Question_Option::new_instance( array( 'QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))), |
|
71 | - EE_Question_Option::new_instance( array( 'QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso'))) |
|
70 | + EE_Question_Option::new_instance(array('QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))), |
|
71 | + EE_Question_Option::new_instance(array('QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso'))) |
|
72 | 72 | ); |
73 | 73 | $sort_values = array( |
74 | - EE_Question_Option::new_instance( array( 'QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))), |
|
75 | - EE_Question_Option::new_instance( array( 'QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso'))) |
|
74 | + EE_Question_Option::new_instance(array('QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))), |
|
75 | + EE_Question_Option::new_instance(array('QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso'))) |
|
76 | 76 | ); |
77 | 77 | |
78 | 78 | ?> |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | <label for="<?php echo $this->get_field_id('title'); ?>"> |
84 | 84 | <?php _e('Title:', 'event_espresso'); ?> |
85 | 85 | </label> |
86 | - <input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" type="text" /> |
|
86 | + <input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" type="text" /> |
|
87 | 87 | </p> |
88 | 88 | <p> |
89 | 89 | <label for="<?php echo $this->get_field_id('category_name'); ?>"> |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | <?php |
93 | 93 | $event_categories = array(); |
94 | 94 | /** @type EEM_Term $EEM_Term */ |
95 | - $EEM_Term = EE_Registry::instance()->load_model( 'Term' ); |
|
96 | - $categories = $EEM_Term->get_all_ee_categories( TRUE ); |
|
97 | - if ( $categories ) { |
|
98 | - foreach ( $categories as $category ) { |
|
99 | - if ( $category instanceof EE_Term ) { |
|
100 | - $event_categories[] = EE_Question_Option::new_instance( array( 'QSO_value' => $category->get( 'slug' ), 'QSO_desc' => $category->get( 'name' ))); |
|
95 | + $EEM_Term = EE_Registry::instance()->load_model('Term'); |
|
96 | + $categories = $EEM_Term->get_all_ee_categories(TRUE); |
|
97 | + if ($categories) { |
|
98 | + foreach ($categories as $category) { |
|
99 | + if ($category instanceof EE_Term) { |
|
100 | + $event_categories[] = EE_Question_Option::new_instance(array('QSO_value' => $category->get('slug'), 'QSO_desc' => $category->get('name'))); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | } |
104 | - array_unshift( $event_categories, EE_Question_Option::new_instance( array( 'QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso')))); |
|
104 | + array_unshift($event_categories, EE_Question_Option::new_instance(array('QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso')))); |
|
105 | 105 | echo EEH_Form_Fields::select( |
106 | 106 | __('Event Category:', 'event_espresso'), |
107 | 107 | $instance['category_name'], |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | __('Show Expired Events:', 'event_espresso'), |
127 | 127 | $instance['show_expired'], |
128 | 128 | array( |
129 | - EE_Question_Option::new_instance( array( 'QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), |
|
130 | - EE_Question_Option::new_instance( array( 'QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), |
|
131 | - EE_Question_Option::new_instance( array( 'QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), |
|
129 | + EE_Question_Option::new_instance(array('QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), |
|
130 | + EE_Question_Option::new_instance(array('QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), |
|
131 | + EE_Question_Option::new_instance(array('QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), |
|
132 | 132 | ), |
133 | 133 | $this->get_field_name('show_expired'), |
134 | 134 | $this->get_field_id('show_expired') |
@@ -156,16 +156,16 @@ discard block |
||
156 | 156 | <?php |
157 | 157 | $image_sizes = array(); |
158 | 158 | $sizes = get_intermediate_image_sizes(); |
159 | - if ( $sizes ) { |
|
159 | + if ($sizes) { |
|
160 | 160 | // loop thru images and create option objects out of them |
161 | - foreach ( $sizes as $image_size ) { |
|
162 | - $image_size = trim( $image_size ); |
|
161 | + foreach ($sizes as $image_size) { |
|
162 | + $image_size = trim($image_size); |
|
163 | 163 | // no big images plz |
164 | - if ( ! in_array( $image_size, array( 'large', 'post-thumbnail' ))) { |
|
165 | - $image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => $image_size, 'QSO_desc' => $image_size )); |
|
164 | + if ( ! in_array($image_size, array('large', 'post-thumbnail'))) { |
|
165 | + $image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => $image_size, 'QSO_desc' => $image_size)); |
|
166 | 166 | } |
167 | 167 | } |
168 | - $image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => 'none', 'QSO_desc' => __('don\'t show images', 'event_espresso') )); |
|
168 | + $image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => 'none', 'QSO_desc' => __('don\'t show images', 'event_espresso'))); |
|
169 | 169 | } |
170 | 170 | echo EEH_Form_Fields::select( |
171 | 171 | __('Image Size:', 'event_espresso'), |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | <label for="<?php echo $this->get_field_id('date_limit'); ?>"> |
224 | 224 | <?php _e('Number of Dates to Display:', 'event_espresso'); ?> |
225 | 225 | </label> |
226 | - <input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr( $instance['date_limit'] ); ?>" size="3" type="text" /> |
|
226 | + <input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr($instance['date_limit']); ?>" size="3" type="text" /> |
|
227 | 227 | </p> |
228 | 228 | <p> |
229 | 229 | <label for="<?php echo $this->get_field_id('date_range'); ?>"> |
@@ -255,9 +255,9 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @return array Updated safe values to be saved. |
257 | 257 | */ |
258 | - public function update( $new_instance, $old_instance ) { |
|
258 | + public function update($new_instance, $old_instance) { |
|
259 | 259 | $instance = $old_instance; |
260 | - $instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
|
260 | + $instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; |
|
261 | 261 | $instance['category_name'] = $new_instance['category_name']; |
262 | 262 | $instance['show_expired'] = $new_instance['show_expired']; |
263 | 263 | $instance['limit'] = $new_instance['limit']; |
@@ -281,18 +281,18 @@ discard block |
||
281 | 281 | * @param array $args Widget arguments. |
282 | 282 | * @param array $instance Saved values from database. |
283 | 283 | */ |
284 | - public function widget( $args, $instance ) { |
|
284 | + public function widget($args, $instance) { |
|
285 | 285 | |
286 | 286 | global $post; |
287 | 287 | // make sure there is some kinda post object |
288 | - if ( $post instanceof WP_Post ) { |
|
288 | + if ($post instanceof WP_Post) { |
|
289 | 289 | $before_widget = ''; |
290 | 290 | $before_title = ''; |
291 | 291 | $after_title = ''; |
292 | 292 | $after_widget = ''; |
293 | 293 | // but NOT an events archives page, cuz that would be like two event lists on the same page |
294 | - $show_everywhere = isset( $instance['show_everywhere'] ) ? (bool) absint( $instance['show_everywhere'] ) : TRUE; |
|
295 | - if ( $show_everywhere || ! ( $post->post_type == 'espresso_events' && is_archive() )) { |
|
294 | + $show_everywhere = isset($instance['show_everywhere']) ? (bool) absint($instance['show_everywhere']) : TRUE; |
|
295 | + if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) { |
|
296 | 296 | // let's use some of the event helper functions' |
297 | 297 | // make separate vars out of attributes |
298 | 298 | |
@@ -311,88 +311,88 @@ discard block |
||
311 | 311 | // Before widget (defined by themes). |
312 | 312 | echo $before_widget; |
313 | 313 | // Display the widget title if one was input (before and after defined by themes). |
314 | - if ( ! empty( $title )) { |
|
315 | - echo $before_title . $title . $after_title; |
|
314 | + if ( ! empty($title)) { |
|
315 | + echo $before_title.$title.$after_title; |
|
316 | 316 | } |
317 | 317 | // grab widget settings |
318 | - $category = isset( $instance['category_name'] ) && ! empty( $instance['category_name'] ) ? $instance['category_name'] : FALSE; |
|
319 | - $show_expired = isset( $instance['show_expired'] ) ? absint( $instance['show_expired'] ) : 0; |
|
320 | - $image_size = isset( $instance['image_size'] ) && ! empty( $instance['image_size'] ) ? $instance['image_size'] : 'medium'; |
|
321 | - $show_desc = isset( $instance['show_desc'] ) ? (bool) absint( $instance['show_desc'] ) : TRUE; |
|
322 | - $show_dates = isset( $instance['show_dates'] ) ? (bool) absint( $instance['show_dates'] ) : TRUE; |
|
323 | - $date_limit = isset( $instance['date_limit'] ) && ! empty( $instance['date_limit'] ) ? $instance['date_limit'] : NULL; |
|
324 | - $date_range = isset( $instance['date_range'] ) && ! empty( $instance['date_range'] ) ? $instance['date_range'] : FALSE; |
|
318 | + $category = isset($instance['category_name']) && ! empty($instance['category_name']) ? $instance['category_name'] : FALSE; |
|
319 | + $show_expired = isset($instance['show_expired']) ? absint($instance['show_expired']) : 0; |
|
320 | + $image_size = isset($instance['image_size']) && ! empty($instance['image_size']) ? $instance['image_size'] : 'medium'; |
|
321 | + $show_desc = isset($instance['show_desc']) ? (bool) absint($instance['show_desc']) : TRUE; |
|
322 | + $show_dates = isset($instance['show_dates']) ? (bool) absint($instance['show_dates']) : TRUE; |
|
323 | + $date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) ? $instance['date_limit'] : NULL; |
|
324 | + $date_range = isset($instance['date_range']) && ! empty($instance['date_range']) ? $instance['date_range'] : FALSE; |
|
325 | 325 | // start to build our where clause |
326 | 326 | $where = array( |
327 | 327 | // 'Datetime.DTT_is_primary' => 1, |
328 | - 'status' => array( 'IN', array( 'publish', 'sold_out' ) ) |
|
328 | + 'status' => array('IN', array('publish', 'sold_out')) |
|
329 | 329 | ); |
330 | 330 | // add category |
331 | - if ( $category ) { |
|
331 | + if ($category) { |
|
332 | 332 | $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
333 | 333 | $where['Term_Taxonomy.Term.slug'] = $category; |
334 | 334 | } |
335 | 335 | // if NOT expired then we want events that start today or in the future |
336 | 336 | // if NOT show expired then we want events that start today or in the future |
337 | - if ( $show_expired == 0 ) { |
|
338 | - $where['Datetime.DTT_EVT_end'] = array( '>=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ); |
|
337 | + if ($show_expired == 0) { |
|
338 | + $where['Datetime.DTT_EVT_end'] = array('>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')); |
|
339 | 339 | } |
340 | 340 | // if show ONLY expired we want events that ended prior to today |
341 | - if ( $show_expired == 2 ) { |
|
342 | - $where['Datetime.DTT_EVT_end'] = array( '<=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); |
|
341 | + if ($show_expired == 2) { |
|
342 | + $where['Datetime.DTT_EVT_end'] = array('<=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); |
|
343 | 343 | } |
344 | 344 | // allow $where to be filtered |
345 | - $where = apply_filters( 'FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired ); |
|
345 | + $where = apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired); |
|
346 | 346 | // run the query |
347 | - $events = EE_Registry::instance()->load_model( 'Event' )->get_all( array( |
|
347 | + $events = EE_Registry::instance()->load_model('Event')->get_all(array( |
|
348 | 348 | $where, |
349 | - 'limit' => $instance['limit'] > 0 ? '0,' . $instance['limit'] : '0,10', |
|
349 | + 'limit' => $instance['limit'] > 0 ? '0,'.$instance['limit'] : '0,10', |
|
350 | 350 | 'order_by' => 'Datetime.DTT_EVT_start', |
351 | 351 | 'order' => isset($instance['sort']) ? $instance['sort'] : 'ASC', |
352 | 352 | 'group_by' => 'EVT_ID' |
353 | 353 | )); |
354 | 354 | |
355 | - if ( ! empty( $events )) { |
|
355 | + if ( ! empty($events)) { |
|
356 | 356 | echo '<ul class="ee-upcoming-events-widget-ul">'; |
357 | - foreach ( $events as $event ) { |
|
358 | - if ( $event instanceof EE_Event && ( !is_single() || $post->ID != $event->ID() ) ) { |
|
357 | + foreach ($events as $event) { |
|
358 | + if ($event instanceof EE_Event && ( ! is_single() || $post->ID != $event->ID())) { |
|
359 | 359 | //printr( $event, '$event <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
360 | - echo '<li id="ee-upcoming-events-widget-li-' . $event->ID() . '" class="ee-upcoming-events-widget-li">'; |
|
360 | + echo '<li id="ee-upcoming-events-widget-li-'.$event->ID().'" class="ee-upcoming-events-widget-li">'; |
|
361 | 361 | // how big is the event name ? |
362 | - $name_length = strlen( $event->name() ); |
|
363 | - switch( $name_length ) { |
|
362 | + $name_length = strlen($event->name()); |
|
363 | + switch ($name_length) { |
|
364 | 364 | case $name_length > 70 : |
365 | - $len_class = ' three-line'; |
|
365 | + $len_class = ' three-line'; |
|
366 | 366 | break; |
367 | 367 | case $name_length > 35 : |
368 | - $len_class = ' two-line'; |
|
368 | + $len_class = ' two-line'; |
|
369 | 369 | break; |
370 | 370 | default : |
371 | - $len_class = ' one-line'; |
|
371 | + $len_class = ' one-line'; |
|
372 | 372 | } |
373 | - $event_url = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event ); |
|
374 | - echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a' . $len_class . '" href="' . $event_url . '">' . $event->name() . '</a></h5>'; |
|
375 | - if ( post_password_required( $event->ID() ) ) { |
|
376 | - $pswd_form = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form( $event->ID() ), $event ); |
|
373 | + $event_url = apply_filters('FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event); |
|
374 | + echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a'.$len_class.'" href="'.$event_url.'">'.$event->name().'</a></h5>'; |
|
375 | + if (post_password_required($event->ID())) { |
|
376 | + $pswd_form = apply_filters('FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form($event->ID()), $event); |
|
377 | 377 | echo $pswd_form; |
378 | 378 | } else { |
379 | - if ( has_post_thumbnail( $event->ID() ) && $image_size != 'none' ) { |
|
380 | - echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="' . $event_url . '">' . get_the_post_thumbnail( $event->ID(), $image_size ) . '</a></div>'; |
|
379 | + if (has_post_thumbnail($event->ID()) && $image_size != 'none') { |
|
380 | + echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="'.$event_url.'">'.get_the_post_thumbnail($event->ID(), $image_size).'</a></div>'; |
|
381 | 381 | } |
382 | - $desc = $event->short_description( 25 ); |
|
383 | - if ( $show_dates ) { |
|
384 | - $date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', get_option( 'date_format' )); |
|
385 | - $time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', get_option( 'time_format' )); |
|
386 | - $single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', get_option( 'date_format' )); |
|
387 | - $single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', get_option( 'time_format' )); |
|
388 | - if ( $date_range == TRUE ) { |
|
389 | - echo espresso_event_date_range( $date_format, $time_format, $single_date_format, $single_time_format, $event->ID() ); |
|
390 | - }else{ |
|
391 | - echo espresso_list_of_event_dates( $event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit ); |
|
382 | + $desc = $event->short_description(25); |
|
383 | + if ($show_dates) { |
|
384 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', get_option('date_format')); |
|
385 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', get_option('time_format')); |
|
386 | + $single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', get_option('date_format')); |
|
387 | + $single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', get_option('time_format')); |
|
388 | + if ($date_range == TRUE) { |
|
389 | + echo espresso_event_date_range($date_format, $time_format, $single_date_format, $single_time_format, $event->ID()); |
|
390 | + } else { |
|
391 | + echo espresso_list_of_event_dates($event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit); |
|
392 | 392 | } |
393 | 393 | } |
394 | - if ( $show_desc && $desc ) { |
|
395 | - echo '<p style="margin-top: .5em">' . $desc . '</p>'; |
|
394 | + if ($show_desc && $desc) { |
|
395 | + echo '<p style="margin-top: .5em">'.$desc.'</p>'; |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | echo '</li>'; |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | * @return string |
417 | 417 | */ |
418 | 418 | public function make_the_title_a_link($title) { |
419 | - return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>'; |
|
419 | + return '<a href="'.EEH_Event_View::event_archive_url().'">'.$title.'</a>'; |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * cancelTicketSelections |
44 | 44 | * |
45 | - * @return string |
|
45 | + * @return false|null |
|
46 | 46 | * @throws EE_Error |
47 | 47 | * @throws InvalidArgumentException |
48 | 48 | * @throws InvalidInterfaceException |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | /** |
115 | 115 | * process_ticket_selections |
116 | 116 | * |
117 | - * @return array|bool |
|
117 | + * @return null|boolean |
|
118 | 118 | * @throws \ReflectionException |
119 | 119 | * @throws InvalidArgumentException |
120 | 120 | * @throws InvalidInterfaceException |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * validate_post_data |
299 | 299 | * |
300 | 300 | * @param int $id |
301 | - * @return array|FALSE |
|
301 | + * @return string |
|
302 | 302 | * @throws \ReflectionException |
303 | 303 | * @throws InvalidArgumentException |
304 | 304 | * @throws InvalidInterfaceException |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @param EE_Ticket $ticket |
423 | 423 | * @param int $qty |
424 | - * @return TRUE on success, FALSE on fail |
|
424 | + * @return boolean on success, FALSE on fail |
|
425 | 425 | * @throws InvalidArgumentException |
426 | 426 | * @throws InvalidInterfaceException |
427 | 427 | * @throws InvalidDataTypeException |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use InvalidArgumentException; |
15 | 15 | |
16 | 16 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
17 | - exit('No direct script access allowed'); |
|
17 | + exit('No direct script access allowed'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | |
@@ -31,602 +31,602 @@ discard block |
||
31 | 31 | class ProcessTicketSelector |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * array of datetimes and the spaces available for them |
|
36 | - * |
|
37 | - * @var array[][] |
|
38 | - */ |
|
39 | - private static $_available_spaces = array(); |
|
34 | + /** |
|
35 | + * array of datetimes and the spaces available for them |
|
36 | + * |
|
37 | + * @var array[][] |
|
38 | + */ |
|
39 | + private static $_available_spaces = array(); |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * cancelTicketSelections |
|
44 | - * |
|
45 | - * @return string |
|
46 | - * @throws EE_Error |
|
47 | - * @throws InvalidArgumentException |
|
48 | - * @throws InvalidInterfaceException |
|
49 | - * @throws InvalidDataTypeException |
|
50 | - */ |
|
51 | - public function cancelTicketSelections() |
|
52 | - { |
|
53 | - // check nonce |
|
54 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
55 | - return false; |
|
56 | - } |
|
57 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
58 | - if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
59 | - wp_safe_redirect( |
|
60 | - EEH_Event_View::event_link_url( |
|
61 | - EE_Registry::instance()->REQ->get('event_id') |
|
62 | - ) |
|
63 | - ); |
|
64 | - } else { |
|
65 | - wp_safe_redirect( |
|
66 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
67 | - ); |
|
68 | - } |
|
69 | - exit(); |
|
70 | - } |
|
42 | + /** |
|
43 | + * cancelTicketSelections |
|
44 | + * |
|
45 | + * @return string |
|
46 | + * @throws EE_Error |
|
47 | + * @throws InvalidArgumentException |
|
48 | + * @throws InvalidInterfaceException |
|
49 | + * @throws InvalidDataTypeException |
|
50 | + */ |
|
51 | + public function cancelTicketSelections() |
|
52 | + { |
|
53 | + // check nonce |
|
54 | + if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
55 | + return false; |
|
56 | + } |
|
57 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
58 | + if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
59 | + wp_safe_redirect( |
|
60 | + EEH_Event_View::event_link_url( |
|
61 | + EE_Registry::instance()->REQ->get('event_id') |
|
62 | + ) |
|
63 | + ); |
|
64 | + } else { |
|
65 | + wp_safe_redirect( |
|
66 | + site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
67 | + ); |
|
68 | + } |
|
69 | + exit(); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * processTicketSelectorNonce |
|
75 | - * |
|
76 | - * @param string $nonce_name |
|
77 | - * @param string $id |
|
78 | - * @return bool |
|
79 | - * @throws InvalidArgumentException |
|
80 | - * @throws InvalidInterfaceException |
|
81 | - * @throws InvalidDataTypeException |
|
82 | - */ |
|
83 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
84 | - { |
|
85 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
86 | - if ( |
|
87 | - ! is_admin() |
|
88 | - && ( |
|
89 | - ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
90 | - || ! wp_verify_nonce( |
|
91 | - EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
92 | - $nonce_name |
|
93 | - ) |
|
94 | - ) |
|
95 | - ) { |
|
96 | - EE_Error::add_error( |
|
97 | - sprintf( |
|
98 | - __( |
|
99 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
100 | - 'event_espresso' |
|
101 | - ), |
|
102 | - '<br/>' |
|
103 | - ), |
|
104 | - __FILE__, |
|
105 | - __FUNCTION__, |
|
106 | - __LINE__ |
|
107 | - ); |
|
108 | - return false; |
|
109 | - } |
|
110 | - return true; |
|
111 | - } |
|
73 | + /** |
|
74 | + * processTicketSelectorNonce |
|
75 | + * |
|
76 | + * @param string $nonce_name |
|
77 | + * @param string $id |
|
78 | + * @return bool |
|
79 | + * @throws InvalidArgumentException |
|
80 | + * @throws InvalidInterfaceException |
|
81 | + * @throws InvalidDataTypeException |
|
82 | + */ |
|
83 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
84 | + { |
|
85 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
86 | + if ( |
|
87 | + ! is_admin() |
|
88 | + && ( |
|
89 | + ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
90 | + || ! wp_verify_nonce( |
|
91 | + EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
92 | + $nonce_name |
|
93 | + ) |
|
94 | + ) |
|
95 | + ) { |
|
96 | + EE_Error::add_error( |
|
97 | + sprintf( |
|
98 | + __( |
|
99 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
100 | + 'event_espresso' |
|
101 | + ), |
|
102 | + '<br/>' |
|
103 | + ), |
|
104 | + __FILE__, |
|
105 | + __FUNCTION__, |
|
106 | + __LINE__ |
|
107 | + ); |
|
108 | + return false; |
|
109 | + } |
|
110 | + return true; |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * process_ticket_selections |
|
116 | - * |
|
117 | - * @return array|bool |
|
118 | - * @throws \ReflectionException |
|
119 | - * @throws InvalidArgumentException |
|
120 | - * @throws InvalidInterfaceException |
|
121 | - * @throws InvalidDataTypeException |
|
122 | - * @throws EE_Error |
|
123 | - */ |
|
124 | - public function processTicketSelections() |
|
125 | - { |
|
126 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
127 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
128 | - if($request->isBot()) { |
|
129 | - wp_safe_redirect( |
|
130 | - apply_filters( |
|
131 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
132 | - site_url() |
|
133 | - ) |
|
134 | - ); |
|
135 | - exit(); |
|
136 | - } |
|
137 | - // do we have an event id? |
|
138 | - if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
139 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
140 | - EE_Error::add_error( |
|
141 | - sprintf( |
|
142 | - __( |
|
143 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
144 | - 'event_espresso' |
|
145 | - ), |
|
146 | - '<br/>' |
|
147 | - ), |
|
148 | - __FILE__, |
|
149 | - __FUNCTION__, |
|
150 | - __LINE__ |
|
151 | - ); |
|
152 | - } |
|
153 | - //if event id is valid |
|
154 | - $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
155 | - // d( \EE_Registry::instance()->REQ ); |
|
156 | - self::$_available_spaces = array( |
|
157 | - 'tickets' => array(), |
|
158 | - 'datetimes' => array(), |
|
159 | - ); |
|
160 | - //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
161 | - // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
162 | - EE_Registry::instance()->load_core('Session'); |
|
163 | - // unless otherwise requested, clear the session |
|
164 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
165 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
166 | - } |
|
167 | - //d( \EE_Registry::instance()->SSN ); |
|
168 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
169 | - // validate/sanitize data |
|
170 | - $valid = $this->validatePostData($id); |
|
171 | - //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
172 | - //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
173 | - //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
174 | - //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
175 | - //check total tickets ordered vs max number of attendees that can register |
|
176 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
177 | - // ordering too many tickets !!! |
|
178 | - $total_tickets_string = _n( |
|
179 | - 'You have attempted to purchase %s ticket.', |
|
180 | - 'You have attempted to purchase %s tickets.', |
|
181 | - $valid['total_tickets'], |
|
182 | - 'event_espresso' |
|
183 | - ); |
|
184 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
185 | - // dev only message |
|
186 | - $max_atndz_string = _n( |
|
187 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
188 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
189 | - $valid['max_atndz'], |
|
190 | - 'event_espresso' |
|
191 | - ); |
|
192 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
193 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
194 | - } else { |
|
195 | - // all data appears to be valid |
|
196 | - $tckts_slctd = false; |
|
197 | - $tickets_added = 0; |
|
198 | - $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
199 | - $valid); |
|
200 | - if ($valid['total_tickets'] > 0) { |
|
201 | - // load cart |
|
202 | - EE_Registry::instance()->load_core('Cart'); |
|
203 | - // cycle thru the number of data rows sent from the event listing |
|
204 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
205 | - // does this row actually contain a ticket quantity? |
|
206 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
207 | - // YES we have a ticket quantity |
|
208 | - $tckts_slctd = true; |
|
209 | - // d( $valid['ticket_obj'][$x] ); |
|
210 | - if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
211 | - // then add ticket to cart |
|
212 | - $tickets_added += $this->addTicketToCart( |
|
213 | - $valid['ticket_obj'][ $x ], |
|
214 | - $valid['qty'][ $x ] |
|
215 | - ); |
|
216 | - if (EE_Error::has_error()) { |
|
217 | - break; |
|
218 | - } |
|
219 | - } else { |
|
220 | - // nothing added to cart retrieved |
|
221 | - EE_Error::add_error( |
|
222 | - sprintf( |
|
223 | - __( |
|
224 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
225 | - 'event_espresso' |
|
226 | - ), |
|
227 | - '<br/>' |
|
228 | - ), |
|
229 | - __FILE__, __FUNCTION__, __LINE__ |
|
230 | - ); |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - } |
|
235 | - do_action( |
|
236 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
237 | - EE_Registry::instance()->CART, |
|
238 | - $this |
|
239 | - ); |
|
240 | - //d( \EE_Registry::instance()->CART ); |
|
241 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
242 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
243 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
244 | - do_action( |
|
245 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
246 | - EE_Registry::instance()->CART, |
|
247 | - $this |
|
248 | - ); |
|
249 | - EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
250 | - EE_Registry::instance()->CART->save_cart(false); |
|
251 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
252 | - // just return TRUE for registrations being made from admin |
|
253 | - if (is_admin()) { |
|
254 | - return true; |
|
255 | - } |
|
256 | - EE_Error::get_notices(false, true); |
|
257 | - wp_safe_redirect( |
|
258 | - apply_filters( |
|
259 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
260 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
261 | - ) |
|
262 | - ); |
|
263 | - exit(); |
|
264 | - } else { |
|
265 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
266 | - // nothing added to cart |
|
267 | - EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
268 | - __FILE__, __FUNCTION__, __LINE__); |
|
269 | - } |
|
270 | - } |
|
271 | - } else { |
|
272 | - // no ticket quantities were selected |
|
273 | - EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
274 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
275 | - } |
|
276 | - } |
|
277 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
278 | - // at this point, just return if registration is being made from admin |
|
279 | - if (is_admin()) { |
|
280 | - return false; |
|
281 | - } |
|
282 | - if ($valid['return_url']) { |
|
283 | - EE_Error::get_notices(false, true); |
|
284 | - wp_safe_redirect($valid['return_url']); |
|
285 | - exit(); |
|
286 | - } elseif (isset($event_to_add['id'])) { |
|
287 | - EE_Error::get_notices(false, true); |
|
288 | - wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
289 | - exit(); |
|
290 | - } else { |
|
291 | - echo EE_Error::get_notices(); |
|
292 | - } |
|
293 | - return false; |
|
294 | - } |
|
114 | + /** |
|
115 | + * process_ticket_selections |
|
116 | + * |
|
117 | + * @return array|bool |
|
118 | + * @throws \ReflectionException |
|
119 | + * @throws InvalidArgumentException |
|
120 | + * @throws InvalidInterfaceException |
|
121 | + * @throws InvalidDataTypeException |
|
122 | + * @throws EE_Error |
|
123 | + */ |
|
124 | + public function processTicketSelections() |
|
125 | + { |
|
126 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
127 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
128 | + if($request->isBot()) { |
|
129 | + wp_safe_redirect( |
|
130 | + apply_filters( |
|
131 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
132 | + site_url() |
|
133 | + ) |
|
134 | + ); |
|
135 | + exit(); |
|
136 | + } |
|
137 | + // do we have an event id? |
|
138 | + if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
139 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
140 | + EE_Error::add_error( |
|
141 | + sprintf( |
|
142 | + __( |
|
143 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
144 | + 'event_espresso' |
|
145 | + ), |
|
146 | + '<br/>' |
|
147 | + ), |
|
148 | + __FILE__, |
|
149 | + __FUNCTION__, |
|
150 | + __LINE__ |
|
151 | + ); |
|
152 | + } |
|
153 | + //if event id is valid |
|
154 | + $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
155 | + // d( \EE_Registry::instance()->REQ ); |
|
156 | + self::$_available_spaces = array( |
|
157 | + 'tickets' => array(), |
|
158 | + 'datetimes' => array(), |
|
159 | + ); |
|
160 | + //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
161 | + // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
162 | + EE_Registry::instance()->load_core('Session'); |
|
163 | + // unless otherwise requested, clear the session |
|
164 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
165 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
166 | + } |
|
167 | + //d( \EE_Registry::instance()->SSN ); |
|
168 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
169 | + // validate/sanitize data |
|
170 | + $valid = $this->validatePostData($id); |
|
171 | + //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
172 | + //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
173 | + //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
174 | + //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
175 | + //check total tickets ordered vs max number of attendees that can register |
|
176 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
177 | + // ordering too many tickets !!! |
|
178 | + $total_tickets_string = _n( |
|
179 | + 'You have attempted to purchase %s ticket.', |
|
180 | + 'You have attempted to purchase %s tickets.', |
|
181 | + $valid['total_tickets'], |
|
182 | + 'event_espresso' |
|
183 | + ); |
|
184 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
185 | + // dev only message |
|
186 | + $max_atndz_string = _n( |
|
187 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
188 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
189 | + $valid['max_atndz'], |
|
190 | + 'event_espresso' |
|
191 | + ); |
|
192 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
193 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
194 | + } else { |
|
195 | + // all data appears to be valid |
|
196 | + $tckts_slctd = false; |
|
197 | + $tickets_added = 0; |
|
198 | + $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
199 | + $valid); |
|
200 | + if ($valid['total_tickets'] > 0) { |
|
201 | + // load cart |
|
202 | + EE_Registry::instance()->load_core('Cart'); |
|
203 | + // cycle thru the number of data rows sent from the event listing |
|
204 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
205 | + // does this row actually contain a ticket quantity? |
|
206 | + if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
207 | + // YES we have a ticket quantity |
|
208 | + $tckts_slctd = true; |
|
209 | + // d( $valid['ticket_obj'][$x] ); |
|
210 | + if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
211 | + // then add ticket to cart |
|
212 | + $tickets_added += $this->addTicketToCart( |
|
213 | + $valid['ticket_obj'][ $x ], |
|
214 | + $valid['qty'][ $x ] |
|
215 | + ); |
|
216 | + if (EE_Error::has_error()) { |
|
217 | + break; |
|
218 | + } |
|
219 | + } else { |
|
220 | + // nothing added to cart retrieved |
|
221 | + EE_Error::add_error( |
|
222 | + sprintf( |
|
223 | + __( |
|
224 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
225 | + 'event_espresso' |
|
226 | + ), |
|
227 | + '<br/>' |
|
228 | + ), |
|
229 | + __FILE__, __FUNCTION__, __LINE__ |
|
230 | + ); |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + } |
|
235 | + do_action( |
|
236 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
237 | + EE_Registry::instance()->CART, |
|
238 | + $this |
|
239 | + ); |
|
240 | + //d( \EE_Registry::instance()->CART ); |
|
241 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
242 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
243 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
244 | + do_action( |
|
245 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
246 | + EE_Registry::instance()->CART, |
|
247 | + $this |
|
248 | + ); |
|
249 | + EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
250 | + EE_Registry::instance()->CART->save_cart(false); |
|
251 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
252 | + // just return TRUE for registrations being made from admin |
|
253 | + if (is_admin()) { |
|
254 | + return true; |
|
255 | + } |
|
256 | + EE_Error::get_notices(false, true); |
|
257 | + wp_safe_redirect( |
|
258 | + apply_filters( |
|
259 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
260 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
261 | + ) |
|
262 | + ); |
|
263 | + exit(); |
|
264 | + } else { |
|
265 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
266 | + // nothing added to cart |
|
267 | + EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
268 | + __FILE__, __FUNCTION__, __LINE__); |
|
269 | + } |
|
270 | + } |
|
271 | + } else { |
|
272 | + // no ticket quantities were selected |
|
273 | + EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
274 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
275 | + } |
|
276 | + } |
|
277 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
278 | + // at this point, just return if registration is being made from admin |
|
279 | + if (is_admin()) { |
|
280 | + return false; |
|
281 | + } |
|
282 | + if ($valid['return_url']) { |
|
283 | + EE_Error::get_notices(false, true); |
|
284 | + wp_safe_redirect($valid['return_url']); |
|
285 | + exit(); |
|
286 | + } elseif (isset($event_to_add['id'])) { |
|
287 | + EE_Error::get_notices(false, true); |
|
288 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
289 | + exit(); |
|
290 | + } else { |
|
291 | + echo EE_Error::get_notices(); |
|
292 | + } |
|
293 | + return false; |
|
294 | + } |
|
295 | 295 | |
296 | 296 | |
297 | - /** |
|
298 | - * validate_post_data |
|
299 | - * |
|
300 | - * @param int $id |
|
301 | - * @return array|FALSE |
|
302 | - * @throws \ReflectionException |
|
303 | - * @throws InvalidArgumentException |
|
304 | - * @throws InvalidInterfaceException |
|
305 | - * @throws InvalidDataTypeException |
|
306 | - * @throws EE_Error |
|
307 | - */ |
|
308 | - private function validatePostData($id = 0) |
|
309 | - { |
|
310 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
311 | - if (! $id) { |
|
312 | - EE_Error::add_error( |
|
313 | - __('The event id provided was not valid.', 'event_espresso'), |
|
314 | - __FILE__, |
|
315 | - __FUNCTION__, |
|
316 | - __LINE__ |
|
317 | - ); |
|
318 | - return false; |
|
319 | - } |
|
320 | - // start with an empty array() |
|
321 | - $valid_data = array(); |
|
322 | - // grab valid id |
|
323 | - $valid_data['id'] = $id; |
|
324 | - // array of other form names |
|
325 | - $inputs_to_clean = array( |
|
326 | - 'event_id' => 'tkt-slctr-event-id', |
|
327 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
328 | - 'rows' => 'tkt-slctr-rows-', |
|
329 | - 'qty' => 'tkt-slctr-qty-', |
|
330 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
331 | - 'return_url' => 'tkt-slctr-return-url-', |
|
332 | - ); |
|
333 | - // let's track the total number of tickets ordered.' |
|
334 | - $valid_data['total_tickets'] = 0; |
|
335 | - // cycle through $inputs_to_clean array |
|
336 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
337 | - // check for POST data |
|
338 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
339 | - // grab value |
|
340 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
341 | - switch ($what) { |
|
342 | - // integers |
|
343 | - case 'event_id': |
|
344 | - $valid_data[ $what ] = absint($input_value); |
|
345 | - // get event via the event id we put in the form |
|
346 | - $valid_data['event'] = EE_Registry::instance() |
|
347 | - ->load_model('Event') |
|
348 | - ->get_one_by_ID($valid_data['event_id']); |
|
349 | - break; |
|
350 | - case 'rows': |
|
351 | - case 'max_atndz': |
|
352 | - $valid_data[ $what ] = absint($input_value); |
|
353 | - break; |
|
354 | - // arrays of integers |
|
355 | - case 'qty': |
|
356 | - /** @var array $row_qty */ |
|
357 | - $row_qty = $input_value; |
|
358 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
359 | - if (! is_array($row_qty)) { |
|
360 | - // get number of rows |
|
361 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
362 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
363 | - : 1; |
|
364 | - // explode ints by the dash |
|
365 | - $row_qty = explode('-', $row_qty); |
|
366 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
367 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
368 | - $row_qty = array($row => $qty); |
|
369 | - for ($x = 1; $x <= $rows; $x++) { |
|
370 | - if (! isset($row_qty[ $x ])) { |
|
371 | - $row_qty[ $x ] = 0; |
|
372 | - } |
|
373 | - } |
|
374 | - } |
|
375 | - ksort($row_qty); |
|
376 | - // cycle thru values |
|
377 | - foreach ($row_qty as $qty) { |
|
378 | - $qty = absint($qty); |
|
379 | - // sanitize as integers |
|
380 | - $valid_data[ $what ][] = $qty; |
|
381 | - $valid_data['total_tickets'] += $qty; |
|
382 | - } |
|
383 | - break; |
|
384 | - // array of integers |
|
385 | - case 'ticket_id': |
|
386 | - $value_array = array(); |
|
387 | - // cycle thru values |
|
388 | - foreach ((array) $input_value as $key => $value) { |
|
389 | - // allow only numbers, letters, spaces, commas and dashes |
|
390 | - $value_array[ $key ] = wp_strip_all_tags($value); |
|
391 | - // get ticket via the ticket id we put in the form |
|
392 | - $ticket_obj = EE_Registry::instance() |
|
393 | - ->load_model('Ticket') |
|
394 | - ->get_one_by_ID($value); |
|
395 | - $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
396 | - } |
|
397 | - $valid_data[ $what ] = $value_array; |
|
398 | - break; |
|
399 | - case 'return_url' : |
|
400 | - // grab and sanitize return-url |
|
401 | - $input_value = esc_url_raw($input_value); |
|
402 | - // was the request coming from an iframe ? if so, then: |
|
403 | - if (strpos($input_value, 'event_list=iframe')) { |
|
404 | - // get anchor fragment |
|
405 | - $input_value = explode('#', $input_value); |
|
406 | - $input_value = end($input_value); |
|
407 | - // use event list url instead, but append anchor |
|
408 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
409 | - } |
|
410 | - $valid_data[ $what ] = $input_value; |
|
411 | - break; |
|
412 | - } // end switch $what |
|
413 | - } |
|
414 | - } // end foreach $inputs_to_clean |
|
415 | - return $valid_data; |
|
416 | - } |
|
297 | + /** |
|
298 | + * validate_post_data |
|
299 | + * |
|
300 | + * @param int $id |
|
301 | + * @return array|FALSE |
|
302 | + * @throws \ReflectionException |
|
303 | + * @throws InvalidArgumentException |
|
304 | + * @throws InvalidInterfaceException |
|
305 | + * @throws InvalidDataTypeException |
|
306 | + * @throws EE_Error |
|
307 | + */ |
|
308 | + private function validatePostData($id = 0) |
|
309 | + { |
|
310 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
311 | + if (! $id) { |
|
312 | + EE_Error::add_error( |
|
313 | + __('The event id provided was not valid.', 'event_espresso'), |
|
314 | + __FILE__, |
|
315 | + __FUNCTION__, |
|
316 | + __LINE__ |
|
317 | + ); |
|
318 | + return false; |
|
319 | + } |
|
320 | + // start with an empty array() |
|
321 | + $valid_data = array(); |
|
322 | + // grab valid id |
|
323 | + $valid_data['id'] = $id; |
|
324 | + // array of other form names |
|
325 | + $inputs_to_clean = array( |
|
326 | + 'event_id' => 'tkt-slctr-event-id', |
|
327 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
328 | + 'rows' => 'tkt-slctr-rows-', |
|
329 | + 'qty' => 'tkt-slctr-qty-', |
|
330 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
331 | + 'return_url' => 'tkt-slctr-return-url-', |
|
332 | + ); |
|
333 | + // let's track the total number of tickets ordered.' |
|
334 | + $valid_data['total_tickets'] = 0; |
|
335 | + // cycle through $inputs_to_clean array |
|
336 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
337 | + // check for POST data |
|
338 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
339 | + // grab value |
|
340 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
341 | + switch ($what) { |
|
342 | + // integers |
|
343 | + case 'event_id': |
|
344 | + $valid_data[ $what ] = absint($input_value); |
|
345 | + // get event via the event id we put in the form |
|
346 | + $valid_data['event'] = EE_Registry::instance() |
|
347 | + ->load_model('Event') |
|
348 | + ->get_one_by_ID($valid_data['event_id']); |
|
349 | + break; |
|
350 | + case 'rows': |
|
351 | + case 'max_atndz': |
|
352 | + $valid_data[ $what ] = absint($input_value); |
|
353 | + break; |
|
354 | + // arrays of integers |
|
355 | + case 'qty': |
|
356 | + /** @var array $row_qty */ |
|
357 | + $row_qty = $input_value; |
|
358 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
359 | + if (! is_array($row_qty)) { |
|
360 | + // get number of rows |
|
361 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
362 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
363 | + : 1; |
|
364 | + // explode ints by the dash |
|
365 | + $row_qty = explode('-', $row_qty); |
|
366 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
367 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
368 | + $row_qty = array($row => $qty); |
|
369 | + for ($x = 1; $x <= $rows; $x++) { |
|
370 | + if (! isset($row_qty[ $x ])) { |
|
371 | + $row_qty[ $x ] = 0; |
|
372 | + } |
|
373 | + } |
|
374 | + } |
|
375 | + ksort($row_qty); |
|
376 | + // cycle thru values |
|
377 | + foreach ($row_qty as $qty) { |
|
378 | + $qty = absint($qty); |
|
379 | + // sanitize as integers |
|
380 | + $valid_data[ $what ][] = $qty; |
|
381 | + $valid_data['total_tickets'] += $qty; |
|
382 | + } |
|
383 | + break; |
|
384 | + // array of integers |
|
385 | + case 'ticket_id': |
|
386 | + $value_array = array(); |
|
387 | + // cycle thru values |
|
388 | + foreach ((array) $input_value as $key => $value) { |
|
389 | + // allow only numbers, letters, spaces, commas and dashes |
|
390 | + $value_array[ $key ] = wp_strip_all_tags($value); |
|
391 | + // get ticket via the ticket id we put in the form |
|
392 | + $ticket_obj = EE_Registry::instance() |
|
393 | + ->load_model('Ticket') |
|
394 | + ->get_one_by_ID($value); |
|
395 | + $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
396 | + } |
|
397 | + $valid_data[ $what ] = $value_array; |
|
398 | + break; |
|
399 | + case 'return_url' : |
|
400 | + // grab and sanitize return-url |
|
401 | + $input_value = esc_url_raw($input_value); |
|
402 | + // was the request coming from an iframe ? if so, then: |
|
403 | + if (strpos($input_value, 'event_list=iframe')) { |
|
404 | + // get anchor fragment |
|
405 | + $input_value = explode('#', $input_value); |
|
406 | + $input_value = end($input_value); |
|
407 | + // use event list url instead, but append anchor |
|
408 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
409 | + } |
|
410 | + $valid_data[ $what ] = $input_value; |
|
411 | + break; |
|
412 | + } // end switch $what |
|
413 | + } |
|
414 | + } // end foreach $inputs_to_clean |
|
415 | + return $valid_data; |
|
416 | + } |
|
417 | 417 | |
418 | 418 | |
419 | - /** |
|
420 | - * adds a ticket to the cart |
|
421 | - * |
|
422 | - * @param EE_Ticket $ticket |
|
423 | - * @param int $qty |
|
424 | - * @return TRUE on success, FALSE on fail |
|
425 | - * @throws InvalidArgumentException |
|
426 | - * @throws InvalidInterfaceException |
|
427 | - * @throws InvalidDataTypeException |
|
428 | - * @throws EE_Error |
|
429 | - */ |
|
430 | - private function addTicketToCart(EE_Ticket $ticket = null, $qty = 1) |
|
431 | - { |
|
432 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
433 | - // get the number of spaces left for this datetime ticket |
|
434 | - $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
435 | - // compare available spaces against the number of tickets being purchased |
|
436 | - if ($available_spaces >= $qty) { |
|
437 | - // allow addons to prevent a ticket from being added to cart |
|
438 | - if ( |
|
439 | - ! apply_filters( |
|
440 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
441 | - true, |
|
442 | - $ticket, |
|
443 | - $qty, |
|
444 | - $available_spaces |
|
445 | - ) |
|
446 | - ) { |
|
447 | - return false; |
|
448 | - } |
|
449 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
450 | - // add event to cart |
|
451 | - if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
452 | - $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
453 | - return true; |
|
454 | - } |
|
455 | - return false; |
|
456 | - } |
|
457 | - // tickets can not be purchased but let's find the exact number left |
|
458 | - // for the last ticket selected PRIOR to subtracting tickets |
|
459 | - $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
460 | - // greedy greedy greedy eh? |
|
461 | - if ($available_spaces > 0) { |
|
462 | - if ( |
|
463 | - apply_filters( |
|
464 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
465 | - true, |
|
466 | - $ticket, |
|
467 | - $qty, |
|
468 | - $available_spaces |
|
469 | - ) |
|
470 | - ) { |
|
471 | - $this->displayAvailabilityError($available_spaces); |
|
472 | - } |
|
473 | - } else { |
|
474 | - EE_Error::add_error( |
|
475 | - __( |
|
476 | - 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
477 | - 'event_espresso' |
|
478 | - ), |
|
479 | - __FILE__, __FUNCTION__, __LINE__ |
|
480 | - ); |
|
481 | - } |
|
482 | - return false; |
|
483 | - } |
|
419 | + /** |
|
420 | + * adds a ticket to the cart |
|
421 | + * |
|
422 | + * @param EE_Ticket $ticket |
|
423 | + * @param int $qty |
|
424 | + * @return TRUE on success, FALSE on fail |
|
425 | + * @throws InvalidArgumentException |
|
426 | + * @throws InvalidInterfaceException |
|
427 | + * @throws InvalidDataTypeException |
|
428 | + * @throws EE_Error |
|
429 | + */ |
|
430 | + private function addTicketToCart(EE_Ticket $ticket = null, $qty = 1) |
|
431 | + { |
|
432 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
433 | + // get the number of spaces left for this datetime ticket |
|
434 | + $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
435 | + // compare available spaces against the number of tickets being purchased |
|
436 | + if ($available_spaces >= $qty) { |
|
437 | + // allow addons to prevent a ticket from being added to cart |
|
438 | + if ( |
|
439 | + ! apply_filters( |
|
440 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
441 | + true, |
|
442 | + $ticket, |
|
443 | + $qty, |
|
444 | + $available_spaces |
|
445 | + ) |
|
446 | + ) { |
|
447 | + return false; |
|
448 | + } |
|
449 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
450 | + // add event to cart |
|
451 | + if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
452 | + $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
453 | + return true; |
|
454 | + } |
|
455 | + return false; |
|
456 | + } |
|
457 | + // tickets can not be purchased but let's find the exact number left |
|
458 | + // for the last ticket selected PRIOR to subtracting tickets |
|
459 | + $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
460 | + // greedy greedy greedy eh? |
|
461 | + if ($available_spaces > 0) { |
|
462 | + if ( |
|
463 | + apply_filters( |
|
464 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
465 | + true, |
|
466 | + $ticket, |
|
467 | + $qty, |
|
468 | + $available_spaces |
|
469 | + ) |
|
470 | + ) { |
|
471 | + $this->displayAvailabilityError($available_spaces); |
|
472 | + } |
|
473 | + } else { |
|
474 | + EE_Error::add_error( |
|
475 | + __( |
|
476 | + 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
477 | + 'event_espresso' |
|
478 | + ), |
|
479 | + __FILE__, __FUNCTION__, __LINE__ |
|
480 | + ); |
|
481 | + } |
|
482 | + return false; |
|
483 | + } |
|
484 | 484 | |
485 | 485 | |
486 | - /** |
|
487 | - * @param int $available_spaces |
|
488 | - * @throws InvalidArgumentException |
|
489 | - * @throws InvalidInterfaceException |
|
490 | - * @throws InvalidDataTypeException |
|
491 | - * @throws EE_Error |
|
492 | - */ |
|
493 | - private function displayAvailabilityError($available_spaces = 1) |
|
494 | - { |
|
495 | - // add error messaging - we're using the _n function that will generate |
|
496 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
497 | - if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
498 | - $msg = sprintf( |
|
499 | - _n( |
|
500 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
501 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
502 | - $available_spaces, |
|
503 | - 'event_espresso' |
|
504 | - ), |
|
505 | - $available_spaces, |
|
506 | - '<br />' |
|
507 | - ); |
|
508 | - } else { |
|
509 | - $msg = sprintf( |
|
510 | - _n( |
|
511 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
512 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
513 | - $available_spaces, |
|
514 | - 'event_espresso' |
|
515 | - ), |
|
516 | - $available_spaces, |
|
517 | - '<br />' |
|
518 | - ); |
|
519 | - } |
|
520 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
521 | - } |
|
486 | + /** |
|
487 | + * @param int $available_spaces |
|
488 | + * @throws InvalidArgumentException |
|
489 | + * @throws InvalidInterfaceException |
|
490 | + * @throws InvalidDataTypeException |
|
491 | + * @throws EE_Error |
|
492 | + */ |
|
493 | + private function displayAvailabilityError($available_spaces = 1) |
|
494 | + { |
|
495 | + // add error messaging - we're using the _n function that will generate |
|
496 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
497 | + if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
498 | + $msg = sprintf( |
|
499 | + _n( |
|
500 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
501 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
502 | + $available_spaces, |
|
503 | + 'event_espresso' |
|
504 | + ), |
|
505 | + $available_spaces, |
|
506 | + '<br />' |
|
507 | + ); |
|
508 | + } else { |
|
509 | + $msg = sprintf( |
|
510 | + _n( |
|
511 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
512 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
513 | + $available_spaces, |
|
514 | + 'event_espresso' |
|
515 | + ), |
|
516 | + $available_spaces, |
|
517 | + '<br />' |
|
518 | + ); |
|
519 | + } |
|
520 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
521 | + } |
|
522 | 522 | |
523 | 523 | |
524 | - /** |
|
525 | - * ticketDatetimeAvailability |
|
526 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
527 | - * and tracks the spaces remaining for each of those datetimes |
|
528 | - * |
|
529 | - * @param EE_Ticket $ticket - selected ticket |
|
530 | - * @param bool $get_original_ticket_spaces |
|
531 | - * @return int |
|
532 | - * @throws InvalidArgumentException |
|
533 | - * @throws InvalidInterfaceException |
|
534 | - * @throws InvalidDataTypeException |
|
535 | - * @throws EE_Error |
|
536 | - */ |
|
537 | - private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
538 | - { |
|
539 | - // if the $_available_spaces array has not been set up yet... |
|
540 | - if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
541 | - $this->setInitialTicketDatetimeAvailability($ticket); |
|
542 | - } |
|
543 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
544 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
545 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
546 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
547 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
548 | - if ($get_original_ticket_spaces) { |
|
549 | - // then grab the available spaces from the "tickets" array |
|
550 | - // and compare with the above to get the lowest number |
|
551 | - $available_spaces = min( |
|
552 | - $available_spaces, |
|
553 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
554 | - ); |
|
555 | - } else { |
|
556 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
557 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
558 | - } |
|
559 | - } |
|
560 | - } |
|
561 | - return $available_spaces; |
|
562 | - } |
|
524 | + /** |
|
525 | + * ticketDatetimeAvailability |
|
526 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
527 | + * and tracks the spaces remaining for each of those datetimes |
|
528 | + * |
|
529 | + * @param EE_Ticket $ticket - selected ticket |
|
530 | + * @param bool $get_original_ticket_spaces |
|
531 | + * @return int |
|
532 | + * @throws InvalidArgumentException |
|
533 | + * @throws InvalidInterfaceException |
|
534 | + * @throws InvalidDataTypeException |
|
535 | + * @throws EE_Error |
|
536 | + */ |
|
537 | + private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
538 | + { |
|
539 | + // if the $_available_spaces array has not been set up yet... |
|
540 | + if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
541 | + $this->setInitialTicketDatetimeAvailability($ticket); |
|
542 | + } |
|
543 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
544 | + if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
545 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
546 | + foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
547 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
548 | + if ($get_original_ticket_spaces) { |
|
549 | + // then grab the available spaces from the "tickets" array |
|
550 | + // and compare with the above to get the lowest number |
|
551 | + $available_spaces = min( |
|
552 | + $available_spaces, |
|
553 | + self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
554 | + ); |
|
555 | + } else { |
|
556 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
557 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
558 | + } |
|
559 | + } |
|
560 | + } |
|
561 | + return $available_spaces; |
|
562 | + } |
|
563 | 563 | |
564 | 564 | |
565 | - /** |
|
566 | - * @param EE_Ticket $ticket |
|
567 | - * @return void |
|
568 | - * @throws InvalidArgumentException |
|
569 | - * @throws InvalidInterfaceException |
|
570 | - * @throws InvalidDataTypeException |
|
571 | - * @throws EE_Error |
|
572 | - */ |
|
573 | - private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
574 | - { |
|
575 | - // first, get all of the datetimes that are available to this ticket |
|
576 | - $datetimes = $ticket->get_many_related( |
|
577 | - 'Datetime', |
|
578 | - array( |
|
579 | - array( |
|
580 | - 'DTT_EVT_end' => array( |
|
581 | - '>=', |
|
582 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
583 | - ), |
|
584 | - ), |
|
585 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
586 | - ) |
|
587 | - ); |
|
588 | - if (! empty($datetimes)) { |
|
589 | - // now loop thru all of the datetimes |
|
590 | - foreach ($datetimes as $datetime) { |
|
591 | - if ($datetime instanceof EE_Datetime) { |
|
592 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
593 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
594 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
595 | - // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
596 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
597 | - $ticket->qty() - $ticket->sold(), |
|
598 | - $spaces_remaining |
|
599 | - ); |
|
600 | - // if the remaining spaces for this datetime is already set, |
|
601 | - // then compare that against the datetime spaces remaining, and take the lowest number, |
|
602 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
603 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
604 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
605 | - ) |
|
606 | - ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
607 | - : $spaces_remaining; |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - } |
|
565 | + /** |
|
566 | + * @param EE_Ticket $ticket |
|
567 | + * @return void |
|
568 | + * @throws InvalidArgumentException |
|
569 | + * @throws InvalidInterfaceException |
|
570 | + * @throws InvalidDataTypeException |
|
571 | + * @throws EE_Error |
|
572 | + */ |
|
573 | + private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
574 | + { |
|
575 | + // first, get all of the datetimes that are available to this ticket |
|
576 | + $datetimes = $ticket->get_many_related( |
|
577 | + 'Datetime', |
|
578 | + array( |
|
579 | + array( |
|
580 | + 'DTT_EVT_end' => array( |
|
581 | + '>=', |
|
582 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
583 | + ), |
|
584 | + ), |
|
585 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
586 | + ) |
|
587 | + ); |
|
588 | + if (! empty($datetimes)) { |
|
589 | + // now loop thru all of the datetimes |
|
590 | + foreach ($datetimes as $datetime) { |
|
591 | + if ($datetime instanceof EE_Datetime) { |
|
592 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
593 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
594 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
595 | + // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
596 | + self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
597 | + $ticket->qty() - $ticket->sold(), |
|
598 | + $spaces_remaining |
|
599 | + ); |
|
600 | + // if the remaining spaces for this datetime is already set, |
|
601 | + // then compare that against the datetime spaces remaining, and take the lowest number, |
|
602 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
603 | + self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
604 | + self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
605 | + ) |
|
606 | + ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
607 | + : $spaces_remaining; |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + } |
|
612 | 612 | |
613 | 613 | |
614 | - /** |
|
615 | - * @param EE_Ticket $ticket |
|
616 | - * @param int $qty |
|
617 | - * @return void |
|
618 | - * @throws EE_Error |
|
619 | - */ |
|
620 | - private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
621 | - { |
|
622 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
623 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
624 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
625 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
626 | - self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
627 | - } |
|
628 | - } |
|
629 | - } |
|
614 | + /** |
|
615 | + * @param EE_Ticket $ticket |
|
616 | + * @param int $qty |
|
617 | + * @return void |
|
618 | + * @throws EE_Error |
|
619 | + */ |
|
620 | + private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
621 | + { |
|
622 | + if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
623 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
624 | + foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
625 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
626 | + self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
627 | + } |
|
628 | + } |
|
629 | + } |
|
630 | 630 | } |
631 | 631 | // End of file ProcessTicketSelector.php |
632 | 632 | // Location: /ProcessTicketSelector.php |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use EventEspresso\core\services\loaders\LoaderFactory; |
14 | 14 | use InvalidArgumentException; |
15 | 15 | |
16 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
16 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
17 | 17 | exit('No direct script access allowed'); |
18 | 18 | } |
19 | 19 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | public function cancelTicketSelections() |
52 | 52 | { |
53 | 53 | // check nonce |
54 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
54 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ); |
64 | 64 | } else { |
65 | 65 | wp_safe_redirect( |
66 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
66 | + site_url('/'.EE_Registry::instance()->CFG->core->event_cpt_slug.'/') |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | exit(); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | { |
126 | 126 | do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
127 | 127 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
128 | - if($request->isBot()) { |
|
128 | + if ($request->isBot()) { |
|
129 | 129 | wp_safe_redirect( |
130 | 130 | apply_filters( |
131 | 131 | 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | exit(); |
136 | 136 | } |
137 | 137 | // do we have an event id? |
138 | - if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
138 | + if ( ! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
139 | 139 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
140 | 140 | EE_Error::add_error( |
141 | 141 | sprintf( |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $valid['total_tickets'], |
182 | 182 | 'event_espresso' |
183 | 183 | ); |
184 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
184 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
185 | 185 | // dev only message |
186 | 186 | $max_atndz_string = _n( |
187 | 187 | 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | $valid['max_atndz'], |
190 | 190 | 'event_espresso' |
191 | 191 | ); |
192 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
193 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
192 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
193 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
194 | 194 | } else { |
195 | 195 | // all data appears to be valid |
196 | 196 | $tckts_slctd = false; |
@@ -203,15 +203,15 @@ discard block |
||
203 | 203 | // cycle thru the number of data rows sent from the event listing |
204 | 204 | for ($x = 0; $x < $valid['rows']; $x++) { |
205 | 205 | // does this row actually contain a ticket quantity? |
206 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
206 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
207 | 207 | // YES we have a ticket quantity |
208 | 208 | $tckts_slctd = true; |
209 | 209 | // d( $valid['ticket_obj'][$x] ); |
210 | - if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
210 | + if ($valid['ticket_obj'][$x] instanceof EE_Ticket) { |
|
211 | 211 | // then add ticket to cart |
212 | 212 | $tickets_added += $this->addTicketToCart( |
213 | - $valid['ticket_obj'][ $x ], |
|
214 | - $valid['qty'][ $x ] |
|
213 | + $valid['ticket_obj'][$x], |
|
214 | + $valid['qty'][$x] |
|
215 | 215 | ); |
216 | 216 | if (EE_Error::has_error()) { |
217 | 217 | break; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | ); |
263 | 263 | exit(); |
264 | 264 | } else { |
265 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
265 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
266 | 266 | // nothing added to cart |
267 | 267 | EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
268 | 268 | __FILE__, __FUNCTION__, __LINE__); |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | private function validatePostData($id = 0) |
309 | 309 | { |
310 | 310 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
311 | - if (! $id) { |
|
311 | + if ( ! $id) { |
|
312 | 312 | EE_Error::add_error( |
313 | 313 | __('The event id provided was not valid.', 'event_espresso'), |
314 | 314 | __FILE__, |
@@ -335,13 +335,13 @@ discard block |
||
335 | 335 | // cycle through $inputs_to_clean array |
336 | 336 | foreach ($inputs_to_clean as $what => $input_to_clean) { |
337 | 337 | // check for POST data |
338 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
338 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean.$id)) { |
|
339 | 339 | // grab value |
340 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
340 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean.$id); |
|
341 | 341 | switch ($what) { |
342 | 342 | // integers |
343 | 343 | case 'event_id': |
344 | - $valid_data[ $what ] = absint($input_value); |
|
344 | + $valid_data[$what] = absint($input_value); |
|
345 | 345 | // get event via the event id we put in the form |
346 | 346 | $valid_data['event'] = EE_Registry::instance() |
347 | 347 | ->load_model('Event') |
@@ -349,17 +349,17 @@ discard block |
||
349 | 349 | break; |
350 | 350 | case 'rows': |
351 | 351 | case 'max_atndz': |
352 | - $valid_data[ $what ] = absint($input_value); |
|
352 | + $valid_data[$what] = absint($input_value); |
|
353 | 353 | break; |
354 | 354 | // arrays of integers |
355 | 355 | case 'qty': |
356 | 356 | /** @var array $row_qty */ |
357 | 357 | $row_qty = $input_value; |
358 | 358 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
359 | - if (! is_array($row_qty)) { |
|
359 | + if ( ! is_array($row_qty)) { |
|
360 | 360 | // get number of rows |
361 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
362 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
361 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-'.$id) |
|
362 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-'.$id)) |
|
363 | 363 | : 1; |
364 | 364 | // explode ints by the dash |
365 | 365 | $row_qty = explode('-', $row_qty); |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
368 | 368 | $row_qty = array($row => $qty); |
369 | 369 | for ($x = 1; $x <= $rows; $x++) { |
370 | - if (! isset($row_qty[ $x ])) { |
|
371 | - $row_qty[ $x ] = 0; |
|
370 | + if ( ! isset($row_qty[$x])) { |
|
371 | + $row_qty[$x] = 0; |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | } |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | foreach ($row_qty as $qty) { |
378 | 378 | $qty = absint($qty); |
379 | 379 | // sanitize as integers |
380 | - $valid_data[ $what ][] = $qty; |
|
380 | + $valid_data[$what][] = $qty; |
|
381 | 381 | $valid_data['total_tickets'] += $qty; |
382 | 382 | } |
383 | 383 | break; |
@@ -387,14 +387,14 @@ discard block |
||
387 | 387 | // cycle thru values |
388 | 388 | foreach ((array) $input_value as $key => $value) { |
389 | 389 | // allow only numbers, letters, spaces, commas and dashes |
390 | - $value_array[ $key ] = wp_strip_all_tags($value); |
|
390 | + $value_array[$key] = wp_strip_all_tags($value); |
|
391 | 391 | // get ticket via the ticket id we put in the form |
392 | 392 | $ticket_obj = EE_Registry::instance() |
393 | 393 | ->load_model('Ticket') |
394 | 394 | ->get_one_by_ID($value); |
395 | - $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
395 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
396 | 396 | } |
397 | - $valid_data[ $what ] = $value_array; |
|
397 | + $valid_data[$what] = $value_array; |
|
398 | 398 | break; |
399 | 399 | case 'return_url' : |
400 | 400 | // grab and sanitize return-url |
@@ -405,9 +405,9 @@ discard block |
||
405 | 405 | $input_value = explode('#', $input_value); |
406 | 406 | $input_value = end($input_value); |
407 | 407 | // use event list url instead, but append anchor |
408 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
408 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; |
|
409 | 409 | } |
410 | - $valid_data[ $what ] = $input_value; |
|
410 | + $valid_data[$what] = $input_value; |
|
411 | 411 | break; |
412 | 412 | } // end switch $what |
413 | 413 | } |
@@ -537,24 +537,24 @@ discard block |
||
537 | 537 | private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
538 | 538 | { |
539 | 539 | // if the $_available_spaces array has not been set up yet... |
540 | - if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
540 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
541 | 541 | $this->setInitialTicketDatetimeAvailability($ticket); |
542 | 542 | } |
543 | 543 | $available_spaces = $ticket->qty() - $ticket->sold(); |
544 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
544 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
545 | 545 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
546 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
546 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
547 | 547 | // if we want the original datetime availability BEFORE we started subtracting tickets ? |
548 | 548 | if ($get_original_ticket_spaces) { |
549 | 549 | // then grab the available spaces from the "tickets" array |
550 | 550 | // and compare with the above to get the lowest number |
551 | 551 | $available_spaces = min( |
552 | 552 | $available_spaces, |
553 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
553 | + self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
554 | 554 | ); |
555 | 555 | } else { |
556 | 556 | // we want the updated ticket availability as stored in the "datetimes" array |
557 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
557 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | } |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | 'order_by' => array('DTT_EVT_start' => 'ASC'), |
586 | 586 | ) |
587 | 587 | ); |
588 | - if (! empty($datetimes)) { |
|
588 | + if ( ! empty($datetimes)) { |
|
589 | 589 | // now loop thru all of the datetimes |
590 | 590 | foreach ($datetimes as $datetime) { |
591 | 591 | if ($datetime instanceof EE_Datetime) { |
@@ -593,17 +593,17 @@ discard block |
||
593 | 593 | $spaces_remaining = $datetime->spaces_remaining(); |
594 | 594 | // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
595 | 595 | // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
596 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
596 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
597 | 597 | $ticket->qty() - $ticket->sold(), |
598 | 598 | $spaces_remaining |
599 | 599 | ); |
600 | 600 | // if the remaining spaces for this datetime is already set, |
601 | 601 | // then compare that against the datetime spaces remaining, and take the lowest number, |
602 | 602 | // else just take the datetime spaces remaining, and assign to the datetimes array |
603 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
604 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
603 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
604 | + self::$_available_spaces['datetimes'][$datetime->ID()] |
|
605 | 605 | ) |
606 | - ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
606 | + ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
607 | 607 | : $spaces_remaining; |
608 | 608 | } |
609 | 609 | } |
@@ -619,11 +619,11 @@ discard block |
||
619 | 619 | */ |
620 | 620 | private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
621 | 621 | { |
622 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
622 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
623 | 623 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
624 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
624 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
625 | 625 | // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
626 | - self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
626 | + self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
627 | 627 | } |
628 | 628 | } |
629 | 629 | } |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | // if you're a dev and want to receive all errors via email |
12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -27,256 +27,256 @@ discard block |
||
27 | 27 | class EE_Error extends Exception |
28 | 28 | { |
29 | 29 | |
30 | - const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * name of the file to log exceptions to |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | - |
|
40 | - /** |
|
41 | - * stores details for all exception |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private static $_all_exceptions = array(); |
|
46 | - |
|
47 | - /** |
|
48 | - * tracks number of errors |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - private static $_error_count = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $_espresso_notices |
|
56 | - */ |
|
57 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @override default exception handling |
|
63 | - * @param string $message |
|
64 | - * @param int $code |
|
65 | - * @param Exception|null $previous |
|
66 | - */ |
|
67 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | - { |
|
69 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | - parent::__construct($message, $code); |
|
71 | - } else { |
|
72 | - parent::__construct($message, $code, $previous); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * error_handler |
|
80 | - * |
|
81 | - * @param $code |
|
82 | - * @param $message |
|
83 | - * @param $file |
|
84 | - * @param $line |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public static function error_handler($code, $message, $file, $line) |
|
88 | - { |
|
89 | - $type = EE_Error::error_type($code); |
|
90 | - $site = site_url(); |
|
91 | - switch ($site) { |
|
92 | - case 'http://ee4.eventespresso.com/' : |
|
93 | - case 'http://ee4decaf.eventespresso.com/' : |
|
94 | - case 'http://ee4hf.eventespresso.com/' : |
|
95 | - case 'http://ee4a.eventespresso.com/' : |
|
96 | - case 'http://ee4ad.eventespresso.com/' : |
|
97 | - case 'http://ee4b.eventespresso.com/' : |
|
98 | - case 'http://ee4bd.eventespresso.com/' : |
|
99 | - case 'http://ee4d.eventespresso.com/' : |
|
100 | - case 'http://ee4dd.eventespresso.com/' : |
|
101 | - $to = '[email protected]'; |
|
102 | - break; |
|
103 | - default : |
|
104 | - $to = get_option('admin_email'); |
|
105 | - } |
|
106 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
107 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
108 | - if (function_exists('wp_mail')) { |
|
109 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
110 | - wp_mail($to, $subject, $msg); |
|
111 | - } |
|
112 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
113 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
114 | - echo '<br /></p></div>'; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * error_type |
|
121 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
122 | - * |
|
123 | - * @param $code |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public static function error_type($code) |
|
127 | - { |
|
128 | - switch ($code) { |
|
129 | - case E_ERROR: // 1 // |
|
130 | - return 'E_ERROR'; |
|
131 | - case E_WARNING: // 2 // |
|
132 | - return 'E_WARNING'; |
|
133 | - case E_PARSE: // 4 // |
|
134 | - return 'E_PARSE'; |
|
135 | - case E_NOTICE: // 8 // |
|
136 | - return 'E_NOTICE'; |
|
137 | - case E_CORE_ERROR: // 16 // |
|
138 | - return 'E_CORE_ERROR'; |
|
139 | - case E_CORE_WARNING: // 32 // |
|
140 | - return 'E_CORE_WARNING'; |
|
141 | - case E_COMPILE_ERROR: // 64 // |
|
142 | - return 'E_COMPILE_ERROR'; |
|
143 | - case E_COMPILE_WARNING: // 128 // |
|
144 | - return 'E_COMPILE_WARNING'; |
|
145 | - case E_USER_ERROR: // 256 // |
|
146 | - return 'E_USER_ERROR'; |
|
147 | - case E_USER_WARNING: // 512 // |
|
148 | - return 'E_USER_WARNING'; |
|
149 | - case E_USER_NOTICE: // 1024 // |
|
150 | - return 'E_USER_NOTICE'; |
|
151 | - case E_STRICT: // 2048 // |
|
152 | - return 'E_STRICT'; |
|
153 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
154 | - return 'E_RECOVERABLE_ERROR'; |
|
155 | - case E_DEPRECATED: // 8192 // |
|
156 | - return 'E_DEPRECATED'; |
|
157 | - case E_USER_DEPRECATED: // 16384 // |
|
158 | - return 'E_USER_DEPRECATED'; |
|
159 | - case E_ALL: // 16384 // |
|
160 | - return 'E_ALL'; |
|
161 | - } |
|
162 | - return ''; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * fatal_error_handler |
|
169 | - * |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - public static function fatal_error_handler() |
|
173 | - { |
|
174 | - $last_error = error_get_last(); |
|
175 | - if ($last_error['type'] === E_ERROR) { |
|
176 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * _format_error |
|
184 | - * |
|
185 | - * @param $code |
|
186 | - * @param $message |
|
187 | - * @param $file |
|
188 | - * @param $line |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - private static function _format_error($code, $message, $file, $line) |
|
192 | - { |
|
193 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
194 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
195 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
196 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
197 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
198 | - $html .= '</tbody></table>'; |
|
199 | - return $html; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * set_content_type |
|
206 | - * |
|
207 | - * @param $content_type |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public static function set_content_type($content_type) |
|
211 | - { |
|
212 | - return 'text/html'; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * @return void |
|
219 | - * @throws EE_Error |
|
220 | - * @throws ReflectionException |
|
221 | - */ |
|
222 | - public function get_error() |
|
223 | - { |
|
224 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
225 | - throw $this; |
|
226 | - } |
|
227 | - // get separate user and developer messages if they exist |
|
228 | - $msg = explode('||', $this->getMessage()); |
|
229 | - $user_msg = $msg[0]; |
|
230 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
231 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
232 | - // add details to _all_exceptions array |
|
233 | - $x_time = time(); |
|
234 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
235 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
236 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
237 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
238 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
239 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
240 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
241 | - self::$_error_count++; |
|
242 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
243 | - $this->display_errors(); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * @param bool $check_stored |
|
250 | - * @param string $type_to_check |
|
251 | - * @return bool |
|
252 | - */ |
|
253 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
254 | - { |
|
255 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
256 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
257 | - ? true |
|
258 | - : false; |
|
259 | - if ($check_stored && ! $has_error) { |
|
260 | - $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | - foreach ($notices as $type => $notice) { |
|
262 | - if ($type === $type_to_check && $notice) { |
|
263 | - return true; |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - return $has_error; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @echo string |
|
274 | - * @throws \ReflectionException |
|
275 | - */ |
|
276 | - public function display_errors() |
|
277 | - { |
|
278 | - $trace_details = ''; |
|
279 | - $output = ' |
|
30 | + const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * name of the file to log exceptions to |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | + |
|
40 | + /** |
|
41 | + * stores details for all exception |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private static $_all_exceptions = array(); |
|
46 | + |
|
47 | + /** |
|
48 | + * tracks number of errors |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + private static $_error_count = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $_espresso_notices |
|
56 | + */ |
|
57 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @override default exception handling |
|
63 | + * @param string $message |
|
64 | + * @param int $code |
|
65 | + * @param Exception|null $previous |
|
66 | + */ |
|
67 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | + { |
|
69 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | + parent::__construct($message, $code); |
|
71 | + } else { |
|
72 | + parent::__construct($message, $code, $previous); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * error_handler |
|
80 | + * |
|
81 | + * @param $code |
|
82 | + * @param $message |
|
83 | + * @param $file |
|
84 | + * @param $line |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public static function error_handler($code, $message, $file, $line) |
|
88 | + { |
|
89 | + $type = EE_Error::error_type($code); |
|
90 | + $site = site_url(); |
|
91 | + switch ($site) { |
|
92 | + case 'http://ee4.eventespresso.com/' : |
|
93 | + case 'http://ee4decaf.eventespresso.com/' : |
|
94 | + case 'http://ee4hf.eventespresso.com/' : |
|
95 | + case 'http://ee4a.eventespresso.com/' : |
|
96 | + case 'http://ee4ad.eventespresso.com/' : |
|
97 | + case 'http://ee4b.eventespresso.com/' : |
|
98 | + case 'http://ee4bd.eventespresso.com/' : |
|
99 | + case 'http://ee4d.eventespresso.com/' : |
|
100 | + case 'http://ee4dd.eventespresso.com/' : |
|
101 | + $to = '[email protected]'; |
|
102 | + break; |
|
103 | + default : |
|
104 | + $to = get_option('admin_email'); |
|
105 | + } |
|
106 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
107 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
108 | + if (function_exists('wp_mail')) { |
|
109 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
110 | + wp_mail($to, $subject, $msg); |
|
111 | + } |
|
112 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
113 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
114 | + echo '<br /></p></div>'; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * error_type |
|
121 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
122 | + * |
|
123 | + * @param $code |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public static function error_type($code) |
|
127 | + { |
|
128 | + switch ($code) { |
|
129 | + case E_ERROR: // 1 // |
|
130 | + return 'E_ERROR'; |
|
131 | + case E_WARNING: // 2 // |
|
132 | + return 'E_WARNING'; |
|
133 | + case E_PARSE: // 4 // |
|
134 | + return 'E_PARSE'; |
|
135 | + case E_NOTICE: // 8 // |
|
136 | + return 'E_NOTICE'; |
|
137 | + case E_CORE_ERROR: // 16 // |
|
138 | + return 'E_CORE_ERROR'; |
|
139 | + case E_CORE_WARNING: // 32 // |
|
140 | + return 'E_CORE_WARNING'; |
|
141 | + case E_COMPILE_ERROR: // 64 // |
|
142 | + return 'E_COMPILE_ERROR'; |
|
143 | + case E_COMPILE_WARNING: // 128 // |
|
144 | + return 'E_COMPILE_WARNING'; |
|
145 | + case E_USER_ERROR: // 256 // |
|
146 | + return 'E_USER_ERROR'; |
|
147 | + case E_USER_WARNING: // 512 // |
|
148 | + return 'E_USER_WARNING'; |
|
149 | + case E_USER_NOTICE: // 1024 // |
|
150 | + return 'E_USER_NOTICE'; |
|
151 | + case E_STRICT: // 2048 // |
|
152 | + return 'E_STRICT'; |
|
153 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
154 | + return 'E_RECOVERABLE_ERROR'; |
|
155 | + case E_DEPRECATED: // 8192 // |
|
156 | + return 'E_DEPRECATED'; |
|
157 | + case E_USER_DEPRECATED: // 16384 // |
|
158 | + return 'E_USER_DEPRECATED'; |
|
159 | + case E_ALL: // 16384 // |
|
160 | + return 'E_ALL'; |
|
161 | + } |
|
162 | + return ''; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * fatal_error_handler |
|
169 | + * |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + public static function fatal_error_handler() |
|
173 | + { |
|
174 | + $last_error = error_get_last(); |
|
175 | + if ($last_error['type'] === E_ERROR) { |
|
176 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * _format_error |
|
184 | + * |
|
185 | + * @param $code |
|
186 | + * @param $message |
|
187 | + * @param $file |
|
188 | + * @param $line |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + private static function _format_error($code, $message, $file, $line) |
|
192 | + { |
|
193 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
194 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
195 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
196 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
197 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
198 | + $html .= '</tbody></table>'; |
|
199 | + return $html; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * set_content_type |
|
206 | + * |
|
207 | + * @param $content_type |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + public static function set_content_type($content_type) |
|
211 | + { |
|
212 | + return 'text/html'; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * @return void |
|
219 | + * @throws EE_Error |
|
220 | + * @throws ReflectionException |
|
221 | + */ |
|
222 | + public function get_error() |
|
223 | + { |
|
224 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
225 | + throw $this; |
|
226 | + } |
|
227 | + // get separate user and developer messages if they exist |
|
228 | + $msg = explode('||', $this->getMessage()); |
|
229 | + $user_msg = $msg[0]; |
|
230 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
231 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
232 | + // add details to _all_exceptions array |
|
233 | + $x_time = time(); |
|
234 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
235 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
236 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
237 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
238 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
239 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
240 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
241 | + self::$_error_count++; |
|
242 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
243 | + $this->display_errors(); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * @param bool $check_stored |
|
250 | + * @param string $type_to_check |
|
251 | + * @return bool |
|
252 | + */ |
|
253 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
254 | + { |
|
255 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
256 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
257 | + ? true |
|
258 | + : false; |
|
259 | + if ($check_stored && ! $has_error) { |
|
260 | + $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | + foreach ($notices as $type => $notice) { |
|
262 | + if ($type === $type_to_check && $notice) { |
|
263 | + return true; |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + return $has_error; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @echo string |
|
274 | + * @throws \ReflectionException |
|
275 | + */ |
|
276 | + public function display_errors() |
|
277 | + { |
|
278 | + $trace_details = ''; |
|
279 | + $output = ' |
|
280 | 280 | <style type="text/css"> |
281 | 281 | #ee-error-message { |
282 | 282 | max-width:90% !important; |
@@ -332,21 +332,21 @@ discard block |
||
332 | 332 | } |
333 | 333 | </style> |
334 | 334 | <div id="ee-error-message" class="error">'; |
335 | - if (! WP_DEBUG) { |
|
336 | - $output .= ' |
|
335 | + if (! WP_DEBUG) { |
|
336 | + $output .= ' |
|
337 | 337 | <p>'; |
338 | - } |
|
339 | - // cycle thru errors |
|
340 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
341 | - $error_code = ''; |
|
342 | - // process trace info |
|
343 | - if (empty($ex['trace'])) { |
|
344 | - $trace_details .= __( |
|
345 | - 'Sorry, but no trace information was available for this exception.', |
|
346 | - 'event_espresso' |
|
347 | - ); |
|
348 | - } else { |
|
349 | - $trace_details .= ' |
|
338 | + } |
|
339 | + // cycle thru errors |
|
340 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
341 | + $error_code = ''; |
|
342 | + // process trace info |
|
343 | + if (empty($ex['trace'])) { |
|
344 | + $trace_details .= __( |
|
345 | + 'Sorry, but no trace information was available for this exception.', |
|
346 | + 'event_espresso' |
|
347 | + ); |
|
348 | + } else { |
|
349 | + $trace_details .= ' |
|
350 | 350 | <div id="ee-trace-details"> |
351 | 351 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
352 | 352 | <tr> |
@@ -356,43 +356,43 @@ discard block |
||
356 | 356 | <th scope="col" align="left">Class</th> |
357 | 357 | <th scope="col" align="left">Method( arguments )</th> |
358 | 358 | </tr>'; |
359 | - $last_on_stack = count($ex['trace']) - 1; |
|
360 | - // reverse array so that stack is in proper chronological order |
|
361 | - $sorted_trace = array_reverse($ex['trace']); |
|
362 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
363 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
364 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
365 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
366 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
367 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
368 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
369 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
370 | - if (empty($file) && ! empty($class)) { |
|
371 | - $a = new ReflectionClass($class); |
|
372 | - $file = $a->getFileName(); |
|
373 | - if (empty($line) && ! empty($function)) { |
|
374 | - try { |
|
375 | - //if $function is a closure, this throws an exception |
|
376 | - $b = new ReflectionMethod($class, $function); |
|
377 | - $line = $b->getStartLine(); |
|
378 | - } catch (Exception $closure_exception) { |
|
379 | - $line = 'unknown'; |
|
380 | - } |
|
381 | - } |
|
382 | - } |
|
383 | - if ($nmbr === $last_on_stack) { |
|
384 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
385 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
386 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
387 | - } |
|
388 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
389 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
390 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
391 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
392 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
393 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
394 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
395 | - $trace_details .= ' |
|
359 | + $last_on_stack = count($ex['trace']) - 1; |
|
360 | + // reverse array so that stack is in proper chronological order |
|
361 | + $sorted_trace = array_reverse($ex['trace']); |
|
362 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
363 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
364 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
365 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
366 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
367 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
368 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
369 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
370 | + if (empty($file) && ! empty($class)) { |
|
371 | + $a = new ReflectionClass($class); |
|
372 | + $file = $a->getFileName(); |
|
373 | + if (empty($line) && ! empty($function)) { |
|
374 | + try { |
|
375 | + //if $function is a closure, this throws an exception |
|
376 | + $b = new ReflectionMethod($class, $function); |
|
377 | + $line = $b->getStartLine(); |
|
378 | + } catch (Exception $closure_exception) { |
|
379 | + $line = 'unknown'; |
|
380 | + } |
|
381 | + } |
|
382 | + } |
|
383 | + if ($nmbr === $last_on_stack) { |
|
384 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
385 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
386 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
387 | + } |
|
388 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
389 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
390 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
391 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
392 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
393 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
394 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
395 | + $trace_details .= ' |
|
396 | 396 | <tr> |
397 | 397 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
398 | 398 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -400,523 +400,523 @@ discard block |
||
400 | 400 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
401 | 401 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
402 | 402 | </tr>'; |
403 | - } |
|
404 | - $trace_details .= ' |
|
403 | + } |
|
404 | + $trace_details .= ' |
|
405 | 405 | </table> |
406 | 406 | </div>'; |
407 | - } |
|
408 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
409 | - // add generic non-identifying messages for non-privileged users |
|
410 | - if (! WP_DEBUG) { |
|
411 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
412 | - . trim($ex['msg']) |
|
413 | - . '</span> <sup>' |
|
414 | - . $ex['code'] |
|
415 | - . '</sup><br />'; |
|
416 | - } else { |
|
417 | - // or helpful developer messages if debugging is on |
|
418 | - $output .= ' |
|
407 | + } |
|
408 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
409 | + // add generic non-identifying messages for non-privileged users |
|
410 | + if (! WP_DEBUG) { |
|
411 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
412 | + . trim($ex['msg']) |
|
413 | + . '</span> <sup>' |
|
414 | + . $ex['code'] |
|
415 | + . '</sup><br />'; |
|
416 | + } else { |
|
417 | + // or helpful developer messages if debugging is on |
|
418 | + $output .= ' |
|
419 | 419 | <div class="ee-error-dev-msg-dv"> |
420 | 420 | <p class="ee-error-dev-msg-pg"> |
421 | 421 | <strong class="ee-error-dev-msg-str">An ' |
422 | - . $ex['name'] |
|
423 | - . ' exception was thrown!</strong> <span>code: ' |
|
424 | - . $ex['code'] |
|
425 | - . '</span><br /> |
|
422 | + . $ex['name'] |
|
423 | + . ' exception was thrown!</strong> <span>code: ' |
|
424 | + . $ex['code'] |
|
425 | + . '</span><br /> |
|
426 | 426 | <span class="big-text">"' |
427 | - . trim($ex['msg']) |
|
428 | - . '"</span><br/> |
|
427 | + . trim($ex['msg']) |
|
428 | + . '"</span><br/> |
|
429 | 429 | <a id="display-ee-error-trace-' |
430 | - . self::$_error_count |
|
431 | - . $time |
|
432 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
433 | - . self::$_error_count |
|
434 | - . $time |
|
435 | - . '"> |
|
430 | + . self::$_error_count |
|
431 | + . $time |
|
432 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
433 | + . self::$_error_count |
|
434 | + . $time |
|
435 | + . '"> |
|
436 | 436 | ' |
437 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
438 | - . ' |
|
437 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
438 | + . ' |
|
439 | 439 | </a><br /> |
440 | 440 | <span class="small-text lt-grey-text">' |
441 | - . $ex['file'] |
|
442 | - . ' ( line no: ' |
|
443 | - . $ex['line'] |
|
444 | - . ' )</span> |
|
441 | + . $ex['file'] |
|
442 | + . ' ( line no: ' |
|
443 | + . $ex['line'] |
|
444 | + . ' )</span> |
|
445 | 445 | </p> |
446 | 446 | <div id="ee-error-trace-' |
447 | - . self::$_error_count |
|
448 | - . $time |
|
449 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
447 | + . self::$_error_count |
|
448 | + . $time |
|
449 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
450 | 450 | ' |
451 | - . $trace_details; |
|
452 | - if (! empty($class)) { |
|
453 | - $output .= ' |
|
451 | + . $trace_details; |
|
452 | + if (! empty($class)) { |
|
453 | + $output .= ' |
|
454 | 454 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
455 | 455 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
456 | 456 | <h3>Class Details</h3>'; |
457 | - $a = new ReflectionClass($class); |
|
458 | - $output .= ' |
|
457 | + $a = new ReflectionClass($class); |
|
458 | + $output .= ' |
|
459 | 459 | <pre>' . $a . '</pre> |
460 | 460 | </div> |
461 | 461 | </div>'; |
462 | - } |
|
463 | - $output .= ' |
|
462 | + } |
|
463 | + $output .= ' |
|
464 | 464 | </div> |
465 | 465 | </div> |
466 | 466 | <br />'; |
467 | - } |
|
468 | - $this->write_to_error_log($time, $ex); |
|
469 | - } |
|
470 | - // remove last linebreak |
|
471 | - $output = substr($output, 0, -6); |
|
472 | - if (! WP_DEBUG) { |
|
473 | - $output .= ' |
|
467 | + } |
|
468 | + $this->write_to_error_log($time, $ex); |
|
469 | + } |
|
470 | + // remove last linebreak |
|
471 | + $output = substr($output, 0, -6); |
|
472 | + if (! WP_DEBUG) { |
|
473 | + $output .= ' |
|
474 | 474 | </p>'; |
475 | - } |
|
476 | - $output .= ' |
|
475 | + } |
|
476 | + $output .= ' |
|
477 | 477 | </div>'; |
478 | - $output .= self::_print_scripts(true); |
|
479 | - if (defined('DOING_AJAX')) { |
|
480 | - echo wp_json_encode(array('error' => $output)); |
|
481 | - exit(); |
|
482 | - } |
|
483 | - echo $output; |
|
484 | - die(); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * generate string from exception trace args |
|
491 | - * |
|
492 | - * @param array $arguments |
|
493 | - * @param bool $array |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
497 | - { |
|
498 | - $arg_string = ''; |
|
499 | - if (! empty($arguments)) { |
|
500 | - $args = array(); |
|
501 | - foreach ($arguments as $arg) { |
|
502 | - if (! empty($arg)) { |
|
503 | - if (is_string($arg)) { |
|
504 | - $args[] = " '" . $arg . "'"; |
|
505 | - } elseif (is_array($arg)) { |
|
506 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
507 | - } elseif ($arg === null) { |
|
508 | - $args[] = ' NULL'; |
|
509 | - } elseif (is_bool($arg)) { |
|
510 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
511 | - } elseif (is_object($arg)) { |
|
512 | - $args[] = ' OBJECT ' . get_class($arg); |
|
513 | - } elseif (is_resource($arg)) { |
|
514 | - $args[] = get_resource_type($arg); |
|
515 | - } else { |
|
516 | - $args[] = $arg; |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
520 | - $arg_string = implode(', ', $args); |
|
521 | - } |
|
522 | - if ($array) { |
|
523 | - $arg_string .= ' )'; |
|
524 | - } |
|
525 | - return $arg_string; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * add error message |
|
532 | - * |
|
533 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
534 | - * separate messages for user || dev |
|
535 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
536 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
537 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
538 | - * @return void |
|
539 | - */ |
|
540 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
541 | - { |
|
542 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
543 | - self::$_error_count++; |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
550 | - * adds an error |
|
551 | - * |
|
552 | - * @param string $msg |
|
553 | - * @param string $file |
|
554 | - * @param string $func |
|
555 | - * @param string $line |
|
556 | - * @throws EE_Error |
|
557 | - */ |
|
558 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
559 | - { |
|
560 | - if (WP_DEBUG) { |
|
561 | - throw new EE_Error($msg); |
|
562 | - } |
|
563 | - EE_Error::add_error($msg, $file, $func, $line); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * add success message |
|
570 | - * |
|
571 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
572 | - * separate messages for user || dev |
|
573 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
574 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
575 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
576 | - * @return void |
|
577 | - */ |
|
578 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
579 | - { |
|
580 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * add attention message |
|
587 | - * |
|
588 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
589 | - * separate messages for user || dev |
|
590 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
591 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
592 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
593 | - * @return void |
|
594 | - */ |
|
595 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
596 | - { |
|
597 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * @param string $type whether the message is for a success or error notification |
|
604 | - * @param string $msg the message to display to users or developers |
|
605 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
606 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
607 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
608 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
609 | - * @return void |
|
610 | - */ |
|
611 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
612 | - { |
|
613 | - if (empty($msg)) { |
|
614 | - EE_Error::doing_it_wrong( |
|
615 | - 'EE_Error::add_' . $type . '()', |
|
616 | - sprintf( |
|
617 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
618 | - 'event_espresso'), |
|
619 | - $type, |
|
620 | - $file, |
|
621 | - $line |
|
622 | - ), |
|
623 | - EVENT_ESPRESSO_VERSION |
|
624 | - ); |
|
625 | - } |
|
626 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
627 | - EE_Error::doing_it_wrong( |
|
628 | - 'EE_Error::add_error()', |
|
629 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
630 | - 'event_espresso'), |
|
631 | - EVENT_ESPRESSO_VERSION |
|
632 | - ); |
|
633 | - } |
|
634 | - // get separate user and developer messages if they exist |
|
635 | - $msg = explode('||', $msg); |
|
636 | - $user_msg = $msg[0]; |
|
637 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
638 | - /** |
|
639 | - * Do an action so other code can be triggered when a notice is created |
|
640 | - * |
|
641 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
642 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
643 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
644 | - * @param string $file file where error was generated |
|
645 | - * @param string $func function where error was generated |
|
646 | - * @param string $line line where error was generated |
|
647 | - */ |
|
648 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
649 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
650 | - // add notice if message exists |
|
651 | - if (! empty($msg)) { |
|
652 | - // get error code |
|
653 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
654 | - if (WP_DEBUG && $type === 'errors') { |
|
655 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
656 | - } |
|
657 | - // add notice. Index by code if it's not blank |
|
658 | - if ($notice_code) { |
|
659 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
660 | - } else { |
|
661 | - self::$_espresso_notices[$type][] = $msg; |
|
662 | - } |
|
663 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
664 | - } |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * in some case it may be necessary to overwrite the existing success messages |
|
670 | - * |
|
671 | - * @return void |
|
672 | - */ |
|
673 | - public static function overwrite_success() |
|
674 | - { |
|
675 | - self::$_espresso_notices['success'] = false; |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * in some case it may be necessary to overwrite the existing attention messages |
|
682 | - * |
|
683 | - * @return void |
|
684 | - */ |
|
685 | - public static function overwrite_attention() |
|
686 | - { |
|
687 | - self::$_espresso_notices['attention'] = false; |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * in some case it may be necessary to overwrite the existing error messages |
|
694 | - * |
|
695 | - * @return void |
|
696 | - */ |
|
697 | - public static function overwrite_errors() |
|
698 | - { |
|
699 | - self::$_espresso_notices['errors'] = false; |
|
700 | - } |
|
701 | - |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * @return void |
|
706 | - */ |
|
707 | - public static function reset_notices() |
|
708 | - { |
|
709 | - self::$_espresso_notices['success'] = false; |
|
710 | - self::$_espresso_notices['attention'] = false; |
|
711 | - self::$_espresso_notices['errors'] = false; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * @return int |
|
718 | - */ |
|
719 | - public static function has_notices() |
|
720 | - { |
|
721 | - $has_notices = 0; |
|
722 | - // check for success messages |
|
723 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
724 | - ? 3 |
|
725 | - : $has_notices; |
|
726 | - // check for attention messages |
|
727 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
728 | - ? 2 |
|
729 | - : $has_notices; |
|
730 | - // check for error messages |
|
731 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
732 | - ? 1 |
|
733 | - : $has_notices; |
|
734 | - return $has_notices; |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
740 | - * |
|
741 | - * @since 4.9.0 |
|
742 | - * @return array |
|
743 | - */ |
|
744 | - public static function get_vanilla_notices() |
|
745 | - { |
|
746 | - return array( |
|
747 | - 'success' => isset(self::$_espresso_notices['success']) |
|
748 | - ? self::$_espresso_notices['success'] |
|
749 | - : array(), |
|
750 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
751 | - ? self::$_espresso_notices['attention'] |
|
752 | - : array(), |
|
753 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
754 | - ? self::$_espresso_notices['errors'] |
|
755 | - : array(), |
|
756 | - ); |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * compile all error or success messages into one string |
|
763 | - * |
|
764 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
765 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
766 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
767 | - * - ONLY do this just before redirecting |
|
768 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
769 | - * @return array |
|
770 | - */ |
|
771 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
772 | - { |
|
773 | - // do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
774 | - $success_messages = ''; |
|
775 | - $attention_messages = ''; |
|
776 | - $error_messages = ''; |
|
777 | - $print_scripts = false; |
|
778 | - // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
779 | - // either save notices to the db |
|
780 | - if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
781 | - $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | - $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
|
783 | - self::$_espresso_notices = array_merge( |
|
784 | - $existing_notices, |
|
785 | - self::$_espresso_notices |
|
786 | - ); |
|
787 | - update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices); |
|
788 | - return array(); |
|
789 | - } |
|
790 | - // grab any notices that have been previously saved |
|
791 | - if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) { |
|
792 | - foreach ($notices as $type => $notice) { |
|
793 | - if (is_array($notice) && ! empty($notice)) { |
|
794 | - // make sure that existing notice type is an array |
|
795 | - self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
796 | - && ! empty(self::$_espresso_notices[$type]) |
|
797 | - ? self::$_espresso_notices[$type] |
|
798 | - : array(); |
|
799 | - // merge stored notices with any newly created ones |
|
800 | - self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
801 | - $print_scripts = true; |
|
802 | - } |
|
803 | - } |
|
804 | - // now clear any stored notices |
|
805 | - update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
806 | - } |
|
807 | - // check for success messages |
|
808 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
809 | - // combine messages |
|
810 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
811 | - $print_scripts = true; |
|
812 | - } |
|
813 | - // check for attention messages |
|
814 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
815 | - // combine messages |
|
816 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
817 | - $print_scripts = true; |
|
818 | - } |
|
819 | - // check for error messages |
|
820 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
821 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
822 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
823 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
824 | - // combine messages |
|
825 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
826 | - $print_scripts = true; |
|
827 | - } |
|
828 | - if ($format_output) { |
|
829 | - |
|
830 | - $notices = '<div id="espresso-notices">'; |
|
831 | - $close = is_admin() ? '' |
|
832 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
833 | - if ($success_messages !== '') { |
|
834 | - $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
835 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
836 | - //showMessage( $success_messages ); |
|
837 | - $notices .= '<div id="' |
|
838 | - . $css_id |
|
839 | - . '" class="espresso-notices ' |
|
840 | - . $css_class |
|
841 | - . '" style="display:none;"><p>' |
|
842 | - . $success_messages |
|
843 | - . '</p>' |
|
844 | - . $close |
|
845 | - . '</div>'; |
|
846 | - } |
|
847 | - if ($attention_messages !== '') { |
|
848 | - $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
849 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
850 | - //showMessage( $error_messages, TRUE ); |
|
851 | - $notices .= '<div id="' |
|
852 | - . $css_id |
|
853 | - . '" class="espresso-notices ' |
|
854 | - . $css_class |
|
855 | - . '" style="display:none;"><p>' |
|
856 | - . $attention_messages |
|
857 | - . '</p>' |
|
858 | - . $close |
|
859 | - . '</div>'; |
|
860 | - } |
|
861 | - if ($error_messages !== '') { |
|
862 | - $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
863 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
864 | - //showMessage( $error_messages, TRUE ); |
|
865 | - $notices .= '<div id="' |
|
866 | - . $css_id |
|
867 | - . '" class="espresso-notices ' |
|
868 | - . $css_class |
|
869 | - . '" style="display:none;"><p>' |
|
870 | - . $error_messages |
|
871 | - . '</p>' |
|
872 | - . $close |
|
873 | - . '</div>'; |
|
874 | - } |
|
875 | - $notices .= '</div>'; |
|
876 | - } else { |
|
877 | - |
|
878 | - $notices = array( |
|
879 | - 'success' => $success_messages, |
|
880 | - 'attention' => $attention_messages, |
|
881 | - 'errors' => $error_messages, |
|
882 | - ); |
|
883 | - if ($remove_empty) { |
|
884 | - // remove empty notices |
|
885 | - foreach ($notices as $type => $notice) { |
|
886 | - if (empty($notice)) { |
|
887 | - unset($notices[$type]); |
|
888 | - } |
|
889 | - } |
|
890 | - } |
|
891 | - } |
|
892 | - if ($print_scripts) { |
|
893 | - self::_print_scripts(); |
|
894 | - } |
|
895 | - return $notices; |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * _print_scripts |
|
902 | - * |
|
903 | - * @param bool $force_print |
|
904 | - * @return string |
|
905 | - */ |
|
906 | - private static function _print_scripts($force_print = false) |
|
907 | - { |
|
908 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
910 | - return ''; |
|
911 | - } |
|
912 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
913 | - wp_enqueue_style('espresso_default'); |
|
914 | - wp_enqueue_style('espresso_custom_css'); |
|
915 | - wp_enqueue_script('ee_error_js'); |
|
916 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
917 | - } |
|
918 | - } else { |
|
919 | - return ' |
|
478 | + $output .= self::_print_scripts(true); |
|
479 | + if (defined('DOING_AJAX')) { |
|
480 | + echo wp_json_encode(array('error' => $output)); |
|
481 | + exit(); |
|
482 | + } |
|
483 | + echo $output; |
|
484 | + die(); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * generate string from exception trace args |
|
491 | + * |
|
492 | + * @param array $arguments |
|
493 | + * @param bool $array |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
497 | + { |
|
498 | + $arg_string = ''; |
|
499 | + if (! empty($arguments)) { |
|
500 | + $args = array(); |
|
501 | + foreach ($arguments as $arg) { |
|
502 | + if (! empty($arg)) { |
|
503 | + if (is_string($arg)) { |
|
504 | + $args[] = " '" . $arg . "'"; |
|
505 | + } elseif (is_array($arg)) { |
|
506 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
507 | + } elseif ($arg === null) { |
|
508 | + $args[] = ' NULL'; |
|
509 | + } elseif (is_bool($arg)) { |
|
510 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
511 | + } elseif (is_object($arg)) { |
|
512 | + $args[] = ' OBJECT ' . get_class($arg); |
|
513 | + } elseif (is_resource($arg)) { |
|
514 | + $args[] = get_resource_type($arg); |
|
515 | + } else { |
|
516 | + $args[] = $arg; |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | + $arg_string = implode(', ', $args); |
|
521 | + } |
|
522 | + if ($array) { |
|
523 | + $arg_string .= ' )'; |
|
524 | + } |
|
525 | + return $arg_string; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * add error message |
|
532 | + * |
|
533 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
534 | + * separate messages for user || dev |
|
535 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
536 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
537 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
538 | + * @return void |
|
539 | + */ |
|
540 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
541 | + { |
|
542 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
543 | + self::$_error_count++; |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
550 | + * adds an error |
|
551 | + * |
|
552 | + * @param string $msg |
|
553 | + * @param string $file |
|
554 | + * @param string $func |
|
555 | + * @param string $line |
|
556 | + * @throws EE_Error |
|
557 | + */ |
|
558 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
559 | + { |
|
560 | + if (WP_DEBUG) { |
|
561 | + throw new EE_Error($msg); |
|
562 | + } |
|
563 | + EE_Error::add_error($msg, $file, $func, $line); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * add success message |
|
570 | + * |
|
571 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
572 | + * separate messages for user || dev |
|
573 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
574 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
575 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
576 | + * @return void |
|
577 | + */ |
|
578 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
579 | + { |
|
580 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * add attention message |
|
587 | + * |
|
588 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
589 | + * separate messages for user || dev |
|
590 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
591 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
592 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
593 | + * @return void |
|
594 | + */ |
|
595 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
596 | + { |
|
597 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * @param string $type whether the message is for a success or error notification |
|
604 | + * @param string $msg the message to display to users or developers |
|
605 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
606 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
607 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
608 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
609 | + * @return void |
|
610 | + */ |
|
611 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
612 | + { |
|
613 | + if (empty($msg)) { |
|
614 | + EE_Error::doing_it_wrong( |
|
615 | + 'EE_Error::add_' . $type . '()', |
|
616 | + sprintf( |
|
617 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
618 | + 'event_espresso'), |
|
619 | + $type, |
|
620 | + $file, |
|
621 | + $line |
|
622 | + ), |
|
623 | + EVENT_ESPRESSO_VERSION |
|
624 | + ); |
|
625 | + } |
|
626 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
627 | + EE_Error::doing_it_wrong( |
|
628 | + 'EE_Error::add_error()', |
|
629 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
630 | + 'event_espresso'), |
|
631 | + EVENT_ESPRESSO_VERSION |
|
632 | + ); |
|
633 | + } |
|
634 | + // get separate user and developer messages if they exist |
|
635 | + $msg = explode('||', $msg); |
|
636 | + $user_msg = $msg[0]; |
|
637 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
638 | + /** |
|
639 | + * Do an action so other code can be triggered when a notice is created |
|
640 | + * |
|
641 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
642 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
643 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
644 | + * @param string $file file where error was generated |
|
645 | + * @param string $func function where error was generated |
|
646 | + * @param string $line line where error was generated |
|
647 | + */ |
|
648 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
649 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
650 | + // add notice if message exists |
|
651 | + if (! empty($msg)) { |
|
652 | + // get error code |
|
653 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
654 | + if (WP_DEBUG && $type === 'errors') { |
|
655 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
656 | + } |
|
657 | + // add notice. Index by code if it's not blank |
|
658 | + if ($notice_code) { |
|
659 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
660 | + } else { |
|
661 | + self::$_espresso_notices[$type][] = $msg; |
|
662 | + } |
|
663 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
664 | + } |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * in some case it may be necessary to overwrite the existing success messages |
|
670 | + * |
|
671 | + * @return void |
|
672 | + */ |
|
673 | + public static function overwrite_success() |
|
674 | + { |
|
675 | + self::$_espresso_notices['success'] = false; |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * in some case it may be necessary to overwrite the existing attention messages |
|
682 | + * |
|
683 | + * @return void |
|
684 | + */ |
|
685 | + public static function overwrite_attention() |
|
686 | + { |
|
687 | + self::$_espresso_notices['attention'] = false; |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * in some case it may be necessary to overwrite the existing error messages |
|
694 | + * |
|
695 | + * @return void |
|
696 | + */ |
|
697 | + public static function overwrite_errors() |
|
698 | + { |
|
699 | + self::$_espresso_notices['errors'] = false; |
|
700 | + } |
|
701 | + |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * @return void |
|
706 | + */ |
|
707 | + public static function reset_notices() |
|
708 | + { |
|
709 | + self::$_espresso_notices['success'] = false; |
|
710 | + self::$_espresso_notices['attention'] = false; |
|
711 | + self::$_espresso_notices['errors'] = false; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * @return int |
|
718 | + */ |
|
719 | + public static function has_notices() |
|
720 | + { |
|
721 | + $has_notices = 0; |
|
722 | + // check for success messages |
|
723 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
724 | + ? 3 |
|
725 | + : $has_notices; |
|
726 | + // check for attention messages |
|
727 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
728 | + ? 2 |
|
729 | + : $has_notices; |
|
730 | + // check for error messages |
|
731 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
732 | + ? 1 |
|
733 | + : $has_notices; |
|
734 | + return $has_notices; |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
740 | + * |
|
741 | + * @since 4.9.0 |
|
742 | + * @return array |
|
743 | + */ |
|
744 | + public static function get_vanilla_notices() |
|
745 | + { |
|
746 | + return array( |
|
747 | + 'success' => isset(self::$_espresso_notices['success']) |
|
748 | + ? self::$_espresso_notices['success'] |
|
749 | + : array(), |
|
750 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
751 | + ? self::$_espresso_notices['attention'] |
|
752 | + : array(), |
|
753 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
754 | + ? self::$_espresso_notices['errors'] |
|
755 | + : array(), |
|
756 | + ); |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * compile all error or success messages into one string |
|
763 | + * |
|
764 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
765 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
766 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
767 | + * - ONLY do this just before redirecting |
|
768 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
769 | + * @return array |
|
770 | + */ |
|
771 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
772 | + { |
|
773 | + // do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
774 | + $success_messages = ''; |
|
775 | + $attention_messages = ''; |
|
776 | + $error_messages = ''; |
|
777 | + $print_scripts = false; |
|
778 | + // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
779 | + // either save notices to the db |
|
780 | + if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
781 | + $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | + $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
|
783 | + self::$_espresso_notices = array_merge( |
|
784 | + $existing_notices, |
|
785 | + self::$_espresso_notices |
|
786 | + ); |
|
787 | + update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices); |
|
788 | + return array(); |
|
789 | + } |
|
790 | + // grab any notices that have been previously saved |
|
791 | + if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) { |
|
792 | + foreach ($notices as $type => $notice) { |
|
793 | + if (is_array($notice) && ! empty($notice)) { |
|
794 | + // make sure that existing notice type is an array |
|
795 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
796 | + && ! empty(self::$_espresso_notices[$type]) |
|
797 | + ? self::$_espresso_notices[$type] |
|
798 | + : array(); |
|
799 | + // merge stored notices with any newly created ones |
|
800 | + self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
801 | + $print_scripts = true; |
|
802 | + } |
|
803 | + } |
|
804 | + // now clear any stored notices |
|
805 | + update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
806 | + } |
|
807 | + // check for success messages |
|
808 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
809 | + // combine messages |
|
810 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
811 | + $print_scripts = true; |
|
812 | + } |
|
813 | + // check for attention messages |
|
814 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
815 | + // combine messages |
|
816 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
817 | + $print_scripts = true; |
|
818 | + } |
|
819 | + // check for error messages |
|
820 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
821 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
822 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
823 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
824 | + // combine messages |
|
825 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
826 | + $print_scripts = true; |
|
827 | + } |
|
828 | + if ($format_output) { |
|
829 | + |
|
830 | + $notices = '<div id="espresso-notices">'; |
|
831 | + $close = is_admin() ? '' |
|
832 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
833 | + if ($success_messages !== '') { |
|
834 | + $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
835 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
836 | + //showMessage( $success_messages ); |
|
837 | + $notices .= '<div id="' |
|
838 | + . $css_id |
|
839 | + . '" class="espresso-notices ' |
|
840 | + . $css_class |
|
841 | + . '" style="display:none;"><p>' |
|
842 | + . $success_messages |
|
843 | + . '</p>' |
|
844 | + . $close |
|
845 | + . '</div>'; |
|
846 | + } |
|
847 | + if ($attention_messages !== '') { |
|
848 | + $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
849 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
850 | + //showMessage( $error_messages, TRUE ); |
|
851 | + $notices .= '<div id="' |
|
852 | + . $css_id |
|
853 | + . '" class="espresso-notices ' |
|
854 | + . $css_class |
|
855 | + . '" style="display:none;"><p>' |
|
856 | + . $attention_messages |
|
857 | + . '</p>' |
|
858 | + . $close |
|
859 | + . '</div>'; |
|
860 | + } |
|
861 | + if ($error_messages !== '') { |
|
862 | + $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
863 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
864 | + //showMessage( $error_messages, TRUE ); |
|
865 | + $notices .= '<div id="' |
|
866 | + . $css_id |
|
867 | + . '" class="espresso-notices ' |
|
868 | + . $css_class |
|
869 | + . '" style="display:none;"><p>' |
|
870 | + . $error_messages |
|
871 | + . '</p>' |
|
872 | + . $close |
|
873 | + . '</div>'; |
|
874 | + } |
|
875 | + $notices .= '</div>'; |
|
876 | + } else { |
|
877 | + |
|
878 | + $notices = array( |
|
879 | + 'success' => $success_messages, |
|
880 | + 'attention' => $attention_messages, |
|
881 | + 'errors' => $error_messages, |
|
882 | + ); |
|
883 | + if ($remove_empty) { |
|
884 | + // remove empty notices |
|
885 | + foreach ($notices as $type => $notice) { |
|
886 | + if (empty($notice)) { |
|
887 | + unset($notices[$type]); |
|
888 | + } |
|
889 | + } |
|
890 | + } |
|
891 | + } |
|
892 | + if ($print_scripts) { |
|
893 | + self::_print_scripts(); |
|
894 | + } |
|
895 | + return $notices; |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * _print_scripts |
|
902 | + * |
|
903 | + * @param bool $force_print |
|
904 | + * @return string |
|
905 | + */ |
|
906 | + private static function _print_scripts($force_print = false) |
|
907 | + { |
|
908 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
910 | + return ''; |
|
911 | + } |
|
912 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
913 | + wp_enqueue_style('espresso_default'); |
|
914 | + wp_enqueue_style('espresso_custom_css'); |
|
915 | + wp_enqueue_script('ee_error_js'); |
|
916 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
917 | + } |
|
918 | + } else { |
|
919 | + return ' |
|
920 | 920 | <script> |
921 | 921 | /* <![CDATA[ */ |
922 | 922 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -926,223 +926,223 @@ discard block |
||
926 | 926 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
927 | 927 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
928 | 928 | '; |
929 | - } |
|
930 | - return ''; |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - |
|
935 | - /** |
|
936 | - * @return void |
|
937 | - */ |
|
938 | - public static function enqueue_error_scripts() |
|
939 | - { |
|
940 | - self::_print_scripts(); |
|
941 | - } |
|
942 | - |
|
943 | - |
|
944 | - |
|
945 | - /** |
|
946 | - * create error code from filepath, function name, |
|
947 | - * and line number where exception or error was thrown |
|
948 | - * |
|
949 | - * @param string $file |
|
950 | - * @param string $func |
|
951 | - * @param string $line |
|
952 | - * @return string |
|
953 | - */ |
|
954 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
955 | - { |
|
956 | - $file = explode('.', basename($file)); |
|
957 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
958 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
960 | - return $error_code; |
|
961 | - } |
|
962 | - |
|
963 | - |
|
964 | - |
|
965 | - /** |
|
966 | - * write exception details to log file |
|
967 | - * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
968 | - * |
|
969 | - * @param int $time |
|
970 | - * @param array $ex |
|
971 | - * @param bool $clear |
|
972 | - * @return void |
|
973 | - */ |
|
974 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
975 | - { |
|
976 | - if (empty($ex)) { |
|
977 | - return; |
|
978 | - } |
|
979 | - if (! $time) { |
|
980 | - $time = time(); |
|
981 | - } |
|
982 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
983 | - . PHP_EOL; |
|
984 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
991 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
992 | - . PHP_EOL; |
|
993 | - try { |
|
994 | - error_log($exception_log); |
|
995 | - } catch (EE_Error $e) { |
|
996 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
997 | - 'event_espresso'), $e->getMessage())); |
|
998 | - } |
|
999 | - } |
|
1000 | - |
|
1001 | - |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1005 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1006 | - * but the code execution is done in a manner that could lead to unexpected results |
|
1007 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
1008 | - * A good test for knowing whether to use this method is: |
|
1009 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1010 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1011 | - * 2. If this is loaded before something else, it won't break anything, |
|
1012 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1013 | - * |
|
1014 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1015 | - * @param string $function The function that was called |
|
1016 | - * @param string $message A message explaining what has been done incorrectly |
|
1017 | - * @param string $version The version of Event Espresso where the error was added |
|
1018 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1019 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
1020 | - * but not have any notices appear until a later version. This allows developers |
|
1021 | - * extra time to update their code before notices appear. |
|
1022 | - * @param int $error_type |
|
1023 | - */ |
|
1024 | - public static function doing_it_wrong( |
|
1025 | - $function, |
|
1026 | - $message, |
|
1027 | - $version, |
|
1028 | - $applies_when = '', |
|
1029 | - $error_type = null |
|
1030 | - ) { |
|
1031 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1032 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1033 | - } |
|
1034 | - } |
|
1035 | - |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
1040 | - * |
|
1041 | - * @return array { |
|
1042 | - * @type array $success all the success messages |
|
1043 | - * @type array $errors all the error messages |
|
1044 | - * @type array $attention all the attention messages |
|
1045 | - * } |
|
1046 | - */ |
|
1047 | - public static function get_raw_notices() |
|
1048 | - { |
|
1049 | - return self::$_espresso_notices; |
|
1050 | - } |
|
1051 | - |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * @deprecated 4.9.27 |
|
1056 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1057 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1058 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1059 | - * @return void |
|
1060 | - * @throws InvalidDataTypeException |
|
1061 | - */ |
|
1062 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1063 | - { |
|
1064 | - new PersistentAdminNotice( |
|
1065 | - $pan_name, |
|
1066 | - $pan_message, |
|
1067 | - $force_update |
|
1068 | - ); |
|
1069 | - EE_Error::doing_it_wrong( |
|
1070 | - __METHOD__, |
|
1071 | - sprintf( |
|
1072 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1073 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1074 | - ), |
|
1075 | - '4.9.27' |
|
1076 | - ); |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * @deprecated 4.9.27 |
|
1083 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1084 | - * @param bool $purge |
|
1085 | - * @param bool $return |
|
1086 | - * @throws DomainException |
|
1087 | - * @throws InvalidInterfaceException |
|
1088 | - * @throws InvalidDataTypeException |
|
1089 | - * @throws ServiceNotFoundException |
|
1090 | - * @throws InvalidArgumentException |
|
1091 | - */ |
|
1092 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1093 | - { |
|
1094 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1095 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1096 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1097 | - ); |
|
1098 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1099 | - EE_Error::doing_it_wrong( |
|
1100 | - __METHOD__, |
|
1101 | - sprintf( |
|
1102 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1103 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1104 | - ), |
|
1105 | - '4.9.27' |
|
1106 | - ); |
|
1107 | - } |
|
1108 | - |
|
1109 | - |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * @deprecated 4.9.27 |
|
1113 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1114 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1115 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
1116 | - */ |
|
1117 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1118 | - { |
|
1119 | - EE_Error::doing_it_wrong( |
|
1120 | - __METHOD__, |
|
1121 | - sprintf( |
|
1122 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1123 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1124 | - ), |
|
1125 | - '4.9.27' |
|
1126 | - ); |
|
1127 | - } |
|
1128 | - |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * @deprecated 4.9.27 |
|
1133 | - * @param string $return_url |
|
1134 | - */ |
|
1135 | - public static function get_persistent_admin_notices($return_url = '') |
|
1136 | - { |
|
1137 | - EE_Error::doing_it_wrong( |
|
1138 | - __METHOD__, |
|
1139 | - sprintf( |
|
1140 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1141 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1142 | - ), |
|
1143 | - '4.9.27' |
|
1144 | - ); |
|
1145 | - } |
|
929 | + } |
|
930 | + return ''; |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + |
|
935 | + /** |
|
936 | + * @return void |
|
937 | + */ |
|
938 | + public static function enqueue_error_scripts() |
|
939 | + { |
|
940 | + self::_print_scripts(); |
|
941 | + } |
|
942 | + |
|
943 | + |
|
944 | + |
|
945 | + /** |
|
946 | + * create error code from filepath, function name, |
|
947 | + * and line number where exception or error was thrown |
|
948 | + * |
|
949 | + * @param string $file |
|
950 | + * @param string $func |
|
951 | + * @param string $line |
|
952 | + * @return string |
|
953 | + */ |
|
954 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
955 | + { |
|
956 | + $file = explode('.', basename($file)); |
|
957 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
958 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
960 | + return $error_code; |
|
961 | + } |
|
962 | + |
|
963 | + |
|
964 | + |
|
965 | + /** |
|
966 | + * write exception details to log file |
|
967 | + * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
968 | + * |
|
969 | + * @param int $time |
|
970 | + * @param array $ex |
|
971 | + * @param bool $clear |
|
972 | + * @return void |
|
973 | + */ |
|
974 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
975 | + { |
|
976 | + if (empty($ex)) { |
|
977 | + return; |
|
978 | + } |
|
979 | + if (! $time) { |
|
980 | + $time = time(); |
|
981 | + } |
|
982 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
983 | + . PHP_EOL; |
|
984 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
991 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
992 | + . PHP_EOL; |
|
993 | + try { |
|
994 | + error_log($exception_log); |
|
995 | + } catch (EE_Error $e) { |
|
996 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
997 | + 'event_espresso'), $e->getMessage())); |
|
998 | + } |
|
999 | + } |
|
1000 | + |
|
1001 | + |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1005 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1006 | + * but the code execution is done in a manner that could lead to unexpected results |
|
1007 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
1008 | + * A good test for knowing whether to use this method is: |
|
1009 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1010 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1011 | + * 2. If this is loaded before something else, it won't break anything, |
|
1012 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1013 | + * |
|
1014 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1015 | + * @param string $function The function that was called |
|
1016 | + * @param string $message A message explaining what has been done incorrectly |
|
1017 | + * @param string $version The version of Event Espresso where the error was added |
|
1018 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1019 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
1020 | + * but not have any notices appear until a later version. This allows developers |
|
1021 | + * extra time to update their code before notices appear. |
|
1022 | + * @param int $error_type |
|
1023 | + */ |
|
1024 | + public static function doing_it_wrong( |
|
1025 | + $function, |
|
1026 | + $message, |
|
1027 | + $version, |
|
1028 | + $applies_when = '', |
|
1029 | + $error_type = null |
|
1030 | + ) { |
|
1031 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1032 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1033 | + } |
|
1034 | + } |
|
1035 | + |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
1040 | + * |
|
1041 | + * @return array { |
|
1042 | + * @type array $success all the success messages |
|
1043 | + * @type array $errors all the error messages |
|
1044 | + * @type array $attention all the attention messages |
|
1045 | + * } |
|
1046 | + */ |
|
1047 | + public static function get_raw_notices() |
|
1048 | + { |
|
1049 | + return self::$_espresso_notices; |
|
1050 | + } |
|
1051 | + |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * @deprecated 4.9.27 |
|
1056 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1057 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1058 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1059 | + * @return void |
|
1060 | + * @throws InvalidDataTypeException |
|
1061 | + */ |
|
1062 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1063 | + { |
|
1064 | + new PersistentAdminNotice( |
|
1065 | + $pan_name, |
|
1066 | + $pan_message, |
|
1067 | + $force_update |
|
1068 | + ); |
|
1069 | + EE_Error::doing_it_wrong( |
|
1070 | + __METHOD__, |
|
1071 | + sprintf( |
|
1072 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1073 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1074 | + ), |
|
1075 | + '4.9.27' |
|
1076 | + ); |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * @deprecated 4.9.27 |
|
1083 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1084 | + * @param bool $purge |
|
1085 | + * @param bool $return |
|
1086 | + * @throws DomainException |
|
1087 | + * @throws InvalidInterfaceException |
|
1088 | + * @throws InvalidDataTypeException |
|
1089 | + * @throws ServiceNotFoundException |
|
1090 | + * @throws InvalidArgumentException |
|
1091 | + */ |
|
1092 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1093 | + { |
|
1094 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1095 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1096 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1097 | + ); |
|
1098 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1099 | + EE_Error::doing_it_wrong( |
|
1100 | + __METHOD__, |
|
1101 | + sprintf( |
|
1102 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1103 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1104 | + ), |
|
1105 | + '4.9.27' |
|
1106 | + ); |
|
1107 | + } |
|
1108 | + |
|
1109 | + |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * @deprecated 4.9.27 |
|
1113 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1114 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1115 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
1116 | + */ |
|
1117 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1118 | + { |
|
1119 | + EE_Error::doing_it_wrong( |
|
1120 | + __METHOD__, |
|
1121 | + sprintf( |
|
1122 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1123 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1124 | + ), |
|
1125 | + '4.9.27' |
|
1126 | + ); |
|
1127 | + } |
|
1128 | + |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * @deprecated 4.9.27 |
|
1133 | + * @param string $return_url |
|
1134 | + */ |
|
1135 | + public static function get_persistent_admin_notices($return_url = '') |
|
1136 | + { |
|
1137 | + EE_Error::doing_it_wrong( |
|
1138 | + __METHOD__, |
|
1139 | + sprintf( |
|
1140 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1141 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1142 | + ), |
|
1143 | + '4.9.27' |
|
1144 | + ); |
|
1145 | + } |
|
1146 | 1146 | |
1147 | 1147 | |
1148 | 1148 | |
@@ -1157,27 +1157,27 @@ discard block |
||
1157 | 1157 | */ |
1158 | 1158 | function espresso_error_enqueue_scripts() |
1159 | 1159 | { |
1160 | - // js for error handling |
|
1161 | - wp_register_script( |
|
1162 | - 'espresso_core', |
|
1163 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1164 | - array('jquery'), |
|
1165 | - EVENT_ESPRESSO_VERSION, |
|
1166 | - false |
|
1167 | - ); |
|
1168 | - wp_register_script( |
|
1169 | - 'ee_error_js', |
|
1170 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1171 | - array('espresso_core'), |
|
1172 | - EVENT_ESPRESSO_VERSION, |
|
1173 | - false |
|
1174 | - ); |
|
1160 | + // js for error handling |
|
1161 | + wp_register_script( |
|
1162 | + 'espresso_core', |
|
1163 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1164 | + array('jquery'), |
|
1165 | + EVENT_ESPRESSO_VERSION, |
|
1166 | + false |
|
1167 | + ); |
|
1168 | + wp_register_script( |
|
1169 | + 'ee_error_js', |
|
1170 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1171 | + array('espresso_core'), |
|
1172 | + EVENT_ESPRESSO_VERSION, |
|
1173 | + false |
|
1174 | + ); |
|
1175 | 1175 | } |
1176 | 1176 | |
1177 | 1177 | if (is_admin()) { |
1178 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1178 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1179 | 1179 | } else { |
1180 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1180 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 |
@@ -9,22 +9,22 @@ discard block |
||
9 | 9 | */ |
10 | 10 | function espresso_load_error_handling() |
11 | 11 | { |
12 | - static $error_handling_loaded = false; |
|
13 | - if ($error_handling_loaded) { |
|
14 | - return; |
|
15 | - } |
|
16 | - // load debugging tools |
|
17 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
18 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
19 | - \EEH_Debug_Tools::instance(); |
|
20 | - } |
|
21 | - // load error handling |
|
22 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
23 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
24 | - } else { |
|
25 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
26 | - } |
|
27 | - $error_handling_loaded = true; |
|
12 | + static $error_handling_loaded = false; |
|
13 | + if ($error_handling_loaded) { |
|
14 | + return; |
|
15 | + } |
|
16 | + // load debugging tools |
|
17 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
18 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
19 | + \EEH_Debug_Tools::instance(); |
|
20 | + } |
|
21 | + // load error handling |
|
22 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
23 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
24 | + } else { |
|
25 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
26 | + } |
|
27 | + $error_handling_loaded = true; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | |
@@ -38,19 +38,19 @@ discard block |
||
38 | 38 | */ |
39 | 39 | function espresso_load_required($classname, $full_path_to_file) |
40 | 40 | { |
41 | - if (is_readable($full_path_to_file)) { |
|
42 | - require_once $full_path_to_file; |
|
43 | - } else { |
|
44 | - throw new \EE_Error ( |
|
45 | - sprintf( |
|
46 | - esc_html__( |
|
47 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
48 | - 'event_espresso' |
|
49 | - ), |
|
50 | - $classname |
|
51 | - ) |
|
52 | - ); |
|
53 | - } |
|
41 | + if (is_readable($full_path_to_file)) { |
|
42 | + require_once $full_path_to_file; |
|
43 | + } else { |
|
44 | + throw new \EE_Error ( |
|
45 | + sprintf( |
|
46 | + esc_html__( |
|
47 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
48 | + 'event_espresso' |
|
49 | + ), |
|
50 | + $classname |
|
51 | + ) |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | |
@@ -69,41 +69,41 @@ discard block |
||
69 | 69 | */ |
70 | 70 | function bootstrap_espresso() |
71 | 71 | { |
72 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
73 | - try { |
|
74 | - espresso_load_error_handling(); |
|
75 | - espresso_load_required( |
|
76 | - 'EEH_Base', |
|
77 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
78 | - ); |
|
79 | - espresso_load_required( |
|
80 | - 'EEH_File', |
|
81 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
82 | - ); |
|
83 | - espresso_load_required( |
|
84 | - 'EEH_File', |
|
85 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
86 | - ); |
|
87 | - espresso_load_required( |
|
88 | - 'EEH_Array', |
|
89 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
90 | - ); |
|
91 | - // instantiate and configure PSR4 autoloader |
|
92 | - espresso_load_required( |
|
93 | - 'Psr4Autoloader', |
|
94 | - EE_CORE . 'Psr4Autoloader.php' |
|
95 | - ); |
|
96 | - espresso_load_required( |
|
97 | - 'EE_Psr4AutoloaderInit', |
|
98 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
99 | - ); |
|
100 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
101 | - $AutoloaderInit->initializeAutoloader(); |
|
102 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
103 | - } catch (Exception $e) { |
|
104 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
105 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
106 | - } |
|
72 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
73 | + try { |
|
74 | + espresso_load_error_handling(); |
|
75 | + espresso_load_required( |
|
76 | + 'EEH_Base', |
|
77 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
78 | + ); |
|
79 | + espresso_load_required( |
|
80 | + 'EEH_File', |
|
81 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
82 | + ); |
|
83 | + espresso_load_required( |
|
84 | + 'EEH_File', |
|
85 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
86 | + ); |
|
87 | + espresso_load_required( |
|
88 | + 'EEH_Array', |
|
89 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
90 | + ); |
|
91 | + // instantiate and configure PSR4 autoloader |
|
92 | + espresso_load_required( |
|
93 | + 'Psr4Autoloader', |
|
94 | + EE_CORE . 'Psr4Autoloader.php' |
|
95 | + ); |
|
96 | + espresso_load_required( |
|
97 | + 'EE_Psr4AutoloaderInit', |
|
98 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
99 | + ); |
|
100 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
101 | + $AutoloaderInit->initializeAutoloader(); |
|
102 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
103 | + } catch (Exception $e) { |
|
104 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
105 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
106 | + } |
|
107 | 107 | } |
108 | 108 | |
109 | 109 |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | return; |
15 | 15 | } |
16 | 16 | // load debugging tools |
17 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
18 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
17 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
18 | + require_once EE_HELPERS.'EEH_Debug_Tools.helper.php'; |
|
19 | 19 | \EEH_Debug_Tools::instance(); |
20 | 20 | } |
21 | 21 | // load error handling |
22 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
23 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
22 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
23 | + require_once EE_CORE.'EE_Error.core.php'; |
|
24 | 24 | } else { |
25 | 25 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
26 | 26 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | if (is_readable($full_path_to_file)) { |
42 | 42 | require_once $full_path_to_file; |
43 | 43 | } else { |
44 | - throw new \EE_Error ( |
|
44 | + throw new \EE_Error( |
|
45 | 45 | sprintf( |
46 | 46 | esc_html__( |
47 | 47 | 'The %s class file could not be located or is not readable due to file permissions.', |
@@ -69,39 +69,39 @@ discard block |
||
69 | 69 | */ |
70 | 70 | function bootstrap_espresso() |
71 | 71 | { |
72 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
72 | + require_once __DIR__.'/espresso_definitions.php'; |
|
73 | 73 | try { |
74 | 74 | espresso_load_error_handling(); |
75 | 75 | espresso_load_required( |
76 | 76 | 'EEH_Base', |
77 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
77 | + EE_CORE.'helpers'.DS.'EEH_Base.helper.php' |
|
78 | 78 | ); |
79 | 79 | espresso_load_required( |
80 | 80 | 'EEH_File', |
81 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
81 | + EE_CORE.'interfaces'.DS.'EEHI_File.interface.php' |
|
82 | 82 | ); |
83 | 83 | espresso_load_required( |
84 | 84 | 'EEH_File', |
85 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
85 | + EE_CORE.'helpers'.DS.'EEH_File.helper.php' |
|
86 | 86 | ); |
87 | 87 | espresso_load_required( |
88 | 88 | 'EEH_Array', |
89 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
89 | + EE_CORE.'helpers'.DS.'EEH_Array.helper.php' |
|
90 | 90 | ); |
91 | 91 | // instantiate and configure PSR4 autoloader |
92 | 92 | espresso_load_required( |
93 | 93 | 'Psr4Autoloader', |
94 | - EE_CORE . 'Psr4Autoloader.php' |
|
94 | + EE_CORE.'Psr4Autoloader.php' |
|
95 | 95 | ); |
96 | 96 | espresso_load_required( |
97 | 97 | 'EE_Psr4AutoloaderInit', |
98 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
98 | + EE_CORE.'EE_Psr4AutoloaderInit.core.php' |
|
99 | 99 | ); |
100 | 100 | $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
101 | 101 | $AutoloaderInit->initializeAutoloader(); |
102 | 102 | new EventEspresso\core\services\bootstrap\BootstrapCore(); |
103 | 103 | } catch (Exception $e) { |
104 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
104 | + require_once EE_CORE.'exceptions'.DS.'ExceptionStackTraceDisplay.php'; |
|
105 | 105 | new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
106 | 106 | } |
107 | 107 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + if ( ! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | 42 | /** |
43 | 43 | * espresso_duplicate_plugin_error |
44 | 44 | * displays if more than one version of EE is activated at the same time |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | } else { |
65 | 65 | define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | 67 | /** |
68 | 68 | * espresso_minimum_php_version_error |
69 | 69 | * @return void |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | |
117 | 117 | register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
119 | + require_once __DIR__.'/core/bootstrap_espresso.php'; |
|
120 | 120 | bootstrap_espresso(); |
121 | 121 | } |
122 | 122 | } |
123 | -if (! function_exists('espresso_deactivate_plugin')) { |
|
123 | +if ( ! function_exists('espresso_deactivate_plugin')) { |
|
124 | 124 | /** |
125 | 125 | * deactivate_plugin |
126 | 126 | * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | */ |
132 | 132 | function espresso_deactivate_plugin($plugin_basename = '') |
133 | 133 | { |
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
134 | + if ( ! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
136 | 136 | } |
137 | 137 | unset($_GET['activate'], $_REQUEST['activate']); |
138 | 138 | deactivate_plugins($plugin_basename); |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.013'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.013'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -45,8 +45,8 @@ |
||
45 | 45 | } |
46 | 46 | } |
47 | 47 | } |
48 | - return true; |
|
49 | - } |
|
48 | + return true; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | 52 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\services\request\middleware\RecommendedVersions; |
4 | 4 | |
5 | 5 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | /** |
@@ -28,470 +28,470 @@ discard block |
||
28 | 28 | { |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * This gets set in _setup_cpt |
|
33 | - * It will contain the object for the custom post type. |
|
34 | - * |
|
35 | - * @var EE_CPT_Base |
|
36 | - */ |
|
37 | - protected $_cpt_object; |
|
38 | - |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * a boolean flag to set whether the current route is a cpt route or not. |
|
43 | - * |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - protected $_cpt_route = false; |
|
47 | - |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
52 | - * //in this array we define what the custom post type for this route is. |
|
53 | - * array( |
|
54 | - * 'route_name' => 'custom_post_type_slug' |
|
55 | - * ) |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - protected $_cpt_routes = array(); |
|
60 | - |
|
31 | + /** |
|
32 | + * This gets set in _setup_cpt |
|
33 | + * It will contain the object for the custom post type. |
|
34 | + * |
|
35 | + * @var EE_CPT_Base |
|
36 | + */ |
|
37 | + protected $_cpt_object; |
|
38 | + |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * a boolean flag to set whether the current route is a cpt route or not. |
|
43 | + * |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + protected $_cpt_route = false; |
|
47 | + |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
52 | + * //in this array we define what the custom post type for this route is. |
|
53 | + * array( |
|
54 | + * 'route_name' => 'custom_post_type_slug' |
|
55 | + * ) |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + protected $_cpt_routes = array(); |
|
60 | + |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
65 | - * in this format: |
|
66 | - * array( |
|
67 | - * 'post_type_slug' => 'edit_route' |
|
68 | - * ) |
|
69 | - * |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - protected $_cpt_edit_routes = array(); |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
78 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
79 | - * _cpt_model_names property should be in the following format: array( |
|
80 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
81 | - * |
|
82 | - * @var array $_cpt_model_names |
|
83 | - */ |
|
84 | - protected $_cpt_model_names = array(); |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @var EE_CPT_Base |
|
89 | - */ |
|
90 | - protected $_cpt_model_obj = false; |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
96 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
97 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
98 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
99 | - * |
|
100 | - * @var array() |
|
101 | - */ |
|
102 | - protected $_autosave_containers = array(); |
|
103 | - protected $_autosave_fields = array(); |
|
104 | - |
|
105 | - /** |
|
106 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
107 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
108 | - * |
|
109 | - * @var array |
|
110 | - */ |
|
111 | - protected $_pagenow_map; |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
117 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
118 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
119 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
120 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
121 | - * |
|
122 | - * @access protected |
|
123 | - * @abstract |
|
124 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
125 | - * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
134 | - * |
|
135 | - * @abstract |
|
136 | - * @access public |
|
137 | - * @param string $post_id The ID of the cpt that was trashed |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - abstract public function trash_cpt_item($post_id); |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
146 | - * |
|
147 | - * @param string $post_id theID of the cpt that was untrashed |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - abstract public function restore_cpt_item($post_id); |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
156 | - * from the db |
|
157 | - * |
|
158 | - * @param string $post_id the ID of the cpt that was deleted |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - abstract public function delete_cpt_item($post_id); |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
167 | - * |
|
168 | - * @access protected |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - protected function _before_page_setup() |
|
172 | - { |
|
173 | - $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
174 | - $this->_cpt_routes = array_merge(array( |
|
175 | - 'create_new' => $this->page_slug, |
|
176 | - 'edit' => $this->page_slug, |
|
177 | - 'trash' => $this->page_slug, |
|
178 | - ), $this->_cpt_routes); |
|
179 | - //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
180 | - $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
181 | - ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
182 | - : get_post_type_object($page); |
|
183 | - //tweak pagenow for page loading. |
|
184 | - if ( ! $this->_pagenow_map) { |
|
185 | - $this->_pagenow_map = array( |
|
186 | - 'create_new' => 'post-new.php', |
|
187 | - 'edit' => 'post.php', |
|
188 | - 'trash' => 'post.php', |
|
189 | - ); |
|
190 | - } |
|
191 | - add_action('current_screen', array($this, 'modify_pagenow')); |
|
192 | - //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
193 | - //get current page from autosave |
|
194 | - $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
195 | - ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
196 | - : null; |
|
197 | - $this->_current_page = isset($this->_req_data['current_page']) |
|
198 | - ? $this->_req_data['current_page'] |
|
199 | - : $current_page; |
|
200 | - //autosave... make sure its only for the correct page |
|
201 | - //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
202 | - //setup autosave ajax hook |
|
203 | - //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
204 | - //} |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
211 | - * |
|
212 | - * @param WP_Screen $current_screen |
|
213 | - * @return void |
|
214 | - */ |
|
215 | - public function modify_pagenow($current_screen) |
|
216 | - { |
|
217 | - global $pagenow, $hook_suffix; |
|
218 | - //possibly reset pagenow. |
|
219 | - if ( ! empty($this->_req_data['page']) |
|
220 | - && $this->_req_data['page'] == $this->page_slug |
|
221 | - && ! empty($this->_req_data['action']) |
|
222 | - && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
223 | - ) { |
|
224 | - $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
225 | - $hook_suffix = $pagenow; |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
233 | - * |
|
234 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
235 | - * automatically register the id for the post metabox as a container. |
|
236 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
237 | - * you would send along the id of a metabox container. |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - protected function _register_autosave_containers($ids) |
|
241 | - { |
|
242 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
249 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
250 | - */ |
|
251 | - protected function _set_autosave_containers() |
|
252 | - { |
|
253 | - global $wp_meta_boxes; |
|
254 | - $containers = array(); |
|
255 | - if (empty($wp_meta_boxes)) { |
|
256 | - return; |
|
257 | - } |
|
258 | - $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
259 | - foreach ($current_metaboxes as $box_context) { |
|
260 | - foreach ($box_context as $box_details) { |
|
261 | - foreach ($box_details as $box) { |
|
262 | - if ( |
|
263 | - is_array($box['callback']) |
|
264 | - && ( |
|
265 | - $box['callback'][0] instanceof EE_Admin_Page |
|
266 | - || $box['callback'][0] instanceof EE_Admin_Hooks |
|
267 | - ) |
|
268 | - ) { |
|
269 | - $containers[] = $box['id']; |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
273 | - } |
|
274 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
275 | - //add hidden inputs container |
|
276 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - protected function _load_autosave_scripts_styles() |
|
282 | - { |
|
283 | - /*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 ); |
|
63 | + /** |
|
64 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
65 | + * in this format: |
|
66 | + * array( |
|
67 | + * 'post_type_slug' => 'edit_route' |
|
68 | + * ) |
|
69 | + * |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $_cpt_edit_routes = array(); |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
78 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
79 | + * _cpt_model_names property should be in the following format: array( |
|
80 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
81 | + * |
|
82 | + * @var array $_cpt_model_names |
|
83 | + */ |
|
84 | + protected $_cpt_model_names = array(); |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @var EE_CPT_Base |
|
89 | + */ |
|
90 | + protected $_cpt_model_obj = false; |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
96 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
97 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
98 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
99 | + * |
|
100 | + * @var array() |
|
101 | + */ |
|
102 | + protected $_autosave_containers = array(); |
|
103 | + protected $_autosave_fields = array(); |
|
104 | + |
|
105 | + /** |
|
106 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
107 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
108 | + * |
|
109 | + * @var array |
|
110 | + */ |
|
111 | + protected $_pagenow_map; |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
117 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
118 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
119 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
120 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
121 | + * |
|
122 | + * @access protected |
|
123 | + * @abstract |
|
124 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
125 | + * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
134 | + * |
|
135 | + * @abstract |
|
136 | + * @access public |
|
137 | + * @param string $post_id The ID of the cpt that was trashed |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + abstract public function trash_cpt_item($post_id); |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
146 | + * |
|
147 | + * @param string $post_id theID of the cpt that was untrashed |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + abstract public function restore_cpt_item($post_id); |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
156 | + * from the db |
|
157 | + * |
|
158 | + * @param string $post_id the ID of the cpt that was deleted |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + abstract public function delete_cpt_item($post_id); |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
167 | + * |
|
168 | + * @access protected |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + protected function _before_page_setup() |
|
172 | + { |
|
173 | + $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
174 | + $this->_cpt_routes = array_merge(array( |
|
175 | + 'create_new' => $this->page_slug, |
|
176 | + 'edit' => $this->page_slug, |
|
177 | + 'trash' => $this->page_slug, |
|
178 | + ), $this->_cpt_routes); |
|
179 | + //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
180 | + $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
181 | + ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
182 | + : get_post_type_object($page); |
|
183 | + //tweak pagenow for page loading. |
|
184 | + if ( ! $this->_pagenow_map) { |
|
185 | + $this->_pagenow_map = array( |
|
186 | + 'create_new' => 'post-new.php', |
|
187 | + 'edit' => 'post.php', |
|
188 | + 'trash' => 'post.php', |
|
189 | + ); |
|
190 | + } |
|
191 | + add_action('current_screen', array($this, 'modify_pagenow')); |
|
192 | + //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
193 | + //get current page from autosave |
|
194 | + $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
195 | + ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
196 | + : null; |
|
197 | + $this->_current_page = isset($this->_req_data['current_page']) |
|
198 | + ? $this->_req_data['current_page'] |
|
199 | + : $current_page; |
|
200 | + //autosave... make sure its only for the correct page |
|
201 | + //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
202 | + //setup autosave ajax hook |
|
203 | + //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
204 | + //} |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
211 | + * |
|
212 | + * @param WP_Screen $current_screen |
|
213 | + * @return void |
|
214 | + */ |
|
215 | + public function modify_pagenow($current_screen) |
|
216 | + { |
|
217 | + global $pagenow, $hook_suffix; |
|
218 | + //possibly reset pagenow. |
|
219 | + if ( ! empty($this->_req_data['page']) |
|
220 | + && $this->_req_data['page'] == $this->page_slug |
|
221 | + && ! empty($this->_req_data['action']) |
|
222 | + && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
223 | + ) { |
|
224 | + $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
225 | + $hook_suffix = $pagenow; |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
233 | + * |
|
234 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
235 | + * automatically register the id for the post metabox as a container. |
|
236 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
237 | + * you would send along the id of a metabox container. |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + protected function _register_autosave_containers($ids) |
|
241 | + { |
|
242 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
249 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
250 | + */ |
|
251 | + protected function _set_autosave_containers() |
|
252 | + { |
|
253 | + global $wp_meta_boxes; |
|
254 | + $containers = array(); |
|
255 | + if (empty($wp_meta_boxes)) { |
|
256 | + return; |
|
257 | + } |
|
258 | + $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
259 | + foreach ($current_metaboxes as $box_context) { |
|
260 | + foreach ($box_context as $box_details) { |
|
261 | + foreach ($box_details as $box) { |
|
262 | + if ( |
|
263 | + is_array($box['callback']) |
|
264 | + && ( |
|
265 | + $box['callback'][0] instanceof EE_Admin_Page |
|
266 | + || $box['callback'][0] instanceof EE_Admin_Hooks |
|
267 | + ) |
|
268 | + ) { |
|
269 | + $containers[] = $box['id']; |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | + } |
|
274 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
275 | + //add hidden inputs container |
|
276 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + protected function _load_autosave_scripts_styles() |
|
282 | + { |
|
283 | + /*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 ); |
|
284 | 284 | wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2 |
285 | 285 | |
286 | - //filter _autosave_containers |
|
287 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
288 | - $this->_autosave_containers, $this); |
|
289 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
290 | - $containers, $this); |
|
291 | - |
|
292 | - wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
293 | - $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
294 | - |
|
295 | - $unsaved_data_msg = array( |
|
296 | - 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
297 | - 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
298 | - 'inputChanged' => 0, |
|
299 | - ); |
|
300 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - public function load_page_dependencies() |
|
306 | - { |
|
307 | - try { |
|
308 | - $this->_load_page_dependencies(); |
|
309 | - } catch (EE_Error $e) { |
|
310 | - $e->get_error(); |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
318 | - * |
|
319 | - * @access protected |
|
320 | - * @return void |
|
321 | - */ |
|
322 | - protected function _load_page_dependencies() |
|
323 | - { |
|
324 | - //we only add stuff if this is a cpt_route! |
|
325 | - if ( ! $this->_cpt_route) { |
|
326 | - parent::_load_page_dependencies(); |
|
327 | - return; |
|
328 | - } |
|
329 | - // now let's do some automatic filters into the wp_system |
|
330 | - // and we'll check to make sure the CHILD class |
|
331 | - // automatically has the required methods in place. |
|
332 | - // the following filters are for setting all the redirects |
|
333 | - // on DEFAULT WP custom post type actions |
|
334 | - // let's add a hidden input to the post-edit form |
|
335 | - // so we know when we have to trigger our custom redirects! |
|
336 | - // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
337 | - add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
338 | - // inject our Admin page nav tabs... |
|
339 | - // let's make sure the nav tabs are set if they aren't already |
|
340 | - // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
341 | - add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
342 | - // modify the post_updated messages array |
|
343 | - add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
344 | - // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
345 | - // cpts use the same format for shortlinks as posts! |
|
346 | - add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
347 | - // This basically allows us to change the title of the "publish" metabox area |
|
348 | - // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
349 | - if ( ! empty($this->_labels['publishbox'])) { |
|
350 | - $box_label = is_array($this->_labels['publishbox']) |
|
351 | - && isset($this->_labels['publishbox'][$this->_req_action]) |
|
352 | - ? $this->_labels['publishbox'][$this->_req_action] |
|
353 | - : $this->_labels['publishbox']; |
|
354 | - add_meta_box( |
|
355 | - 'submitdiv', |
|
356 | - $box_label, |
|
357 | - 'post_submit_meta_box', |
|
358 | - $this->_cpt_routes[$this->_req_action], |
|
359 | - 'side', |
|
360 | - 'core' |
|
361 | - ); |
|
362 | - } |
|
363 | - //let's add page_templates metabox if this cpt added support for it. |
|
364 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
365 | - add_meta_box( |
|
366 | - 'page_templates', |
|
367 | - __('Page Template', 'event_espresso'), |
|
368 | - array($this, 'page_template_meta_box'), |
|
369 | - $this->_cpt_routes[$this->_req_action], |
|
370 | - 'side', |
|
371 | - 'default' |
|
372 | - ); |
|
373 | - } |
|
374 | - //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
375 | - if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
376 | - add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
377 | - } |
|
378 | - //add preview button |
|
379 | - add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
380 | - //insert our own post_stati dropdown |
|
381 | - add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
382 | - //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
383 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
384 | - add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
385 | - } |
|
386 | - // This allows for adding additional stuff after the title field on the wp post edit form. |
|
387 | - // This is also before the wp_editor for post description field. |
|
388 | - if (method_exists($this, 'edit_form_after_title')) { |
|
389 | - add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
390 | - } |
|
391 | - /** |
|
392 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
393 | - */ |
|
394 | - add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
395 | - parent::_load_page_dependencies(); |
|
396 | - // notice we are ALSO going to load the pagenow hook set for this route |
|
397 | - // (see _before_page_setup for the reset of the pagenow global ). |
|
398 | - // This is for any plugins that are doing things properly |
|
399 | - // and hooking into the load page hook for core wp cpt routes. |
|
400 | - global $pagenow; |
|
401 | - do_action('load-' . $pagenow); |
|
402 | - $this->modify_current_screen(); |
|
403 | - add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
404 | - //we route REALLY early. |
|
405 | - try { |
|
406 | - $this->_route_admin_request(); |
|
407 | - } catch (EE_Error $e) { |
|
408 | - $e->get_error(); |
|
409 | - } |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
416 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
417 | - * route instead. |
|
418 | - * |
|
419 | - * @param string $good_protocol_url The escaped url. |
|
420 | - * @param string $original_url The original url. |
|
421 | - * @param string $_context The context sent to the esc_url method. |
|
422 | - * @return string possibly a new url for our route. |
|
423 | - */ |
|
424 | - public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
425 | - { |
|
426 | - $routes_to_match = array( |
|
427 | - 0 => array( |
|
428 | - 'edit.php?post_type=espresso_attendees', |
|
429 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
430 | - ), |
|
431 | - 1 => array( |
|
432 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
433 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
434 | - ), |
|
435 | - ); |
|
436 | - foreach ($routes_to_match as $route_matches) { |
|
437 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
438 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
439 | - } |
|
440 | - } |
|
441 | - return $good_protocol_url; |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * Determine whether the current cpt supports page templates or not. |
|
448 | - * |
|
449 | - * @since %VER% |
|
450 | - * @param string $cpt_name The cpt slug we're checking on. |
|
451 | - * @return bool True supported, false not. |
|
452 | - */ |
|
453 | - private function _supports_page_templates($cpt_name) |
|
454 | - { |
|
455 | - |
|
456 | - $cpt_args = EE_Register_CPTs::get_CPTs(); |
|
457 | - $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
458 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
459 | - |
|
460 | - //if the installed version of WP is > 4.7 we do some additional checks. |
|
461 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
462 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
463 | - //if there are $post_templates for this cpt, then we return false for this method because |
|
464 | - //that means we aren't going to load our page template manager and leave that up to the native |
|
465 | - //cpt template manager. |
|
466 | - $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
467 | - } |
|
468 | - |
|
469 | - return $cpt_has_support; |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * Callback for the page_templates metabox selector. |
|
475 | - * |
|
476 | - * @since %VER% |
|
477 | - * @return void |
|
478 | - */ |
|
479 | - public function page_template_meta_box() |
|
480 | - { |
|
481 | - global $post; |
|
482 | - $template = ''; |
|
483 | - |
|
484 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
485 | - $page_template_count = count(get_page_templates()); |
|
486 | - } else { |
|
487 | - $page_template_count = count(get_page_templates($post)); |
|
488 | - }; |
|
489 | - |
|
490 | - if ($page_template_count) { |
|
491 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
492 | - $template = ! empty($page_template) ? $page_template : ''; |
|
493 | - } |
|
494 | - ?> |
|
286 | + //filter _autosave_containers |
|
287 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
288 | + $this->_autosave_containers, $this); |
|
289 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
290 | + $containers, $this); |
|
291 | + |
|
292 | + wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
|
293 | + $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
294 | + |
|
295 | + $unsaved_data_msg = array( |
|
296 | + 'eventmsg' => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.", |
|
297 | + 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
298 | + 'inputChanged' => 0, |
|
299 | + ); |
|
300 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + public function load_page_dependencies() |
|
306 | + { |
|
307 | + try { |
|
308 | + $this->_load_page_dependencies(); |
|
309 | + } catch (EE_Error $e) { |
|
310 | + $e->get_error(); |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
318 | + * |
|
319 | + * @access protected |
|
320 | + * @return void |
|
321 | + */ |
|
322 | + protected function _load_page_dependencies() |
|
323 | + { |
|
324 | + //we only add stuff if this is a cpt_route! |
|
325 | + if ( ! $this->_cpt_route) { |
|
326 | + parent::_load_page_dependencies(); |
|
327 | + return; |
|
328 | + } |
|
329 | + // now let's do some automatic filters into the wp_system |
|
330 | + // and we'll check to make sure the CHILD class |
|
331 | + // automatically has the required methods in place. |
|
332 | + // the following filters are for setting all the redirects |
|
333 | + // on DEFAULT WP custom post type actions |
|
334 | + // let's add a hidden input to the post-edit form |
|
335 | + // so we know when we have to trigger our custom redirects! |
|
336 | + // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
337 | + add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
338 | + // inject our Admin page nav tabs... |
|
339 | + // let's make sure the nav tabs are set if they aren't already |
|
340 | + // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
341 | + add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
342 | + // modify the post_updated messages array |
|
343 | + add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
344 | + // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
345 | + // cpts use the same format for shortlinks as posts! |
|
346 | + add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
347 | + // This basically allows us to change the title of the "publish" metabox area |
|
348 | + // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
349 | + if ( ! empty($this->_labels['publishbox'])) { |
|
350 | + $box_label = is_array($this->_labels['publishbox']) |
|
351 | + && isset($this->_labels['publishbox'][$this->_req_action]) |
|
352 | + ? $this->_labels['publishbox'][$this->_req_action] |
|
353 | + : $this->_labels['publishbox']; |
|
354 | + add_meta_box( |
|
355 | + 'submitdiv', |
|
356 | + $box_label, |
|
357 | + 'post_submit_meta_box', |
|
358 | + $this->_cpt_routes[$this->_req_action], |
|
359 | + 'side', |
|
360 | + 'core' |
|
361 | + ); |
|
362 | + } |
|
363 | + //let's add page_templates metabox if this cpt added support for it. |
|
364 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
365 | + add_meta_box( |
|
366 | + 'page_templates', |
|
367 | + __('Page Template', 'event_espresso'), |
|
368 | + array($this, 'page_template_meta_box'), |
|
369 | + $this->_cpt_routes[$this->_req_action], |
|
370 | + 'side', |
|
371 | + 'default' |
|
372 | + ); |
|
373 | + } |
|
374 | + //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
375 | + if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
376 | + add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
377 | + } |
|
378 | + //add preview button |
|
379 | + add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
380 | + //insert our own post_stati dropdown |
|
381 | + add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
382 | + //This allows adding additional information to the publish post submitbox on the wp post edit form |
|
383 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
384 | + add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
385 | + } |
|
386 | + // This allows for adding additional stuff after the title field on the wp post edit form. |
|
387 | + // This is also before the wp_editor for post description field. |
|
388 | + if (method_exists($this, 'edit_form_after_title')) { |
|
389 | + add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
390 | + } |
|
391 | + /** |
|
392 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
393 | + */ |
|
394 | + add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
395 | + parent::_load_page_dependencies(); |
|
396 | + // notice we are ALSO going to load the pagenow hook set for this route |
|
397 | + // (see _before_page_setup for the reset of the pagenow global ). |
|
398 | + // This is for any plugins that are doing things properly |
|
399 | + // and hooking into the load page hook for core wp cpt routes. |
|
400 | + global $pagenow; |
|
401 | + do_action('load-' . $pagenow); |
|
402 | + $this->modify_current_screen(); |
|
403 | + add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
404 | + //we route REALLY early. |
|
405 | + try { |
|
406 | + $this->_route_admin_request(); |
|
407 | + } catch (EE_Error $e) { |
|
408 | + $e->get_error(); |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
416 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
417 | + * route instead. |
|
418 | + * |
|
419 | + * @param string $good_protocol_url The escaped url. |
|
420 | + * @param string $original_url The original url. |
|
421 | + * @param string $_context The context sent to the esc_url method. |
|
422 | + * @return string possibly a new url for our route. |
|
423 | + */ |
|
424 | + public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
425 | + { |
|
426 | + $routes_to_match = array( |
|
427 | + 0 => array( |
|
428 | + 'edit.php?post_type=espresso_attendees', |
|
429 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
430 | + ), |
|
431 | + 1 => array( |
|
432 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
433 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
434 | + ), |
|
435 | + ); |
|
436 | + foreach ($routes_to_match as $route_matches) { |
|
437 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
438 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
439 | + } |
|
440 | + } |
|
441 | + return $good_protocol_url; |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * Determine whether the current cpt supports page templates or not. |
|
448 | + * |
|
449 | + * @since %VER% |
|
450 | + * @param string $cpt_name The cpt slug we're checking on. |
|
451 | + * @return bool True supported, false not. |
|
452 | + */ |
|
453 | + private function _supports_page_templates($cpt_name) |
|
454 | + { |
|
455 | + |
|
456 | + $cpt_args = EE_Register_CPTs::get_CPTs(); |
|
457 | + $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
458 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
459 | + |
|
460 | + //if the installed version of WP is > 4.7 we do some additional checks. |
|
461 | + if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
462 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
463 | + //if there are $post_templates for this cpt, then we return false for this method because |
|
464 | + //that means we aren't going to load our page template manager and leave that up to the native |
|
465 | + //cpt template manager. |
|
466 | + $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
467 | + } |
|
468 | + |
|
469 | + return $cpt_has_support; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * Callback for the page_templates metabox selector. |
|
475 | + * |
|
476 | + * @since %VER% |
|
477 | + * @return void |
|
478 | + */ |
|
479 | + public function page_template_meta_box() |
|
480 | + { |
|
481 | + global $post; |
|
482 | + $template = ''; |
|
483 | + |
|
484 | + if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
485 | + $page_template_count = count(get_page_templates()); |
|
486 | + } else { |
|
487 | + $page_template_count = count(get_page_templates($post)); |
|
488 | + }; |
|
489 | + |
|
490 | + if ($page_template_count) { |
|
491 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
492 | + $template = ! empty($page_template) ? $page_template : ''; |
|
493 | + } |
|
494 | + ?> |
|
495 | 495 | <p><strong><?php _e('Template') ?></strong></p> |
496 | 496 | <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select |
497 | 497 | name="page_template" id="page_template"> |
@@ -499,450 +499,450 @@ discard block |
||
499 | 499 | <?php page_template_dropdown($template); ?> |
500 | 500 | </select> |
501 | 501 | <?php |
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
508 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
509 | - * |
|
510 | - * @param string $return the current html |
|
511 | - * @param int $id the post id for the page |
|
512 | - * @param string $new_title What the title is |
|
513 | - * @param string $new_slug what the slug is |
|
514 | - * @return string The new html string for the permalink area |
|
515 | - */ |
|
516 | - public function preview_button_html($return, $id, $new_title, $new_slug) |
|
517 | - { |
|
518 | - $post = get_post($id); |
|
519 | - if ('publish' !== get_post_status($post)) { |
|
520 | - //include shims for the `get_preview_post_link` function |
|
521 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
522 | - $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
523 | - . get_preview_post_link($id) |
|
524 | - . '" class="button button-small">' |
|
525 | - . __('Preview', 'event_espresso') |
|
526 | - . '</a></span>' |
|
527 | - . "\n"; |
|
528 | - } |
|
529 | - return $return; |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * add our custom post stati dropdown on the wp post page for this cpt |
|
536 | - * |
|
537 | - * @return void |
|
538 | - */ |
|
539 | - public function custom_post_stati_dropdown() |
|
540 | - { |
|
541 | - |
|
542 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
543 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
544 | - ? $statuses[$this->_cpt_model_obj->status()] |
|
545 | - : ''; |
|
546 | - $template_args = array( |
|
547 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
548 | - 'statuses' => $statuses, |
|
549 | - 'cur_status_label' => $cur_status_label, |
|
550 | - 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
551 | - ); |
|
552 | - //we'll add a trash post status (WP doesn't add one for some reason) |
|
553 | - if ($this->_cpt_model_obj->status() === 'trash') { |
|
554 | - $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
555 | - $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
556 | - $template_args['statuses'] = $statuses; |
|
557 | - } |
|
558 | - |
|
559 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
560 | - EEH_Template::display_template($template, $template_args); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - |
|
565 | - public function setup_autosave_hooks() |
|
566 | - { |
|
567 | - $this->_set_autosave_containers(); |
|
568 | - $this->_load_autosave_scripts_styles(); |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
575 | - * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
576 | - * for the nonce in here, but then this method looks for two things: |
|
577 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
578 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
579 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
580 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
581 | - * template args. |
|
582 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
583 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
584 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
585 | - * $this->_template_args['data']['items'] = array( |
|
586 | - * 'event-datetime-ids' => '1,2,3'; |
|
587 | - * ); |
|
588 | - * Keep in mind the following things: |
|
589 | - * - "where" index is for the input with the id as that string. |
|
590 | - * - "what" index is what will be used for the value of that input. |
|
591 | - * |
|
592 | - * @return void |
|
593 | - */ |
|
594 | - public function do_extra_autosave_stuff() |
|
595 | - { |
|
596 | - //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
597 | - $nonce = isset($this->_req_data['autosavenonce']) |
|
598 | - ? $this->_req_data['autosavenonce'] |
|
599 | - : null; |
|
600 | - $this->_verify_nonce($nonce, 'autosave'); |
|
601 | - //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
602 | - if ( ! defined('DOING_AUTOSAVE')) { |
|
603 | - define('DOING_AUTOSAVE', true); |
|
604 | - } |
|
605 | - //if we made it here then the nonce checked out. Let's run our methods and actions |
|
606 | - $autosave = "_ee_autosave_{$this->_current_view}"; |
|
607 | - if (method_exists($this, $autosave)) { |
|
608 | - $this->$autosave(); |
|
609 | - } else { |
|
610 | - $this->_template_args['success'] = true; |
|
611 | - } |
|
612 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
613 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
614 | - //now let's return json |
|
615 | - $this->_return_json(); |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
622 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
623 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
624 | - * |
|
625 | - * @access protected |
|
626 | - * @throws EE_Error |
|
627 | - * @return void |
|
628 | - */ |
|
629 | - protected function _extend_page_config_for_cpt() |
|
630 | - { |
|
631 | - //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
632 | - if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
633 | - return; |
|
634 | - } |
|
635 | - //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
636 | - if ( ! empty($this->_cpt_object)) { |
|
637 | - $this->_page_routes = array_merge(array( |
|
638 | - 'create_new' => '_create_new_cpt_item', |
|
639 | - 'edit' => '_edit_cpt_item', |
|
640 | - ), $this->_page_routes); |
|
641 | - $this->_page_config = array_merge(array( |
|
642 | - 'create_new' => array( |
|
643 | - 'nav' => array( |
|
644 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
645 | - 'order' => 5, |
|
646 | - ), |
|
647 | - 'require_nonce' => false, |
|
648 | - ), |
|
649 | - 'edit' => array( |
|
650 | - 'nav' => array( |
|
651 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
652 | - 'order' => 5, |
|
653 | - 'persistent' => false, |
|
654 | - 'url' => '', |
|
655 | - ), |
|
656 | - 'require_nonce' => false, |
|
657 | - ), |
|
658 | - ), |
|
659 | - $this->_page_config |
|
660 | - ); |
|
661 | - } |
|
662 | - //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
663 | - if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
664 | - return; |
|
665 | - } |
|
666 | - $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
667 | - //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
668 | - if (empty($this->_cpt_object)) { |
|
669 | - $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).'), |
|
670 | - $this->page_slug, $this->_req_action, get_class($this)); |
|
671 | - throw new EE_Error($msg); |
|
672 | - } |
|
673 | - if ($this->_cpt_route) { |
|
674 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
675 | - $this->_set_model_object($id); |
|
676 | - } |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
683 | - * |
|
684 | - * @access protected |
|
685 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
686 | - * @param bool $ignore_route_check |
|
687 | - * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
688 | - * @throws EE_Error |
|
689 | - */ |
|
690 | - protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
691 | - { |
|
692 | - $model = null; |
|
693 | - if ( |
|
694 | - empty($this->_cpt_model_names) |
|
695 | - || ( |
|
696 | - ! $ignore_route_check |
|
697 | - && ! isset($this->_cpt_routes[$this->_req_action]) |
|
698 | - ) || ( |
|
699 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
700 | - && $this->_cpt_model_obj->ID() === $id |
|
701 | - ) |
|
702 | - ) { |
|
703 | - //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. |
|
704 | - return; |
|
705 | - } |
|
706 | - //if ignore_route_check is true, then get the model name via EE_Register_CPTs |
|
707 | - if ($ignore_route_check) { |
|
708 | - $model_names = EE_Register_CPTs::get_cpt_model_names(); |
|
709 | - $post_type = get_post_type($id); |
|
710 | - if (isset($model_names[$post_type])) { |
|
711 | - $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
712 | - } |
|
713 | - } else { |
|
714 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
715 | - } |
|
716 | - if ($model instanceof EEM_Base) { |
|
717 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
718 | - } |
|
719 | - do_action( |
|
720 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
721 | - $this->_cpt_model_obj, |
|
722 | - $req_type |
|
723 | - ); |
|
724 | - } |
|
725 | - |
|
726 | - |
|
727 | - |
|
728 | - /** |
|
729 | - * admin_init_global |
|
730 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
731 | - * This method executes for ALL EE Admin pages. |
|
732 | - * |
|
733 | - * @access public |
|
734 | - * @return void |
|
735 | - */ |
|
736 | - public function admin_init_global() |
|
737 | - { |
|
738 | - $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
739 | - //its possible this is a new save so let's catch that instead |
|
740 | - $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
741 | - $post_type = $post ? $post->post_type : false; |
|
742 | - $current_route = isset($this->_req_data['current_route']) |
|
743 | - ? $this->_req_data['current_route'] |
|
744 | - : 'shouldneverwork'; |
|
745 | - $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
746 | - ? $this->_cpt_routes[$current_route] |
|
747 | - : ''; |
|
748 | - add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
749 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
750 | - if ($post_type === $route_to_check) { |
|
751 | - add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
752 | - } |
|
753 | - //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
754 | - $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
755 | - if ( ! empty($revision)) { |
|
756 | - $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
757 | - //doing a restore? |
|
758 | - if ( ! empty($action) && $action === 'restore') { |
|
759 | - //get post for revision |
|
760 | - $rev_post = get_post($revision); |
|
761 | - $rev_parent = get_post($rev_post->post_parent); |
|
762 | - //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
763 | - if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
764 | - add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
765 | - //restores of revisions |
|
766 | - add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
767 | - } |
|
768 | - } |
|
769 | - } |
|
770 | - //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! |
|
771 | - if ($post_type && $post_type === $route_to_check) { |
|
772 | - //$post_id, $post |
|
773 | - add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
774 | - //$post_id |
|
775 | - add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
776 | - add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
777 | - add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
778 | - add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
779 | - } |
|
780 | - } |
|
781 | - |
|
782 | - |
|
783 | - |
|
784 | - /** |
|
785 | - * Callback for the WordPress trashed_post hook. |
|
786 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
787 | - * |
|
788 | - * @param int $post_id |
|
789 | - * @throws \EE_Error |
|
790 | - */ |
|
791 | - public function before_trash_cpt_item($post_id) |
|
792 | - { |
|
793 | - $this->_set_model_object($post_id, true, 'trash'); |
|
794 | - //if our cpt object isn't existent then get out immediately. |
|
795 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
796 | - return; |
|
797 | - } |
|
798 | - $this->trash_cpt_item($post_id); |
|
799 | - } |
|
800 | - |
|
801 | - |
|
802 | - |
|
803 | - /** |
|
804 | - * Callback for the WordPress untrashed_post hook. |
|
805 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
806 | - * |
|
807 | - * @param $post_id |
|
808 | - * @throws \EE_Error |
|
809 | - */ |
|
810 | - public function before_restore_cpt_item($post_id) |
|
811 | - { |
|
812 | - $this->_set_model_object($post_id, true, 'restore'); |
|
813 | - //if our cpt object isn't existent then get out immediately. |
|
814 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
815 | - return; |
|
816 | - } |
|
817 | - $this->restore_cpt_item($post_id); |
|
818 | - } |
|
819 | - |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * Callback for the WordPress after_delete_post hook. |
|
824 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
825 | - * |
|
826 | - * @param $post_id |
|
827 | - * @throws \EE_Error |
|
828 | - */ |
|
829 | - public function before_delete_cpt_item($post_id) |
|
830 | - { |
|
831 | - $this->_set_model_object($post_id, true, 'delete'); |
|
832 | - //if our cpt object isn't existent then get out immediately. |
|
833 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
834 | - return; |
|
835 | - } |
|
836 | - $this->delete_cpt_item($post_id); |
|
837 | - } |
|
838 | - |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
843 | - * accordingly. |
|
844 | - * |
|
845 | - * @access public |
|
846 | - * @throws EE_Error |
|
847 | - * @return void |
|
848 | - */ |
|
849 | - public function verify_cpt_object() |
|
850 | - { |
|
851 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
852 | - // verify event object |
|
853 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
854 | - 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', |
|
855 | - 'event_espresso'), $label)); |
|
856 | - } |
|
857 | - //if auto-draft then throw an error |
|
858 | - if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
859 | - EE_Error::overwrite_errors(); |
|
860 | - 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.'), |
|
861 | - $label), __FILE__, __FUNCTION__, __LINE__); |
|
862 | - } |
|
863 | - } |
|
864 | - |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * admin_footer_scripts_global |
|
869 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
870 | - * will apply on ALL EE_Admin pages. |
|
871 | - * |
|
872 | - * @access public |
|
873 | - * @return void |
|
874 | - */ |
|
875 | - public function admin_footer_scripts_global() |
|
876 | - { |
|
877 | - $this->_add_admin_page_ajax_loading_img(); |
|
878 | - $this->_add_admin_page_overlay(); |
|
879 | - } |
|
880 | - |
|
881 | - |
|
882 | - |
|
883 | - /** |
|
884 | - * add in any global scripts for cpt routes |
|
885 | - * |
|
886 | - * @return void |
|
887 | - */ |
|
888 | - public function load_global_scripts_styles() |
|
889 | - { |
|
890 | - parent::load_global_scripts_styles(); |
|
891 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
892 | - //setup custom post status object for localize script but only if we've got a cpt object |
|
893 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
894 | - if ( ! empty($statuses)) { |
|
895 | - //get ALL statuses! |
|
896 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
897 | - //setup object |
|
898 | - $ee_cpt_statuses = array(); |
|
899 | - foreach ($statuses as $status => $label) { |
|
900 | - $ee_cpt_statuses[$status] = array( |
|
901 | - 'label' => $label, |
|
902 | - 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
903 | - ); |
|
904 | - } |
|
905 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
906 | - } |
|
907 | - } |
|
908 | - } |
|
909 | - |
|
910 | - |
|
911 | - |
|
912 | - /** |
|
913 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
914 | - * insert/updates |
|
915 | - * |
|
916 | - * @param int $post_id ID of post being updated |
|
917 | - * @param WP_Post $post Post object from WP |
|
918 | - * @param bool $update Whether this is an update or a new save. |
|
919 | - * @return void |
|
920 | - * @throws \EE_Error |
|
921 | - */ |
|
922 | - public function insert_update($post_id, $post, $update) |
|
923 | - { |
|
924 | - //make sure that if this is a revision OR trash action that we don't do any updates! |
|
925 | - if ( |
|
926 | - isset($this->_req_data['action']) |
|
927 | - && ( |
|
928 | - $this->_req_data['action'] === 'restore' |
|
929 | - || $this->_req_data['action'] === 'trash' |
|
930 | - ) |
|
931 | - ) { |
|
932 | - return; |
|
933 | - } |
|
934 | - $this->_set_model_object($post_id, true, 'insert_update'); |
|
935 | - //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
936 | - if ($update |
|
937 | - && ( |
|
938 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
939 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
940 | - ) |
|
941 | - ) { |
|
942 | - return; |
|
943 | - } |
|
944 | - //check for autosave and update our req_data property accordingly. |
|
945 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
508 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
509 | + * |
|
510 | + * @param string $return the current html |
|
511 | + * @param int $id the post id for the page |
|
512 | + * @param string $new_title What the title is |
|
513 | + * @param string $new_slug what the slug is |
|
514 | + * @return string The new html string for the permalink area |
|
515 | + */ |
|
516 | + public function preview_button_html($return, $id, $new_title, $new_slug) |
|
517 | + { |
|
518 | + $post = get_post($id); |
|
519 | + if ('publish' !== get_post_status($post)) { |
|
520 | + //include shims for the `get_preview_post_link` function |
|
521 | + require_once( EE_CORE . 'wordpress-shims.php' ); |
|
522 | + $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
523 | + . get_preview_post_link($id) |
|
524 | + . '" class="button button-small">' |
|
525 | + . __('Preview', 'event_espresso') |
|
526 | + . '</a></span>' |
|
527 | + . "\n"; |
|
528 | + } |
|
529 | + return $return; |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * add our custom post stati dropdown on the wp post page for this cpt |
|
536 | + * |
|
537 | + * @return void |
|
538 | + */ |
|
539 | + public function custom_post_stati_dropdown() |
|
540 | + { |
|
541 | + |
|
542 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
543 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
544 | + ? $statuses[$this->_cpt_model_obj->status()] |
|
545 | + : ''; |
|
546 | + $template_args = array( |
|
547 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
548 | + 'statuses' => $statuses, |
|
549 | + 'cur_status_label' => $cur_status_label, |
|
550 | + 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
551 | + ); |
|
552 | + //we'll add a trash post status (WP doesn't add one for some reason) |
|
553 | + if ($this->_cpt_model_obj->status() === 'trash') { |
|
554 | + $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
555 | + $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
556 | + $template_args['statuses'] = $statuses; |
|
557 | + } |
|
558 | + |
|
559 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
560 | + EEH_Template::display_template($template, $template_args); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + |
|
565 | + public function setup_autosave_hooks() |
|
566 | + { |
|
567 | + $this->_set_autosave_containers(); |
|
568 | + $this->_load_autosave_scripts_styles(); |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
575 | + * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
576 | + * for the nonce in here, but then this method looks for two things: |
|
577 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
578 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
579 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
580 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
581 | + * template args. |
|
582 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
583 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
584 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
585 | + * $this->_template_args['data']['items'] = array( |
|
586 | + * 'event-datetime-ids' => '1,2,3'; |
|
587 | + * ); |
|
588 | + * Keep in mind the following things: |
|
589 | + * - "where" index is for the input with the id as that string. |
|
590 | + * - "what" index is what will be used for the value of that input. |
|
591 | + * |
|
592 | + * @return void |
|
593 | + */ |
|
594 | + public function do_extra_autosave_stuff() |
|
595 | + { |
|
596 | + //next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
597 | + $nonce = isset($this->_req_data['autosavenonce']) |
|
598 | + ? $this->_req_data['autosavenonce'] |
|
599 | + : null; |
|
600 | + $this->_verify_nonce($nonce, 'autosave'); |
|
601 | + //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
602 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
603 | + define('DOING_AUTOSAVE', true); |
|
604 | + } |
|
605 | + //if we made it here then the nonce checked out. Let's run our methods and actions |
|
606 | + $autosave = "_ee_autosave_{$this->_current_view}"; |
|
607 | + if (method_exists($this, $autosave)) { |
|
608 | + $this->$autosave(); |
|
609 | + } else { |
|
610 | + $this->_template_args['success'] = true; |
|
611 | + } |
|
612 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
613 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
614 | + //now let's return json |
|
615 | + $this->_return_json(); |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
622 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
623 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
624 | + * |
|
625 | + * @access protected |
|
626 | + * @throws EE_Error |
|
627 | + * @return void |
|
628 | + */ |
|
629 | + protected function _extend_page_config_for_cpt() |
|
630 | + { |
|
631 | + //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
632 | + if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
633 | + return; |
|
634 | + } |
|
635 | + //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
636 | + if ( ! empty($this->_cpt_object)) { |
|
637 | + $this->_page_routes = array_merge(array( |
|
638 | + 'create_new' => '_create_new_cpt_item', |
|
639 | + 'edit' => '_edit_cpt_item', |
|
640 | + ), $this->_page_routes); |
|
641 | + $this->_page_config = array_merge(array( |
|
642 | + 'create_new' => array( |
|
643 | + 'nav' => array( |
|
644 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
645 | + 'order' => 5, |
|
646 | + ), |
|
647 | + 'require_nonce' => false, |
|
648 | + ), |
|
649 | + 'edit' => array( |
|
650 | + 'nav' => array( |
|
651 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
652 | + 'order' => 5, |
|
653 | + 'persistent' => false, |
|
654 | + 'url' => '', |
|
655 | + ), |
|
656 | + 'require_nonce' => false, |
|
657 | + ), |
|
658 | + ), |
|
659 | + $this->_page_config |
|
660 | + ); |
|
661 | + } |
|
662 | + //load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
663 | + if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
664 | + return; |
|
665 | + } |
|
666 | + $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
667 | + //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
668 | + if (empty($this->_cpt_object)) { |
|
669 | + $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).'), |
|
670 | + $this->page_slug, $this->_req_action, get_class($this)); |
|
671 | + throw new EE_Error($msg); |
|
672 | + } |
|
673 | + if ($this->_cpt_route) { |
|
674 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
675 | + $this->_set_model_object($id); |
|
676 | + } |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
683 | + * |
|
684 | + * @access protected |
|
685 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
686 | + * @param bool $ignore_route_check |
|
687 | + * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
688 | + * @throws EE_Error |
|
689 | + */ |
|
690 | + protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
691 | + { |
|
692 | + $model = null; |
|
693 | + if ( |
|
694 | + empty($this->_cpt_model_names) |
|
695 | + || ( |
|
696 | + ! $ignore_route_check |
|
697 | + && ! isset($this->_cpt_routes[$this->_req_action]) |
|
698 | + ) || ( |
|
699 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
700 | + && $this->_cpt_model_obj->ID() === $id |
|
701 | + ) |
|
702 | + ) { |
|
703 | + //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. |
|
704 | + return; |
|
705 | + } |
|
706 | + //if ignore_route_check is true, then get the model name via EE_Register_CPTs |
|
707 | + if ($ignore_route_check) { |
|
708 | + $model_names = EE_Register_CPTs::get_cpt_model_names(); |
|
709 | + $post_type = get_post_type($id); |
|
710 | + if (isset($model_names[$post_type])) { |
|
711 | + $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
712 | + } |
|
713 | + } else { |
|
714 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
715 | + } |
|
716 | + if ($model instanceof EEM_Base) { |
|
717 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
718 | + } |
|
719 | + do_action( |
|
720 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
721 | + $this->_cpt_model_obj, |
|
722 | + $req_type |
|
723 | + ); |
|
724 | + } |
|
725 | + |
|
726 | + |
|
727 | + |
|
728 | + /** |
|
729 | + * admin_init_global |
|
730 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
731 | + * This method executes for ALL EE Admin pages. |
|
732 | + * |
|
733 | + * @access public |
|
734 | + * @return void |
|
735 | + */ |
|
736 | + public function admin_init_global() |
|
737 | + { |
|
738 | + $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
739 | + //its possible this is a new save so let's catch that instead |
|
740 | + $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
741 | + $post_type = $post ? $post->post_type : false; |
|
742 | + $current_route = isset($this->_req_data['current_route']) |
|
743 | + ? $this->_req_data['current_route'] |
|
744 | + : 'shouldneverwork'; |
|
745 | + $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
746 | + ? $this->_cpt_routes[$current_route] |
|
747 | + : ''; |
|
748 | + add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
749 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
750 | + if ($post_type === $route_to_check) { |
|
751 | + add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
752 | + } |
|
753 | + //now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
754 | + $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
755 | + if ( ! empty($revision)) { |
|
756 | + $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
757 | + //doing a restore? |
|
758 | + if ( ! empty($action) && $action === 'restore') { |
|
759 | + //get post for revision |
|
760 | + $rev_post = get_post($revision); |
|
761 | + $rev_parent = get_post($rev_post->post_parent); |
|
762 | + //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
763 | + if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
764 | + add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
765 | + //restores of revisions |
|
766 | + add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
767 | + } |
|
768 | + } |
|
769 | + } |
|
770 | + //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! |
|
771 | + if ($post_type && $post_type === $route_to_check) { |
|
772 | + //$post_id, $post |
|
773 | + add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
774 | + //$post_id |
|
775 | + add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
776 | + add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
777 | + add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
778 | + add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
779 | + } |
|
780 | + } |
|
781 | + |
|
782 | + |
|
783 | + |
|
784 | + /** |
|
785 | + * Callback for the WordPress trashed_post hook. |
|
786 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
787 | + * |
|
788 | + * @param int $post_id |
|
789 | + * @throws \EE_Error |
|
790 | + */ |
|
791 | + public function before_trash_cpt_item($post_id) |
|
792 | + { |
|
793 | + $this->_set_model_object($post_id, true, 'trash'); |
|
794 | + //if our cpt object isn't existent then get out immediately. |
|
795 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
796 | + return; |
|
797 | + } |
|
798 | + $this->trash_cpt_item($post_id); |
|
799 | + } |
|
800 | + |
|
801 | + |
|
802 | + |
|
803 | + /** |
|
804 | + * Callback for the WordPress untrashed_post hook. |
|
805 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
806 | + * |
|
807 | + * @param $post_id |
|
808 | + * @throws \EE_Error |
|
809 | + */ |
|
810 | + public function before_restore_cpt_item($post_id) |
|
811 | + { |
|
812 | + $this->_set_model_object($post_id, true, 'restore'); |
|
813 | + //if our cpt object isn't existent then get out immediately. |
|
814 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
815 | + return; |
|
816 | + } |
|
817 | + $this->restore_cpt_item($post_id); |
|
818 | + } |
|
819 | + |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * Callback for the WordPress after_delete_post hook. |
|
824 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
825 | + * |
|
826 | + * @param $post_id |
|
827 | + * @throws \EE_Error |
|
828 | + */ |
|
829 | + public function before_delete_cpt_item($post_id) |
|
830 | + { |
|
831 | + $this->_set_model_object($post_id, true, 'delete'); |
|
832 | + //if our cpt object isn't existent then get out immediately. |
|
833 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
834 | + return; |
|
835 | + } |
|
836 | + $this->delete_cpt_item($post_id); |
|
837 | + } |
|
838 | + |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
843 | + * accordingly. |
|
844 | + * |
|
845 | + * @access public |
|
846 | + * @throws EE_Error |
|
847 | + * @return void |
|
848 | + */ |
|
849 | + public function verify_cpt_object() |
|
850 | + { |
|
851 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
852 | + // verify event object |
|
853 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
854 | + 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', |
|
855 | + 'event_espresso'), $label)); |
|
856 | + } |
|
857 | + //if auto-draft then throw an error |
|
858 | + if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
859 | + EE_Error::overwrite_errors(); |
|
860 | + 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.'), |
|
861 | + $label), __FILE__, __FUNCTION__, __LINE__); |
|
862 | + } |
|
863 | + } |
|
864 | + |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * admin_footer_scripts_global |
|
869 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
870 | + * will apply on ALL EE_Admin pages. |
|
871 | + * |
|
872 | + * @access public |
|
873 | + * @return void |
|
874 | + */ |
|
875 | + public function admin_footer_scripts_global() |
|
876 | + { |
|
877 | + $this->_add_admin_page_ajax_loading_img(); |
|
878 | + $this->_add_admin_page_overlay(); |
|
879 | + } |
|
880 | + |
|
881 | + |
|
882 | + |
|
883 | + /** |
|
884 | + * add in any global scripts for cpt routes |
|
885 | + * |
|
886 | + * @return void |
|
887 | + */ |
|
888 | + public function load_global_scripts_styles() |
|
889 | + { |
|
890 | + parent::load_global_scripts_styles(); |
|
891 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
892 | + //setup custom post status object for localize script but only if we've got a cpt object |
|
893 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
894 | + if ( ! empty($statuses)) { |
|
895 | + //get ALL statuses! |
|
896 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
897 | + //setup object |
|
898 | + $ee_cpt_statuses = array(); |
|
899 | + foreach ($statuses as $status => $label) { |
|
900 | + $ee_cpt_statuses[$status] = array( |
|
901 | + 'label' => $label, |
|
902 | + 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
903 | + ); |
|
904 | + } |
|
905 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
906 | + } |
|
907 | + } |
|
908 | + } |
|
909 | + |
|
910 | + |
|
911 | + |
|
912 | + /** |
|
913 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
914 | + * insert/updates |
|
915 | + * |
|
916 | + * @param int $post_id ID of post being updated |
|
917 | + * @param WP_Post $post Post object from WP |
|
918 | + * @param bool $update Whether this is an update or a new save. |
|
919 | + * @return void |
|
920 | + * @throws \EE_Error |
|
921 | + */ |
|
922 | + public function insert_update($post_id, $post, $update) |
|
923 | + { |
|
924 | + //make sure that if this is a revision OR trash action that we don't do any updates! |
|
925 | + if ( |
|
926 | + isset($this->_req_data['action']) |
|
927 | + && ( |
|
928 | + $this->_req_data['action'] === 'restore' |
|
929 | + || $this->_req_data['action'] === 'trash' |
|
930 | + ) |
|
931 | + ) { |
|
932 | + return; |
|
933 | + } |
|
934 | + $this->_set_model_object($post_id, true, 'insert_update'); |
|
935 | + //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
936 | + if ($update |
|
937 | + && ( |
|
938 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
939 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
940 | + ) |
|
941 | + ) { |
|
942 | + return; |
|
943 | + } |
|
944 | + //check for autosave and update our req_data property accordingly. |
|
945 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
946 | 946 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
947 | 947 | |
948 | 948 | foreach ( (array) $values as $key => $value ) { |
@@ -952,542 +952,542 @@ discard block |
||
952 | 952 | |
953 | 953 | }/**/ //TODO reactivate after autosave is implemented in 4.2 |
954 | 954 | |
955 | - //take care of updating any selected page_template IF this cpt supports it. |
|
956 | - if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
957 | - //wp version aware. |
|
958 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
959 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
960 | - } else { |
|
961 | - $post->page_template = $this->_req_data['page_template']; |
|
962 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
963 | - } |
|
964 | - if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
965 | - EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
966 | - } else { |
|
967 | - update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
968 | - } |
|
969 | - } |
|
970 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
971 | - return; |
|
972 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
973 | - $this->_insert_update_cpt_item($post_id, $post); |
|
974 | - } |
|
975 | - |
|
976 | - |
|
977 | - |
|
978 | - /** |
|
979 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
980 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
981 | - * so we don't have to check for our CPT. |
|
982 | - * |
|
983 | - * @param int $post_id ID of the post |
|
984 | - * @return void |
|
985 | - */ |
|
986 | - public function dont_permanently_delete_ee_cpts($post_id) |
|
987 | - { |
|
988 | - //only do this if we're actually processing one of our CPTs |
|
989 | - //if our cpt object isn't existent then get out immediately. |
|
990 | - if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
991 | - return; |
|
992 | - } |
|
993 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
994 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
995 | - //our cpts may have comments so let's take care of that too |
|
996 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
997 | - } |
|
998 | - |
|
999 | - |
|
1000 | - |
|
1001 | - /** |
|
1002 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1003 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1004 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1005 | - * |
|
1006 | - * @param int $post_id ID of cpt item |
|
1007 | - * @param int $revision_id ID of revision being restored |
|
1008 | - * @return void |
|
1009 | - */ |
|
1010 | - public function restore_revision($post_id, $revision_id) |
|
1011 | - { |
|
1012 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
1013 | - //global action |
|
1014 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1015 | - //class specific action so you can limit hooking into a specific page. |
|
1016 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1017 | - } |
|
1018 | - |
|
1019 | - |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * @see restore_revision() for details |
|
1023 | - * @param int $post_id ID of cpt item |
|
1024 | - * @param int $revision_id ID of revision for item |
|
1025 | - * @return void |
|
1026 | - */ |
|
1027 | - abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1028 | - |
|
1029 | - |
|
1030 | - |
|
1031 | - /** |
|
1032 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1033 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1034 | - * To fix we have to reset the current_screen using the page_slug |
|
1035 | - * (which is identical - or should be - to our registered_post_type id.) |
|
1036 | - * Also, since the core WP file loads the admin_header.php for WP |
|
1037 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1038 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1039 | - * |
|
1040 | - * @return void |
|
1041 | - */ |
|
1042 | - public function modify_current_screen() |
|
1043 | - { |
|
1044 | - //ONLY do this if the current page_route IS a cpt route |
|
1045 | - if ( ! $this->_cpt_route) { |
|
1046 | - return; |
|
1047 | - } |
|
1048 | - //routing things REALLY early b/c this is a cpt admin page |
|
1049 | - set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1050 | - $this->_current_screen = get_current_screen(); |
|
1051 | - $this->_current_screen->base = 'event-espresso'; |
|
1052 | - $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
1053 | - /*try { |
|
955 | + //take care of updating any selected page_template IF this cpt supports it. |
|
956 | + if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
957 | + //wp version aware. |
|
958 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
959 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
960 | + } else { |
|
961 | + $post->page_template = $this->_req_data['page_template']; |
|
962 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
963 | + } |
|
964 | + if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
965 | + EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
966 | + } else { |
|
967 | + update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
968 | + } |
|
969 | + } |
|
970 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
971 | + return; |
|
972 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
973 | + $this->_insert_update_cpt_item($post_id, $post); |
|
974 | + } |
|
975 | + |
|
976 | + |
|
977 | + |
|
978 | + /** |
|
979 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
980 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
981 | + * so we don't have to check for our CPT. |
|
982 | + * |
|
983 | + * @param int $post_id ID of the post |
|
984 | + * @return void |
|
985 | + */ |
|
986 | + public function dont_permanently_delete_ee_cpts($post_id) |
|
987 | + { |
|
988 | + //only do this if we're actually processing one of our CPTs |
|
989 | + //if our cpt object isn't existent then get out immediately. |
|
990 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
991 | + return; |
|
992 | + } |
|
993 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
994 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
995 | + //our cpts may have comments so let's take care of that too |
|
996 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
997 | + } |
|
998 | + |
|
999 | + |
|
1000 | + |
|
1001 | + /** |
|
1002 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1003 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1004 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1005 | + * |
|
1006 | + * @param int $post_id ID of cpt item |
|
1007 | + * @param int $revision_id ID of revision being restored |
|
1008 | + * @return void |
|
1009 | + */ |
|
1010 | + public function restore_revision($post_id, $revision_id) |
|
1011 | + { |
|
1012 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
1013 | + //global action |
|
1014 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1015 | + //class specific action so you can limit hooking into a specific page. |
|
1016 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1017 | + } |
|
1018 | + |
|
1019 | + |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * @see restore_revision() for details |
|
1023 | + * @param int $post_id ID of cpt item |
|
1024 | + * @param int $revision_id ID of revision for item |
|
1025 | + * @return void |
|
1026 | + */ |
|
1027 | + abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1028 | + |
|
1029 | + |
|
1030 | + |
|
1031 | + /** |
|
1032 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1033 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1034 | + * To fix we have to reset the current_screen using the page_slug |
|
1035 | + * (which is identical - or should be - to our registered_post_type id.) |
|
1036 | + * Also, since the core WP file loads the admin_header.php for WP |
|
1037 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1038 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1039 | + * |
|
1040 | + * @return void |
|
1041 | + */ |
|
1042 | + public function modify_current_screen() |
|
1043 | + { |
|
1044 | + //ONLY do this if the current page_route IS a cpt route |
|
1045 | + if ( ! $this->_cpt_route) { |
|
1046 | + return; |
|
1047 | + } |
|
1048 | + //routing things REALLY early b/c this is a cpt admin page |
|
1049 | + set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1050 | + $this->_current_screen = get_current_screen(); |
|
1051 | + $this->_current_screen->base = 'event-espresso'; |
|
1052 | + $this->_add_help_tabs(); //we make sure we add any help tabs back in! |
|
1053 | + /*try { |
|
1054 | 1054 | $this->_route_admin_request(); |
1055 | 1055 | } catch ( EE_Error $e ) { |
1056 | 1056 | $e->get_error(); |
1057 | 1057 | }/**/ |
1058 | - } |
|
1059 | - |
|
1060 | - |
|
1061 | - |
|
1062 | - /** |
|
1063 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1064 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1065 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1066 | - * default to be. |
|
1067 | - * |
|
1068 | - * @param string $title The new title (or existing if there is no editor_title defined) |
|
1069 | - * @return string |
|
1070 | - */ |
|
1071 | - public function add_custom_editor_default_title($title) |
|
1072 | - { |
|
1073 | - return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1074 | - ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1075 | - : $title; |
|
1076 | - } |
|
1077 | - |
|
1078 | - |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1082 | - * |
|
1083 | - * @param string $shortlink The already generated shortlink |
|
1084 | - * @param int $id Post ID for this item |
|
1085 | - * @param string $context The context for the link |
|
1086 | - * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1087 | - * @return string |
|
1088 | - */ |
|
1089 | - public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1090 | - { |
|
1091 | - if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1092 | - $post = get_post($id); |
|
1093 | - if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1094 | - $shortlink = home_url('?p=' . $post->ID); |
|
1095 | - } |
|
1096 | - } |
|
1097 | - return $shortlink; |
|
1098 | - } |
|
1099 | - |
|
1100 | - |
|
1101 | - |
|
1102 | - /** |
|
1103 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1104 | - * already run in modify_current_screen()) |
|
1105 | - * |
|
1106 | - * @return void |
|
1107 | - */ |
|
1108 | - public function route_admin_request() |
|
1109 | - { |
|
1110 | - if ($this->_cpt_route) { |
|
1111 | - return; |
|
1112 | - } |
|
1113 | - try { |
|
1114 | - $this->_route_admin_request(); |
|
1115 | - } catch (EE_Error $e) { |
|
1116 | - $e->get_error(); |
|
1117 | - } |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1124 | - * |
|
1125 | - * @return void |
|
1126 | - */ |
|
1127 | - public function cpt_post_form_hidden_input() |
|
1128 | - { |
|
1129 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1130 | - //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1131 | - echo '<div id="ee-cpt-hidden-inputs">'; |
|
1132 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1133 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1134 | - echo '</div>'; |
|
1135 | - } |
|
1136 | - |
|
1137 | - |
|
1138 | - |
|
1139 | - /** |
|
1140 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1141 | - * |
|
1142 | - * @param string $location Original location url |
|
1143 | - * @param int $status Status for http header |
|
1144 | - * @return string new (or original) url to redirect to. |
|
1145 | - */ |
|
1146 | - public function revision_redirect($location, $status) |
|
1147 | - { |
|
1148 | - //get revision |
|
1149 | - $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1150 | - //can't do anything without revision so let's get out if not present |
|
1151 | - if (empty($rev_id)) { |
|
1152 | - return $location; |
|
1153 | - } |
|
1154 | - //get rev_post_data |
|
1155 | - $rev = get_post($rev_id); |
|
1156 | - $admin_url = $this->_admin_base_url; |
|
1157 | - $query_args = array( |
|
1158 | - 'action' => 'edit', |
|
1159 | - 'post' => $rev->post_parent, |
|
1160 | - 'revision' => $rev_id, |
|
1161 | - 'message' => 5, |
|
1162 | - ); |
|
1163 | - $this->_process_notices($query_args, true); |
|
1164 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1165 | - } |
|
1166 | - |
|
1167 | - |
|
1168 | - |
|
1169 | - /** |
|
1170 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1171 | - * |
|
1172 | - * @param string $link the original generated link |
|
1173 | - * @param int $id post id |
|
1174 | - * @param string $context optional, defaults to display. How to write the '&' |
|
1175 | - * @return string the link |
|
1176 | - */ |
|
1177 | - public function modify_edit_post_link($link, $id, $context) |
|
1178 | - { |
|
1179 | - $post = get_post($id); |
|
1180 | - if ( ! isset($this->_req_data['action']) |
|
1181 | - || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1182 | - || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1183 | - ) { |
|
1184 | - return $link; |
|
1185 | - } |
|
1186 | - $query_args = array( |
|
1187 | - 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1188 | - ? $this->_cpt_edit_routes[$post->post_type] |
|
1189 | - : 'edit', |
|
1190 | - 'post' => $id, |
|
1191 | - ); |
|
1192 | - return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1193 | - } |
|
1194 | - |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1198 | - * our routes. |
|
1199 | - * |
|
1200 | - * @param string $delete_link original delete link |
|
1201 | - * @param int $post_id id of cpt object |
|
1202 | - * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1203 | - * @return string new delete link |
|
1204 | - * @throws EE_Error |
|
1205 | - */ |
|
1206 | - public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1207 | - { |
|
1208 | - $post = get_post($post_id); |
|
1209 | - |
|
1210 | - if (empty($this->_req_data['action']) |
|
1211 | - || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1212 | - || ! $post instanceof WP_Post |
|
1213 | - || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1214 | - ) { |
|
1215 | - return $delete_link; |
|
1216 | - } |
|
1217 | - $this->_set_model_object($post->ID, true); |
|
1218 | - |
|
1219 | - //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1220 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1221 | - |
|
1222 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
1223 | - array( |
|
1224 | - 'page' => $this->_req_data['page'], |
|
1225 | - 'action' => $action, |
|
1226 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1227 | - => $post->ID |
|
1228 | - ), |
|
1229 | - admin_url() |
|
1230 | - ); |
|
1231 | - } |
|
1232 | - |
|
1233 | - |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1237 | - * so that we can hijack the default redirect locations for wp custom post types |
|
1238 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1239 | - * |
|
1240 | - * @param string $location This is the incoming currently set redirect location |
|
1241 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1242 | - * @return string the new location to redirect to |
|
1243 | - */ |
|
1244 | - public function cpt_post_location_redirect($location, $post_id) |
|
1245 | - { |
|
1246 | - //we DO have a match so let's setup the url |
|
1247 | - //we have to get the post to determine our route |
|
1248 | - $post = get_post($post_id); |
|
1249 | - $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1250 | - //shared query_args |
|
1251 | - $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1252 | - $admin_url = $this->_admin_base_url; |
|
1253 | - if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1254 | - $status = get_post_status($post_id); |
|
1255 | - if (isset($this->_req_data['publish'])) { |
|
1256 | - switch ($status) { |
|
1257 | - case 'pending': |
|
1258 | - $message = 8; |
|
1259 | - break; |
|
1260 | - case 'future': |
|
1261 | - $message = 9; |
|
1262 | - break; |
|
1263 | - default: |
|
1264 | - $message = 6; |
|
1265 | - } |
|
1266 | - } else { |
|
1267 | - $message = 'draft' === $status ? 10 : 1; |
|
1268 | - } |
|
1269 | - } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1270 | - $message = 2; |
|
1271 | - // $append = '#postcustom'; |
|
1272 | - } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1273 | - $message = 3; |
|
1274 | - // $append = '#postcustom'; |
|
1275 | - } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1276 | - $message = 7; |
|
1277 | - } else { |
|
1278 | - $message = 4; |
|
1279 | - } |
|
1280 | - //change the message if the post type is not viewable on the frontend |
|
1281 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
1282 | - $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1283 | - $query_args = array_merge(array('message' => $message), $query_args); |
|
1284 | - $this->_process_notices($query_args, true); |
|
1285 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1286 | - } |
|
1287 | - |
|
1288 | - |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * This method is called to inject nav tabs on core WP cpt pages |
|
1292 | - * |
|
1293 | - * @access public |
|
1294 | - * @return void |
|
1295 | - */ |
|
1296 | - public function inject_nav_tabs() |
|
1297 | - { |
|
1298 | - //can we hijack and insert the nav_tabs? |
|
1299 | - $nav_tabs = $this->_get_main_nav_tabs(); |
|
1300 | - //first close off existing form tag |
|
1301 | - $html = '>'; |
|
1302 | - $html .= $nav_tabs; |
|
1303 | - //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1304 | - $html .= '<span></span'; |
|
1305 | - echo $html; |
|
1306 | - } |
|
1307 | - |
|
1308 | - |
|
1309 | - |
|
1310 | - /** |
|
1311 | - * This just sets up the post update messages when an update form is loaded |
|
1312 | - * |
|
1313 | - * @access public |
|
1314 | - * @param array $messages the original messages array |
|
1315 | - * @return array the new messages array |
|
1316 | - */ |
|
1317 | - public function post_update_messages($messages) |
|
1318 | - { |
|
1319 | - global $post; |
|
1320 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1321 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1322 | - // $post_type = $post ? $post->post_type : false; |
|
1323 | - /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1058 | + } |
|
1059 | + |
|
1060 | + |
|
1061 | + |
|
1062 | + /** |
|
1063 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1064 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1065 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1066 | + * default to be. |
|
1067 | + * |
|
1068 | + * @param string $title The new title (or existing if there is no editor_title defined) |
|
1069 | + * @return string |
|
1070 | + */ |
|
1071 | + public function add_custom_editor_default_title($title) |
|
1072 | + { |
|
1073 | + return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1074 | + ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1075 | + : $title; |
|
1076 | + } |
|
1077 | + |
|
1078 | + |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1082 | + * |
|
1083 | + * @param string $shortlink The already generated shortlink |
|
1084 | + * @param int $id Post ID for this item |
|
1085 | + * @param string $context The context for the link |
|
1086 | + * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1087 | + * @return string |
|
1088 | + */ |
|
1089 | + public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1090 | + { |
|
1091 | + if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1092 | + $post = get_post($id); |
|
1093 | + if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1094 | + $shortlink = home_url('?p=' . $post->ID); |
|
1095 | + } |
|
1096 | + } |
|
1097 | + return $shortlink; |
|
1098 | + } |
|
1099 | + |
|
1100 | + |
|
1101 | + |
|
1102 | + /** |
|
1103 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1104 | + * already run in modify_current_screen()) |
|
1105 | + * |
|
1106 | + * @return void |
|
1107 | + */ |
|
1108 | + public function route_admin_request() |
|
1109 | + { |
|
1110 | + if ($this->_cpt_route) { |
|
1111 | + return; |
|
1112 | + } |
|
1113 | + try { |
|
1114 | + $this->_route_admin_request(); |
|
1115 | + } catch (EE_Error $e) { |
|
1116 | + $e->get_error(); |
|
1117 | + } |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1124 | + * |
|
1125 | + * @return void |
|
1126 | + */ |
|
1127 | + public function cpt_post_form_hidden_input() |
|
1128 | + { |
|
1129 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1130 | + //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1131 | + echo '<div id="ee-cpt-hidden-inputs">'; |
|
1132 | + echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1133 | + echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1134 | + echo '</div>'; |
|
1135 | + } |
|
1136 | + |
|
1137 | + |
|
1138 | + |
|
1139 | + /** |
|
1140 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1141 | + * |
|
1142 | + * @param string $location Original location url |
|
1143 | + * @param int $status Status for http header |
|
1144 | + * @return string new (or original) url to redirect to. |
|
1145 | + */ |
|
1146 | + public function revision_redirect($location, $status) |
|
1147 | + { |
|
1148 | + //get revision |
|
1149 | + $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1150 | + //can't do anything without revision so let's get out if not present |
|
1151 | + if (empty($rev_id)) { |
|
1152 | + return $location; |
|
1153 | + } |
|
1154 | + //get rev_post_data |
|
1155 | + $rev = get_post($rev_id); |
|
1156 | + $admin_url = $this->_admin_base_url; |
|
1157 | + $query_args = array( |
|
1158 | + 'action' => 'edit', |
|
1159 | + 'post' => $rev->post_parent, |
|
1160 | + 'revision' => $rev_id, |
|
1161 | + 'message' => 5, |
|
1162 | + ); |
|
1163 | + $this->_process_notices($query_args, true); |
|
1164 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1165 | + } |
|
1166 | + |
|
1167 | + |
|
1168 | + |
|
1169 | + /** |
|
1170 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1171 | + * |
|
1172 | + * @param string $link the original generated link |
|
1173 | + * @param int $id post id |
|
1174 | + * @param string $context optional, defaults to display. How to write the '&' |
|
1175 | + * @return string the link |
|
1176 | + */ |
|
1177 | + public function modify_edit_post_link($link, $id, $context) |
|
1178 | + { |
|
1179 | + $post = get_post($id); |
|
1180 | + if ( ! isset($this->_req_data['action']) |
|
1181 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1182 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1183 | + ) { |
|
1184 | + return $link; |
|
1185 | + } |
|
1186 | + $query_args = array( |
|
1187 | + 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1188 | + ? $this->_cpt_edit_routes[$post->post_type] |
|
1189 | + : 'edit', |
|
1190 | + 'post' => $id, |
|
1191 | + ); |
|
1192 | + return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1193 | + } |
|
1194 | + |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1198 | + * our routes. |
|
1199 | + * |
|
1200 | + * @param string $delete_link original delete link |
|
1201 | + * @param int $post_id id of cpt object |
|
1202 | + * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1203 | + * @return string new delete link |
|
1204 | + * @throws EE_Error |
|
1205 | + */ |
|
1206 | + public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1207 | + { |
|
1208 | + $post = get_post($post_id); |
|
1209 | + |
|
1210 | + if (empty($this->_req_data['action']) |
|
1211 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1212 | + || ! $post instanceof WP_Post |
|
1213 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1214 | + ) { |
|
1215 | + return $delete_link; |
|
1216 | + } |
|
1217 | + $this->_set_model_object($post->ID, true); |
|
1218 | + |
|
1219 | + //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1220 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1221 | + |
|
1222 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
1223 | + array( |
|
1224 | + 'page' => $this->_req_data['page'], |
|
1225 | + 'action' => $action, |
|
1226 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1227 | + => $post->ID |
|
1228 | + ), |
|
1229 | + admin_url() |
|
1230 | + ); |
|
1231 | + } |
|
1232 | + |
|
1233 | + |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1237 | + * so that we can hijack the default redirect locations for wp custom post types |
|
1238 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1239 | + * |
|
1240 | + * @param string $location This is the incoming currently set redirect location |
|
1241 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1242 | + * @return string the new location to redirect to |
|
1243 | + */ |
|
1244 | + public function cpt_post_location_redirect($location, $post_id) |
|
1245 | + { |
|
1246 | + //we DO have a match so let's setup the url |
|
1247 | + //we have to get the post to determine our route |
|
1248 | + $post = get_post($post_id); |
|
1249 | + $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1250 | + //shared query_args |
|
1251 | + $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1252 | + $admin_url = $this->_admin_base_url; |
|
1253 | + if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1254 | + $status = get_post_status($post_id); |
|
1255 | + if (isset($this->_req_data['publish'])) { |
|
1256 | + switch ($status) { |
|
1257 | + case 'pending': |
|
1258 | + $message = 8; |
|
1259 | + break; |
|
1260 | + case 'future': |
|
1261 | + $message = 9; |
|
1262 | + break; |
|
1263 | + default: |
|
1264 | + $message = 6; |
|
1265 | + } |
|
1266 | + } else { |
|
1267 | + $message = 'draft' === $status ? 10 : 1; |
|
1268 | + } |
|
1269 | + } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1270 | + $message = 2; |
|
1271 | + // $append = '#postcustom'; |
|
1272 | + } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1273 | + $message = 3; |
|
1274 | + // $append = '#postcustom'; |
|
1275 | + } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1276 | + $message = 7; |
|
1277 | + } else { |
|
1278 | + $message = 4; |
|
1279 | + } |
|
1280 | + //change the message if the post type is not viewable on the frontend |
|
1281 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
1282 | + $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1283 | + $query_args = array_merge(array('message' => $message), $query_args); |
|
1284 | + $this->_process_notices($query_args, true); |
|
1285 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1286 | + } |
|
1287 | + |
|
1288 | + |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * This method is called to inject nav tabs on core WP cpt pages |
|
1292 | + * |
|
1293 | + * @access public |
|
1294 | + * @return void |
|
1295 | + */ |
|
1296 | + public function inject_nav_tabs() |
|
1297 | + { |
|
1298 | + //can we hijack and insert the nav_tabs? |
|
1299 | + $nav_tabs = $this->_get_main_nav_tabs(); |
|
1300 | + //first close off existing form tag |
|
1301 | + $html = '>'; |
|
1302 | + $html .= $nav_tabs; |
|
1303 | + //now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1304 | + $html .= '<span></span'; |
|
1305 | + echo $html; |
|
1306 | + } |
|
1307 | + |
|
1308 | + |
|
1309 | + |
|
1310 | + /** |
|
1311 | + * This just sets up the post update messages when an update form is loaded |
|
1312 | + * |
|
1313 | + * @access public |
|
1314 | + * @param array $messages the original messages array |
|
1315 | + * @return array the new messages array |
|
1316 | + */ |
|
1317 | + public function post_update_messages($messages) |
|
1318 | + { |
|
1319 | + global $post; |
|
1320 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1321 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1322 | + // $post_type = $post ? $post->post_type : false; |
|
1323 | + /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1324 | 1324 | |
1325 | 1325 | $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/ |
1326 | - $messages[$post->post_type] = array( |
|
1327 | - 0 => '', //Unused. Messages start at index 1. |
|
1328 | - 1 => sprintf( |
|
1329 | - __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1330 | - $this->_cpt_object->labels->singular_name, |
|
1331 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1332 | - '</a>' |
|
1333 | - ), |
|
1334 | - 2 => __('Custom field updated'), |
|
1335 | - 3 => __('Custom field deleted.'), |
|
1336 | - 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1337 | - 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
1338 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1339 | - : false, |
|
1340 | - 6 => sprintf( |
|
1341 | - __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1342 | - $this->_cpt_object->labels->singular_name, |
|
1343 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1344 | - '</a>' |
|
1345 | - ), |
|
1346 | - 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1347 | - 8 => sprintf( |
|
1348 | - __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1349 | - $this->_cpt_object->labels->singular_name, |
|
1350 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1351 | - '</a>' |
|
1352 | - ), |
|
1353 | - 9 => sprintf( |
|
1354 | - __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1355 | - $this->_cpt_object->labels->singular_name, |
|
1356 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1357 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1358 | - '</a>' |
|
1359 | - ), |
|
1360 | - 10 => sprintf( |
|
1361 | - __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1362 | - $this->_cpt_object->labels->singular_name, |
|
1363 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1364 | - '</a>' |
|
1365 | - ), |
|
1366 | - ); |
|
1367 | - return $messages; |
|
1368 | - } |
|
1369 | - |
|
1370 | - |
|
1371 | - |
|
1372 | - /** |
|
1373 | - * default method for the 'create_new' route for cpt admin pages. |
|
1374 | - * For reference what to include in here, see wp-admin/post-new.php |
|
1375 | - * |
|
1376 | - * @access protected |
|
1377 | - * @return void |
|
1378 | - */ |
|
1379 | - protected function _create_new_cpt_item() |
|
1380 | - { |
|
1381 | - // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1382 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1383 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1384 | - $post_type_object = $this->_cpt_object; |
|
1385 | - $title = $post_type_object->labels->add_new_item; |
|
1386 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1387 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1388 | - //modify the default editor title field with default title. |
|
1389 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1390 | - $this->loadEditorTemplate(true); |
|
1391 | - } |
|
1392 | - |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * Enqueues auto-save and loads the editor template |
|
1396 | - * |
|
1397 | - * @param bool $creating |
|
1398 | - */ |
|
1399 | - private function loadEditorTemplate($creating = true) { |
|
1400 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1401 | - //these vars are used by the template |
|
1402 | - $editing = true; |
|
1403 | - $post_ID = $post->ID; |
|
1404 | - if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1405 | - //only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1406 | - //otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1407 | - if ($creating) { |
|
1408 | - wp_enqueue_script('autosave'); |
|
1409 | - } else { |
|
1410 | - if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1411 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1412 | - ) { |
|
1413 | - $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1414 | - 'create_new', $this); |
|
1415 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1416 | - 'action' => $create_new_action, |
|
1417 | - 'page' => $this->page_slug, |
|
1418 | - ), 'admin.php'); |
|
1419 | - } |
|
1420 | - } |
|
1421 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1422 | - } |
|
1423 | - } |
|
1424 | - |
|
1425 | - |
|
1426 | - |
|
1427 | - public function add_new_admin_page_global() |
|
1428 | - { |
|
1429 | - $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1430 | - ?> |
|
1326 | + $messages[$post->post_type] = array( |
|
1327 | + 0 => '', //Unused. Messages start at index 1. |
|
1328 | + 1 => sprintf( |
|
1329 | + __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1330 | + $this->_cpt_object->labels->singular_name, |
|
1331 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1332 | + '</a>' |
|
1333 | + ), |
|
1334 | + 2 => __('Custom field updated'), |
|
1335 | + 3 => __('Custom field deleted.'), |
|
1336 | + 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1337 | + 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
|
1338 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1339 | + : false, |
|
1340 | + 6 => sprintf( |
|
1341 | + __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1342 | + $this->_cpt_object->labels->singular_name, |
|
1343 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1344 | + '</a>' |
|
1345 | + ), |
|
1346 | + 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1347 | + 8 => sprintf( |
|
1348 | + __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1349 | + $this->_cpt_object->labels->singular_name, |
|
1350 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1351 | + '</a>' |
|
1352 | + ), |
|
1353 | + 9 => sprintf( |
|
1354 | + __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1355 | + $this->_cpt_object->labels->singular_name, |
|
1356 | + '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1357 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1358 | + '</a>' |
|
1359 | + ), |
|
1360 | + 10 => sprintf( |
|
1361 | + __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1362 | + $this->_cpt_object->labels->singular_name, |
|
1363 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1364 | + '</a>' |
|
1365 | + ), |
|
1366 | + ); |
|
1367 | + return $messages; |
|
1368 | + } |
|
1369 | + |
|
1370 | + |
|
1371 | + |
|
1372 | + /** |
|
1373 | + * default method for the 'create_new' route for cpt admin pages. |
|
1374 | + * For reference what to include in here, see wp-admin/post-new.php |
|
1375 | + * |
|
1376 | + * @access protected |
|
1377 | + * @return void |
|
1378 | + */ |
|
1379 | + protected function _create_new_cpt_item() |
|
1380 | + { |
|
1381 | + // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1382 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1383 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1384 | + $post_type_object = $this->_cpt_object; |
|
1385 | + $title = $post_type_object->labels->add_new_item; |
|
1386 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1387 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1388 | + //modify the default editor title field with default title. |
|
1389 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1390 | + $this->loadEditorTemplate(true); |
|
1391 | + } |
|
1392 | + |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * Enqueues auto-save and loads the editor template |
|
1396 | + * |
|
1397 | + * @param bool $creating |
|
1398 | + */ |
|
1399 | + private function loadEditorTemplate($creating = true) { |
|
1400 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1401 | + //these vars are used by the template |
|
1402 | + $editing = true; |
|
1403 | + $post_ID = $post->ID; |
|
1404 | + if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1405 | + //only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1406 | + //otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1407 | + if ($creating) { |
|
1408 | + wp_enqueue_script('autosave'); |
|
1409 | + } else { |
|
1410 | + if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1411 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1412 | + ) { |
|
1413 | + $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1414 | + 'create_new', $this); |
|
1415 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1416 | + 'action' => $create_new_action, |
|
1417 | + 'page' => $this->page_slug, |
|
1418 | + ), 'admin.php'); |
|
1419 | + } |
|
1420 | + } |
|
1421 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1422 | + } |
|
1423 | + } |
|
1424 | + |
|
1425 | + |
|
1426 | + |
|
1427 | + public function add_new_admin_page_global() |
|
1428 | + { |
|
1429 | + $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1430 | + ?> |
|
1431 | 1431 | <script type="text/javascript"> |
1432 | 1432 | adminpage = '<?php echo $admin_page; ?>'; |
1433 | 1433 | </script> |
1434 | 1434 | <?php |
1435 | - } |
|
1436 | - |
|
1437 | - |
|
1438 | - |
|
1439 | - /** |
|
1440 | - * default method for the 'edit' route for cpt admin pages |
|
1441 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
1442 | - * |
|
1443 | - * @access protected |
|
1444 | - * @return string template for edit cpt form |
|
1445 | - */ |
|
1446 | - protected function _edit_cpt_item() |
|
1447 | - { |
|
1448 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1449 | - $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1450 | - $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1451 | - if (empty ($post)) { |
|
1452 | - wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
1453 | - } |
|
1454 | - if ( ! empty($_GET['get-post-lock'])) { |
|
1455 | - wp_set_post_lock($post_id); |
|
1456 | - wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1457 | - exit(); |
|
1458 | - } |
|
1459 | - |
|
1460 | - // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1461 | - $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1462 | - $post_type_object = $this->_cpt_object; |
|
1463 | - |
|
1464 | - if ( ! wp_check_post_lock($post->ID)) { |
|
1465 | - wp_set_post_lock($post->ID); |
|
1466 | - } |
|
1467 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
1468 | - if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1469 | - wp_enqueue_script('admin-comments'); |
|
1470 | - enqueue_comment_hotkeys_js(); |
|
1471 | - } |
|
1472 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1473 | - //modify the default editor title field with default title. |
|
1474 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1475 | - $this->loadEditorTemplate(false); |
|
1476 | - } |
|
1477 | - |
|
1478 | - |
|
1479 | - |
|
1480 | - /** |
|
1481 | - * some getters |
|
1482 | - */ |
|
1483 | - /** |
|
1484 | - * This returns the protected _cpt_model_obj property |
|
1485 | - * |
|
1486 | - * @return EE_CPT_Base |
|
1487 | - */ |
|
1488 | - public function get_cpt_model_obj() |
|
1489 | - { |
|
1490 | - return $this->_cpt_model_obj; |
|
1491 | - } |
|
1435 | + } |
|
1436 | + |
|
1437 | + |
|
1438 | + |
|
1439 | + /** |
|
1440 | + * default method for the 'edit' route for cpt admin pages |
|
1441 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
1442 | + * |
|
1443 | + * @access protected |
|
1444 | + * @return string template for edit cpt form |
|
1445 | + */ |
|
1446 | + protected function _edit_cpt_item() |
|
1447 | + { |
|
1448 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1449 | + $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1450 | + $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1451 | + if (empty ($post)) { |
|
1452 | + wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?')); |
|
1453 | + } |
|
1454 | + if ( ! empty($_GET['get-post-lock'])) { |
|
1455 | + wp_set_post_lock($post_id); |
|
1456 | + wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1457 | + exit(); |
|
1458 | + } |
|
1459 | + |
|
1460 | + // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1461 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1462 | + $post_type_object = $this->_cpt_object; |
|
1463 | + |
|
1464 | + if ( ! wp_check_post_lock($post->ID)) { |
|
1465 | + wp_set_post_lock($post->ID); |
|
1466 | + } |
|
1467 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
1468 | + if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1469 | + wp_enqueue_script('admin-comments'); |
|
1470 | + enqueue_comment_hotkeys_js(); |
|
1471 | + } |
|
1472 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1473 | + //modify the default editor title field with default title. |
|
1474 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1475 | + $this->loadEditorTemplate(false); |
|
1476 | + } |
|
1477 | + |
|
1478 | + |
|
1479 | + |
|
1480 | + /** |
|
1481 | + * some getters |
|
1482 | + */ |
|
1483 | + /** |
|
1484 | + * This returns the protected _cpt_model_obj property |
|
1485 | + * |
|
1486 | + * @return EE_CPT_Base |
|
1487 | + */ |
|
1488 | + public function get_cpt_model_obj() |
|
1489 | + { |
|
1490 | + return $this->_cpt_model_obj; |
|
1491 | + } |
|
1492 | 1492 | |
1493 | 1493 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | protected function _register_autosave_containers($ids) |
241 | 241 | { |
242 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids); |
|
242 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | //filter _autosave_containers |
287 | 287 | $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
288 | 288 | $this->_autosave_containers, $this); |
289 | - $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
289 | + $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers', |
|
290 | 290 | $containers, $this); |
291 | 291 | |
292 | 292 | wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS', |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | // This is for any plugins that are doing things properly |
399 | 399 | // and hooking into the load page hook for core wp cpt routes. |
400 | 400 | global $pagenow; |
401 | - do_action('load-' . $pagenow); |
|
401 | + do_action('load-'.$pagenow); |
|
402 | 402 | $this->modify_current_screen(); |
403 | 403 | add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
404 | 404 | //we route REALLY early. |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | 'admin.php?page=espresso_registrations&action=contact_list', |
430 | 430 | ), |
431 | 431 | 1 => array( |
432 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
433 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
432 | + 'edit.php?post_type='.$this->_cpt_object->name, |
|
433 | + 'admin.php?page='.$this->_cpt_object->name, |
|
434 | 434 | ), |
435 | 435 | ); |
436 | 436 | foreach ($routes_to_match as $route_matches) { |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | $cpt_has_support = ! empty($cpt_args['page_templates']); |
459 | 459 | |
460 | 460 | //if the installed version of WP is > 4.7 we do some additional checks. |
461 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
461 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
462 | 462 | $post_templates = wp_get_theme()->get_post_templates(); |
463 | 463 | //if there are $post_templates for this cpt, then we return false for this method because |
464 | 464 | //that means we aren't going to load our page template manager and leave that up to the native |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | global $post; |
482 | 482 | $template = ''; |
483 | 483 | |
484 | - if (RecommendedVersions::compareWordPressVersion('4.7','>=')) { |
|
484 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
485 | 485 | $page_template_count = count(get_page_templates()); |
486 | 486 | } else { |
487 | 487 | $page_template_count = count(get_page_templates($post)); |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | $post = get_post($id); |
519 | 519 | if ('publish' !== get_post_status($post)) { |
520 | 520 | //include shims for the `get_preview_post_link` function |
521 | - require_once( EE_CORE . 'wordpress-shims.php' ); |
|
521 | + require_once(EE_CORE.'wordpress-shims.php'); |
|
522 | 522 | $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
523 | 523 | . get_preview_post_link($id) |
524 | 524 | . '" class="button button-small">' |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | $template_args['statuses'] = $statuses; |
557 | 557 | } |
558 | 558 | |
559 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
559 | + $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php'; |
|
560 | 560 | EEH_Template::display_template($template, $template_args); |
561 | 561 | } |
562 | 562 | |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | $this->_template_args['success'] = true; |
611 | 611 | } |
612 | 612 | do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
613 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
613 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this); |
|
614 | 614 | //now let's return json |
615 | 615 | $this->_return_json(); |
616 | 616 | } |
@@ -1013,7 +1013,7 @@ discard block |
||
1013 | 1013 | //global action |
1014 | 1014 | do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
1015 | 1015 | //class specific action so you can limit hooking into a specific page. |
1016 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1016 | + do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | 1019 | |
@@ -1091,7 +1091,7 @@ discard block |
||
1091 | 1091 | if ( ! empty($id) && get_option('permalink_structure') !== '') { |
1092 | 1092 | $post = get_post($id); |
1093 | 1093 | if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
1094 | - $shortlink = home_url('?p=' . $post->ID); |
|
1094 | + $shortlink = home_url('?p='.$post->ID); |
|
1095 | 1095 | } |
1096 | 1096 | } |
1097 | 1097 | return $shortlink; |
@@ -1126,11 +1126,11 @@ discard block |
||
1126 | 1126 | */ |
1127 | 1127 | public function cpt_post_form_hidden_input() |
1128 | 1128 | { |
1129 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1129 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />'; |
|
1130 | 1130 | //we're also going to add the route value and the current page so we can direct autosave parsing correctly |
1131 | 1131 | echo '<div id="ee-cpt-hidden-inputs">'; |
1132 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1133 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1132 | + echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />'; |
|
1133 | + echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />'; |
|
1134 | 1134 | echo '</div>'; |
1135 | 1135 | } |
1136 | 1136 | |
@@ -1217,7 +1217,7 @@ discard block |
||
1217 | 1217 | $this->_set_model_object($post->ID, true); |
1218 | 1218 | |
1219 | 1219 | //returns something like `trash_event` or `trash_attendee` or `trash_venue` |
1220 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1220 | + $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1221 | 1221 | |
1222 | 1222 | return EE_Admin_Page::add_query_args_and_nonce( |
1223 | 1223 | array( |
@@ -1328,39 +1328,39 @@ discard block |
||
1328 | 1328 | 1 => sprintf( |
1329 | 1329 | __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
1330 | 1330 | $this->_cpt_object->labels->singular_name, |
1331 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1331 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1332 | 1332 | '</a>' |
1333 | 1333 | ), |
1334 | 1334 | 2 => __('Custom field updated'), |
1335 | 1335 | 3 => __('Custom field deleted.'), |
1336 | 1336 | 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1337 | 1337 | 5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'), |
1338 | - $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false)) |
|
1338 | + $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false)) |
|
1339 | 1339 | : false, |
1340 | 1340 | 6 => sprintf( |
1341 | 1341 | __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
1342 | 1342 | $this->_cpt_object->labels->singular_name, |
1343 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1343 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1344 | 1344 | '</a>' |
1345 | 1345 | ), |
1346 | 1346 | 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1347 | 1347 | 8 => sprintf( |
1348 | 1348 | __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
1349 | 1349 | $this->_cpt_object->labels->singular_name, |
1350 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1350 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">', |
|
1351 | 1351 | '</a>' |
1352 | 1352 | ), |
1353 | 1353 | 9 => sprintf( |
1354 | 1354 | __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
1355 | 1355 | $this->_cpt_object->labels->singular_name, |
1356 | - '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>', |
|
1357 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1356 | + '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>', |
|
1357 | + '<a target="_blank" href="'.esc_url(get_permalink($id)), |
|
1358 | 1358 | '</a>' |
1359 | 1359 | ), |
1360 | 1360 | 10 => sprintf( |
1361 | 1361 | __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
1362 | 1362 | $this->_cpt_object->labels->singular_name, |
1363 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1363 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1364 | 1364 | '</a>' |
1365 | 1365 | ), |
1366 | 1366 | ); |
@@ -1383,7 +1383,7 @@ discard block |
||
1383 | 1383 | $post_type = $this->_cpt_routes[$this->_req_action]; |
1384 | 1384 | $post_type_object = $this->_cpt_object; |
1385 | 1385 | $title = $post_type_object->labels->add_new_item; |
1386 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1386 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1387 | 1387 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
1388 | 1388 | //modify the default editor title field with default title. |
1389 | 1389 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
@@ -1418,7 +1418,7 @@ discard block |
||
1418 | 1418 | ), 'admin.php'); |
1419 | 1419 | } |
1420 | 1420 | } |
1421 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1421 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
1422 | 1422 | } |
1423 | 1423 | } |
1424 | 1424 |
@@ -23,996 +23,996 @@ |
||
23 | 23 | class EED_Ticket_Sales_Monitor extends EED_Module |
24 | 24 | { |
25 | 25 | |
26 | - const debug = false; // true false |
|
27 | - |
|
28 | - /** |
|
29 | - * an array of raw ticket data from EED_Ticket_Selector |
|
30 | - * |
|
31 | - * @var array $ticket_selections |
|
32 | - */ |
|
33 | - protected $ticket_selections = array(); |
|
34 | - |
|
35 | - /** |
|
36 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
37 | - * according to how they are displayed in the actual Ticket_Selector |
|
38 | - * this tracks the current row being processed |
|
39 | - * |
|
40 | - * @var int $current_row |
|
41 | - */ |
|
42 | - protected $current_row = 0; |
|
43 | - |
|
44 | - /** |
|
45 | - * an array for tracking names of tickets that have sold out |
|
46 | - * |
|
47 | - * @var array $sold_out_tickets |
|
48 | - */ |
|
49 | - protected $sold_out_tickets = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * an array for tracking names of tickets that have had their quantities reduced |
|
53 | - * |
|
54 | - * @var array $decremented_tickets |
|
55 | - */ |
|
56 | - protected $decremented_tickets = array(); |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public static function set_hooks() |
|
66 | - { |
|
67 | - // release tickets for expired carts |
|
68 | - add_action( |
|
69 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
70 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
71 | - 1 |
|
72 | - ); |
|
73 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
74 | - add_filter( |
|
75 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
76 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
77 | - 20, |
|
78 | - 3 |
|
79 | - ); |
|
80 | - // add notices for sold out tickets |
|
81 | - add_action( |
|
82 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
83 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
84 | - 10 |
|
85 | - ); |
|
86 | - // handle ticket quantities adjusted in cart |
|
87 | - //add_action( |
|
88 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
89 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
90 | - // 10, 2 |
|
91 | - //); |
|
92 | - // handle tickets deleted from cart |
|
93 | - add_action( |
|
94 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
95 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
96 | - 10, |
|
97 | - 2 |
|
98 | - ); |
|
99 | - // handle emptied carts |
|
100 | - add_action( |
|
101 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
102 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
103 | - 10, |
|
104 | - 1 |
|
105 | - ); |
|
106 | - add_action( |
|
107 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
108 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
109 | - 10, |
|
110 | - 1 |
|
111 | - ); |
|
112 | - // handle cancelled registrations |
|
113 | - add_action( |
|
114 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
115 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
116 | - 10, |
|
117 | - 1 |
|
118 | - ); |
|
119 | - // cron tasks |
|
120 | - add_action( |
|
121 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
122 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
123 | - 10, |
|
124 | - 1 |
|
125 | - ); |
|
126 | - add_action( |
|
127 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
128 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
129 | - 10, |
|
130 | - 1 |
|
131 | - ); |
|
132 | - add_action( |
|
133 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
134 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
135 | - 10, |
|
136 | - 1 |
|
137 | - ); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
144 | - * |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - public static function set_hooks_admin() |
|
148 | - { |
|
149 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
156 | - */ |
|
157 | - public static function instance() |
|
158 | - { |
|
159 | - return parent::get_instance(__CLASS__); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @param WP_Query $WP_Query |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function run($WP_Query) |
|
169 | - { |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Retrieves grand totals from the line items that have no TXN ID |
|
180 | - * and timestamps less than the current time minus the session lifespan. |
|
181 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
182 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
183 | - * |
|
184 | - * @return void |
|
185 | - * @throws DomainException |
|
186 | - * @throws EE_Error |
|
187 | - * @throws InvalidArgumentException |
|
188 | - * @throws InvalidDataTypeException |
|
189 | - * @throws InvalidInterfaceException |
|
190 | - * @throws UnexpectedEntityException |
|
191 | - */ |
|
192 | - public static function release_tickets_for_expired_carts() |
|
193 | - { |
|
194 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
195 | - $expired_ticket_IDs = array(); |
|
196 | - $valid_ticket_line_items = array(); |
|
197 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
198 | - if (empty($total_line_items)) { |
|
199 | - do_action( |
|
200 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
201 | - $total_line_items, |
|
202 | - $valid_ticket_line_items, |
|
203 | - $expired_ticket_IDs |
|
204 | - ); |
|
205 | - return; |
|
206 | - } |
|
207 | - $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
208 | - foreach ($total_line_items as $total_line_item) { |
|
209 | - /** @var EE_Line_Item $total_line_item */ |
|
210 | - $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
211 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
212 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
213 | - continue; |
|
214 | - } |
|
215 | - if ($total_line_item->timestamp(true) <= $expired) { |
|
216 | - $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
217 | - } else { |
|
218 | - $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - if (! empty($expired_ticket_IDs)) { |
|
223 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
224 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
225 | - $valid_ticket_line_items |
|
226 | - ); |
|
227 | - // let's get rid of expired line items so that they can't interfere with tracking |
|
228 | - add_action( |
|
229 | - 'shutdown', |
|
230 | - array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
231 | - 999 |
|
232 | - ); |
|
233 | - } |
|
234 | - do_action( |
|
235 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
236 | - $total_line_items, |
|
237 | - $valid_ticket_line_items, |
|
238 | - $expired_ticket_IDs |
|
239 | - ); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
250 | - * |
|
251 | - * @param int $qty |
|
252 | - * @param EE_Ticket $ticket |
|
253 | - * @return bool |
|
254 | - * @throws UnexpectedEntityException |
|
255 | - * @throws EE_Error |
|
256 | - */ |
|
257 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
258 | - { |
|
259 | - $qty = absint($qty); |
|
260 | - if ($qty > 0) { |
|
261 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
262 | - } |
|
263 | - if (self::debug) { |
|
264 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
265 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
266 | - } |
|
267 | - return $qty; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
274 | - * |
|
275 | - * @param EE_Ticket $ticket |
|
276 | - * @param int $qty |
|
277 | - * @return int |
|
278 | - * @throws UnexpectedEntityException |
|
279 | - * @throws EE_Error |
|
280 | - */ |
|
281 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
282 | - { |
|
283 | - if (self::debug) { |
|
284 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
285 | - } |
|
286 | - if (! $ticket instanceof EE_Ticket) { |
|
287 | - return 0; |
|
288 | - } |
|
289 | - if (self::debug) { |
|
290 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
291 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
292 | - } |
|
293 | - $ticket->refresh_from_db(); |
|
294 | - // first let's determine the ticket availability based on sales |
|
295 | - $available = $ticket->qty('saleable'); |
|
296 | - if (self::debug) { |
|
297 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
298 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
299 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
300 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
301 | - echo '<br /> . . . available: ' . $available; |
|
302 | - } |
|
303 | - if ($available < 1) { |
|
304 | - $this->_ticket_sold_out($ticket); |
|
305 | - return 0; |
|
306 | - } |
|
307 | - if (self::debug) { |
|
308 | - echo '<br /> . . . qty: ' . $qty; |
|
309 | - } |
|
310 | - if ($available < $qty) { |
|
311 | - $qty = $available; |
|
312 | - if (self::debug) { |
|
313 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
314 | - } |
|
315 | - $this->_ticket_quantity_decremented($ticket); |
|
316 | - } |
|
317 | - $this->_reserve_ticket($ticket, $qty); |
|
318 | - return $qty; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * increments ticket reserved based on quantity passed |
|
325 | - * |
|
326 | - * @param EE_Ticket $ticket |
|
327 | - * @param int $quantity |
|
328 | - * @return bool |
|
329 | - * @throws EE_Error |
|
330 | - */ |
|
331 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
332 | - { |
|
333 | - if (self::debug) { |
|
334 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
335 | - } |
|
336 | - $ticket->increase_reserved($quantity); |
|
337 | - return $ticket->save(); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * @param EE_Ticket $ticket |
|
344 | - * @param int $quantity |
|
345 | - * @return bool |
|
346 | - * @throws EE_Error |
|
347 | - */ |
|
348 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
349 | - { |
|
350 | - if (self::debug) { |
|
351 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
352 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
353 | - } |
|
354 | - $ticket->decrease_reserved($quantity); |
|
355 | - if (self::debug) { |
|
356 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
357 | - } |
|
358 | - return $ticket->save() ? 1 : 0; |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * removes quantities within the ticket selector based on zero ticket availability |
|
365 | - * |
|
366 | - * @param EE_Ticket $ticket |
|
367 | - * @return void |
|
368 | - * @throws UnexpectedEntityException |
|
369 | - * @throws EE_Error |
|
370 | - */ |
|
371 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
372 | - { |
|
373 | - if (self::debug) { |
|
374 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
375 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
376 | - } |
|
377 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
384 | - * |
|
385 | - * @param EE_Ticket $ticket |
|
386 | - * @return void |
|
387 | - * @throws UnexpectedEntityException |
|
388 | - * @throws EE_Error |
|
389 | - */ |
|
390 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
391 | - { |
|
392 | - if (self::debug) { |
|
393 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
394 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
395 | - } |
|
396 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * builds string out of ticket and event name |
|
403 | - * |
|
404 | - * @param EE_Ticket $ticket |
|
405 | - * @return string |
|
406 | - * @throws UnexpectedEntityException |
|
407 | - * @throws EE_Error |
|
408 | - */ |
|
409 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
410 | - { |
|
411 | - $event = $ticket->get_related_event(); |
|
412 | - if ($event instanceof EE_Event) { |
|
413 | - $ticket_name = sprintf( |
|
414 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
415 | - $ticket->name(), |
|
416 | - $event->name() |
|
417 | - ); |
|
418 | - } else { |
|
419 | - $ticket_name = $ticket->name(); |
|
420 | - } |
|
421 | - return $ticket_name; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /********************************** EVENT CART **********************************/ |
|
427 | - |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * releases or reserves ticket(s) based on quantity passed |
|
432 | - * |
|
433 | - * @param EE_Line_Item $line_item |
|
434 | - * @param int $quantity |
|
435 | - * @return void |
|
436 | - * @throws EE_Error |
|
437 | - * @throws InvalidArgumentException |
|
438 | - * @throws InvalidDataTypeException |
|
439 | - * @throws InvalidInterfaceException |
|
440 | - */ |
|
441 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
442 | - { |
|
443 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
444 | - if ($ticket instanceof EE_Ticket) { |
|
445 | - if ($quantity > 0) { |
|
446 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
447 | - } else { |
|
448 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
449 | - } |
|
450 | - } |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * releases reserved ticket(s) based on quantity passed |
|
457 | - * |
|
458 | - * @param EE_Ticket $ticket |
|
459 | - * @param int $quantity |
|
460 | - * @return void |
|
461 | - * @throws EE_Error |
|
462 | - */ |
|
463 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
464 | - { |
|
465 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /********************************** POST_NOTICES **********************************/ |
|
471 | - |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * @return void |
|
476 | - * @throws EE_Error |
|
477 | - * @throws InvalidArgumentException |
|
478 | - * @throws ReflectionException |
|
479 | - * @throws InvalidDataTypeException |
|
480 | - * @throws InvalidInterfaceException |
|
481 | - */ |
|
482 | - public static function post_notices() |
|
483 | - { |
|
484 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * @return void |
|
491 | - * @throws EE_Error |
|
492 | - * @throws InvalidArgumentException |
|
493 | - * @throws ReflectionException |
|
494 | - * @throws InvalidDataTypeException |
|
495 | - * @throws InvalidInterfaceException |
|
496 | - */ |
|
497 | - protected function _post_notices() |
|
498 | - { |
|
499 | - if (self::debug) { |
|
500 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
501 | - } |
|
502 | - $refresh_msg = ''; |
|
503 | - $none_added_msg = ''; |
|
504 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
505 | - $refresh_msg = __( |
|
506 | - 'Please refresh the page to view updated ticket quantities.', |
|
507 | - 'event_espresso' |
|
508 | - ); |
|
509 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
510 | - } |
|
511 | - if (! empty($this->sold_out_tickets)) { |
|
512 | - EE_Error::add_attention( |
|
513 | - sprintf( |
|
514 | - apply_filters( |
|
515 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
516 | - __( |
|
517 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
518 | - 'event_espresso' |
|
519 | - ) |
|
520 | - ), |
|
521 | - '<br />', |
|
522 | - implode('<br />', $this->sold_out_tickets), |
|
523 | - $none_added_msg, |
|
524 | - $refresh_msg |
|
525 | - ) |
|
526 | - ); |
|
527 | - // alter code flow in the Ticket Selector for better UX |
|
528 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
529 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
530 | - $this->sold_out_tickets = array(); |
|
531 | - // and reset the cart |
|
532 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
533 | - } |
|
534 | - if (! empty($this->decremented_tickets)) { |
|
535 | - EE_Error::add_attention( |
|
536 | - sprintf( |
|
537 | - apply_filters( |
|
538 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
539 | - __( |
|
540 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
541 | - 'event_espresso' |
|
542 | - ) |
|
543 | - ), |
|
544 | - '<br />', |
|
545 | - implode('<br />', $this->decremented_tickets), |
|
546 | - $none_added_msg, |
|
547 | - $refresh_msg |
|
548 | - ) |
|
549 | - ); |
|
550 | - $this->decremented_tickets = array(); |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - |
|
556 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
557 | - |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
562 | - * by default, will NOT release tickets for finalized transactions |
|
563 | - * |
|
564 | - * @param EE_Transaction $transaction |
|
565 | - * @return int |
|
566 | - * @throws EE_Error |
|
567 | - * @throws InvalidSessionDataException |
|
568 | - */ |
|
569 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
570 | - { |
|
571 | - if (self::debug) { |
|
572 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
573 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
574 | - } |
|
575 | - // check if 'finalize_registration' step has been completed... |
|
576 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
577 | - if (self::debug) { |
|
578 | - // DEBUG LOG |
|
579 | - EEH_Debug_Tools::log( |
|
580 | - __CLASS__, |
|
581 | - __FUNCTION__, |
|
582 | - __LINE__, |
|
583 | - array('finalized' => $finalized), |
|
584 | - false, |
|
585 | - 'EE_Transaction: ' . $transaction->ID() |
|
586 | - ); |
|
587 | - } |
|
588 | - // how many tickets were released |
|
589 | - $count = 0; |
|
590 | - if (self::debug) { |
|
591 | - echo '<br /> . . . finalized: ' . $finalized; |
|
592 | - } |
|
593 | - $release_tickets_with_TXN_status = array( |
|
594 | - EEM_Transaction::failed_status_code, |
|
595 | - EEM_Transaction::abandoned_status_code, |
|
596 | - EEM_Transaction::incomplete_status_code, |
|
597 | - ); |
|
598 | - // if the session is getting cleared BEFORE the TXN has been finalized |
|
599 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
600 | - // let's cancel any reserved tickets |
|
601 | - $registrations = $transaction->registrations(); |
|
602 | - if (! empty($registrations)) { |
|
603 | - foreach ($registrations as $registration) { |
|
604 | - if ($registration instanceof EE_Registration) { |
|
605 | - $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
606 | - } |
|
607 | - } |
|
608 | - } |
|
609 | - } |
|
610 | - return $count; |
|
611 | - } |
|
612 | - |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * releases reserved tickets for an EE_Registration |
|
617 | - * by default, will NOT release tickets for APPROVED registrations |
|
618 | - * |
|
619 | - * @param EE_Registration $registration |
|
620 | - * @param EE_Transaction $transaction |
|
621 | - * @return int |
|
622 | - * @throws EE_Error |
|
623 | - */ |
|
624 | - protected function _release_reserved_ticket_for_registration( |
|
625 | - EE_Registration $registration, |
|
626 | - EE_Transaction $transaction |
|
627 | - ) { |
|
628 | - $STS_ID = $transaction->status_ID(); |
|
629 | - if (self::debug) { |
|
630 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
631 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
632 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
633 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
634 | - } |
|
635 | - if ( |
|
636 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
637 | - $STS_ID === EEM_Transaction::failed_status_code |
|
638 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
639 | - || ( |
|
640 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
641 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
642 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
643 | - ) |
|
644 | - ) { |
|
645 | - $ticket = $registration->ticket(); |
|
646 | - if ($ticket instanceof EE_Ticket) { |
|
647 | - return $this->_release_reserved_ticket($ticket); |
|
648 | - } |
|
649 | - } |
|
650 | - return 0; |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - |
|
655 | - /********************************** SESSION_CART_RESET **********************************/ |
|
656 | - |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
661 | - * |
|
662 | - * @param EE_Session $session |
|
663 | - * @return void |
|
664 | - * @throws EE_Error |
|
665 | - * @throws InvalidArgumentException |
|
666 | - * @throws ReflectionException |
|
667 | - * @throws InvalidDataTypeException |
|
668 | - * @throws InvalidInterfaceException |
|
669 | - */ |
|
670 | - public static function session_cart_reset(EE_Session $session) |
|
671 | - { |
|
672 | - if (self::debug) { |
|
673 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
674 | - } |
|
675 | - $cart = $session->cart(); |
|
676 | - if ($cart instanceof EE_Cart) { |
|
677 | - if (self::debug) { |
|
678 | - echo '<br /><br /> cart instance of EE_Cart: '; |
|
679 | - } |
|
680 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
681 | - } else { |
|
682 | - if (self::debug) { |
|
683 | - echo '<br /><br /> invalid EE_Cart: '; |
|
684 | - var_export($cart, true); |
|
685 | - } |
|
686 | - } |
|
687 | - } |
|
688 | - |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * releases reserved tickets in the EE_Cart |
|
693 | - * |
|
694 | - * @param EE_Cart $cart |
|
695 | - * @return void |
|
696 | - * @throws EE_Error |
|
697 | - * @throws InvalidArgumentException |
|
698 | - * @throws ReflectionException |
|
699 | - * @throws InvalidDataTypeException |
|
700 | - * @throws InvalidInterfaceException |
|
701 | - */ |
|
702 | - protected function _session_cart_reset(EE_Cart $cart) |
|
703 | - { |
|
704 | - if (self::debug) { |
|
705 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
706 | - } |
|
707 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
708 | - $ticket_line_items = $cart->get_tickets(); |
|
709 | - if (empty($ticket_line_items)) { |
|
710 | - return; |
|
711 | - } |
|
712 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
713 | - if (self::debug) { |
|
714 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
715 | - } |
|
716 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
717 | - if (self::debug) { |
|
718 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
719 | - } |
|
720 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
721 | - if ($ticket instanceof EE_Ticket) { |
|
722 | - if (self::debug) { |
|
723 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
724 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
725 | - } |
|
726 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
727 | - } |
|
728 | - } |
|
729 | - } |
|
730 | - if (self::debug) { |
|
731 | - echo '<br /><br /> RESET COMPLETED '; |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - |
|
737 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
738 | - |
|
739 | - |
|
740 | - |
|
741 | - /** |
|
742 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
743 | - * |
|
744 | - * @param EE_Session $session |
|
745 | - * @return void |
|
746 | - * @throws EE_Error |
|
747 | - * @throws InvalidSessionDataException |
|
748 | - */ |
|
749 | - public static function session_checkout_reset(EE_Session $session) |
|
750 | - { |
|
751 | - $checkout = $session->checkout(); |
|
752 | - if ($checkout instanceof EE_Checkout) { |
|
753 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
754 | - } |
|
755 | - } |
|
756 | - |
|
757 | - |
|
758 | - |
|
759 | - /** |
|
760 | - * releases reserved tickets for the EE_Checkout->transaction |
|
761 | - * |
|
762 | - * @param EE_Checkout $checkout |
|
763 | - * @return void |
|
764 | - * @throws EE_Error |
|
765 | - * @throws InvalidSessionDataException |
|
766 | - */ |
|
767 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
768 | - { |
|
769 | - if (self::debug) { |
|
770 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
771 | - } |
|
772 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
773 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
774 | - return; |
|
775 | - } |
|
776 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
777 | - } |
|
778 | - |
|
779 | - |
|
780 | - |
|
781 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
782 | - |
|
783 | - |
|
784 | - |
|
785 | - /** |
|
786 | - * @param EE_Session $session |
|
787 | - * @return void |
|
788 | - */ |
|
789 | - public static function session_expired_reset(EE_Session $session) |
|
790 | - { |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - |
|
795 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
796 | - |
|
797 | - |
|
798 | - |
|
799 | - /** |
|
800 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
801 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
802 | - * |
|
803 | - * @param EE_Transaction $transaction |
|
804 | - * @return void |
|
805 | - * @throws EE_Error |
|
806 | - * @throws InvalidSessionDataException |
|
807 | - */ |
|
808 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
809 | - { |
|
810 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
811 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
812 | - if (self::debug) { |
|
813 | - // DEBUG LOG |
|
814 | - EEH_Debug_Tools::log( |
|
815 | - __CLASS__, |
|
816 | - __FUNCTION__, |
|
817 | - __LINE__, |
|
818 | - array($transaction), |
|
819 | - false, |
|
820 | - 'EE_Transaction: ' . $transaction->ID() |
|
821 | - ); |
|
822 | - } |
|
823 | - return; |
|
824 | - } |
|
825 | - // have their been any successful payments made ? |
|
826 | - $payments = $transaction->payments(); |
|
827 | - foreach ($payments as $payment) { |
|
828 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
829 | - if (self::debug) { |
|
830 | - // DEBUG LOG |
|
831 | - EEH_Debug_Tools::log( |
|
832 | - __CLASS__, |
|
833 | - __FUNCTION__, |
|
834 | - __LINE__, |
|
835 | - array($payment), |
|
836 | - false, |
|
837 | - 'EE_Transaction: ' . $transaction->ID() |
|
838 | - ); |
|
839 | - } |
|
840 | - return; |
|
841 | - } |
|
842 | - } |
|
843 | - // since you haven't even attempted to pay for your ticket... |
|
844 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
845 | - } |
|
846 | - |
|
847 | - |
|
848 | - |
|
849 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
850 | - |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
855 | - * |
|
856 | - * @param EE_Transaction $transaction |
|
857 | - * @return void |
|
858 | - * @throws EE_Error |
|
859 | - * @throws InvalidSessionDataException |
|
860 | - */ |
|
861 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
862 | - { |
|
863 | - // since you haven't even attempted to pay for your ticket... |
|
864 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
865 | - } |
|
866 | - |
|
867 | - |
|
868 | - |
|
869 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
870 | - |
|
871 | - |
|
872 | - |
|
873 | - /** |
|
874 | - * Resets all ticket and datetime reserved counts to zero |
|
875 | - * Tickets that are currently associated with a Transaction that is in progress |
|
876 | - * |
|
877 | - * @throws EE_Error |
|
878 | - * @throws DomainException |
|
879 | - * @throws InvalidDataTypeException |
|
880 | - * @throws InvalidInterfaceException |
|
881 | - * @throws InvalidArgumentException |
|
882 | - * @throws UnexpectedEntityException |
|
883 | - */ |
|
884 | - public static function reset_reservation_counts() |
|
885 | - { |
|
886 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
887 | - $valid_reserved_tickets = array(); |
|
888 | - /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
889 | - $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
890 | - foreach ($transactions_not_in_progress as $transaction) { |
|
891 | - // if this TXN has been fully completed, then skip it |
|
892 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
893 | - continue; |
|
894 | - } |
|
895 | - $total_line_item = $transaction->total_line_item(); |
|
896 | - // $transaction_in_progress->line |
|
897 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
898 | - throw new DomainException( |
|
899 | - esc_html__( |
|
900 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
901 | - 'event_espresso' |
|
902 | - ) |
|
903 | - ); |
|
904 | - } |
|
905 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
906 | - $total_line_item |
|
907 | - ); |
|
908 | - } |
|
909 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
910 | - foreach ($total_line_items as $total_line_item) { |
|
911 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
912 | - $total_line_item |
|
913 | - ); |
|
914 | - } |
|
915 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
916 | - EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
917 | - $valid_reserved_tickets |
|
918 | - ); |
|
919 | - } |
|
920 | - |
|
921 | - |
|
922 | - |
|
923 | - /** |
|
924 | - * @param EE_Line_Item $total_line_item |
|
925 | - * @return EE_Line_Item[] |
|
926 | - */ |
|
927 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
928 | - { |
|
929 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
930 | - $valid_reserved_tickets = array(); |
|
931 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
932 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
933 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
934 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
935 | - } |
|
936 | - } |
|
937 | - return $valid_reserved_tickets; |
|
938 | - } |
|
939 | - |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * @param EE_Ticket[] $tickets_with_reservations |
|
944 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
945 | - * @return int |
|
946 | - * @throws UnexpectedEntityException |
|
947 | - * @throws DomainException |
|
948 | - * @throws EE_Error |
|
949 | - */ |
|
950 | - private static function release_reservations_for_tickets( |
|
951 | - array $tickets_with_reservations, |
|
952 | - array $valid_reserved_ticket_line_items = array() |
|
953 | - ) { |
|
954 | - $total_tickets_released = 0; |
|
955 | - $sold_out_events = array(); |
|
956 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
957 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
958 | - continue; |
|
959 | - } |
|
960 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
961 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
962 | - if ( |
|
963 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
964 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
965 | - ) { |
|
966 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
967 | - } |
|
968 | - } |
|
969 | - if ($reserved_qty > 0) { |
|
970 | - $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
971 | - $ticket_with_reservations->save(); |
|
972 | - $total_tickets_released += $reserved_qty; |
|
973 | - $event = $ticket_with_reservations->get_related_event(); |
|
974 | - // track sold out events |
|
975 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
976 | - $sold_out_events[] = $event; |
|
977 | - } |
|
978 | - } |
|
979 | - } |
|
980 | - // double check whether sold out events should remain sold out after releasing tickets |
|
981 | - if($sold_out_events !== array()){ |
|
982 | - foreach ($sold_out_events as $sold_out_event) { |
|
983 | - /** @var EE_Event $sold_out_event */ |
|
984 | - $sold_out_event->perform_sold_out_status_check(); |
|
985 | - } |
|
986 | - } |
|
987 | - return $total_tickets_released; |
|
988 | - } |
|
989 | - |
|
990 | - |
|
991 | - |
|
992 | - /********************************** SHUTDOWN **********************************/ |
|
993 | - |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * @return false|int |
|
998 | - * @throws EE_Error |
|
999 | - * @throws InvalidArgumentException |
|
1000 | - * @throws InvalidDataTypeException |
|
1001 | - * @throws InvalidInterfaceException |
|
1002 | - */ |
|
1003 | - public static function clear_expired_line_items_with_no_transaction() |
|
1004 | - { |
|
1005 | - /** @type WPDB $wpdb */ |
|
1006 | - global $wpdb; |
|
1007 | - return $wpdb->query( |
|
1008 | - $wpdb->prepare( |
|
1009 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
26 | + const debug = false; // true false |
|
27 | + |
|
28 | + /** |
|
29 | + * an array of raw ticket data from EED_Ticket_Selector |
|
30 | + * |
|
31 | + * @var array $ticket_selections |
|
32 | + */ |
|
33 | + protected $ticket_selections = array(); |
|
34 | + |
|
35 | + /** |
|
36 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
37 | + * according to how they are displayed in the actual Ticket_Selector |
|
38 | + * this tracks the current row being processed |
|
39 | + * |
|
40 | + * @var int $current_row |
|
41 | + */ |
|
42 | + protected $current_row = 0; |
|
43 | + |
|
44 | + /** |
|
45 | + * an array for tracking names of tickets that have sold out |
|
46 | + * |
|
47 | + * @var array $sold_out_tickets |
|
48 | + */ |
|
49 | + protected $sold_out_tickets = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * an array for tracking names of tickets that have had their quantities reduced |
|
53 | + * |
|
54 | + * @var array $decremented_tickets |
|
55 | + */ |
|
56 | + protected $decremented_tickets = array(); |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public static function set_hooks() |
|
66 | + { |
|
67 | + // release tickets for expired carts |
|
68 | + add_action( |
|
69 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
70 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
71 | + 1 |
|
72 | + ); |
|
73 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
74 | + add_filter( |
|
75 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
76 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
77 | + 20, |
|
78 | + 3 |
|
79 | + ); |
|
80 | + // add notices for sold out tickets |
|
81 | + add_action( |
|
82 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
83 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
84 | + 10 |
|
85 | + ); |
|
86 | + // handle ticket quantities adjusted in cart |
|
87 | + //add_action( |
|
88 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
89 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
90 | + // 10, 2 |
|
91 | + //); |
|
92 | + // handle tickets deleted from cart |
|
93 | + add_action( |
|
94 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
95 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
96 | + 10, |
|
97 | + 2 |
|
98 | + ); |
|
99 | + // handle emptied carts |
|
100 | + add_action( |
|
101 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
102 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
103 | + 10, |
|
104 | + 1 |
|
105 | + ); |
|
106 | + add_action( |
|
107 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
108 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
109 | + 10, |
|
110 | + 1 |
|
111 | + ); |
|
112 | + // handle cancelled registrations |
|
113 | + add_action( |
|
114 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
115 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
116 | + 10, |
|
117 | + 1 |
|
118 | + ); |
|
119 | + // cron tasks |
|
120 | + add_action( |
|
121 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
122 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
123 | + 10, |
|
124 | + 1 |
|
125 | + ); |
|
126 | + add_action( |
|
127 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
128 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
129 | + 10, |
|
130 | + 1 |
|
131 | + ); |
|
132 | + add_action( |
|
133 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
134 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
135 | + 10, |
|
136 | + 1 |
|
137 | + ); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
144 | + * |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + public static function set_hooks_admin() |
|
148 | + { |
|
149 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
156 | + */ |
|
157 | + public static function instance() |
|
158 | + { |
|
159 | + return parent::get_instance(__CLASS__); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @param WP_Query $WP_Query |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function run($WP_Query) |
|
169 | + { |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Retrieves grand totals from the line items that have no TXN ID |
|
180 | + * and timestamps less than the current time minus the session lifespan. |
|
181 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
182 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
183 | + * |
|
184 | + * @return void |
|
185 | + * @throws DomainException |
|
186 | + * @throws EE_Error |
|
187 | + * @throws InvalidArgumentException |
|
188 | + * @throws InvalidDataTypeException |
|
189 | + * @throws InvalidInterfaceException |
|
190 | + * @throws UnexpectedEntityException |
|
191 | + */ |
|
192 | + public static function release_tickets_for_expired_carts() |
|
193 | + { |
|
194 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
195 | + $expired_ticket_IDs = array(); |
|
196 | + $valid_ticket_line_items = array(); |
|
197 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
198 | + if (empty($total_line_items)) { |
|
199 | + do_action( |
|
200 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
201 | + $total_line_items, |
|
202 | + $valid_ticket_line_items, |
|
203 | + $expired_ticket_IDs |
|
204 | + ); |
|
205 | + return; |
|
206 | + } |
|
207 | + $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
208 | + foreach ($total_line_items as $total_line_item) { |
|
209 | + /** @var EE_Line_Item $total_line_item */ |
|
210 | + $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
211 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
212 | + if (! $ticket_line_item instanceof EE_Line_Item) { |
|
213 | + continue; |
|
214 | + } |
|
215 | + if ($total_line_item->timestamp(true) <= $expired) { |
|
216 | + $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
217 | + } else { |
|
218 | + $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + if (! empty($expired_ticket_IDs)) { |
|
223 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
224 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
225 | + $valid_ticket_line_items |
|
226 | + ); |
|
227 | + // let's get rid of expired line items so that they can't interfere with tracking |
|
228 | + add_action( |
|
229 | + 'shutdown', |
|
230 | + array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
231 | + 999 |
|
232 | + ); |
|
233 | + } |
|
234 | + do_action( |
|
235 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
236 | + $total_line_items, |
|
237 | + $valid_ticket_line_items, |
|
238 | + $expired_ticket_IDs |
|
239 | + ); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
250 | + * |
|
251 | + * @param int $qty |
|
252 | + * @param EE_Ticket $ticket |
|
253 | + * @return bool |
|
254 | + * @throws UnexpectedEntityException |
|
255 | + * @throws EE_Error |
|
256 | + */ |
|
257 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
258 | + { |
|
259 | + $qty = absint($qty); |
|
260 | + if ($qty > 0) { |
|
261 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
262 | + } |
|
263 | + if (self::debug) { |
|
264 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
265 | + echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
266 | + } |
|
267 | + return $qty; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
274 | + * |
|
275 | + * @param EE_Ticket $ticket |
|
276 | + * @param int $qty |
|
277 | + * @return int |
|
278 | + * @throws UnexpectedEntityException |
|
279 | + * @throws EE_Error |
|
280 | + */ |
|
281 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
282 | + { |
|
283 | + if (self::debug) { |
|
284 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
285 | + } |
|
286 | + if (! $ticket instanceof EE_Ticket) { |
|
287 | + return 0; |
|
288 | + } |
|
289 | + if (self::debug) { |
|
290 | + echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
291 | + echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
292 | + } |
|
293 | + $ticket->refresh_from_db(); |
|
294 | + // first let's determine the ticket availability based on sales |
|
295 | + $available = $ticket->qty('saleable'); |
|
296 | + if (self::debug) { |
|
297 | + echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
298 | + echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
299 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
300 | + echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
301 | + echo '<br /> . . . available: ' . $available; |
|
302 | + } |
|
303 | + if ($available < 1) { |
|
304 | + $this->_ticket_sold_out($ticket); |
|
305 | + return 0; |
|
306 | + } |
|
307 | + if (self::debug) { |
|
308 | + echo '<br /> . . . qty: ' . $qty; |
|
309 | + } |
|
310 | + if ($available < $qty) { |
|
311 | + $qty = $available; |
|
312 | + if (self::debug) { |
|
313 | + echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
314 | + } |
|
315 | + $this->_ticket_quantity_decremented($ticket); |
|
316 | + } |
|
317 | + $this->_reserve_ticket($ticket, $qty); |
|
318 | + return $qty; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * increments ticket reserved based on quantity passed |
|
325 | + * |
|
326 | + * @param EE_Ticket $ticket |
|
327 | + * @param int $quantity |
|
328 | + * @return bool |
|
329 | + * @throws EE_Error |
|
330 | + */ |
|
331 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
332 | + { |
|
333 | + if (self::debug) { |
|
334 | + echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
335 | + } |
|
336 | + $ticket->increase_reserved($quantity); |
|
337 | + return $ticket->save(); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * @param EE_Ticket $ticket |
|
344 | + * @param int $quantity |
|
345 | + * @return bool |
|
346 | + * @throws EE_Error |
|
347 | + */ |
|
348 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
349 | + { |
|
350 | + if (self::debug) { |
|
351 | + echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
352 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
353 | + } |
|
354 | + $ticket->decrease_reserved($quantity); |
|
355 | + if (self::debug) { |
|
356 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
357 | + } |
|
358 | + return $ticket->save() ? 1 : 0; |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * removes quantities within the ticket selector based on zero ticket availability |
|
365 | + * |
|
366 | + * @param EE_Ticket $ticket |
|
367 | + * @return void |
|
368 | + * @throws UnexpectedEntityException |
|
369 | + * @throws EE_Error |
|
370 | + */ |
|
371 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
372 | + { |
|
373 | + if (self::debug) { |
|
374 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
375 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
376 | + } |
|
377 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
384 | + * |
|
385 | + * @param EE_Ticket $ticket |
|
386 | + * @return void |
|
387 | + * @throws UnexpectedEntityException |
|
388 | + * @throws EE_Error |
|
389 | + */ |
|
390 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
391 | + { |
|
392 | + if (self::debug) { |
|
393 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
394 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
395 | + } |
|
396 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * builds string out of ticket and event name |
|
403 | + * |
|
404 | + * @param EE_Ticket $ticket |
|
405 | + * @return string |
|
406 | + * @throws UnexpectedEntityException |
|
407 | + * @throws EE_Error |
|
408 | + */ |
|
409 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
410 | + { |
|
411 | + $event = $ticket->get_related_event(); |
|
412 | + if ($event instanceof EE_Event) { |
|
413 | + $ticket_name = sprintf( |
|
414 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
415 | + $ticket->name(), |
|
416 | + $event->name() |
|
417 | + ); |
|
418 | + } else { |
|
419 | + $ticket_name = $ticket->name(); |
|
420 | + } |
|
421 | + return $ticket_name; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /********************************** EVENT CART **********************************/ |
|
427 | + |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * releases or reserves ticket(s) based on quantity passed |
|
432 | + * |
|
433 | + * @param EE_Line_Item $line_item |
|
434 | + * @param int $quantity |
|
435 | + * @return void |
|
436 | + * @throws EE_Error |
|
437 | + * @throws InvalidArgumentException |
|
438 | + * @throws InvalidDataTypeException |
|
439 | + * @throws InvalidInterfaceException |
|
440 | + */ |
|
441 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
442 | + { |
|
443 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
444 | + if ($ticket instanceof EE_Ticket) { |
|
445 | + if ($quantity > 0) { |
|
446 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
447 | + } else { |
|
448 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
449 | + } |
|
450 | + } |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * releases reserved ticket(s) based on quantity passed |
|
457 | + * |
|
458 | + * @param EE_Ticket $ticket |
|
459 | + * @param int $quantity |
|
460 | + * @return void |
|
461 | + * @throws EE_Error |
|
462 | + */ |
|
463 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
464 | + { |
|
465 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /********************************** POST_NOTICES **********************************/ |
|
471 | + |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * @return void |
|
476 | + * @throws EE_Error |
|
477 | + * @throws InvalidArgumentException |
|
478 | + * @throws ReflectionException |
|
479 | + * @throws InvalidDataTypeException |
|
480 | + * @throws InvalidInterfaceException |
|
481 | + */ |
|
482 | + public static function post_notices() |
|
483 | + { |
|
484 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * @return void |
|
491 | + * @throws EE_Error |
|
492 | + * @throws InvalidArgumentException |
|
493 | + * @throws ReflectionException |
|
494 | + * @throws InvalidDataTypeException |
|
495 | + * @throws InvalidInterfaceException |
|
496 | + */ |
|
497 | + protected function _post_notices() |
|
498 | + { |
|
499 | + if (self::debug) { |
|
500 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
501 | + } |
|
502 | + $refresh_msg = ''; |
|
503 | + $none_added_msg = ''; |
|
504 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
505 | + $refresh_msg = __( |
|
506 | + 'Please refresh the page to view updated ticket quantities.', |
|
507 | + 'event_espresso' |
|
508 | + ); |
|
509 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
510 | + } |
|
511 | + if (! empty($this->sold_out_tickets)) { |
|
512 | + EE_Error::add_attention( |
|
513 | + sprintf( |
|
514 | + apply_filters( |
|
515 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
516 | + __( |
|
517 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
518 | + 'event_espresso' |
|
519 | + ) |
|
520 | + ), |
|
521 | + '<br />', |
|
522 | + implode('<br />', $this->sold_out_tickets), |
|
523 | + $none_added_msg, |
|
524 | + $refresh_msg |
|
525 | + ) |
|
526 | + ); |
|
527 | + // alter code flow in the Ticket Selector for better UX |
|
528 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
529 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
530 | + $this->sold_out_tickets = array(); |
|
531 | + // and reset the cart |
|
532 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
533 | + } |
|
534 | + if (! empty($this->decremented_tickets)) { |
|
535 | + EE_Error::add_attention( |
|
536 | + sprintf( |
|
537 | + apply_filters( |
|
538 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
539 | + __( |
|
540 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
541 | + 'event_espresso' |
|
542 | + ) |
|
543 | + ), |
|
544 | + '<br />', |
|
545 | + implode('<br />', $this->decremented_tickets), |
|
546 | + $none_added_msg, |
|
547 | + $refresh_msg |
|
548 | + ) |
|
549 | + ); |
|
550 | + $this->decremented_tickets = array(); |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + |
|
556 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
557 | + |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
562 | + * by default, will NOT release tickets for finalized transactions |
|
563 | + * |
|
564 | + * @param EE_Transaction $transaction |
|
565 | + * @return int |
|
566 | + * @throws EE_Error |
|
567 | + * @throws InvalidSessionDataException |
|
568 | + */ |
|
569 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
570 | + { |
|
571 | + if (self::debug) { |
|
572 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
573 | + echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
574 | + } |
|
575 | + // check if 'finalize_registration' step has been completed... |
|
576 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
577 | + if (self::debug) { |
|
578 | + // DEBUG LOG |
|
579 | + EEH_Debug_Tools::log( |
|
580 | + __CLASS__, |
|
581 | + __FUNCTION__, |
|
582 | + __LINE__, |
|
583 | + array('finalized' => $finalized), |
|
584 | + false, |
|
585 | + 'EE_Transaction: ' . $transaction->ID() |
|
586 | + ); |
|
587 | + } |
|
588 | + // how many tickets were released |
|
589 | + $count = 0; |
|
590 | + if (self::debug) { |
|
591 | + echo '<br /> . . . finalized: ' . $finalized; |
|
592 | + } |
|
593 | + $release_tickets_with_TXN_status = array( |
|
594 | + EEM_Transaction::failed_status_code, |
|
595 | + EEM_Transaction::abandoned_status_code, |
|
596 | + EEM_Transaction::incomplete_status_code, |
|
597 | + ); |
|
598 | + // if the session is getting cleared BEFORE the TXN has been finalized |
|
599 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
600 | + // let's cancel any reserved tickets |
|
601 | + $registrations = $transaction->registrations(); |
|
602 | + if (! empty($registrations)) { |
|
603 | + foreach ($registrations as $registration) { |
|
604 | + if ($registration instanceof EE_Registration) { |
|
605 | + $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
606 | + } |
|
607 | + } |
|
608 | + } |
|
609 | + } |
|
610 | + return $count; |
|
611 | + } |
|
612 | + |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * releases reserved tickets for an EE_Registration |
|
617 | + * by default, will NOT release tickets for APPROVED registrations |
|
618 | + * |
|
619 | + * @param EE_Registration $registration |
|
620 | + * @param EE_Transaction $transaction |
|
621 | + * @return int |
|
622 | + * @throws EE_Error |
|
623 | + */ |
|
624 | + protected function _release_reserved_ticket_for_registration( |
|
625 | + EE_Registration $registration, |
|
626 | + EE_Transaction $transaction |
|
627 | + ) { |
|
628 | + $STS_ID = $transaction->status_ID(); |
|
629 | + if (self::debug) { |
|
630 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
631 | + echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
632 | + echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
633 | + echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
634 | + } |
|
635 | + if ( |
|
636 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
637 | + $STS_ID === EEM_Transaction::failed_status_code |
|
638 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
639 | + || ( |
|
640 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
641 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
642 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
643 | + ) |
|
644 | + ) { |
|
645 | + $ticket = $registration->ticket(); |
|
646 | + if ($ticket instanceof EE_Ticket) { |
|
647 | + return $this->_release_reserved_ticket($ticket); |
|
648 | + } |
|
649 | + } |
|
650 | + return 0; |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + |
|
655 | + /********************************** SESSION_CART_RESET **********************************/ |
|
656 | + |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
661 | + * |
|
662 | + * @param EE_Session $session |
|
663 | + * @return void |
|
664 | + * @throws EE_Error |
|
665 | + * @throws InvalidArgumentException |
|
666 | + * @throws ReflectionException |
|
667 | + * @throws InvalidDataTypeException |
|
668 | + * @throws InvalidInterfaceException |
|
669 | + */ |
|
670 | + public static function session_cart_reset(EE_Session $session) |
|
671 | + { |
|
672 | + if (self::debug) { |
|
673 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
674 | + } |
|
675 | + $cart = $session->cart(); |
|
676 | + if ($cart instanceof EE_Cart) { |
|
677 | + if (self::debug) { |
|
678 | + echo '<br /><br /> cart instance of EE_Cart: '; |
|
679 | + } |
|
680 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
681 | + } else { |
|
682 | + if (self::debug) { |
|
683 | + echo '<br /><br /> invalid EE_Cart: '; |
|
684 | + var_export($cart, true); |
|
685 | + } |
|
686 | + } |
|
687 | + } |
|
688 | + |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * releases reserved tickets in the EE_Cart |
|
693 | + * |
|
694 | + * @param EE_Cart $cart |
|
695 | + * @return void |
|
696 | + * @throws EE_Error |
|
697 | + * @throws InvalidArgumentException |
|
698 | + * @throws ReflectionException |
|
699 | + * @throws InvalidDataTypeException |
|
700 | + * @throws InvalidInterfaceException |
|
701 | + */ |
|
702 | + protected function _session_cart_reset(EE_Cart $cart) |
|
703 | + { |
|
704 | + if (self::debug) { |
|
705 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
706 | + } |
|
707 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
708 | + $ticket_line_items = $cart->get_tickets(); |
|
709 | + if (empty($ticket_line_items)) { |
|
710 | + return; |
|
711 | + } |
|
712 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
713 | + if (self::debug) { |
|
714 | + echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
715 | + } |
|
716 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
717 | + if (self::debug) { |
|
718 | + echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
719 | + } |
|
720 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
721 | + if ($ticket instanceof EE_Ticket) { |
|
722 | + if (self::debug) { |
|
723 | + echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
724 | + echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
725 | + } |
|
726 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
727 | + } |
|
728 | + } |
|
729 | + } |
|
730 | + if (self::debug) { |
|
731 | + echo '<br /><br /> RESET COMPLETED '; |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + |
|
737 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
738 | + |
|
739 | + |
|
740 | + |
|
741 | + /** |
|
742 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
743 | + * |
|
744 | + * @param EE_Session $session |
|
745 | + * @return void |
|
746 | + * @throws EE_Error |
|
747 | + * @throws InvalidSessionDataException |
|
748 | + */ |
|
749 | + public static function session_checkout_reset(EE_Session $session) |
|
750 | + { |
|
751 | + $checkout = $session->checkout(); |
|
752 | + if ($checkout instanceof EE_Checkout) { |
|
753 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
754 | + } |
|
755 | + } |
|
756 | + |
|
757 | + |
|
758 | + |
|
759 | + /** |
|
760 | + * releases reserved tickets for the EE_Checkout->transaction |
|
761 | + * |
|
762 | + * @param EE_Checkout $checkout |
|
763 | + * @return void |
|
764 | + * @throws EE_Error |
|
765 | + * @throws InvalidSessionDataException |
|
766 | + */ |
|
767 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
768 | + { |
|
769 | + if (self::debug) { |
|
770 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
771 | + } |
|
772 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
773 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
774 | + return; |
|
775 | + } |
|
776 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
777 | + } |
|
778 | + |
|
779 | + |
|
780 | + |
|
781 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
782 | + |
|
783 | + |
|
784 | + |
|
785 | + /** |
|
786 | + * @param EE_Session $session |
|
787 | + * @return void |
|
788 | + */ |
|
789 | + public static function session_expired_reset(EE_Session $session) |
|
790 | + { |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + |
|
795 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
796 | + |
|
797 | + |
|
798 | + |
|
799 | + /** |
|
800 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
801 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
802 | + * |
|
803 | + * @param EE_Transaction $transaction |
|
804 | + * @return void |
|
805 | + * @throws EE_Error |
|
806 | + * @throws InvalidSessionDataException |
|
807 | + */ |
|
808 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
809 | + { |
|
810 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
811 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
812 | + if (self::debug) { |
|
813 | + // DEBUG LOG |
|
814 | + EEH_Debug_Tools::log( |
|
815 | + __CLASS__, |
|
816 | + __FUNCTION__, |
|
817 | + __LINE__, |
|
818 | + array($transaction), |
|
819 | + false, |
|
820 | + 'EE_Transaction: ' . $transaction->ID() |
|
821 | + ); |
|
822 | + } |
|
823 | + return; |
|
824 | + } |
|
825 | + // have their been any successful payments made ? |
|
826 | + $payments = $transaction->payments(); |
|
827 | + foreach ($payments as $payment) { |
|
828 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
829 | + if (self::debug) { |
|
830 | + // DEBUG LOG |
|
831 | + EEH_Debug_Tools::log( |
|
832 | + __CLASS__, |
|
833 | + __FUNCTION__, |
|
834 | + __LINE__, |
|
835 | + array($payment), |
|
836 | + false, |
|
837 | + 'EE_Transaction: ' . $transaction->ID() |
|
838 | + ); |
|
839 | + } |
|
840 | + return; |
|
841 | + } |
|
842 | + } |
|
843 | + // since you haven't even attempted to pay for your ticket... |
|
844 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
845 | + } |
|
846 | + |
|
847 | + |
|
848 | + |
|
849 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
850 | + |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
855 | + * |
|
856 | + * @param EE_Transaction $transaction |
|
857 | + * @return void |
|
858 | + * @throws EE_Error |
|
859 | + * @throws InvalidSessionDataException |
|
860 | + */ |
|
861 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
862 | + { |
|
863 | + // since you haven't even attempted to pay for your ticket... |
|
864 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
865 | + } |
|
866 | + |
|
867 | + |
|
868 | + |
|
869 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
870 | + |
|
871 | + |
|
872 | + |
|
873 | + /** |
|
874 | + * Resets all ticket and datetime reserved counts to zero |
|
875 | + * Tickets that are currently associated with a Transaction that is in progress |
|
876 | + * |
|
877 | + * @throws EE_Error |
|
878 | + * @throws DomainException |
|
879 | + * @throws InvalidDataTypeException |
|
880 | + * @throws InvalidInterfaceException |
|
881 | + * @throws InvalidArgumentException |
|
882 | + * @throws UnexpectedEntityException |
|
883 | + */ |
|
884 | + public static function reset_reservation_counts() |
|
885 | + { |
|
886 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
887 | + $valid_reserved_tickets = array(); |
|
888 | + /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
889 | + $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
890 | + foreach ($transactions_not_in_progress as $transaction) { |
|
891 | + // if this TXN has been fully completed, then skip it |
|
892 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
893 | + continue; |
|
894 | + } |
|
895 | + $total_line_item = $transaction->total_line_item(); |
|
896 | + // $transaction_in_progress->line |
|
897 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
898 | + throw new DomainException( |
|
899 | + esc_html__( |
|
900 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
901 | + 'event_espresso' |
|
902 | + ) |
|
903 | + ); |
|
904 | + } |
|
905 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
906 | + $total_line_item |
|
907 | + ); |
|
908 | + } |
|
909 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
910 | + foreach ($total_line_items as $total_line_item) { |
|
911 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
912 | + $total_line_item |
|
913 | + ); |
|
914 | + } |
|
915 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
916 | + EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
917 | + $valid_reserved_tickets |
|
918 | + ); |
|
919 | + } |
|
920 | + |
|
921 | + |
|
922 | + |
|
923 | + /** |
|
924 | + * @param EE_Line_Item $total_line_item |
|
925 | + * @return EE_Line_Item[] |
|
926 | + */ |
|
927 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
928 | + { |
|
929 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
930 | + $valid_reserved_tickets = array(); |
|
931 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
932 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
933 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
934 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
935 | + } |
|
936 | + } |
|
937 | + return $valid_reserved_tickets; |
|
938 | + } |
|
939 | + |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * @param EE_Ticket[] $tickets_with_reservations |
|
944 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
945 | + * @return int |
|
946 | + * @throws UnexpectedEntityException |
|
947 | + * @throws DomainException |
|
948 | + * @throws EE_Error |
|
949 | + */ |
|
950 | + private static function release_reservations_for_tickets( |
|
951 | + array $tickets_with_reservations, |
|
952 | + array $valid_reserved_ticket_line_items = array() |
|
953 | + ) { |
|
954 | + $total_tickets_released = 0; |
|
955 | + $sold_out_events = array(); |
|
956 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
957 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
958 | + continue; |
|
959 | + } |
|
960 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
961 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
962 | + if ( |
|
963 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
964 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
965 | + ) { |
|
966 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
967 | + } |
|
968 | + } |
|
969 | + if ($reserved_qty > 0) { |
|
970 | + $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
971 | + $ticket_with_reservations->save(); |
|
972 | + $total_tickets_released += $reserved_qty; |
|
973 | + $event = $ticket_with_reservations->get_related_event(); |
|
974 | + // track sold out events |
|
975 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
976 | + $sold_out_events[] = $event; |
|
977 | + } |
|
978 | + } |
|
979 | + } |
|
980 | + // double check whether sold out events should remain sold out after releasing tickets |
|
981 | + if($sold_out_events !== array()){ |
|
982 | + foreach ($sold_out_events as $sold_out_event) { |
|
983 | + /** @var EE_Event $sold_out_event */ |
|
984 | + $sold_out_event->perform_sold_out_status_check(); |
|
985 | + } |
|
986 | + } |
|
987 | + return $total_tickets_released; |
|
988 | + } |
|
989 | + |
|
990 | + |
|
991 | + |
|
992 | + /********************************** SHUTDOWN **********************************/ |
|
993 | + |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * @return false|int |
|
998 | + * @throws EE_Error |
|
999 | + * @throws InvalidArgumentException |
|
1000 | + * @throws InvalidDataTypeException |
|
1001 | + * @throws InvalidInterfaceException |
|
1002 | + */ |
|
1003 | + public static function clear_expired_line_items_with_no_transaction() |
|
1004 | + { |
|
1005 | + /** @type WPDB $wpdb */ |
|
1006 | + global $wpdb; |
|
1007 | + return $wpdb->query( |
|
1008 | + $wpdb->prepare( |
|
1009 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1010 | 1010 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1011 | - // use GMT time because that's what LIN_timestamps are in |
|
1012 | - date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
1013 | - ) |
|
1014 | - ); |
|
1015 | - } |
|
1011 | + // use GMT time because that's what LIN_timestamps are in |
|
1012 | + date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
1013 | + ) |
|
1014 | + ); |
|
1015 | + } |
|
1016 | 1016 | |
1017 | 1017 | } |
1018 | 1018 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | class EED_Ticket_Sales_Monitor extends EED_Module |
24 | 24 | { |
25 | 25 | |
26 | - const debug = false; // true false |
|
26 | + const debug = false; // true false |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * an array of raw ticket data from EED_Ticket_Selector |
@@ -209,17 +209,17 @@ discard block |
||
209 | 209 | /** @var EE_Line_Item $total_line_item */ |
210 | 210 | $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
211 | 211 | foreach ($ticket_line_items as $ticket_line_item) { |
212 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
212 | + if ( ! $ticket_line_item instanceof EE_Line_Item) { |
|
213 | 213 | continue; |
214 | 214 | } |
215 | 215 | if ($total_line_item->timestamp(true) <= $expired) { |
216 | - $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
216 | + $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
217 | 217 | } else { |
218 | - $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
218 | + $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | } |
222 | - if (! empty($expired_ticket_IDs)) { |
|
222 | + if ( ! empty($expired_ticket_IDs)) { |
|
223 | 223 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
224 | 224 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
225 | 225 | $valid_ticket_line_items |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
262 | 262 | } |
263 | 263 | if (self::debug) { |
264 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
265 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
264 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()'; |
|
265 | + echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>'; |
|
266 | 266 | } |
267 | 267 | return $qty; |
268 | 268 | } |
@@ -281,36 +281,36 @@ discard block |
||
281 | 281 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
282 | 282 | { |
283 | 283 | if (self::debug) { |
284 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
284 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
285 | 285 | } |
286 | - if (! $ticket instanceof EE_Ticket) { |
|
286 | + if ( ! $ticket instanceof EE_Ticket) { |
|
287 | 287 | return 0; |
288 | 288 | } |
289 | 289 | if (self::debug) { |
290 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
291 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
290 | + echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
291 | + echo '<br /> . original ticket->reserved: '.$ticket->reserved(); |
|
292 | 292 | } |
293 | 293 | $ticket->refresh_from_db(); |
294 | 294 | // first let's determine the ticket availability based on sales |
295 | 295 | $available = $ticket->qty('saleable'); |
296 | 296 | if (self::debug) { |
297 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
298 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
299 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
300 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
301 | - echo '<br /> . . . available: ' . $available; |
|
297 | + echo '<br /> . . . ticket->qty: '.$ticket->qty(); |
|
298 | + echo '<br /> . . . ticket->sold: '.$ticket->sold(); |
|
299 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
300 | + echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
301 | + echo '<br /> . . . available: '.$available; |
|
302 | 302 | } |
303 | 303 | if ($available < 1) { |
304 | 304 | $this->_ticket_sold_out($ticket); |
305 | 305 | return 0; |
306 | 306 | } |
307 | 307 | if (self::debug) { |
308 | - echo '<br /> . . . qty: ' . $qty; |
|
308 | + echo '<br /> . . . qty: '.$qty; |
|
309 | 309 | } |
310 | 310 | if ($available < $qty) { |
311 | 311 | $qty = $available; |
312 | 312 | if (self::debug) { |
313 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
313 | + echo '<br /> . . . QTY ADJUSTED: '.$qty; |
|
314 | 314 | } |
315 | 315 | $this->_ticket_quantity_decremented($ticket); |
316 | 316 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
332 | 332 | { |
333 | 333 | if (self::debug) { |
334 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
334 | + echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity; |
|
335 | 335 | } |
336 | 336 | $ticket->increase_reserved($quantity); |
337 | 337 | return $ticket->save(); |
@@ -348,12 +348,12 @@ discard block |
||
348 | 348 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
349 | 349 | { |
350 | 350 | if (self::debug) { |
351 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
352 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
351 | + echo '<br /> . . . ticket->ID: '.$ticket->ID(); |
|
352 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
353 | 353 | } |
354 | 354 | $ticket->decrease_reserved($quantity); |
355 | 355 | if (self::debug) { |
356 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
356 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
357 | 357 | } |
358 | 358 | return $ticket->save() ? 1 : 0; |
359 | 359 | } |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | protected function _ticket_sold_out(EE_Ticket $ticket) |
372 | 372 | { |
373 | 373 | if (self::debug) { |
374 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
375 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
374 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
375 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
376 | 376 | } |
377 | 377 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
378 | 378 | } |
@@ -390,8 +390,8 @@ discard block |
||
390 | 390 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
391 | 391 | { |
392 | 392 | if (self::debug) { |
393 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
394 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
393 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
394 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
395 | 395 | } |
396 | 396 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
397 | 397 | } |
@@ -497,18 +497,18 @@ discard block |
||
497 | 497 | protected function _post_notices() |
498 | 498 | { |
499 | 499 | if (self::debug) { |
500 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
500 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
501 | 501 | } |
502 | 502 | $refresh_msg = ''; |
503 | 503 | $none_added_msg = ''; |
504 | 504 | if (defined('DOING_AJAX') && DOING_AJAX) { |
505 | - $refresh_msg = __( |
|
505 | + $refresh_msg = __( |
|
506 | 506 | 'Please refresh the page to view updated ticket quantities.', |
507 | 507 | 'event_espresso' |
508 | 508 | ); |
509 | 509 | $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
510 | 510 | } |
511 | - if (! empty($this->sold_out_tickets)) { |
|
511 | + if ( ! empty($this->sold_out_tickets)) { |
|
512 | 512 | EE_Error::add_attention( |
513 | 513 | sprintf( |
514 | 514 | apply_filters( |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | // and reset the cart |
532 | 532 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
533 | 533 | } |
534 | - if (! empty($this->decremented_tickets)) { |
|
534 | + if ( ! empty($this->decremented_tickets)) { |
|
535 | 535 | EE_Error::add_attention( |
536 | 536 | sprintf( |
537 | 537 | apply_filters( |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
570 | 570 | { |
571 | 571 | if (self::debug) { |
572 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
573 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
572 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
573 | + echo '<br /> . transaction->ID: '.$transaction->ID(); |
|
574 | 574 | } |
575 | 575 | // check if 'finalize_registration' step has been completed... |
576 | 576 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -582,13 +582,13 @@ discard block |
||
582 | 582 | __LINE__, |
583 | 583 | array('finalized' => $finalized), |
584 | 584 | false, |
585 | - 'EE_Transaction: ' . $transaction->ID() |
|
585 | + 'EE_Transaction: '.$transaction->ID() |
|
586 | 586 | ); |
587 | 587 | } |
588 | 588 | // how many tickets were released |
589 | 589 | $count = 0; |
590 | 590 | if (self::debug) { |
591 | - echo '<br /> . . . finalized: ' . $finalized; |
|
591 | + echo '<br /> . . . finalized: '.$finalized; |
|
592 | 592 | } |
593 | 593 | $release_tickets_with_TXN_status = array( |
594 | 594 | EEM_Transaction::failed_status_code, |
@@ -596,10 +596,10 @@ discard block |
||
596 | 596 | EEM_Transaction::incomplete_status_code, |
597 | 597 | ); |
598 | 598 | // if the session is getting cleared BEFORE the TXN has been finalized |
599 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
599 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
600 | 600 | // let's cancel any reserved tickets |
601 | 601 | $registrations = $transaction->registrations(); |
602 | - if (! empty($registrations)) { |
|
602 | + if ( ! empty($registrations)) { |
|
603 | 603 | foreach ($registrations as $registration) { |
604 | 604 | if ($registration instanceof EE_Registration) { |
605 | 605 | $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
@@ -627,10 +627,10 @@ discard block |
||
627 | 627 | ) { |
628 | 628 | $STS_ID = $transaction->status_ID(); |
629 | 629 | if (self::debug) { |
630 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
631 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
632 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
633 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
630 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
631 | + echo '<br /> . . registration->ID: '.$registration->ID(); |
|
632 | + echo '<br /> . . registration->status_ID: '.$registration->status_ID(); |
|
633 | + echo '<br /> . . transaction->status_ID(): '.$STS_ID; |
|
634 | 634 | } |
635 | 635 | if ( |
636 | 636 | // release Tickets for Failed Transactions and Abandoned Transactions |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | public static function session_cart_reset(EE_Session $session) |
671 | 671 | { |
672 | 672 | if (self::debug) { |
673 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
673 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
674 | 674 | } |
675 | 675 | $cart = $session->cart(); |
676 | 676 | if ($cart instanceof EE_Cart) { |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | protected function _session_cart_reset(EE_Cart $cart) |
703 | 703 | { |
704 | 704 | if (self::debug) { |
705 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
705 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
706 | 706 | } |
707 | 707 | EE_Registry::instance()->load_helper('Line_Item'); |
708 | 708 | $ticket_line_items = $cart->get_tickets(); |
@@ -711,17 +711,17 @@ discard block |
||
711 | 711 | } |
712 | 712 | foreach ($ticket_line_items as $ticket_line_item) { |
713 | 713 | if (self::debug) { |
714 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
714 | + echo '<br /> . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
715 | 715 | } |
716 | 716 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
717 | 717 | if (self::debug) { |
718 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
718 | + echo '<br /> . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
719 | 719 | } |
720 | 720 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
721 | 721 | if ($ticket instanceof EE_Ticket) { |
722 | 722 | if (self::debug) { |
723 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
724 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
723 | + echo '<br /> . . ticket->ID(): '.$ticket->ID(); |
|
724 | + echo '<br /> . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
725 | 725 | } |
726 | 726 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
727 | 727 | } |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | protected function _session_checkout_reset(EE_Checkout $checkout) |
768 | 768 | { |
769 | 769 | if (self::debug) { |
770 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
770 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
771 | 771 | } |
772 | 772 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
773 | 773 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | __LINE__, |
818 | 818 | array($transaction), |
819 | 819 | false, |
820 | - 'EE_Transaction: ' . $transaction->ID() |
|
820 | + 'EE_Transaction: '.$transaction->ID() |
|
821 | 821 | ); |
822 | 822 | } |
823 | 823 | return; |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | __LINE__, |
835 | 835 | array($payment), |
836 | 836 | false, |
837 | - 'EE_Transaction: ' . $transaction->ID() |
|
837 | + 'EE_Transaction: '.$transaction->ID() |
|
838 | 838 | ); |
839 | 839 | } |
840 | 840 | return; |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | } |
895 | 895 | $total_line_item = $transaction->total_line_item(); |
896 | 896 | // $transaction_in_progress->line |
897 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
897 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
898 | 898 | throw new DomainException( |
899 | 899 | esc_html__( |
900 | 900 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | $total_tickets_released = 0; |
955 | 955 | $sold_out_events = array(); |
956 | 956 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
957 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
957 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
958 | 958 | continue; |
959 | 959 | } |
960 | 960 | $reserved_qty = $ticket_with_reservations->reserved(); |
@@ -978,7 +978,7 @@ discard block |
||
978 | 978 | } |
979 | 979 | } |
980 | 980 | // double check whether sold out events should remain sold out after releasing tickets |
981 | - if($sold_out_events !== array()){ |
|
981 | + if ($sold_out_events !== array()) { |
|
982 | 982 | foreach ($sold_out_events as $sold_out_event) { |
983 | 983 | /** @var EE_Event $sold_out_event */ |
984 | 984 | $sold_out_event->perform_sold_out_status_check(); |
@@ -1006,7 +1006,7 @@ discard block |
||
1006 | 1006 | global $wpdb; |
1007 | 1007 | return $wpdb->query( |
1008 | 1008 | $wpdb->prepare( |
1009 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1009 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
1010 | 1010 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1011 | 1011 | // use GMT time because that's what LIN_timestamps are in |
1012 | 1012 | date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |