@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php 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 | - ); ?> |
|
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 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
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 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.38.rc.043'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.38.rc.043'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,698 +16,698 @@ discard block |
||
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @return EED_Module|EED_Add_New_State |
|
21 | - */ |
|
22 | - public static function instance() |
|
23 | - { |
|
24 | - return parent::get_instance(__CLASS__); |
|
25 | - } |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function set_hooks() |
|
35 | - { |
|
36 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
37 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
38 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
39 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
40 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
41 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
42 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
43 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
44 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
46 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
48 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
49 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
50 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
51 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
52 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
59 | - * |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public static function set_hooks_admin() |
|
63 | - { |
|
64 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
65 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
66 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
67 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
68 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
69 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
70 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
71 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
72 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
73 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
74 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
75 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
76 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
77 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
78 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
79 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
80 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
81 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
82 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
83 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
84 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
85 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
86 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public static function set_definitions() |
|
95 | - { |
|
96 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
97 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
98 | - '\\', |
|
99 | - DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
100 | - ); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param WP $WP |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function run($WP) |
|
110 | - { |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - public static function translate_js_strings() |
|
119 | - { |
|
120 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
121 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
122 | - 'event_espresso' |
|
123 | - ); |
|
124 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
125 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
126 | - 'event_espresso' |
|
127 | - ); |
|
128 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
129 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
130 | - 'event_espresso' |
|
131 | - ); |
|
132 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
133 | - 'The new state was successfully saved to the database.', |
|
134 | - 'event_espresso' |
|
135 | - ); |
|
136 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
137 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
138 | - 'event_espresso' |
|
139 | - ); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - public static function wp_enqueue_scripts() |
|
148 | - { |
|
149 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
150 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
151 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
152 | - wp_enqueue_script('add_new_state'); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * display_add_new_state_micro_form |
|
160 | - * |
|
161 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
162 | - * @return string |
|
163 | - * @throws EE_Error |
|
164 | - */ |
|
165 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
166 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
167 | - { |
|
168 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
169 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
170 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
171 | - // is the "state" question in this form section? |
|
172 | - $input = $question_group_reg_form->get_subsection('state'); |
|
173 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
174 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
175 | - //by forcing it to set it now, like it did while getting the form for display |
|
176 | - if ($input instanceof EE_State_Select_Input) { |
|
177 | - $input->html_name(); |
|
178 | - } |
|
179 | - return $question_group_reg_form; |
|
180 | - } |
|
181 | - // we're only doing this for state select inputs |
|
182 | - if ($input instanceof EE_State_Select_Input) { |
|
183 | - // grab any set values from the request |
|
184 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
185 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
186 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
187 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
188 | - $country_options = array(); |
|
189 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
190 | - if (! empty($countries)) { |
|
191 | - foreach ($countries as $country) { |
|
192 | - if ($country instanceof EE_Country) { |
|
193 | - $country_options[$country->ID()] = $country->name(); |
|
194 | - } |
|
195 | - } |
|
196 | - } |
|
197 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
198 | - array( |
|
199 | - 'name' => 'new_state_micro_form', |
|
200 | - 'html_id' => 'new_state_micro_form', |
|
201 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
202 | - 'subsections' => array( |
|
203 | - // add hidden input to indicate that a new state is being added |
|
204 | - 'add_new_state' => new EE_Hidden_Input( |
|
205 | - array( |
|
206 | - 'html_name' => str_replace( |
|
207 | - 'state', |
|
208 | - 'nsmf_add_new_state', $input->html_name() |
|
209 | - ), |
|
210 | - 'html_id' => str_replace( |
|
211 | - 'state', |
|
212 | - 'nsmf_add_new_state', $input->html_id() |
|
213 | - ), |
|
214 | - 'default' => 0, |
|
215 | - ) |
|
216 | - ), |
|
217 | - // add link for displaying hidden container |
|
218 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
219 | - apply_filters( |
|
220 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
221 | - EEH_HTML::link( |
|
222 | - '', |
|
223 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
224 | - '', |
|
225 | - 'display-' . $input->html_id(), |
|
226 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
227 | - '', |
|
228 | - 'data-target="' . $input->html_id() . '"' |
|
229 | - ) |
|
230 | - ) |
|
231 | - ), |
|
232 | - // add initial html for hidden container |
|
233 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
234 | - apply_filters( |
|
235 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
236 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
237 | - 'display: none;') . |
|
238 | - EEH_HTML::h6( |
|
239 | - esc_html__( |
|
240 | - 'If your State/Province does not appear in the list above, you can easily add it by doing the following:', |
|
241 | - 'event_espresso' |
|
242 | - ) |
|
243 | - ) . |
|
244 | - EEH_HTML::ul() . |
|
245 | - EEH_HTML::li( |
|
246 | - esc_html__( |
|
247 | - 'first select the Country that your State/Province belongs to', |
|
248 | - 'event_espresso' |
|
249 | - ) |
|
250 | - ) . |
|
251 | - EEH_HTML::li( |
|
252 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
253 | - ) . |
|
254 | - EEH_HTML::li( |
|
255 | - esc_html__( |
|
256 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
257 | - 'event_espresso' |
|
258 | - ) |
|
259 | - ) . |
|
260 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
261 | - EEH_HTML::ulx() |
|
262 | - ) |
|
263 | - ), |
|
264 | - // NEW STATE COUNTRY |
|
265 | - 'new_state_country' => new EE_Country_Select_Input( |
|
266 | - $country_options, |
|
267 | - array( |
|
268 | - 'html_name' => $country_name, |
|
269 | - 'html_id' => str_replace( |
|
270 | - 'state', |
|
271 | - 'nsmf_new_state_country', $input->html_id() |
|
272 | - ), |
|
273 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
274 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
275 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
276 | - 'required' => false, |
|
277 | - ) |
|
278 | - ), |
|
279 | - // NEW STATE NAME |
|
280 | - 'new_state_name' => new EE_Text_Input( |
|
281 | - array( |
|
282 | - 'html_name' => $state_name, |
|
283 | - 'html_id' => str_replace( |
|
284 | - 'state', |
|
285 | - 'nsmf_new_state_name', $input->html_id() |
|
286 | - ), |
|
287 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
288 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
289 | - 'event_espresso'), |
|
290 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
291 | - 'required' => false, |
|
292 | - ) |
|
293 | - ), |
|
294 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
295 | - // NEW STATE NAME |
|
296 | - 'new_state_abbrv' => new EE_Text_Input( |
|
297 | - array( |
|
298 | - 'html_name' => $abbrv_name, |
|
299 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
300 | - $input->html_id()), |
|
301 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
302 | - 'html_label_text' => esc_html__( |
|
303 | - 'New State/Province Abbreviation', |
|
304 | - 'event_espresso' |
|
305 | - ) . ' *', |
|
306 | - 'html_other_attributes' => 'size="24"', |
|
307 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
308 | - 'required' => false, |
|
309 | - ) |
|
310 | - ), |
|
311 | - // "submit" button |
|
312 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
313 | - apply_filters( |
|
314 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
315 | - EEH_HTML::nbsp(3) . |
|
316 | - EEH_HTML::link( |
|
317 | - '', |
|
318 | - esc_html__('ADD', 'event_espresso'), |
|
319 | - '', |
|
320 | - 'submit-' . $new_state_submit_id, |
|
321 | - 'ee-form-add-new-state-submit button button-secondary', |
|
322 | - '', |
|
323 | - 'data-target="' . $new_state_submit_id . '"' |
|
324 | - ) |
|
325 | - ) |
|
326 | - ), |
|
327 | - // extra info |
|
328 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
329 | - apply_filters( |
|
330 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
331 | - EEH_HTML::br(2) |
|
332 | - . |
|
333 | - EEH_HTML::div('', '', 'small-text') |
|
334 | - . |
|
335 | - EEH_HTML::strong( |
|
336 | - '* ' . |
|
337 | - esc_html__( |
|
338 | - 'Don\'t know your State/Province Abbreviation?', |
|
339 | - 'event_espresso' |
|
340 | - ) |
|
341 | - ) |
|
342 | - . |
|
343 | - EEH_HTML::br() |
|
344 | - . |
|
345 | - sprintf( |
|
346 | - esc_html__( |
|
347 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
348 | - 'event_espresso' |
|
349 | - ), |
|
350 | - EEH_HTML::link( |
|
351 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
352 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
353 | - '', |
|
354 | - '', |
|
355 | - 'ee-form-add-new-state-wiki-lnk', |
|
356 | - '', |
|
357 | - 'target="_blank"' |
|
358 | - ) |
|
359 | - ) |
|
360 | - . |
|
361 | - EEH_HTML::divx() |
|
362 | - . |
|
363 | - EEH_HTML::br() |
|
364 | - . |
|
365 | - EEH_HTML::link( |
|
366 | - '', |
|
367 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
368 | - '', |
|
369 | - 'hide-' . $input->html_id(), |
|
370 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
371 | - '', |
|
372 | - 'data-target="' . $input->html_id() . '"' |
|
373 | - ) |
|
374 | - . |
|
375 | - EEH_HTML::divx() |
|
376 | - . |
|
377 | - EEH_HTML::br() |
|
378 | - ) |
|
379 | - ), |
|
380 | - ), |
|
381 | - ) |
|
382 | - ); |
|
383 | - $question_group_reg_form->add_subsections( |
|
384 | - array('new_state_micro_form' => $new_state_micro_form), |
|
385 | - 'state', |
|
386 | - false |
|
387 | - ); |
|
388 | - } |
|
389 | - return $question_group_reg_form; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * set_new_state_input_width |
|
396 | - * |
|
397 | - * @return int|string |
|
398 | - * @throws EE_Error |
|
399 | - */ |
|
400 | - public static function add_new_state() |
|
401 | - { |
|
402 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
403 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
404 | - EE_Registry::instance()->load_model('State'); |
|
405 | - // grab country ISO code, new state name, and new state abbreviation |
|
406 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
407 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
408 | - : false; |
|
409 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
410 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
411 | - : false; |
|
412 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
413 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
414 | - : false; |
|
415 | - if ($state_country && $state_name && $state_abbr) { |
|
416 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
417 | - 'CNT_ISO' => strtoupper($state_country), |
|
418 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
419 | - 'STA_name' => ucwords($state_name), |
|
420 | - 'STA_active' => false, |
|
421 | - )); |
|
422 | - if ($new_state instanceof EE_State) { |
|
423 | - // clean house |
|
424 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
425 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
426 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
427 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
428 | - // get any existing new states |
|
429 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
430 | - 'nsmf_new_states' |
|
431 | - ); |
|
432 | - $new_states[$new_state->ID()] = $new_state; |
|
433 | - EE_Registry::instance()->SSN->set_session_data( |
|
434 | - array('nsmf_new_states' => $new_states) |
|
435 | - ); |
|
436 | - if (EE_Registry::instance()->REQ->ajax) { |
|
437 | - echo wp_json_encode(array( |
|
438 | - 'success' => true, |
|
439 | - 'id' => $new_state->ID(), |
|
440 | - 'name' => $new_state->name(), |
|
441 | - 'abbrev' => $new_state->abbrev(), |
|
442 | - 'country_iso' => $new_state->country_iso(), |
|
443 | - 'country_name' => $new_state->country()->name(), |
|
444 | - )); |
|
445 | - exit(); |
|
446 | - } |
|
447 | - return $new_state->ID(); |
|
448 | - } |
|
449 | - } else { |
|
450 | - $error = esc_html__( |
|
451 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
452 | - 'event_espresso' |
|
453 | - ); |
|
454 | - if (EE_Registry::instance()->REQ->ajax) { |
|
455 | - echo wp_json_encode(array('error' => $error)); |
|
456 | - exit(); |
|
457 | - } |
|
458 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
459 | - } |
|
460 | - } |
|
461 | - return false; |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * recursively drills down through request params to remove any that were added by this module |
|
468 | - * |
|
469 | - * @param array $request_params |
|
470 | - * @return array |
|
471 | - */ |
|
472 | - public static function filter_checkout_request_params($request_params) |
|
473 | - { |
|
474 | - foreach ($request_params as $form_section) { |
|
475 | - if (is_array($form_section)) { |
|
476 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
477 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
478 | - } |
|
479 | - } |
|
480 | - return $request_params; |
|
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * @param array $request_params |
|
487 | - * @return array |
|
488 | - */ |
|
489 | - public static function unset_new_state_request_params($request_params) |
|
490 | - { |
|
491 | - unset( |
|
492 | - $request_params['new_state_micro_form'], |
|
493 | - $request_params['new_state_micro_add_new_state'], |
|
494 | - $request_params['new_state_micro_new_state_country'], |
|
495 | - $request_params['new_state_micro_new_state_name'], |
|
496 | - $request_params['new_state_micro_new_state_abbrv'] |
|
497 | - ); |
|
498 | - return $request_params; |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * @param array $props_n_values |
|
505 | - * @return bool |
|
506 | - * @throws EE_Error |
|
507 | - */ |
|
508 | - public static function save_new_state_to_db($props_n_values = array()) |
|
509 | - { |
|
510 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
511 | - if (! empty($existing_state)) { |
|
512 | - return array_pop($existing_state); |
|
513 | - } |
|
514 | - $new_state = EE_State::new_instance($props_n_values); |
|
515 | - if ($new_state instanceof EE_State) { |
|
516 | - // if not non-ajax admin |
|
517 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
518 | - $new_state_notice = sprintf( |
|
519 | - esc_html__( |
|
520 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
521 | - 'event_espresso' |
|
522 | - ), |
|
523 | - '<b>' . $new_state->name() . '</b>', |
|
524 | - '<b>' . $new_state->abbrev() . '</b>', |
|
525 | - '<b>' . $new_state->country()->name() . '</b>', |
|
526 | - '<a href="' . add_query_arg(array( |
|
527 | - 'page' => 'espresso_general_settings', |
|
528 | - 'action' => 'country_settings', |
|
529 | - 'country' => $new_state->country_iso(), |
|
530 | - ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
531 | - 'event_espresso') . '</a>', |
|
532 | - '<br />' |
|
533 | - ); |
|
534 | - EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
535 | - $new_state->save(); |
|
536 | - EEM_State::instance()->reset_cached_states(); |
|
537 | - return $new_state; |
|
538 | - } |
|
539 | - return false; |
|
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * @param string $CNT_ISO |
|
546 | - * @param string $STA_ID |
|
547 | - * @param array $cols_n_values |
|
548 | - * @return void |
|
549 | - */ |
|
550 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
551 | - { |
|
552 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
|
553 | - if (! $CNT_ISO) { |
|
554 | - EE_Error::add_error( |
|
555 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
556 | - __FILE__, |
|
557 | - __FUNCTION__, |
|
558 | - __LINE__ |
|
559 | - ); |
|
560 | - } |
|
561 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
562 | - : false; |
|
563 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
564 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
565 | - if ($state instanceof EE_State) { |
|
566 | - $STA_abbrev = $state->abbrev(); |
|
567 | - } |
|
568 | - } |
|
569 | - if (! $STA_abbrev) { |
|
570 | - EE_Error::add_error( |
|
571 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
572 | - __FILE__, |
|
573 | - __FUNCTION__, |
|
574 | - __LINE__ |
|
575 | - ); |
|
576 | - } |
|
577 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * @param EE_State[] $state_options |
|
584 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
585 | - * @param EE_Registration $registration |
|
586 | - * @param EE_Question $question |
|
587 | - * @param $answer |
|
588 | - * @return array |
|
589 | - */ |
|
590 | - public static function inject_new_reg_state_into_options( |
|
591 | - $state_options = array(), |
|
592 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
593 | - EE_Registration $registration, |
|
594 | - EE_Question $question, |
|
595 | - $answer |
|
596 | - ) { |
|
597 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
598 | - && $question->type() |
|
599 | - === EEM_Question::QST_type_state |
|
600 | - ) { |
|
601 | - $STA_ID = $answer->value(); |
|
602 | - if (! empty($STA_ID)) { |
|
603 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
604 | - if ($state instanceof EE_State) { |
|
605 | - $country = $state->country(); |
|
606 | - if ($country instanceof EE_Country) { |
|
607 | - if (! isset($state_options[$country->name()])) { |
|
608 | - $state_options[$country->name()] = array(); |
|
609 | - } |
|
610 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
611 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
612 | - } |
|
613 | - } |
|
614 | - } |
|
615 | - } |
|
616 | - } |
|
617 | - return $state_options; |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * @param EE_Country[] $country_options |
|
624 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
625 | - * @param EE_Registration $registration |
|
626 | - * @param EE_Question $question |
|
627 | - * @param $answer |
|
628 | - * @return array |
|
629 | - */ |
|
630 | - public static function inject_new_reg_country_into_options( |
|
631 | - $country_options = array(), |
|
632 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
633 | - EE_Registration $registration, |
|
634 | - EE_Question $question, |
|
635 | - $answer |
|
636 | - ) { |
|
637 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
638 | - && $question->type() |
|
639 | - === EEM_Question::QST_type_country |
|
640 | - ) { |
|
641 | - $CNT_ISO = $answer->value(); |
|
642 | - if (! empty($CNT_ISO)) { |
|
643 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
644 | - if ($country instanceof EE_Country) { |
|
645 | - if (! isset($country_options[$CNT_ISO])) { |
|
646 | - $country_options[$CNT_ISO] = $country->name(); |
|
647 | - } |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - return $country_options; |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * @param EE_State[] $state_options |
|
658 | - * @return array |
|
659 | - * @throws EE_Error |
|
660 | - */ |
|
661 | - public static function state_options($state_options = array()) |
|
662 | - { |
|
663 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
664 | - foreach ($new_states as $new_state) { |
|
665 | - if ( |
|
666 | - $new_state instanceof EE_State |
|
667 | - && $new_state->country() instanceof EE_Country |
|
668 | - ) { |
|
669 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
670 | - } |
|
671 | - } |
|
672 | - return $state_options; |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - |
|
677 | - /** |
|
678 | - * @return array |
|
679 | - */ |
|
680 | - protected static function _get_new_states() |
|
681 | - { |
|
682 | - $new_states = array(); |
|
683 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
684 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
685 | - 'nsmf_new_states' |
|
686 | - ); |
|
687 | - } |
|
688 | - return is_array($new_states) ? $new_states : array(); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * @param EE_Country[] $country_options |
|
695 | - * @return array |
|
696 | - * @throws EE_Error |
|
697 | - */ |
|
698 | - public static function country_options($country_options = array()) |
|
699 | - { |
|
700 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
701 | - foreach ($new_states as $new_state) { |
|
702 | - if ( |
|
703 | - $new_state instanceof EE_State |
|
704 | - && $new_state->country() instanceof EE_Country |
|
705 | - ) { |
|
706 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
707 | - } |
|
708 | - } |
|
709 | - return $country_options; |
|
710 | - } |
|
19 | + /** |
|
20 | + * @return EED_Module|EED_Add_New_State |
|
21 | + */ |
|
22 | + public static function instance() |
|
23 | + { |
|
24 | + return parent::get_instance(__CLASS__); |
|
25 | + } |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function set_hooks() |
|
35 | + { |
|
36 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
37 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
38 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
39 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
40 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
41 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
42 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
43 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
44 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
46 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
48 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
49 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
50 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
51 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
52 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
59 | + * |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public static function set_hooks_admin() |
|
63 | + { |
|
64 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
65 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
66 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
67 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
68 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
69 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
70 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
71 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
72 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
73 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
74 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
75 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
76 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
77 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
78 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
79 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
80 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
81 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
82 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
83 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
84 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
85 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
86 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public static function set_definitions() |
|
95 | + { |
|
96 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
97 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
98 | + '\\', |
|
99 | + DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
100 | + ); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param WP $WP |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function run($WP) |
|
110 | + { |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + public static function translate_js_strings() |
|
119 | + { |
|
120 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
121 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
122 | + 'event_espresso' |
|
123 | + ); |
|
124 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
125 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
126 | + 'event_espresso' |
|
127 | + ); |
|
128 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
129 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
130 | + 'event_espresso' |
|
131 | + ); |
|
132 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
133 | + 'The new state was successfully saved to the database.', |
|
134 | + 'event_espresso' |
|
135 | + ); |
|
136 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
137 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
138 | + 'event_espresso' |
|
139 | + ); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + public static function wp_enqueue_scripts() |
|
148 | + { |
|
149 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
150 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
151 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
152 | + wp_enqueue_script('add_new_state'); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * display_add_new_state_micro_form |
|
160 | + * |
|
161 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
162 | + * @return string |
|
163 | + * @throws EE_Error |
|
164 | + */ |
|
165 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
166 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
167 | + { |
|
168 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
169 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
170 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
171 | + // is the "state" question in this form section? |
|
172 | + $input = $question_group_reg_form->get_subsection('state'); |
|
173 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
174 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
175 | + //by forcing it to set it now, like it did while getting the form for display |
|
176 | + if ($input instanceof EE_State_Select_Input) { |
|
177 | + $input->html_name(); |
|
178 | + } |
|
179 | + return $question_group_reg_form; |
|
180 | + } |
|
181 | + // we're only doing this for state select inputs |
|
182 | + if ($input instanceof EE_State_Select_Input) { |
|
183 | + // grab any set values from the request |
|
184 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
185 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
186 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
187 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
188 | + $country_options = array(); |
|
189 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
190 | + if (! empty($countries)) { |
|
191 | + foreach ($countries as $country) { |
|
192 | + if ($country instanceof EE_Country) { |
|
193 | + $country_options[$country->ID()] = $country->name(); |
|
194 | + } |
|
195 | + } |
|
196 | + } |
|
197 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
198 | + array( |
|
199 | + 'name' => 'new_state_micro_form', |
|
200 | + 'html_id' => 'new_state_micro_form', |
|
201 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
202 | + 'subsections' => array( |
|
203 | + // add hidden input to indicate that a new state is being added |
|
204 | + 'add_new_state' => new EE_Hidden_Input( |
|
205 | + array( |
|
206 | + 'html_name' => str_replace( |
|
207 | + 'state', |
|
208 | + 'nsmf_add_new_state', $input->html_name() |
|
209 | + ), |
|
210 | + 'html_id' => str_replace( |
|
211 | + 'state', |
|
212 | + 'nsmf_add_new_state', $input->html_id() |
|
213 | + ), |
|
214 | + 'default' => 0, |
|
215 | + ) |
|
216 | + ), |
|
217 | + // add link for displaying hidden container |
|
218 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
219 | + apply_filters( |
|
220 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
221 | + EEH_HTML::link( |
|
222 | + '', |
|
223 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
224 | + '', |
|
225 | + 'display-' . $input->html_id(), |
|
226 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
227 | + '', |
|
228 | + 'data-target="' . $input->html_id() . '"' |
|
229 | + ) |
|
230 | + ) |
|
231 | + ), |
|
232 | + // add initial html for hidden container |
|
233 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
234 | + apply_filters( |
|
235 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
236 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
237 | + 'display: none;') . |
|
238 | + EEH_HTML::h6( |
|
239 | + esc_html__( |
|
240 | + 'If your State/Province does not appear in the list above, you can easily add it by doing the following:', |
|
241 | + 'event_espresso' |
|
242 | + ) |
|
243 | + ) . |
|
244 | + EEH_HTML::ul() . |
|
245 | + EEH_HTML::li( |
|
246 | + esc_html__( |
|
247 | + 'first select the Country that your State/Province belongs to', |
|
248 | + 'event_espresso' |
|
249 | + ) |
|
250 | + ) . |
|
251 | + EEH_HTML::li( |
|
252 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
253 | + ) . |
|
254 | + EEH_HTML::li( |
|
255 | + esc_html__( |
|
256 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
257 | + 'event_espresso' |
|
258 | + ) |
|
259 | + ) . |
|
260 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
261 | + EEH_HTML::ulx() |
|
262 | + ) |
|
263 | + ), |
|
264 | + // NEW STATE COUNTRY |
|
265 | + 'new_state_country' => new EE_Country_Select_Input( |
|
266 | + $country_options, |
|
267 | + array( |
|
268 | + 'html_name' => $country_name, |
|
269 | + 'html_id' => str_replace( |
|
270 | + 'state', |
|
271 | + 'nsmf_new_state_country', $input->html_id() |
|
272 | + ), |
|
273 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
274 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
275 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
276 | + 'required' => false, |
|
277 | + ) |
|
278 | + ), |
|
279 | + // NEW STATE NAME |
|
280 | + 'new_state_name' => new EE_Text_Input( |
|
281 | + array( |
|
282 | + 'html_name' => $state_name, |
|
283 | + 'html_id' => str_replace( |
|
284 | + 'state', |
|
285 | + 'nsmf_new_state_name', $input->html_id() |
|
286 | + ), |
|
287 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
288 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
289 | + 'event_espresso'), |
|
290 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
291 | + 'required' => false, |
|
292 | + ) |
|
293 | + ), |
|
294 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
295 | + // NEW STATE NAME |
|
296 | + 'new_state_abbrv' => new EE_Text_Input( |
|
297 | + array( |
|
298 | + 'html_name' => $abbrv_name, |
|
299 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
300 | + $input->html_id()), |
|
301 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
302 | + 'html_label_text' => esc_html__( |
|
303 | + 'New State/Province Abbreviation', |
|
304 | + 'event_espresso' |
|
305 | + ) . ' *', |
|
306 | + 'html_other_attributes' => 'size="24"', |
|
307 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
308 | + 'required' => false, |
|
309 | + ) |
|
310 | + ), |
|
311 | + // "submit" button |
|
312 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
313 | + apply_filters( |
|
314 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
315 | + EEH_HTML::nbsp(3) . |
|
316 | + EEH_HTML::link( |
|
317 | + '', |
|
318 | + esc_html__('ADD', 'event_espresso'), |
|
319 | + '', |
|
320 | + 'submit-' . $new_state_submit_id, |
|
321 | + 'ee-form-add-new-state-submit button button-secondary', |
|
322 | + '', |
|
323 | + 'data-target="' . $new_state_submit_id . '"' |
|
324 | + ) |
|
325 | + ) |
|
326 | + ), |
|
327 | + // extra info |
|
328 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
329 | + apply_filters( |
|
330 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
331 | + EEH_HTML::br(2) |
|
332 | + . |
|
333 | + EEH_HTML::div('', '', 'small-text') |
|
334 | + . |
|
335 | + EEH_HTML::strong( |
|
336 | + '* ' . |
|
337 | + esc_html__( |
|
338 | + 'Don\'t know your State/Province Abbreviation?', |
|
339 | + 'event_espresso' |
|
340 | + ) |
|
341 | + ) |
|
342 | + . |
|
343 | + EEH_HTML::br() |
|
344 | + . |
|
345 | + sprintf( |
|
346 | + esc_html__( |
|
347 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
348 | + 'event_espresso' |
|
349 | + ), |
|
350 | + EEH_HTML::link( |
|
351 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
352 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
353 | + '', |
|
354 | + '', |
|
355 | + 'ee-form-add-new-state-wiki-lnk', |
|
356 | + '', |
|
357 | + 'target="_blank"' |
|
358 | + ) |
|
359 | + ) |
|
360 | + . |
|
361 | + EEH_HTML::divx() |
|
362 | + . |
|
363 | + EEH_HTML::br() |
|
364 | + . |
|
365 | + EEH_HTML::link( |
|
366 | + '', |
|
367 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
368 | + '', |
|
369 | + 'hide-' . $input->html_id(), |
|
370 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
371 | + '', |
|
372 | + 'data-target="' . $input->html_id() . '"' |
|
373 | + ) |
|
374 | + . |
|
375 | + EEH_HTML::divx() |
|
376 | + . |
|
377 | + EEH_HTML::br() |
|
378 | + ) |
|
379 | + ), |
|
380 | + ), |
|
381 | + ) |
|
382 | + ); |
|
383 | + $question_group_reg_form->add_subsections( |
|
384 | + array('new_state_micro_form' => $new_state_micro_form), |
|
385 | + 'state', |
|
386 | + false |
|
387 | + ); |
|
388 | + } |
|
389 | + return $question_group_reg_form; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * set_new_state_input_width |
|
396 | + * |
|
397 | + * @return int|string |
|
398 | + * @throws EE_Error |
|
399 | + */ |
|
400 | + public static function add_new_state() |
|
401 | + { |
|
402 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
403 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
404 | + EE_Registry::instance()->load_model('State'); |
|
405 | + // grab country ISO code, new state name, and new state abbreviation |
|
406 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
407 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
408 | + : false; |
|
409 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
410 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
411 | + : false; |
|
412 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
413 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
414 | + : false; |
|
415 | + if ($state_country && $state_name && $state_abbr) { |
|
416 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
417 | + 'CNT_ISO' => strtoupper($state_country), |
|
418 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
419 | + 'STA_name' => ucwords($state_name), |
|
420 | + 'STA_active' => false, |
|
421 | + )); |
|
422 | + if ($new_state instanceof EE_State) { |
|
423 | + // clean house |
|
424 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
425 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
426 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
427 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
428 | + // get any existing new states |
|
429 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
430 | + 'nsmf_new_states' |
|
431 | + ); |
|
432 | + $new_states[$new_state->ID()] = $new_state; |
|
433 | + EE_Registry::instance()->SSN->set_session_data( |
|
434 | + array('nsmf_new_states' => $new_states) |
|
435 | + ); |
|
436 | + if (EE_Registry::instance()->REQ->ajax) { |
|
437 | + echo wp_json_encode(array( |
|
438 | + 'success' => true, |
|
439 | + 'id' => $new_state->ID(), |
|
440 | + 'name' => $new_state->name(), |
|
441 | + 'abbrev' => $new_state->abbrev(), |
|
442 | + 'country_iso' => $new_state->country_iso(), |
|
443 | + 'country_name' => $new_state->country()->name(), |
|
444 | + )); |
|
445 | + exit(); |
|
446 | + } |
|
447 | + return $new_state->ID(); |
|
448 | + } |
|
449 | + } else { |
|
450 | + $error = esc_html__( |
|
451 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
452 | + 'event_espresso' |
|
453 | + ); |
|
454 | + if (EE_Registry::instance()->REQ->ajax) { |
|
455 | + echo wp_json_encode(array('error' => $error)); |
|
456 | + exit(); |
|
457 | + } |
|
458 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
459 | + } |
|
460 | + } |
|
461 | + return false; |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * recursively drills down through request params to remove any that were added by this module |
|
468 | + * |
|
469 | + * @param array $request_params |
|
470 | + * @return array |
|
471 | + */ |
|
472 | + public static function filter_checkout_request_params($request_params) |
|
473 | + { |
|
474 | + foreach ($request_params as $form_section) { |
|
475 | + if (is_array($form_section)) { |
|
476 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
477 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
478 | + } |
|
479 | + } |
|
480 | + return $request_params; |
|
481 | + } |
|
482 | + |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * @param array $request_params |
|
487 | + * @return array |
|
488 | + */ |
|
489 | + public static function unset_new_state_request_params($request_params) |
|
490 | + { |
|
491 | + unset( |
|
492 | + $request_params['new_state_micro_form'], |
|
493 | + $request_params['new_state_micro_add_new_state'], |
|
494 | + $request_params['new_state_micro_new_state_country'], |
|
495 | + $request_params['new_state_micro_new_state_name'], |
|
496 | + $request_params['new_state_micro_new_state_abbrv'] |
|
497 | + ); |
|
498 | + return $request_params; |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * @param array $props_n_values |
|
505 | + * @return bool |
|
506 | + * @throws EE_Error |
|
507 | + */ |
|
508 | + public static function save_new_state_to_db($props_n_values = array()) |
|
509 | + { |
|
510 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
511 | + if (! empty($existing_state)) { |
|
512 | + return array_pop($existing_state); |
|
513 | + } |
|
514 | + $new_state = EE_State::new_instance($props_n_values); |
|
515 | + if ($new_state instanceof EE_State) { |
|
516 | + // if not non-ajax admin |
|
517 | + $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
518 | + $new_state_notice = sprintf( |
|
519 | + esc_html__( |
|
520 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
521 | + 'event_espresso' |
|
522 | + ), |
|
523 | + '<b>' . $new_state->name() . '</b>', |
|
524 | + '<b>' . $new_state->abbrev() . '</b>', |
|
525 | + '<b>' . $new_state->country()->name() . '</b>', |
|
526 | + '<a href="' . add_query_arg(array( |
|
527 | + 'page' => 'espresso_general_settings', |
|
528 | + 'action' => 'country_settings', |
|
529 | + 'country' => $new_state->country_iso(), |
|
530 | + ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
531 | + 'event_espresso') . '</a>', |
|
532 | + '<br />' |
|
533 | + ); |
|
534 | + EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
|
535 | + $new_state->save(); |
|
536 | + EEM_State::instance()->reset_cached_states(); |
|
537 | + return $new_state; |
|
538 | + } |
|
539 | + return false; |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * @param string $CNT_ISO |
|
546 | + * @param string $STA_ID |
|
547 | + * @param array $cols_n_values |
|
548 | + * @return void |
|
549 | + */ |
|
550 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
551 | + { |
|
552 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
|
553 | + if (! $CNT_ISO) { |
|
554 | + EE_Error::add_error( |
|
555 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
556 | + __FILE__, |
|
557 | + __FUNCTION__, |
|
558 | + __LINE__ |
|
559 | + ); |
|
560 | + } |
|
561 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
562 | + : false; |
|
563 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
564 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
565 | + if ($state instanceof EE_State) { |
|
566 | + $STA_abbrev = $state->abbrev(); |
|
567 | + } |
|
568 | + } |
|
569 | + if (! $STA_abbrev) { |
|
570 | + EE_Error::add_error( |
|
571 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
572 | + __FILE__, |
|
573 | + __FUNCTION__, |
|
574 | + __LINE__ |
|
575 | + ); |
|
576 | + } |
|
577 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * @param EE_State[] $state_options |
|
584 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
585 | + * @param EE_Registration $registration |
|
586 | + * @param EE_Question $question |
|
587 | + * @param $answer |
|
588 | + * @return array |
|
589 | + */ |
|
590 | + public static function inject_new_reg_state_into_options( |
|
591 | + $state_options = array(), |
|
592 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
593 | + EE_Registration $registration, |
|
594 | + EE_Question $question, |
|
595 | + $answer |
|
596 | + ) { |
|
597 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
598 | + && $question->type() |
|
599 | + === EEM_Question::QST_type_state |
|
600 | + ) { |
|
601 | + $STA_ID = $answer->value(); |
|
602 | + if (! empty($STA_ID)) { |
|
603 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
604 | + if ($state instanceof EE_State) { |
|
605 | + $country = $state->country(); |
|
606 | + if ($country instanceof EE_Country) { |
|
607 | + if (! isset($state_options[$country->name()])) { |
|
608 | + $state_options[$country->name()] = array(); |
|
609 | + } |
|
610 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
611 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
612 | + } |
|
613 | + } |
|
614 | + } |
|
615 | + } |
|
616 | + } |
|
617 | + return $state_options; |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * @param EE_Country[] $country_options |
|
624 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
625 | + * @param EE_Registration $registration |
|
626 | + * @param EE_Question $question |
|
627 | + * @param $answer |
|
628 | + * @return array |
|
629 | + */ |
|
630 | + public static function inject_new_reg_country_into_options( |
|
631 | + $country_options = array(), |
|
632 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
633 | + EE_Registration $registration, |
|
634 | + EE_Question $question, |
|
635 | + $answer |
|
636 | + ) { |
|
637 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
638 | + && $question->type() |
|
639 | + === EEM_Question::QST_type_country |
|
640 | + ) { |
|
641 | + $CNT_ISO = $answer->value(); |
|
642 | + if (! empty($CNT_ISO)) { |
|
643 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
644 | + if ($country instanceof EE_Country) { |
|
645 | + if (! isset($country_options[$CNT_ISO])) { |
|
646 | + $country_options[$CNT_ISO] = $country->name(); |
|
647 | + } |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + return $country_options; |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * @param EE_State[] $state_options |
|
658 | + * @return array |
|
659 | + * @throws EE_Error |
|
660 | + */ |
|
661 | + public static function state_options($state_options = array()) |
|
662 | + { |
|
663 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
664 | + foreach ($new_states as $new_state) { |
|
665 | + if ( |
|
666 | + $new_state instanceof EE_State |
|
667 | + && $new_state->country() instanceof EE_Country |
|
668 | + ) { |
|
669 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
670 | + } |
|
671 | + } |
|
672 | + return $state_options; |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + |
|
677 | + /** |
|
678 | + * @return array |
|
679 | + */ |
|
680 | + protected static function _get_new_states() |
|
681 | + { |
|
682 | + $new_states = array(); |
|
683 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
684 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
685 | + 'nsmf_new_states' |
|
686 | + ); |
|
687 | + } |
|
688 | + return is_array($new_states) ? $new_states : array(); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * @param EE_Country[] $country_options |
|
695 | + * @return array |
|
696 | + * @throws EE_Error |
|
697 | + */ |
|
698 | + public static function country_options($country_options = array()) |
|
699 | + { |
|
700 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
701 | + foreach ($new_states as $new_state) { |
|
702 | + if ( |
|
703 | + $new_state instanceof EE_State |
|
704 | + && $new_state->country() instanceof EE_Country |
|
705 | + ) { |
|
706 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
707 | + } |
|
708 | + } |
|
709 | + return $country_options; |
|
710 | + } |
|
711 | 711 | |
712 | 712 | |
713 | 713 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public static function set_definitions() |
95 | 95 | { |
96 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
96 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
97 | 97 | define('ANS_TEMPLATES_PATH', str_replace( |
98 | 98 | '\\', |
99 | - DS, plugin_dir_path(__FILE__)) . 'templates' . DS |
|
99 | + DS, plugin_dir_path(__FILE__)).'templates'.DS |
|
100 | 100 | ); |
101 | 101 | } |
102 | 102 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | public static function wp_enqueue_scripts() |
148 | 148 | { |
149 | 149 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
150 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
150 | + wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js', |
|
151 | 151 | array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
152 | 152 | wp_enqueue_script('add_new_state'); |
153 | 153 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
188 | 188 | $country_options = array(); |
189 | 189 | $countries = EEM_Country::instance()->get_all_countries(); |
190 | - if (! empty($countries)) { |
|
190 | + if ( ! empty($countries)) { |
|
191 | 191 | foreach ($countries as $country) { |
192 | 192 | if ($country instanceof EE_Country) { |
193 | 193 | $country_options[$country->ID()] = $country->name(); |
@@ -222,10 +222,10 @@ discard block |
||
222 | 222 | '', |
223 | 223 | esc_html__('click here to add a new state/province', 'event_espresso'), |
224 | 224 | '', |
225 | - 'display-' . $input->html_id(), |
|
225 | + 'display-'.$input->html_id(), |
|
226 | 226 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
227 | 227 | '', |
228 | - 'data-target="' . $input->html_id() . '"' |
|
228 | + 'data-target="'.$input->html_id().'"' |
|
229 | 229 | ) |
230 | 230 | ) |
231 | 231 | ), |
@@ -233,31 +233,31 @@ discard block |
||
233 | 233 | 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
234 | 234 | apply_filters( |
235 | 235 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
236 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
237 | - 'display: none;') . |
|
236 | + EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv', |
|
237 | + 'display: none;'). |
|
238 | 238 | EEH_HTML::h6( |
239 | 239 | esc_html__( |
240 | 240 | 'If your State/Province does not appear in the list above, you can easily add it by doing the following:', |
241 | 241 | 'event_espresso' |
242 | 242 | ) |
243 | - ) . |
|
244 | - EEH_HTML::ul() . |
|
243 | + ). |
|
244 | + EEH_HTML::ul(). |
|
245 | 245 | EEH_HTML::li( |
246 | 246 | esc_html__( |
247 | 247 | 'first select the Country that your State/Province belongs to', |
248 | 248 | 'event_espresso' |
249 | 249 | ) |
250 | - ) . |
|
250 | + ). |
|
251 | 251 | EEH_HTML::li( |
252 | 252 | esc_html__('enter the name of your State/Province', 'event_espresso') |
253 | - ) . |
|
253 | + ). |
|
254 | 254 | EEH_HTML::li( |
255 | 255 | esc_html__( |
256 | 256 | 'enter a two to six letter abbreviation for the name of your State/Province', |
257 | 257 | 'event_espresso' |
258 | 258 | ) |
259 | - ) . |
|
260 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
259 | + ). |
|
260 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')). |
|
261 | 261 | EEH_HTML::ulx() |
262 | 262 | ) |
263 | 263 | ), |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | 'state', |
271 | 271 | 'nsmf_new_state_country', $input->html_id() |
272 | 272 | ), |
273 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
273 | + 'html_class' => $input->html_class().' new-state-country', |
|
274 | 274 | 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
275 | 275 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
276 | 276 | 'required' => false, |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | 'state', |
285 | 285 | 'nsmf_new_state_name', $input->html_id() |
286 | 286 | ), |
287 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
287 | + 'html_class' => $input->html_class().' new-state-state', |
|
288 | 288 | 'html_label_text' => esc_html__('New State/Province Name', |
289 | 289 | 'event_espresso'), |
290 | 290 | 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
@@ -298,11 +298,11 @@ discard block |
||
298 | 298 | 'html_name' => $abbrv_name, |
299 | 299 | 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
300 | 300 | $input->html_id()), |
301 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
301 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
302 | 302 | 'html_label_text' => esc_html__( |
303 | 303 | 'New State/Province Abbreviation', |
304 | 304 | 'event_espresso' |
305 | - ) . ' *', |
|
305 | + ).' *', |
|
306 | 306 | 'html_other_attributes' => 'size="24"', |
307 | 307 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
308 | 308 | 'required' => false, |
@@ -312,15 +312,15 @@ discard block |
||
312 | 312 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
313 | 313 | apply_filters( |
314 | 314 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
315 | - EEH_HTML::nbsp(3) . |
|
315 | + EEH_HTML::nbsp(3). |
|
316 | 316 | EEH_HTML::link( |
317 | 317 | '', |
318 | 318 | esc_html__('ADD', 'event_espresso'), |
319 | 319 | '', |
320 | - 'submit-' . $new_state_submit_id, |
|
320 | + 'submit-'.$new_state_submit_id, |
|
321 | 321 | 'ee-form-add-new-state-submit button button-secondary', |
322 | 322 | '', |
323 | - 'data-target="' . $new_state_submit_id . '"' |
|
323 | + 'data-target="'.$new_state_submit_id.'"' |
|
324 | 324 | ) |
325 | 325 | ) |
326 | 326 | ), |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | EEH_HTML::div('', '', 'small-text') |
334 | 334 | . |
335 | 335 | EEH_HTML::strong( |
336 | - '* ' . |
|
336 | + '* '. |
|
337 | 337 | esc_html__( |
338 | 338 | 'Don\'t know your State/Province Abbreviation?', |
339 | 339 | 'event_espresso' |
@@ -366,10 +366,10 @@ discard block |
||
366 | 366 | '', |
367 | 367 | esc_html__('cancel new State/Province', 'event_espresso'), |
368 | 368 | '', |
369 | - 'hide-' . $input->html_id(), |
|
369 | + 'hide-'.$input->html_id(), |
|
370 | 370 | 'ee-form-cancel-new-state-lnk smaller-text', |
371 | 371 | '', |
372 | - 'data-target="' . $input->html_id() . '"' |
|
372 | + 'data-target="'.$input->html_id().'"' |
|
373 | 373 | ) |
374 | 374 | . |
375 | 375 | EEH_HTML::divx() |
@@ -508,27 +508,27 @@ discard block |
||
508 | 508 | public static function save_new_state_to_db($props_n_values = array()) |
509 | 509 | { |
510 | 510 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
511 | - if (! empty($existing_state)) { |
|
511 | + if ( ! empty($existing_state)) { |
|
512 | 512 | return array_pop($existing_state); |
513 | 513 | } |
514 | 514 | $new_state = EE_State::new_instance($props_n_values); |
515 | 515 | if ($new_state instanceof EE_State) { |
516 | 516 | // if not non-ajax admin |
517 | - $new_state_key = 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(); |
|
517 | + $new_state_key = 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(); |
|
518 | 518 | $new_state_notice = sprintf( |
519 | 519 | esc_html__( |
520 | 520 | 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
521 | 521 | 'event_espresso' |
522 | 522 | ), |
523 | - '<b>' . $new_state->name() . '</b>', |
|
524 | - '<b>' . $new_state->abbrev() . '</b>', |
|
525 | - '<b>' . $new_state->country()->name() . '</b>', |
|
526 | - '<a href="' . add_query_arg(array( |
|
523 | + '<b>'.$new_state->name().'</b>', |
|
524 | + '<b>'.$new_state->abbrev().'</b>', |
|
525 | + '<b>'.$new_state->country()->name().'</b>', |
|
526 | + '<a href="'.add_query_arg(array( |
|
527 | 527 | 'page' => 'espresso_general_settings', |
528 | 528 | 'action' => 'country_settings', |
529 | 529 | 'country' => $new_state->country_iso(), |
530 | - ), admin_url('admin.php')) . '">' . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
531 | - 'event_espresso') . '</a>', |
|
530 | + ), admin_url('admin.php')).'">'.esc_html__('Event Espresso - General Settings > Countries Tab', |
|
531 | + 'event_espresso').'</a>', |
|
532 | 532 | '<br />' |
533 | 533 | ); |
534 | 534 | EE_Error::add_persistent_admin_notice($new_state_key, $new_state_notice); |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
551 | 551 | { |
552 | 552 | $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : false; |
553 | - if (! $CNT_ISO) { |
|
553 | + if ( ! $CNT_ISO) { |
|
554 | 554 | EE_Error::add_error( |
555 | 555 | esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
556 | 556 | __FILE__, |
@@ -560,13 +560,13 @@ discard block |
||
560 | 560 | } |
561 | 561 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
562 | 562 | : false; |
563 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
563 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
564 | 564 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
565 | 565 | if ($state instanceof EE_State) { |
566 | 566 | $STA_abbrev = $state->abbrev(); |
567 | 567 | } |
568 | 568 | } |
569 | - if (! $STA_abbrev) { |
|
569 | + if ( ! $STA_abbrev) { |
|
570 | 570 | EE_Error::add_error( |
571 | 571 | esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
572 | 572 | __FILE__, |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | __LINE__ |
575 | 575 | ); |
576 | 576 | } |
577 | - EE_Error::dismiss_persistent_admin_notice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
577 | + EE_Error::dismiss_persistent_admin_notice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | |
@@ -599,15 +599,15 @@ discard block |
||
599 | 599 | === EEM_Question::QST_type_state |
600 | 600 | ) { |
601 | 601 | $STA_ID = $answer->value(); |
602 | - if (! empty($STA_ID)) { |
|
602 | + if ( ! empty($STA_ID)) { |
|
603 | 603 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
604 | 604 | if ($state instanceof EE_State) { |
605 | 605 | $country = $state->country(); |
606 | 606 | if ($country instanceof EE_Country) { |
607 | - if (! isset($state_options[$country->name()])) { |
|
607 | + if ( ! isset($state_options[$country->name()])) { |
|
608 | 608 | $state_options[$country->name()] = array(); |
609 | 609 | } |
610 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
610 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
611 | 611 | $state_options[$country->name()][$STA_ID] = $state->name(); |
612 | 612 | } |
613 | 613 | } |
@@ -639,10 +639,10 @@ discard block |
||
639 | 639 | === EEM_Question::QST_type_country |
640 | 640 | ) { |
641 | 641 | $CNT_ISO = $answer->value(); |
642 | - if (! empty($CNT_ISO)) { |
|
642 | + if ( ! empty($CNT_ISO)) { |
|
643 | 643 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
644 | 644 | if ($country instanceof EE_Country) { |
645 | - if (! isset($country_options[$CNT_ISO])) { |
|
645 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
646 | 646 | $country_options[$CNT_ISO] = $country->name(); |
647 | 647 | } |
648 | 648 | } |