@@ -1,39 +1,39 @@ discard block |
||
1 | 1 | <div id="ee-single-page-checkout-dv" class=""> |
2 | 2 | <?php |
3 | -if ( ! $empty_cart ) { |
|
4 | - if ( apply_filters( 'FHEE__registration_page_wrapper_template__display_time_limit', false ) ) { ?> |
|
3 | +if ( ! $empty_cart) { |
|
4 | + if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
|
5 | 5 | <p id="spco-registration-time-limit-pg" class="spco-steps-pg ee-attention important-notice" style="display: none;"> |
6 | 6 | <?php echo sprintf( |
7 | 7 | apply_filters( |
8 | 8 | 'FHEE__registration_page_wrapper_template___time_limit', |
9 | - __( 'You have %1$s to complete your registration.', 'event_espresso' ) |
|
9 | + __('You have %1$s to complete your registration.', 'event_espresso') |
|
10 | 10 | ), |
11 | - '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' . $registration_time_limit . '</span>' |
|
11 | + '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">'.$registration_time_limit.'</span>' |
|
12 | 12 | ); |
13 | 13 | ?> |
14 | 14 | <span id="spco-registration-expiration-spn" class="" style="display:none;"></span> |
15 | 15 | </p> |
16 | 16 | <?php } |
17 | - if ( ! $revisit && apply_filters( 'FHEE__registration_page_wrapper_template__steps_display', TRUE )) { |
|
17 | + if ( ! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', TRUE)) { |
|
18 | 18 | ?> |
19 | 19 | <h2 id="spco-steps-big-hdr" class="spco-steps-big-hdr"><?php _e(' Steps', 'event_espresso'); ?></h2> |
20 | 20 | |
21 | 21 | <div id="spco-steps-display-dv"> |
22 | 22 | <?php |
23 | 23 | $step_nmbr = 1; |
24 | - $total_steps = count( $reg_steps ) - 1; |
|
25 | - foreach ( $reg_steps as $reg_step ) { |
|
26 | - if ( $reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration' ) { |
|
24 | + $total_steps = count($reg_steps) - 1; |
|
25 | + foreach ($reg_steps as $reg_step) { |
|
26 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
27 | 27 | $slug = $reg_step->slug(); |
28 | 28 | $step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step'; |
29 | 29 | ?> |
30 | 30 | <div id="spco-step-<?php echo $slug; ?>-display-dv" class="spco-step-display-dv <?php echo $step_display_dv_class; ?> steps-<?php echo $total_steps; ?>"> |
31 | 31 | <h4 id="spco-step-<?php echo $slug; ?>-display-hdr" class="spco-steps-display-hdr"> |
32 | - <span class="spco-step-big-nmbr"><?php echo $step_nmbr; ?></span> <span class="spco-step-name"><?php echo str_replace( ' ', '<br/> ', $reg_step->name() ); ?></span> |
|
32 | + <span class="spco-step-big-nmbr"><?php echo $step_nmbr; ?></span> <span class="spco-step-name"><?php echo str_replace(' ', '<br/> ', $reg_step->name()); ?></span> |
|
33 | 33 | </h4> |
34 | 34 | </div> |
35 | 35 | |
36 | - <?php if ( $step_nmbr < $total_steps ) { ?> |
|
36 | + <?php if ($step_nmbr < $total_steps) { ?> |
|
37 | 37 | <div class="spco-step-arrow-dv">»</div> |
38 | 38 | <?php |
39 | 39 | } |
@@ -47,22 +47,22 @@ discard block |
||
47 | 47 | <?php |
48 | 48 | } |
49 | 49 | |
50 | - do_action( 'AHEE__SPCO__before_registration_steps' ); |
|
50 | + do_action('AHEE__SPCO__before_registration_steps'); |
|
51 | 51 | $step_nmbr = 1; |
52 | - foreach ( $reg_steps as $reg_step ) { |
|
53 | - if ( $reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration' ) { |
|
52 | + foreach ($reg_steps as $reg_step) { |
|
53 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
54 | 54 | $slug = $reg_step->slug(); |
55 | - do_action( 'AHEE__' . $slug . '__reg_step_start', $reg_step ); |
|
55 | + do_action('AHEE__'.$slug.'__reg_step_start', $reg_step); |
|
56 | 56 | // todo: deprecate hook AHEE__registration_page_attendee_information__start |
57 | 57 | ?> |
58 | 58 | <div id="spco-<?php echo $slug; ?>-dv" class="spco-step-dv <?php echo $reg_step->div_class(); ?>"> |
59 | 59 | <?php echo $reg_step->display_reg_form(); ?> |
60 | - <?php do_action( 'AHEE__SPCO_after_reg_step_form', $slug, $next_step ); ?> |
|
60 | + <?php do_action('AHEE__SPCO_after_reg_step_form', $slug, $next_step); ?> |
|
61 | 61 | </div> |
62 | 62 | <?php $step_nmbr++; |
63 | 63 | } |
64 | 64 | } |
65 | - do_action( 'AHEE__SPCO__after_registration_steps' ); |
|
65 | + do_action('AHEE__SPCO__after_registration_steps'); |
|
66 | 66 | |
67 | 67 | } else { |
68 | 68 | ?> |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | <?php echo $cookies_not_set_msg; ?> |
72 | 72 | <?php |
73 | 73 | } |
74 | -do_action( 'AHEE__SPCO__reg_form_footer' ); |
|
74 | +do_action('AHEE__SPCO__reg_form_footer'); |
|
75 | 75 | ?> |
76 | 76 | |
77 | 77 | </div> |
@@ -16,10 +16,10 @@ |
||
16 | 16 | interface RequiresCapCheckInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @return CapCheckInterface |
|
21 | - */ |
|
22 | - public function getCapCheck(); |
|
19 | + /** |
|
20 | + * @return CapCheckInterface |
|
21 | + */ |
|
22 | + public function getCapCheck(); |
|
23 | 23 | |
24 | 24 | } |
25 | 25 | // End of file RequiresCapCheckInterface.php |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | |
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * _migration_step |
|
56 | - * |
|
57 | - * @access protected |
|
58 | - * @param int $num_items |
|
59 | - * @throws EE_Error |
|
60 | - * @return int number of items ACTUALLY migrated |
|
61 | - * @throws InvalidDataTypeException |
|
62 | - */ |
|
54 | + /** |
|
55 | + * _migration_step |
|
56 | + * |
|
57 | + * @access protected |
|
58 | + * @param int $num_items |
|
59 | + * @throws EE_Error |
|
60 | + * @return int number of items ACTUALLY migrated |
|
61 | + * @throws InvalidDataTypeException |
|
62 | + */ |
|
63 | 63 | protected function _migration_step( $num_items = 1 ){ |
64 | 64 | // if this isn't set then something is really wrong |
65 | 65 | if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config ) { |
@@ -86,29 +86,29 @@ discard block |
||
86 | 86 | //update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code; |
87 | 87 | //also we don't want to build a dependency on the messages code because it is likely to change soon |
88 | 88 | if( ! in_array( $invoice_settings[ 'invoice_css' ], array( '', 'simple.css' ) ) ){ |
89 | - new PersistentAdminNotice( |
|
90 | - 'invoice_css_not_updated', |
|
91 | - sprintf( |
|
92 | - esc_html__( |
|
93 | - 'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.', |
|
94 | - 'event_espresso' |
|
95 | - ), |
|
96 | - $invoice_settings['invoice_css'] |
|
97 | - ) |
|
98 | - ); |
|
89 | + new PersistentAdminNotice( |
|
90 | + 'invoice_css_not_updated', |
|
91 | + sprintf( |
|
92 | + esc_html__( |
|
93 | + 'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.', |
|
94 | + 'event_espresso' |
|
95 | + ), |
|
96 | + $invoice_settings['invoice_css'] |
|
97 | + ) |
|
98 | + ); |
|
99 | 99 | } |
100 | 100 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
101 | 101 | $overridden_invoice_body = EEH_Template::locate_template( $templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE ); |
102 | 102 | $overridden_receipt_body= EEH_Template::locate_template( $templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE ); |
103 | 103 | if( $overridden_invoice_body || $overridden_receipt_body ) { |
104 | - new PersistentAdminNotice( |
|
105 | - 'invoice_overriding_templates', |
|
106 | - esc_html__( |
|
107 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
108 | - 'event_espresso' |
|
109 | - ), |
|
110 | - true |
|
111 | - ); |
|
104 | + new PersistentAdminNotice( |
|
105 | + 'invoice_overriding_templates', |
|
106 | + esc_html__( |
|
107 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
108 | + 'event_espresso' |
|
109 | + ), |
|
110 | + true |
|
111 | + ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * Just initializes the status of the migration |
33 | 33 | */ |
34 | 34 | public function __construct() { |
35 | - $this->_pretty_name = __( 'Update Invoice Gateway Settings', 'event_espresso' ); |
|
35 | + $this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso'); |
|
36 | 36 | parent::__construct(); |
37 | 37 | } |
38 | 38 | |
@@ -60,32 +60,32 @@ discard block |
||
60 | 60 | * @return int number of items ACTUALLY migrated |
61 | 61 | * @throws InvalidDataTypeException |
62 | 62 | */ |
63 | - protected function _migration_step( $num_items = 1 ){ |
|
63 | + protected function _migration_step($num_items = 1) { |
|
64 | 64 | // if this isn't set then something is really wrong |
65 | - if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config ) { |
|
66 | - throw new EE_Error( __( 'It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso' )); |
|
65 | + if ( ! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
66 | + throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso')); |
|
67 | 67 | } |
68 | - $invoice_settings = isset( EE_Config::instance()->gateway->payment_settings[ 'Invoice' ] ) ? EE_Config::instance()->gateway->payment_settings[ 'Invoice' ] : NULL; |
|
69 | - if( ! $invoice_settings ){ |
|
70 | - $this->add_error( __( 'Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso' ) ); |
|
71 | - }else{ |
|
72 | - $invoice_settings[ 'template_payment_instructions' ] = $invoice_settings[ 'pdf_instructions' ]; |
|
73 | - $invoice_settings[ 'template_invoice_payee_name' ] = $invoice_settings[ 'payable_to' ]; |
|
74 | - $invoice_settings[ 'template_invoice_address' ] = $invoice_settings[ 'payment_address' ]; |
|
75 | - $invoice_settings[ 'template_invoice_email' ] = ''; |
|
76 | - $invoice_settings[ 'template_invoice_tax_number' ] = ''; |
|
77 | - unset( $invoice_settings[ 'pdf_instructions' ] ); |
|
78 | - unset( $invoice_settings[ 'payable_to' ] ); |
|
79 | - unset( $invoice_settings[ 'payment_address' ] ); |
|
80 | - EE_Config::instance()->gateway->payment_settings[ 'Invoice' ] = $invoice_settings; |
|
81 | - EE_Config::instance()->update_espresso_config(false,false); |
|
68 | + $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : NULL; |
|
69 | + if ( ! $invoice_settings) { |
|
70 | + $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso')); |
|
71 | + } else { |
|
72 | + $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions']; |
|
73 | + $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to']; |
|
74 | + $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address']; |
|
75 | + $invoice_settings['template_invoice_email'] = ''; |
|
76 | + $invoice_settings['template_invoice_tax_number'] = ''; |
|
77 | + unset($invoice_settings['pdf_instructions']); |
|
78 | + unset($invoice_settings['payable_to']); |
|
79 | + unset($invoice_settings['payment_address']); |
|
80 | + EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings; |
|
81 | + EE_Config::instance()->update_espresso_config(false, false); |
|
82 | 82 | |
83 | 83 | //@todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice |
84 | 84 | //(why is it tough to change? because we want to update the receipt and invoice message template, but |
85 | 85 | //message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to |
86 | 86 | //update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code; |
87 | 87 | //also we don't want to build a dependency on the messages code because it is likely to change soon |
88 | - if( ! in_array( $invoice_settings[ 'invoice_css' ], array( '', 'simple.css' ) ) ){ |
|
88 | + if ( ! in_array($invoice_settings['invoice_css'], array('', 'simple.css'))) { |
|
89 | 89 | new PersistentAdminNotice( |
90 | 90 | 'invoice_css_not_updated', |
91 | 91 | sprintf( |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | ); |
99 | 99 | } |
100 | 100 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
101 | - $overridden_invoice_body = EEH_Template::locate_template( $templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE ); |
|
102 | - $overridden_receipt_body= EEH_Template::locate_template( $templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE ); |
|
103 | - if( $overridden_invoice_body || $overridden_receipt_body ) { |
|
101 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', NULL, FALSE, FALSE, TRUE); |
|
102 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', NULL, FALSE, FALSE, TRUE); |
|
103 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
104 | 104 | new PersistentAdminNotice( |
105 | 105 | 'invoice_overriding_templates', |
106 | 106 | esc_html__( |
@@ -49,29 +49,29 @@ |
||
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * _migration_step |
|
54 | - * |
|
55 | - * @access protected |
|
56 | - * @param int $num_items |
|
57 | - * @throws EE_Error |
|
58 | - * @return int number of items ACTUALLY migrated |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - */ |
|
52 | + /** |
|
53 | + * _migration_step |
|
54 | + * |
|
55 | + * @access protected |
|
56 | + * @param int $num_items |
|
57 | + * @throws EE_Error |
|
58 | + * @return int number of items ACTUALLY migrated |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + */ |
|
61 | 61 | protected function _migration_step( $num_items = 1 ){ |
62 | 62 | |
63 | 63 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
64 | 64 | $overridden_invoice_body = EEH_Template::locate_template( $templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE ); |
65 | 65 | $overridden_receipt_body= EEH_Template::locate_template( $templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE ); |
66 | 66 | if( $overridden_invoice_body || $overridden_receipt_body ) { |
67 | - new PersistentAdminNotice( |
|
68 | - 'invoice_overriding_templates', |
|
69 | - esc_html__( |
|
70 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - true |
|
74 | - ); |
|
67 | + new PersistentAdminNotice( |
|
68 | + 'invoice_overriding_templates', |
|
69 | + esc_html__( |
|
70 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + true |
|
74 | + ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | //regardless of whether it worked or not, we ought to continue the migration |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * Just initializes the status of the migration |
31 | 31 | */ |
32 | 32 | public function __construct() { |
33 | - $this->_pretty_name = __( 'Update Invoice Settings', 'event_espresso' ); |
|
33 | + $this->_pretty_name = __('Update Invoice Settings', 'event_espresso'); |
|
34 | 34 | parent::__construct(); |
35 | 35 | } |
36 | 36 | |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | * @return int number of items ACTUALLY migrated |
59 | 59 | * @throws InvalidDataTypeException |
60 | 60 | */ |
61 | - protected function _migration_step( $num_items = 1 ){ |
|
61 | + protected function _migration_step($num_items = 1) { |
|
62 | 62 | |
63 | 63 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
64 | - $overridden_invoice_body = EEH_Template::locate_template( $templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE ); |
|
65 | - $overridden_receipt_body= EEH_Template::locate_template( $templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE ); |
|
66 | - if( $overridden_invoice_body || $overridden_receipt_body ) { |
|
64 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', NULL, FALSE, FALSE, TRUE); |
|
65 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', NULL, FALSE, FALSE, TRUE); |
|
66 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
67 | 67 | new PersistentAdminNotice( |
68 | 68 | 'invoice_overriding_templates', |
69 | 69 | esc_html__( |
@@ -18,65 +18,65 @@ |
||
18 | 18 | class CoffeeMill |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var CoffeeShop $coffee_shop |
|
23 | - */ |
|
24 | - private static $coffee_shop; |
|
25 | - |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @return mixed |
|
30 | - */ |
|
31 | - public static function getCoffeeShop() |
|
32 | - { |
|
33 | - return self::$coffee_shop; |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @param CoffeeShop $coffee_shop |
|
40 | - */ |
|
41 | - public static function setCoffeeShop(CoffeeShop $coffee_shop) |
|
42 | - { |
|
43 | - self::$coffee_shop = $coffee_shop; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param string $identifier |
|
50 | - * @param array $arguments |
|
51 | - * @param string $type |
|
52 | - * @return mixed |
|
53 | - * @throws ServiceNotFoundException |
|
54 | - */ |
|
55 | - public static function createNew($identifier, $arguments = array(), $type = CoffeeMaker::BREW_NEW) |
|
56 | - { |
|
57 | - return self::$coffee_shop->brew($identifier, $arguments, $type); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * IMPORTANT!!! |
|
64 | - * Usage of this method is discouraged as it promotes service location. |
|
65 | - * It's current use is only as a stop gap measure until the CoffeeShop |
|
66 | - * Dependency Injection Container can be implemented properly for all classes. |
|
67 | - * If it is at all possible, inject your dependencies via your class constructor. |
|
68 | - * This method WILL BE DEPRECATED at some point in the near future. |
|
69 | - * |
|
70 | - * @param string $identifier |
|
71 | - * @param array $arguments |
|
72 | - * @param string $type |
|
73 | - * @return mixed |
|
74 | - * @throws ServiceNotFoundException |
|
75 | - */ |
|
76 | - public static function getService($identifier, $arguments = array(), $type = CoffeeMaker::BREW_SHARED) |
|
77 | - { |
|
78 | - return self::$coffee_shop->brew($identifier, $arguments, $type); |
|
79 | - } |
|
21 | + /** |
|
22 | + * @var CoffeeShop $coffee_shop |
|
23 | + */ |
|
24 | + private static $coffee_shop; |
|
25 | + |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @return mixed |
|
30 | + */ |
|
31 | + public static function getCoffeeShop() |
|
32 | + { |
|
33 | + return self::$coffee_shop; |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @param CoffeeShop $coffee_shop |
|
40 | + */ |
|
41 | + public static function setCoffeeShop(CoffeeShop $coffee_shop) |
|
42 | + { |
|
43 | + self::$coffee_shop = $coffee_shop; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param string $identifier |
|
50 | + * @param array $arguments |
|
51 | + * @param string $type |
|
52 | + * @return mixed |
|
53 | + * @throws ServiceNotFoundException |
|
54 | + */ |
|
55 | + public static function createNew($identifier, $arguments = array(), $type = CoffeeMaker::BREW_NEW) |
|
56 | + { |
|
57 | + return self::$coffee_shop->brew($identifier, $arguments, $type); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * IMPORTANT!!! |
|
64 | + * Usage of this method is discouraged as it promotes service location. |
|
65 | + * It's current use is only as a stop gap measure until the CoffeeShop |
|
66 | + * Dependency Injection Container can be implemented properly for all classes. |
|
67 | + * If it is at all possible, inject your dependencies via your class constructor. |
|
68 | + * This method WILL BE DEPRECATED at some point in the near future. |
|
69 | + * |
|
70 | + * @param string $identifier |
|
71 | + * @param array $arguments |
|
72 | + * @param string $type |
|
73 | + * @return mixed |
|
74 | + * @throws ServiceNotFoundException |
|
75 | + */ |
|
76 | + public static function getService($identifier, $arguments = array(), $type = CoffeeMaker::BREW_SHARED) |
|
77 | + { |
|
78 | + return self::$coffee_shop->brew($identifier, $arguments, $type); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
82 | 82 | // End of file CoffeeMill.php |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
5 | 5 | |
6 | 6 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -20,72 +20,72 @@ discard block |
||
20 | 20 | class CapCheck implements CapCheckInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var string|array $capability |
|
25 | - */ |
|
26 | - private $capability; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var string $context |
|
30 | - */ |
|
31 | - private $context; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var int|string $ID |
|
35 | - */ |
|
36 | - private $ID; |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @param string|array $capability - the capability to be checked, like: 'ee_edit_registrations', |
|
42 | - * or an array of capability strings |
|
43 | - * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
44 | - * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
45 | - * @throws InvalidDataTypeException |
|
46 | - */ |
|
47 | - public function __construct($capability, $context, $ID = 0) |
|
48 | - { |
|
49 | - if ( ! (is_string($capability) || is_array($capability))) { |
|
50 | - throw new InvalidDataTypeException('$capability', $capability, 'string or array'); |
|
51 | - } |
|
52 | - if ( ! is_string($context)) { |
|
53 | - throw new InvalidDataTypeException('$context', $context, 'string'); |
|
54 | - } |
|
55 | - $this->capability = $capability; |
|
56 | - $this->context = strtolower(str_replace(' ', '_', $context)); |
|
57 | - $this->ID = $ID; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return string|array |
|
64 | - */ |
|
65 | - public function capability() |
|
66 | - { |
|
67 | - return $this->capability; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function context() |
|
76 | - { |
|
77 | - return $this->context; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return int|string |
|
84 | - */ |
|
85 | - public function ID() |
|
86 | - { |
|
87 | - return $this->ID; |
|
88 | - } |
|
23 | + /** |
|
24 | + * @var string|array $capability |
|
25 | + */ |
|
26 | + private $capability; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var string $context |
|
30 | + */ |
|
31 | + private $context; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var int|string $ID |
|
35 | + */ |
|
36 | + private $ID; |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @param string|array $capability - the capability to be checked, like: 'ee_edit_registrations', |
|
42 | + * or an array of capability strings |
|
43 | + * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
44 | + * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
45 | + * @throws InvalidDataTypeException |
|
46 | + */ |
|
47 | + public function __construct($capability, $context, $ID = 0) |
|
48 | + { |
|
49 | + if ( ! (is_string($capability) || is_array($capability))) { |
|
50 | + throw new InvalidDataTypeException('$capability', $capability, 'string or array'); |
|
51 | + } |
|
52 | + if ( ! is_string($context)) { |
|
53 | + throw new InvalidDataTypeException('$context', $context, 'string'); |
|
54 | + } |
|
55 | + $this->capability = $capability; |
|
56 | + $this->context = strtolower(str_replace(' ', '_', $context)); |
|
57 | + $this->ID = $ID; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return string|array |
|
64 | + */ |
|
65 | + public function capability() |
|
66 | + { |
|
67 | + return $this->capability; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function context() |
|
76 | + { |
|
77 | + return $this->context; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return int|string |
|
84 | + */ |
|
85 | + public function ID() |
|
86 | + { |
|
87 | + return $this->ID; |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | 91 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @access public |
117 | 117 | * @param mixed $identifier |
118 | - * @return mixed |
|
118 | + * @return boolean |
|
119 | 119 | */ |
120 | 120 | public function get( $identifier ) { |
121 | 121 | $this->rewind(); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * advances pointer to the provided object |
238 | 238 | * |
239 | 239 | * @access public |
240 | - * @param $object |
|
240 | + * @param \EventEspresso\core\libraries\form_sections\form_handlers\SequentialStepForm $object |
|
241 | 241 | * @return boolean |
242 | 242 | */ |
243 | 243 | public function setCurrentUsingObject( $object ) { |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * |
276 | 276 | * @see http://stackoverflow.com/a/8736013 |
277 | 277 | * @param $object |
278 | - * @return boolean|int|string |
|
278 | + * @return integer |
|
279 | 279 | */ |
280 | 280 | public function indexOf( $object ) { |
281 | 281 | if ( ! $this->contains( $object ) ) { |
@@ -83,7 +83,6 @@ discard block |
||
83 | 83 | |
84 | 84 | /** |
85 | 85 | * setIdentifier |
86 | - |
|
87 | 86 | * Sets the data associated with an object in the Collection |
88 | 87 | * if no $identifier is supplied, then the spl_object_hash() is used |
89 | 88 | * |
@@ -172,9 +171,9 @@ discard block |
||
172 | 171 | |
173 | 172 | /** |
174 | 173 | * hasObjects |
175 | - * returns true if there are objects within the Collection, and false if it is empty |
|
176 | - * |
|
177 | - * @access public |
|
174 | + * returns true if there are objects within the Collection, and false if it is empty |
|
175 | + * |
|
176 | + * @access public |
|
178 | 177 | * @return bool |
179 | 178 | */ |
180 | 179 | public function hasObjects() { |
@@ -378,34 +377,34 @@ discard block |
||
378 | 377 | |
379 | 378 | |
380 | 379 | |
381 | - /** |
|
382 | - * detaches ALL objects from the Collection |
|
383 | - */ |
|
384 | - public function detachAll() |
|
385 | - { |
|
386 | - $this->rewind(); |
|
387 | - while ($this->valid()) { |
|
388 | - $object = $this->current(); |
|
389 | - $this->next(); |
|
390 | - $this->detach($object); |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * unsets and detaches ALL objects from the Collection |
|
398 | - */ |
|
399 | - public function trashAndDetachAll() |
|
400 | - { |
|
401 | - $this->rewind(); |
|
402 | - while ($this->valid()) { |
|
403 | - $object = $this->current(); |
|
404 | - $this->next(); |
|
405 | - $this->detach($object); |
|
406 | - unset($object); |
|
407 | - } |
|
408 | - } |
|
380 | + /** |
|
381 | + * detaches ALL objects from the Collection |
|
382 | + */ |
|
383 | + public function detachAll() |
|
384 | + { |
|
385 | + $this->rewind(); |
|
386 | + while ($this->valid()) { |
|
387 | + $object = $this->current(); |
|
388 | + $this->next(); |
|
389 | + $this->detach($object); |
|
390 | + } |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * unsets and detaches ALL objects from the Collection |
|
397 | + */ |
|
398 | + public function trashAndDetachAll() |
|
399 | + { |
|
400 | + $this->rewind(); |
|
401 | + while ($this->valid()) { |
|
402 | + $object = $this->current(); |
|
403 | + $this->next(); |
|
404 | + $this->detach($object); |
|
405 | + unset($object); |
|
406 | + } |
|
407 | + } |
|
409 | 408 | |
410 | 409 | |
411 | 410 |
@@ -18,243 +18,243 @@ discard block |
||
18 | 18 | class EEH_Activation implements ResettableInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * constant used to indicate a cron task is no longer in use |
|
23 | - */ |
|
24 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
25 | - |
|
26 | - /** |
|
27 | - * option name that will indicate whether or not we still |
|
28 | - * need to create EE's folders in the uploads directory |
|
29 | - * (because if EE was installed without file system access, |
|
30 | - * we need to request credentials before we can create them) |
|
31 | - */ |
|
32 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
33 | - |
|
34 | - /** |
|
35 | - * WP_User->ID |
|
36 | - * |
|
37 | - * @var int |
|
38 | - */ |
|
39 | - private static $_default_creator_id; |
|
40 | - |
|
41 | - /** |
|
42 | - * indicates whether or not we've already verified core's default data during this request, |
|
43 | - * because after migrations are done, any addons activated while in maintenance mode |
|
44 | - * will want to setup their own default data, and they might hook into core's default data |
|
45 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
46 | - * This prevents doing that for EVERY single addon. |
|
47 | - * |
|
48 | - * @var boolean |
|
49 | - */ |
|
50 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
54 | - */ |
|
55 | - private static $table_analysis; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
59 | - */ |
|
60 | - private static $table_manager; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
65 | - */ |
|
66 | - public static function getTableAnalysis() |
|
67 | - { |
|
68 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
69 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
70 | - } |
|
71 | - return self::$table_analysis; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return \EventEspresso\core\services\database\TableManager |
|
77 | - */ |
|
78 | - public static function getTableManager() |
|
79 | - { |
|
80 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
81 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
82 | - } |
|
83 | - return self::$table_manager; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * _ensure_table_name_has_prefix |
|
89 | - * |
|
90 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
91 | - * @access public |
|
92 | - * @static |
|
93 | - * @param $table_name |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public static function ensure_table_name_has_prefix($table_name) |
|
97 | - { |
|
98 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * system_initialization |
|
104 | - * ensures the EE configuration settings are loaded with at least default options set |
|
105 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @static |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public static function system_initialization() |
|
112 | - { |
|
113 | - EEH_Activation::reset_and_update_config(); |
|
114 | - //which is fired BEFORE activation of plugin anyways |
|
115 | - EEH_Activation::verify_default_pages_exist(); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Sets the database schema and creates folders. This should |
|
121 | - * be called on plugin activation and reactivation |
|
122 | - * |
|
123 | - * @return boolean success, whether the database and folders are setup properly |
|
124 | - * @throws \EE_Error |
|
125 | - */ |
|
126 | - public static function initialize_db_and_folders() |
|
127 | - { |
|
128 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
129 | - $good_db = EEH_Activation::create_database_tables(); |
|
130 | - return $good_filesystem && $good_db; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * assuming we have an up-to-date database schema, this will populate it |
|
136 | - * with default and initial data. This should be called |
|
137 | - * upon activation of a new plugin, reactivation, and at the end |
|
138 | - * of running migration scripts |
|
139 | - * |
|
140 | - * @throws \EE_Error |
|
141 | - */ |
|
142 | - public static function initialize_db_content() |
|
143 | - { |
|
144 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
145 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
146 | - return; |
|
147 | - } |
|
148 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
149 | - |
|
150 | - EEH_Activation::initialize_system_questions(); |
|
151 | - EEH_Activation::insert_default_status_codes(); |
|
152 | - EEH_Activation::generate_default_message_templates(); |
|
153 | - EEH_Activation::create_no_ticket_prices_array(); |
|
154 | - |
|
155 | - EEH_Activation::validate_messages_system(); |
|
156 | - EEH_Activation::insert_default_payment_methods(); |
|
157 | - //in case we've |
|
158 | - EEH_Activation::remove_cron_tasks(); |
|
159 | - EEH_Activation::create_cron_tasks(); |
|
160 | - // remove all TXN locks since that is being done via extra meta now |
|
161 | - delete_option('ee_locked_transactions'); |
|
162 | - //also, check for CAF default db content |
|
163 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
164 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
165 | - //which users really won't care about on initial activation |
|
166 | - EE_Error::overwrite_success(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
172 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
173 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
174 | - * (null) |
|
175 | - * |
|
176 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
177 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
178 | - * @return array |
|
179 | - * @throws \EE_Error |
|
180 | - */ |
|
181 | - public static function get_cron_tasks($which_to_include) |
|
182 | - { |
|
183 | - $cron_tasks = apply_filters( |
|
184 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
185 | - array( |
|
186 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
21 | + /** |
|
22 | + * constant used to indicate a cron task is no longer in use |
|
23 | + */ |
|
24 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
25 | + |
|
26 | + /** |
|
27 | + * option name that will indicate whether or not we still |
|
28 | + * need to create EE's folders in the uploads directory |
|
29 | + * (because if EE was installed without file system access, |
|
30 | + * we need to request credentials before we can create them) |
|
31 | + */ |
|
32 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
33 | + |
|
34 | + /** |
|
35 | + * WP_User->ID |
|
36 | + * |
|
37 | + * @var int |
|
38 | + */ |
|
39 | + private static $_default_creator_id; |
|
40 | + |
|
41 | + /** |
|
42 | + * indicates whether or not we've already verified core's default data during this request, |
|
43 | + * because after migrations are done, any addons activated while in maintenance mode |
|
44 | + * will want to setup their own default data, and they might hook into core's default data |
|
45 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
46 | + * This prevents doing that for EVERY single addon. |
|
47 | + * |
|
48 | + * @var boolean |
|
49 | + */ |
|
50 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
54 | + */ |
|
55 | + private static $table_analysis; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
59 | + */ |
|
60 | + private static $table_manager; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
65 | + */ |
|
66 | + public static function getTableAnalysis() |
|
67 | + { |
|
68 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
69 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
70 | + } |
|
71 | + return self::$table_analysis; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return \EventEspresso\core\services\database\TableManager |
|
77 | + */ |
|
78 | + public static function getTableManager() |
|
79 | + { |
|
80 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
81 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
82 | + } |
|
83 | + return self::$table_manager; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * _ensure_table_name_has_prefix |
|
89 | + * |
|
90 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
91 | + * @access public |
|
92 | + * @static |
|
93 | + * @param $table_name |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public static function ensure_table_name_has_prefix($table_name) |
|
97 | + { |
|
98 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * system_initialization |
|
104 | + * ensures the EE configuration settings are loaded with at least default options set |
|
105 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @static |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public static function system_initialization() |
|
112 | + { |
|
113 | + EEH_Activation::reset_and_update_config(); |
|
114 | + //which is fired BEFORE activation of plugin anyways |
|
115 | + EEH_Activation::verify_default_pages_exist(); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Sets the database schema and creates folders. This should |
|
121 | + * be called on plugin activation and reactivation |
|
122 | + * |
|
123 | + * @return boolean success, whether the database and folders are setup properly |
|
124 | + * @throws \EE_Error |
|
125 | + */ |
|
126 | + public static function initialize_db_and_folders() |
|
127 | + { |
|
128 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
129 | + $good_db = EEH_Activation::create_database_tables(); |
|
130 | + return $good_filesystem && $good_db; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * assuming we have an up-to-date database schema, this will populate it |
|
136 | + * with default and initial data. This should be called |
|
137 | + * upon activation of a new plugin, reactivation, and at the end |
|
138 | + * of running migration scripts |
|
139 | + * |
|
140 | + * @throws \EE_Error |
|
141 | + */ |
|
142 | + public static function initialize_db_content() |
|
143 | + { |
|
144 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
145 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
146 | + return; |
|
147 | + } |
|
148 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
149 | + |
|
150 | + EEH_Activation::initialize_system_questions(); |
|
151 | + EEH_Activation::insert_default_status_codes(); |
|
152 | + EEH_Activation::generate_default_message_templates(); |
|
153 | + EEH_Activation::create_no_ticket_prices_array(); |
|
154 | + |
|
155 | + EEH_Activation::validate_messages_system(); |
|
156 | + EEH_Activation::insert_default_payment_methods(); |
|
157 | + //in case we've |
|
158 | + EEH_Activation::remove_cron_tasks(); |
|
159 | + EEH_Activation::create_cron_tasks(); |
|
160 | + // remove all TXN locks since that is being done via extra meta now |
|
161 | + delete_option('ee_locked_transactions'); |
|
162 | + //also, check for CAF default db content |
|
163 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
164 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
165 | + //which users really won't care about on initial activation |
|
166 | + EE_Error::overwrite_success(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
172 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
173 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
174 | + * (null) |
|
175 | + * |
|
176 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
177 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
178 | + * @return array |
|
179 | + * @throws \EE_Error |
|
180 | + */ |
|
181 | + public static function get_cron_tasks($which_to_include) |
|
182 | + { |
|
183 | + $cron_tasks = apply_filters( |
|
184 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
185 | + array( |
|
186 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
187 | 187 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
188 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
189 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
190 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
191 | - ) |
|
192 | - ); |
|
193 | - if ($which_to_include === 'old') { |
|
194 | - $cron_tasks = array_filter( |
|
195 | - $cron_tasks, |
|
196 | - function ($value) { |
|
197 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
198 | - } |
|
199 | - ); |
|
200 | - } elseif ($which_to_include === 'current') { |
|
201 | - $cron_tasks = array_filter($cron_tasks); |
|
202 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
203 | - throw new EE_Error( |
|
204 | - sprintf( |
|
205 | - __( |
|
206 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
207 | - 'event_espresso' |
|
208 | - ), |
|
209 | - $which_to_include |
|
210 | - ) |
|
211 | - ); |
|
212 | - } |
|
213 | - return $cron_tasks; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
219 | - * |
|
220 | - * @throws \EE_Error |
|
221 | - */ |
|
222 | - public static function create_cron_tasks() |
|
223 | - { |
|
224 | - |
|
225 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
226 | - if (! wp_next_scheduled($hook_name)) { |
|
227 | - /** |
|
228 | - * This allows client code to define the initial start timestamp for this schedule. |
|
229 | - */ |
|
230 | - if (is_array($frequency) |
|
231 | - && count($frequency) === 2 |
|
232 | - && isset($frequency[0], $frequency[1]) |
|
233 | - ) { |
|
234 | - $start_timestamp = $frequency[0]; |
|
235 | - $frequency = $frequency[1]; |
|
236 | - } else { |
|
237 | - $start_timestamp = time(); |
|
238 | - } |
|
239 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Remove the currently-existing and now-removed cron tasks. |
|
248 | - * |
|
249 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
250 | - * @throws \EE_Error |
|
251 | - */ |
|
252 | - public static function remove_cron_tasks($remove_all = true) |
|
253 | - { |
|
254 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
255 | - $crons = _get_cron_array(); |
|
256 | - $crons = is_array($crons) ? $crons : array(); |
|
257 | - /* reminder of what $crons look like: |
|
188 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
189 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
190 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
191 | + ) |
|
192 | + ); |
|
193 | + if ($which_to_include === 'old') { |
|
194 | + $cron_tasks = array_filter( |
|
195 | + $cron_tasks, |
|
196 | + function ($value) { |
|
197 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
198 | + } |
|
199 | + ); |
|
200 | + } elseif ($which_to_include === 'current') { |
|
201 | + $cron_tasks = array_filter($cron_tasks); |
|
202 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
203 | + throw new EE_Error( |
|
204 | + sprintf( |
|
205 | + __( |
|
206 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
207 | + 'event_espresso' |
|
208 | + ), |
|
209 | + $which_to_include |
|
210 | + ) |
|
211 | + ); |
|
212 | + } |
|
213 | + return $cron_tasks; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
219 | + * |
|
220 | + * @throws \EE_Error |
|
221 | + */ |
|
222 | + public static function create_cron_tasks() |
|
223 | + { |
|
224 | + |
|
225 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
226 | + if (! wp_next_scheduled($hook_name)) { |
|
227 | + /** |
|
228 | + * This allows client code to define the initial start timestamp for this schedule. |
|
229 | + */ |
|
230 | + if (is_array($frequency) |
|
231 | + && count($frequency) === 2 |
|
232 | + && isset($frequency[0], $frequency[1]) |
|
233 | + ) { |
|
234 | + $start_timestamp = $frequency[0]; |
|
235 | + $frequency = $frequency[1]; |
|
236 | + } else { |
|
237 | + $start_timestamp = time(); |
|
238 | + } |
|
239 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Remove the currently-existing and now-removed cron tasks. |
|
248 | + * |
|
249 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
250 | + * @throws \EE_Error |
|
251 | + */ |
|
252 | + public static function remove_cron_tasks($remove_all = true) |
|
253 | + { |
|
254 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
255 | + $crons = _get_cron_array(); |
|
256 | + $crons = is_array($crons) ? $crons : array(); |
|
257 | + /* reminder of what $crons look like: |
|
258 | 258 | * Top-level keys are timestamps, and their values are arrays. |
259 | 259 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
260 | 260 | * and their values are arrays. |
@@ -271,911 +271,911 @@ discard block |
||
271 | 271 | * ... |
272 | 272 | * ... |
273 | 273 | */ |
274 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
275 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
276 | - if (is_array($hooks_to_fire_at_time)) { |
|
277 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
278 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
279 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
280 | - ) { |
|
281 | - unset($crons[$timestamp][$hook_name]); |
|
282 | - } |
|
283 | - } |
|
284 | - //also take care of any empty cron timestamps. |
|
285 | - if (empty($hooks_to_fire_at_time)) { |
|
286 | - unset($crons[$timestamp]); |
|
287 | - } |
|
288 | - } |
|
289 | - } |
|
290 | - _set_cron_array($crons); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * CPT_initialization |
|
296 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @static |
|
300 | - * @return void |
|
301 | - */ |
|
302 | - public static function CPT_initialization() |
|
303 | - { |
|
304 | - // register Custom Post Types |
|
305 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
306 | - flush_rewrite_rules(); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * reset_and_update_config |
|
313 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
314 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
315 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
316 | - * |
|
317 | - * @access public |
|
318 | - * @static |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - public static function reset_and_update_config() |
|
322 | - { |
|
323 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
324 | - add_filter( |
|
325 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
326 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
327 | - 10, |
|
328 | - 3 |
|
329 | - ); |
|
330 | - //EE_Config::reset(); |
|
331 | - if (! EE_Config::logging_enabled()) { |
|
332 | - delete_option(EE_Config::LOG_NAME); |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * load_calendar_config |
|
339 | - * |
|
340 | - * @access public |
|
341 | - * @return void |
|
342 | - */ |
|
343 | - public static function load_calendar_config() |
|
344 | - { |
|
345 | - // grab array of all plugin folders and loop thru it |
|
346 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
347 | - if (empty($plugins)) { |
|
348 | - return; |
|
349 | - } |
|
350 | - foreach ($plugins as $plugin_path) { |
|
351 | - // grab plugin folder name from path |
|
352 | - $plugin = basename($plugin_path); |
|
353 | - // drill down to Espresso plugins |
|
354 | - // then to calendar related plugins |
|
355 | - if ( |
|
356 | - strpos($plugin, 'espresso') !== false |
|
357 | - || strpos($plugin, 'Espresso') !== false |
|
358 | - || strpos($plugin, 'ee4') !== false |
|
359 | - || strpos($plugin, 'EE4') !== false |
|
360 | - || strpos($plugin, 'calendar') !== false |
|
361 | - ) { |
|
362 | - // this is what we are looking for |
|
363 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
364 | - // does it exist in this folder ? |
|
365 | - if (is_readable($calendar_config)) { |
|
366 | - // YEAH! let's load it |
|
367 | - require_once($calendar_config); |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * _migrate_old_config_data |
|
377 | - * |
|
378 | - * @access public |
|
379 | - * @param array|stdClass $settings |
|
380 | - * @param string $config |
|
381 | - * @param \EE_Config $EE_Config |
|
382 | - * @return \stdClass |
|
383 | - */ |
|
384 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
385 | - { |
|
386 | - $convert_from_array = array('addons'); |
|
387 | - // in case old settings were saved as an array |
|
388 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
389 | - // convert existing settings to an object |
|
390 | - $config_array = $settings; |
|
391 | - $settings = new stdClass(); |
|
392 | - foreach ($config_array as $key => $value) { |
|
393 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
394 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
395 | - } else { |
|
396 | - $settings->{$key} = $value; |
|
397 | - } |
|
398 | - } |
|
399 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
400 | - } |
|
401 | - return $settings; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * deactivate_event_espresso |
|
407 | - * |
|
408 | - * @access public |
|
409 | - * @static |
|
410 | - * @return void |
|
411 | - */ |
|
412 | - public static function deactivate_event_espresso() |
|
413 | - { |
|
414 | - // check permissions |
|
415 | - if (current_user_can('activate_plugins')) { |
|
416 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * verify_default_pages_exist |
|
424 | - * |
|
425 | - * @access public |
|
426 | - * @static |
|
427 | - * @return void |
|
428 | - * @throws InvalidDataTypeException |
|
429 | - */ |
|
430 | - public static function verify_default_pages_exist() |
|
431 | - { |
|
432 | - $critical_page_problem = false; |
|
433 | - $critical_pages = array( |
|
434 | - array( |
|
435 | - 'id' => 'reg_page_id', |
|
436 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
437 | - 'post' => null, |
|
438 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
439 | - ), |
|
440 | - array( |
|
441 | - 'id' => 'txn_page_id', |
|
442 | - 'name' => __('Transactions', 'event_espresso'), |
|
443 | - 'post' => null, |
|
444 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
445 | - ), |
|
446 | - array( |
|
447 | - 'id' => 'thank_you_page_id', |
|
448 | - 'name' => __('Thank You', 'event_espresso'), |
|
449 | - 'post' => null, |
|
450 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
451 | - ), |
|
452 | - array( |
|
453 | - 'id' => 'cancel_page_id', |
|
454 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
455 | - 'post' => null, |
|
456 | - 'code' => 'ESPRESSO_CANCELLED', |
|
457 | - ), |
|
458 | - ); |
|
459 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
460 | - foreach ($critical_pages as $critical_page) { |
|
461 | - // is critical page ID set in config ? |
|
462 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
463 | - // attempt to find post by ID |
|
464 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
465 | - } |
|
466 | - // no dice? |
|
467 | - if ($critical_page['post'] === null) { |
|
468 | - // attempt to find post by title |
|
469 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
470 | - // still nothing? |
|
471 | - if ($critical_page['post'] === null) { |
|
472 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
473 | - // REALLY? Still nothing ??!?!? |
|
474 | - if ($critical_page['post'] === null) { |
|
475 | - $msg = __( |
|
476 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
477 | - 'event_espresso' |
|
478 | - ); |
|
479 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
480 | - break; |
|
481 | - } |
|
482 | - } |
|
483 | - } |
|
484 | - // check that Post ID matches critical page ID in config |
|
485 | - if ( |
|
486 | - isset($critical_page['post']->ID) |
|
487 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
488 | - ) { |
|
489 | - //update Config with post ID |
|
490 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
491 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | - $msg = __( |
|
493 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
494 | - 'event_espresso' |
|
495 | - ); |
|
496 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
497 | - } |
|
498 | - } |
|
499 | - $critical_page_problem = |
|
500 | - ! isset($critical_page['post']->post_status) |
|
501 | - || $critical_page['post']->post_status !== 'publish' |
|
502 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
503 | - ? true |
|
504 | - : $critical_page_problem; |
|
505 | - } |
|
506 | - if ($critical_page_problem) { |
|
507 | - new PersistentAdminNotice( |
|
508 | - 'critical_page_problem', |
|
509 | - sprintf( |
|
510 | - esc_html__( |
|
511 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
512 | - 'event_espresso' |
|
513 | - ), |
|
514 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
515 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
516 | - . '</a>' |
|
517 | - ) |
|
518 | - ); |
|
519 | - } |
|
520 | - if (EE_Error::has_notices()) { |
|
521 | - EE_Error::get_notices(false, true, true); |
|
522 | - } |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * Returns the first post which uses the specified shortcode |
|
529 | - * |
|
530 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
531 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
532 | - * "[ESPRESSO_THANK_YOU" |
|
533 | - * (we don't search for the closing shortcode bracket because they might have added |
|
534 | - * parameter to the shortcode |
|
535 | - * @return WP_Post or NULl |
|
536 | - */ |
|
537 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
538 | - { |
|
539 | - global $wpdb; |
|
540 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
541 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
542 | - if ($post_id) { |
|
543 | - return get_post($post_id); |
|
544 | - } else { |
|
545 | - return null; |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * This function generates a post for critical espresso pages |
|
552 | - * |
|
553 | - * @access public |
|
554 | - * @static |
|
555 | - * @param array $critical_page |
|
556 | - * @return array |
|
557 | - */ |
|
558 | - public static function create_critical_page($critical_page) |
|
559 | - { |
|
560 | - |
|
561 | - $post_args = array( |
|
562 | - 'post_title' => $critical_page['name'], |
|
563 | - 'post_status' => 'publish', |
|
564 | - 'post_type' => 'page', |
|
565 | - 'comment_status' => 'closed', |
|
566 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
567 | - ); |
|
568 | - |
|
569 | - $post_id = wp_insert_post($post_args); |
|
570 | - if (! $post_id) { |
|
571 | - $msg = sprintf( |
|
572 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
573 | - $critical_page['name'] |
|
574 | - ); |
|
575 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
576 | - return $critical_page; |
|
577 | - } |
|
578 | - // get newly created post's details |
|
579 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
580 | - $msg = sprintf( |
|
581 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
582 | - $critical_page['name'] |
|
583 | - ); |
|
584 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
585 | - } |
|
586 | - |
|
587 | - return $critical_page; |
|
588 | - |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
596 | - * The role being used to check is filterable. |
|
597 | - * |
|
598 | - * @since 4.6.0 |
|
599 | - * @global WPDB $wpdb |
|
600 | - * @return mixed null|int WP_user ID or NULL |
|
601 | - */ |
|
602 | - public static function get_default_creator_id() |
|
603 | - { |
|
604 | - global $wpdb; |
|
605 | - if ( ! empty(self::$_default_creator_id)) { |
|
606 | - return self::$_default_creator_id; |
|
607 | - }/**/ |
|
608 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
609 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
610 | - $pre_filtered_id = apply_filters( |
|
611 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
612 | - false, |
|
613 | - $role_to_check |
|
614 | - ); |
|
615 | - if ($pre_filtered_id !== false) { |
|
616 | - return (int)$pre_filtered_id; |
|
617 | - } |
|
618 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
619 | - $query = $wpdb->prepare( |
|
620 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
621 | - '%' . $role_to_check . '%' |
|
622 | - ); |
|
623 | - $user_id = $wpdb->get_var($query); |
|
624 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
625 | - if ($user_id && (int)$user_id) { |
|
626 | - self::$_default_creator_id = (int)$user_id; |
|
627 | - return self::$_default_creator_id; |
|
628 | - } else { |
|
629 | - return null; |
|
630 | - } |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * used by EE and EE addons during plugin activation to create tables. |
|
637 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
638 | - * but includes extra logic regarding activations. |
|
639 | - * |
|
640 | - * @access public |
|
641 | - * @static |
|
642 | - * @param string $table_name without the $wpdb->prefix |
|
643 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
644 | - * table query) |
|
645 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
646 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
647 | - * and new once this function is done (ie, you really do want to CREATE a |
|
648 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
649 | - * you just want to verify the table exists and matches this definition |
|
650 | - * (and if it HAS data in it you want to leave it be) |
|
651 | - * @return void |
|
652 | - * @throws EE_Error if there are database errors |
|
653 | - */ |
|
654 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
655 | - { |
|
656 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
657 | - return; |
|
658 | - } |
|
659 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
660 | - if ( ! function_exists('dbDelta')) { |
|
661 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
662 | - } |
|
663 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
664 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
665 | - // do we need to first delete an existing version of this table ? |
|
666 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
667 | - // ok, delete the table... but ONLY if it's empty |
|
668 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
669 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
670 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
671 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
672 | - } else if ( ! $deleted_safely) { |
|
673 | - // so we should be more cautious rather than just dropping tables so easily |
|
674 | - error_log( |
|
675 | - sprintf( |
|
676 | - __( |
|
677 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
678 | - 'event_espresso' |
|
679 | - ), |
|
680 | - $wp_table_name, |
|
681 | - '<br/>', |
|
682 | - 'espresso_db_update' |
|
683 | - ) |
|
684 | - ); |
|
685 | - } |
|
686 | - } |
|
687 | - $engine = str_replace('ENGINE=', '', $engine); |
|
688 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * add_column_if_it_doesn't_exist |
|
695 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
696 | - * |
|
697 | - * @access public |
|
698 | - * @static |
|
699 | - * @deprecated instead use TableManager::addColumn() |
|
700 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
701 | - * @param string $column_name |
|
702 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
703 | - * 'VARCHAR(10)' |
|
704 | - * @return bool|int |
|
705 | - */ |
|
706 | - public static function add_column_if_it_doesnt_exist( |
|
707 | - $table_name, |
|
708 | - $column_name, |
|
709 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
710 | - ) { |
|
711 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * get_fields_on_table |
|
717 | - * Gets all the fields on the database table. |
|
718 | - * |
|
719 | - * @access public |
|
720 | - * @deprecated instead use TableManager::getTableColumns() |
|
721 | - * @static |
|
722 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
723 | - * @return array of database column names |
|
724 | - */ |
|
725 | - public static function get_fields_on_table($table_name = null) |
|
726 | - { |
|
727 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * db_table_is_empty |
|
733 | - * |
|
734 | - * @access public\ |
|
735 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
736 | - * @static |
|
737 | - * @param string $table_name |
|
738 | - * @return bool |
|
739 | - */ |
|
740 | - public static function db_table_is_empty($table_name) |
|
741 | - { |
|
742 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - /** |
|
747 | - * delete_db_table_if_empty |
|
748 | - * |
|
749 | - * @access public |
|
750 | - * @static |
|
751 | - * @param string $table_name |
|
752 | - * @return bool | int |
|
753 | - */ |
|
754 | - public static function delete_db_table_if_empty($table_name) |
|
755 | - { |
|
756 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
757 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | - } |
|
759 | - return false; |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * delete_unused_db_table |
|
765 | - * |
|
766 | - * @access public |
|
767 | - * @static |
|
768 | - * @deprecated instead use TableManager::dropTable() |
|
769 | - * @param string $table_name |
|
770 | - * @return bool | int |
|
771 | - */ |
|
772 | - public static function delete_unused_db_table($table_name) |
|
773 | - { |
|
774 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * drop_index |
|
780 | - * |
|
781 | - * @access public |
|
782 | - * @static |
|
783 | - * @deprecated instead use TableManager::dropIndex() |
|
784 | - * @param string $table_name |
|
785 | - * @param string $index_name |
|
786 | - * @return bool | int |
|
787 | - */ |
|
788 | - public static function drop_index($table_name, $index_name) |
|
789 | - { |
|
790 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * create_database_tables |
|
797 | - * |
|
798 | - * @access public |
|
799 | - * @static |
|
800 | - * @throws EE_Error |
|
801 | - * @return boolean success (whether database is setup properly or not) |
|
802 | - */ |
|
803 | - public static function create_database_tables() |
|
804 | - { |
|
805 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
806 | - //find the migration script that sets the database to be compatible with the code |
|
807 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
808 | - if ($dms_name) { |
|
809 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
810 | - $current_data_migration_script->set_migrating(false); |
|
811 | - $current_data_migration_script->schema_changes_before_migration(); |
|
812 | - $current_data_migration_script->schema_changes_after_migration(); |
|
813 | - if ($current_data_migration_script->get_errors()) { |
|
814 | - if (WP_DEBUG) { |
|
815 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
816 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
817 | - } |
|
818 | - } else { |
|
819 | - EE_Error::add_error( |
|
820 | - __( |
|
821 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
274 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
275 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
276 | + if (is_array($hooks_to_fire_at_time)) { |
|
277 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
278 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
279 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
280 | + ) { |
|
281 | + unset($crons[$timestamp][$hook_name]); |
|
282 | + } |
|
283 | + } |
|
284 | + //also take care of any empty cron timestamps. |
|
285 | + if (empty($hooks_to_fire_at_time)) { |
|
286 | + unset($crons[$timestamp]); |
|
287 | + } |
|
288 | + } |
|
289 | + } |
|
290 | + _set_cron_array($crons); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * CPT_initialization |
|
296 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @static |
|
300 | + * @return void |
|
301 | + */ |
|
302 | + public static function CPT_initialization() |
|
303 | + { |
|
304 | + // register Custom Post Types |
|
305 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
306 | + flush_rewrite_rules(); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * reset_and_update_config |
|
313 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
314 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
315 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
316 | + * |
|
317 | + * @access public |
|
318 | + * @static |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + public static function reset_and_update_config() |
|
322 | + { |
|
323 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
324 | + add_filter( |
|
325 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
326 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
327 | + 10, |
|
328 | + 3 |
|
329 | + ); |
|
330 | + //EE_Config::reset(); |
|
331 | + if (! EE_Config::logging_enabled()) { |
|
332 | + delete_option(EE_Config::LOG_NAME); |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * load_calendar_config |
|
339 | + * |
|
340 | + * @access public |
|
341 | + * @return void |
|
342 | + */ |
|
343 | + public static function load_calendar_config() |
|
344 | + { |
|
345 | + // grab array of all plugin folders and loop thru it |
|
346 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
347 | + if (empty($plugins)) { |
|
348 | + return; |
|
349 | + } |
|
350 | + foreach ($plugins as $plugin_path) { |
|
351 | + // grab plugin folder name from path |
|
352 | + $plugin = basename($plugin_path); |
|
353 | + // drill down to Espresso plugins |
|
354 | + // then to calendar related plugins |
|
355 | + if ( |
|
356 | + strpos($plugin, 'espresso') !== false |
|
357 | + || strpos($plugin, 'Espresso') !== false |
|
358 | + || strpos($plugin, 'ee4') !== false |
|
359 | + || strpos($plugin, 'EE4') !== false |
|
360 | + || strpos($plugin, 'calendar') !== false |
|
361 | + ) { |
|
362 | + // this is what we are looking for |
|
363 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
364 | + // does it exist in this folder ? |
|
365 | + if (is_readable($calendar_config)) { |
|
366 | + // YEAH! let's load it |
|
367 | + require_once($calendar_config); |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * _migrate_old_config_data |
|
377 | + * |
|
378 | + * @access public |
|
379 | + * @param array|stdClass $settings |
|
380 | + * @param string $config |
|
381 | + * @param \EE_Config $EE_Config |
|
382 | + * @return \stdClass |
|
383 | + */ |
|
384 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
385 | + { |
|
386 | + $convert_from_array = array('addons'); |
|
387 | + // in case old settings were saved as an array |
|
388 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
389 | + // convert existing settings to an object |
|
390 | + $config_array = $settings; |
|
391 | + $settings = new stdClass(); |
|
392 | + foreach ($config_array as $key => $value) { |
|
393 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
394 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
395 | + } else { |
|
396 | + $settings->{$key} = $value; |
|
397 | + } |
|
398 | + } |
|
399 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
400 | + } |
|
401 | + return $settings; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * deactivate_event_espresso |
|
407 | + * |
|
408 | + * @access public |
|
409 | + * @static |
|
410 | + * @return void |
|
411 | + */ |
|
412 | + public static function deactivate_event_espresso() |
|
413 | + { |
|
414 | + // check permissions |
|
415 | + if (current_user_can('activate_plugins')) { |
|
416 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * verify_default_pages_exist |
|
424 | + * |
|
425 | + * @access public |
|
426 | + * @static |
|
427 | + * @return void |
|
428 | + * @throws InvalidDataTypeException |
|
429 | + */ |
|
430 | + public static function verify_default_pages_exist() |
|
431 | + { |
|
432 | + $critical_page_problem = false; |
|
433 | + $critical_pages = array( |
|
434 | + array( |
|
435 | + 'id' => 'reg_page_id', |
|
436 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
437 | + 'post' => null, |
|
438 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
439 | + ), |
|
440 | + array( |
|
441 | + 'id' => 'txn_page_id', |
|
442 | + 'name' => __('Transactions', 'event_espresso'), |
|
443 | + 'post' => null, |
|
444 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
445 | + ), |
|
446 | + array( |
|
447 | + 'id' => 'thank_you_page_id', |
|
448 | + 'name' => __('Thank You', 'event_espresso'), |
|
449 | + 'post' => null, |
|
450 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
451 | + ), |
|
452 | + array( |
|
453 | + 'id' => 'cancel_page_id', |
|
454 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
455 | + 'post' => null, |
|
456 | + 'code' => 'ESPRESSO_CANCELLED', |
|
457 | + ), |
|
458 | + ); |
|
459 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
460 | + foreach ($critical_pages as $critical_page) { |
|
461 | + // is critical page ID set in config ? |
|
462 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
463 | + // attempt to find post by ID |
|
464 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
465 | + } |
|
466 | + // no dice? |
|
467 | + if ($critical_page['post'] === null) { |
|
468 | + // attempt to find post by title |
|
469 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
470 | + // still nothing? |
|
471 | + if ($critical_page['post'] === null) { |
|
472 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
473 | + // REALLY? Still nothing ??!?!? |
|
474 | + if ($critical_page['post'] === null) { |
|
475 | + $msg = __( |
|
476 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
477 | + 'event_espresso' |
|
478 | + ); |
|
479 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
480 | + break; |
|
481 | + } |
|
482 | + } |
|
483 | + } |
|
484 | + // check that Post ID matches critical page ID in config |
|
485 | + if ( |
|
486 | + isset($critical_page['post']->ID) |
|
487 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
488 | + ) { |
|
489 | + //update Config with post ID |
|
490 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
491 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | + $msg = __( |
|
493 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
494 | + 'event_espresso' |
|
495 | + ); |
|
496 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
497 | + } |
|
498 | + } |
|
499 | + $critical_page_problem = |
|
500 | + ! isset($critical_page['post']->post_status) |
|
501 | + || $critical_page['post']->post_status !== 'publish' |
|
502 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
503 | + ? true |
|
504 | + : $critical_page_problem; |
|
505 | + } |
|
506 | + if ($critical_page_problem) { |
|
507 | + new PersistentAdminNotice( |
|
508 | + 'critical_page_problem', |
|
509 | + sprintf( |
|
510 | + esc_html__( |
|
511 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
512 | + 'event_espresso' |
|
513 | + ), |
|
514 | + '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
515 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
516 | + . '</a>' |
|
517 | + ) |
|
518 | + ); |
|
519 | + } |
|
520 | + if (EE_Error::has_notices()) { |
|
521 | + EE_Error::get_notices(false, true, true); |
|
522 | + } |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * Returns the first post which uses the specified shortcode |
|
529 | + * |
|
530 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
531 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
532 | + * "[ESPRESSO_THANK_YOU" |
|
533 | + * (we don't search for the closing shortcode bracket because they might have added |
|
534 | + * parameter to the shortcode |
|
535 | + * @return WP_Post or NULl |
|
536 | + */ |
|
537 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
538 | + { |
|
539 | + global $wpdb; |
|
540 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
541 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
542 | + if ($post_id) { |
|
543 | + return get_post($post_id); |
|
544 | + } else { |
|
545 | + return null; |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * This function generates a post for critical espresso pages |
|
552 | + * |
|
553 | + * @access public |
|
554 | + * @static |
|
555 | + * @param array $critical_page |
|
556 | + * @return array |
|
557 | + */ |
|
558 | + public static function create_critical_page($critical_page) |
|
559 | + { |
|
560 | + |
|
561 | + $post_args = array( |
|
562 | + 'post_title' => $critical_page['name'], |
|
563 | + 'post_status' => 'publish', |
|
564 | + 'post_type' => 'page', |
|
565 | + 'comment_status' => 'closed', |
|
566 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
567 | + ); |
|
568 | + |
|
569 | + $post_id = wp_insert_post($post_args); |
|
570 | + if (! $post_id) { |
|
571 | + $msg = sprintf( |
|
572 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
573 | + $critical_page['name'] |
|
574 | + ); |
|
575 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
576 | + return $critical_page; |
|
577 | + } |
|
578 | + // get newly created post's details |
|
579 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
580 | + $msg = sprintf( |
|
581 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
582 | + $critical_page['name'] |
|
583 | + ); |
|
584 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
585 | + } |
|
586 | + |
|
587 | + return $critical_page; |
|
588 | + |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
596 | + * The role being used to check is filterable. |
|
597 | + * |
|
598 | + * @since 4.6.0 |
|
599 | + * @global WPDB $wpdb |
|
600 | + * @return mixed null|int WP_user ID or NULL |
|
601 | + */ |
|
602 | + public static function get_default_creator_id() |
|
603 | + { |
|
604 | + global $wpdb; |
|
605 | + if ( ! empty(self::$_default_creator_id)) { |
|
606 | + return self::$_default_creator_id; |
|
607 | + }/**/ |
|
608 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
609 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
610 | + $pre_filtered_id = apply_filters( |
|
611 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
612 | + false, |
|
613 | + $role_to_check |
|
614 | + ); |
|
615 | + if ($pre_filtered_id !== false) { |
|
616 | + return (int)$pre_filtered_id; |
|
617 | + } |
|
618 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
619 | + $query = $wpdb->prepare( |
|
620 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
621 | + '%' . $role_to_check . '%' |
|
622 | + ); |
|
623 | + $user_id = $wpdb->get_var($query); |
|
624 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
625 | + if ($user_id && (int)$user_id) { |
|
626 | + self::$_default_creator_id = (int)$user_id; |
|
627 | + return self::$_default_creator_id; |
|
628 | + } else { |
|
629 | + return null; |
|
630 | + } |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * used by EE and EE addons during plugin activation to create tables. |
|
637 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
638 | + * but includes extra logic regarding activations. |
|
639 | + * |
|
640 | + * @access public |
|
641 | + * @static |
|
642 | + * @param string $table_name without the $wpdb->prefix |
|
643 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
644 | + * table query) |
|
645 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
646 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
647 | + * and new once this function is done (ie, you really do want to CREATE a |
|
648 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
649 | + * you just want to verify the table exists and matches this definition |
|
650 | + * (and if it HAS data in it you want to leave it be) |
|
651 | + * @return void |
|
652 | + * @throws EE_Error if there are database errors |
|
653 | + */ |
|
654 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
655 | + { |
|
656 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
657 | + return; |
|
658 | + } |
|
659 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
660 | + if ( ! function_exists('dbDelta')) { |
|
661 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
662 | + } |
|
663 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
664 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
665 | + // do we need to first delete an existing version of this table ? |
|
666 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
667 | + // ok, delete the table... but ONLY if it's empty |
|
668 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
669 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
670 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
671 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
672 | + } else if ( ! $deleted_safely) { |
|
673 | + // so we should be more cautious rather than just dropping tables so easily |
|
674 | + error_log( |
|
675 | + sprintf( |
|
676 | + __( |
|
677 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
678 | + 'event_espresso' |
|
679 | + ), |
|
680 | + $wp_table_name, |
|
681 | + '<br/>', |
|
682 | + 'espresso_db_update' |
|
683 | + ) |
|
684 | + ); |
|
685 | + } |
|
686 | + } |
|
687 | + $engine = str_replace('ENGINE=', '', $engine); |
|
688 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * add_column_if_it_doesn't_exist |
|
695 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
696 | + * |
|
697 | + * @access public |
|
698 | + * @static |
|
699 | + * @deprecated instead use TableManager::addColumn() |
|
700 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
701 | + * @param string $column_name |
|
702 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
703 | + * 'VARCHAR(10)' |
|
704 | + * @return bool|int |
|
705 | + */ |
|
706 | + public static function add_column_if_it_doesnt_exist( |
|
707 | + $table_name, |
|
708 | + $column_name, |
|
709 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
710 | + ) { |
|
711 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * get_fields_on_table |
|
717 | + * Gets all the fields on the database table. |
|
718 | + * |
|
719 | + * @access public |
|
720 | + * @deprecated instead use TableManager::getTableColumns() |
|
721 | + * @static |
|
722 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
723 | + * @return array of database column names |
|
724 | + */ |
|
725 | + public static function get_fields_on_table($table_name = null) |
|
726 | + { |
|
727 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * db_table_is_empty |
|
733 | + * |
|
734 | + * @access public\ |
|
735 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
736 | + * @static |
|
737 | + * @param string $table_name |
|
738 | + * @return bool |
|
739 | + */ |
|
740 | + public static function db_table_is_empty($table_name) |
|
741 | + { |
|
742 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + /** |
|
747 | + * delete_db_table_if_empty |
|
748 | + * |
|
749 | + * @access public |
|
750 | + * @static |
|
751 | + * @param string $table_name |
|
752 | + * @return bool | int |
|
753 | + */ |
|
754 | + public static function delete_db_table_if_empty($table_name) |
|
755 | + { |
|
756 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
757 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | + } |
|
759 | + return false; |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * delete_unused_db_table |
|
765 | + * |
|
766 | + * @access public |
|
767 | + * @static |
|
768 | + * @deprecated instead use TableManager::dropTable() |
|
769 | + * @param string $table_name |
|
770 | + * @return bool | int |
|
771 | + */ |
|
772 | + public static function delete_unused_db_table($table_name) |
|
773 | + { |
|
774 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * drop_index |
|
780 | + * |
|
781 | + * @access public |
|
782 | + * @static |
|
783 | + * @deprecated instead use TableManager::dropIndex() |
|
784 | + * @param string $table_name |
|
785 | + * @param string $index_name |
|
786 | + * @return bool | int |
|
787 | + */ |
|
788 | + public static function drop_index($table_name, $index_name) |
|
789 | + { |
|
790 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * create_database_tables |
|
797 | + * |
|
798 | + * @access public |
|
799 | + * @static |
|
800 | + * @throws EE_Error |
|
801 | + * @return boolean success (whether database is setup properly or not) |
|
802 | + */ |
|
803 | + public static function create_database_tables() |
|
804 | + { |
|
805 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
806 | + //find the migration script that sets the database to be compatible with the code |
|
807 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
808 | + if ($dms_name) { |
|
809 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
810 | + $current_data_migration_script->set_migrating(false); |
|
811 | + $current_data_migration_script->schema_changes_before_migration(); |
|
812 | + $current_data_migration_script->schema_changes_after_migration(); |
|
813 | + if ($current_data_migration_script->get_errors()) { |
|
814 | + if (WP_DEBUG) { |
|
815 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
816 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
817 | + } |
|
818 | + } else { |
|
819 | + EE_Error::add_error( |
|
820 | + __( |
|
821 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
822 | 822 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
823 | - 'event_espresso' |
|
824 | - ) |
|
825 | - ); |
|
826 | - } |
|
827 | - return false; |
|
828 | - } |
|
829 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
830 | - } else { |
|
831 | - EE_Error::add_error( |
|
832 | - __( |
|
833 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
823 | + 'event_espresso' |
|
824 | + ) |
|
825 | + ); |
|
826 | + } |
|
827 | + return false; |
|
828 | + } |
|
829 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
830 | + } else { |
|
831 | + EE_Error::add_error( |
|
832 | + __( |
|
833 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
834 | 834 | structure. So database is probably not setup properly', |
835 | - 'event_espresso' |
|
836 | - ), |
|
837 | - __FILE__, |
|
838 | - __FUNCTION__, |
|
839 | - __LINE__ |
|
840 | - ); |
|
841 | - return false; |
|
842 | - } |
|
843 | - return true; |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - |
|
848 | - /** |
|
849 | - * initialize_system_questions |
|
850 | - * |
|
851 | - * @access public |
|
852 | - * @static |
|
853 | - * @return void |
|
854 | - */ |
|
855 | - public static function initialize_system_questions() |
|
856 | - { |
|
857 | - // QUESTION GROUPS |
|
858 | - global $wpdb; |
|
859 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
860 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
861 | - // what we have |
|
862 | - $question_groups = $wpdb->get_col($SQL); |
|
863 | - // check the response |
|
864 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
865 | - // what we should have |
|
866 | - $QSG_systems = array(1, 2); |
|
867 | - // loop thru what we should have and compare to what we have |
|
868 | - foreach ($QSG_systems as $QSG_system) { |
|
869 | - // reset values array |
|
870 | - $QSG_values = array(); |
|
871 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
872 | - if (! in_array("$QSG_system", $question_groups)) { |
|
873 | - // add it |
|
874 | - switch ($QSG_system) { |
|
875 | - case 1: |
|
876 | - $QSG_values = array( |
|
877 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
878 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
879 | - 'QSG_desc' => '', |
|
880 | - 'QSG_order' => 1, |
|
881 | - 'QSG_show_group_name' => 1, |
|
882 | - 'QSG_show_group_desc' => 1, |
|
883 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
884 | - 'QSG_deleted' => 0, |
|
885 | - ); |
|
886 | - break; |
|
887 | - case 2: |
|
888 | - $QSG_values = array( |
|
889 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
890 | - 'QSG_identifier' => 'address-information-' . time(), |
|
891 | - 'QSG_desc' => '', |
|
892 | - 'QSG_order' => 2, |
|
893 | - 'QSG_show_group_name' => 1, |
|
894 | - 'QSG_show_group_desc' => 1, |
|
895 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
896 | - 'QSG_deleted' => 0, |
|
897 | - ); |
|
898 | - break; |
|
899 | - } |
|
900 | - // make sure we have some values before inserting them |
|
901 | - if (! empty($QSG_values)) { |
|
902 | - // insert system question |
|
903 | - $wpdb->insert( |
|
904 | - $table_name, |
|
905 | - $QSG_values, |
|
906 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
907 | - ); |
|
908 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
909 | - } |
|
910 | - } |
|
911 | - } |
|
912 | - // QUESTIONS |
|
913 | - global $wpdb; |
|
914 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
915 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
916 | - // what we have |
|
917 | - $questions = $wpdb->get_col($SQL); |
|
918 | - // what we should have |
|
919 | - $QST_systems = array( |
|
920 | - 'fname', |
|
921 | - 'lname', |
|
922 | - 'email', |
|
923 | - 'address', |
|
924 | - 'address2', |
|
925 | - 'city', |
|
926 | - 'country', |
|
927 | - 'state', |
|
928 | - 'zip', |
|
929 | - 'phone', |
|
930 | - ); |
|
931 | - $order_for_group_1 = 1; |
|
932 | - $order_for_group_2 = 1; |
|
933 | - // loop thru what we should have and compare to what we have |
|
934 | - foreach ($QST_systems as $QST_system) { |
|
935 | - // reset values array |
|
936 | - $QST_values = array(); |
|
937 | - // if we don't have what we should have |
|
938 | - if (! in_array($QST_system, $questions)) { |
|
939 | - // add it |
|
940 | - switch ($QST_system) { |
|
941 | - case 'fname': |
|
942 | - $QST_values = array( |
|
943 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
944 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
945 | - 'QST_system' => 'fname', |
|
946 | - 'QST_type' => 'TEXT', |
|
947 | - 'QST_required' => 1, |
|
948 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
949 | - 'QST_order' => 1, |
|
950 | - 'QST_admin_only' => 0, |
|
951 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
952 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
953 | - 'QST_deleted' => 0, |
|
954 | - ); |
|
955 | - break; |
|
956 | - case 'lname': |
|
957 | - $QST_values = array( |
|
958 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
959 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
960 | - 'QST_system' => 'lname', |
|
961 | - 'QST_type' => 'TEXT', |
|
962 | - 'QST_required' => 1, |
|
963 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
964 | - 'QST_order' => 2, |
|
965 | - 'QST_admin_only' => 0, |
|
966 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
967 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
968 | - 'QST_deleted' => 0, |
|
969 | - ); |
|
970 | - break; |
|
971 | - case 'email': |
|
972 | - $QST_values = array( |
|
973 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
974 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
975 | - 'QST_system' => 'email', |
|
976 | - 'QST_type' => 'EMAIL', |
|
977 | - 'QST_required' => 1, |
|
978 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
979 | - 'QST_order' => 3, |
|
980 | - 'QST_admin_only' => 0, |
|
981 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
982 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
983 | - 'QST_deleted' => 0, |
|
984 | - ); |
|
985 | - break; |
|
986 | - case 'address': |
|
987 | - $QST_values = array( |
|
988 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
989 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
990 | - 'QST_system' => 'address', |
|
991 | - 'QST_type' => 'TEXT', |
|
992 | - 'QST_required' => 0, |
|
993 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
994 | - 'QST_order' => 4, |
|
995 | - 'QST_admin_only' => 0, |
|
996 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
997 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
998 | - 'QST_deleted' => 0, |
|
999 | - ); |
|
1000 | - break; |
|
1001 | - case 'address2': |
|
1002 | - $QST_values = array( |
|
1003 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1004 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1005 | - 'QST_system' => 'address2', |
|
1006 | - 'QST_type' => 'TEXT', |
|
1007 | - 'QST_required' => 0, |
|
1008 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1009 | - 'QST_order' => 5, |
|
1010 | - 'QST_admin_only' => 0, |
|
1011 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1012 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1013 | - 'QST_deleted' => 0, |
|
1014 | - ); |
|
1015 | - break; |
|
1016 | - case 'city': |
|
1017 | - $QST_values = array( |
|
1018 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
1019 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1020 | - 'QST_system' => 'city', |
|
1021 | - 'QST_type' => 'TEXT', |
|
1022 | - 'QST_required' => 0, |
|
1023 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1024 | - 'QST_order' => 6, |
|
1025 | - 'QST_admin_only' => 0, |
|
1026 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1027 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1028 | - 'QST_deleted' => 0, |
|
1029 | - ); |
|
1030 | - break; |
|
1031 | - case 'country': |
|
1032 | - $QST_values = array( |
|
1033 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
1034 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1035 | - 'QST_system' => 'country', |
|
1036 | - 'QST_type' => 'COUNTRY', |
|
1037 | - 'QST_required' => 0, |
|
1038 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1039 | - 'QST_order' => 7, |
|
1040 | - 'QST_admin_only' => 0, |
|
1041 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1042 | - 'QST_deleted' => 0, |
|
1043 | - ); |
|
1044 | - break; |
|
1045 | - case 'state': |
|
1046 | - $QST_values = array( |
|
1047 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1048 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1049 | - 'QST_system' => 'state', |
|
1050 | - 'QST_type' => 'STATE', |
|
1051 | - 'QST_required' => 0, |
|
1052 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1053 | - 'QST_order' => 8, |
|
1054 | - 'QST_admin_only' => 0, |
|
1055 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1056 | - 'QST_deleted' => 0, |
|
1057 | - ); |
|
1058 | - break; |
|
1059 | - case 'zip': |
|
1060 | - $QST_values = array( |
|
1061 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1062 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1063 | - 'QST_system' => 'zip', |
|
1064 | - 'QST_type' => 'TEXT', |
|
1065 | - 'QST_required' => 0, |
|
1066 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1067 | - 'QST_order' => 9, |
|
1068 | - 'QST_admin_only' => 0, |
|
1069 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1070 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1071 | - 'QST_deleted' => 0, |
|
1072 | - ); |
|
1073 | - break; |
|
1074 | - case 'phone': |
|
1075 | - $QST_values = array( |
|
1076 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1077 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1078 | - 'QST_system' => 'phone', |
|
1079 | - 'QST_type' => 'TEXT', |
|
1080 | - 'QST_required' => 0, |
|
1081 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1082 | - 'QST_order' => 10, |
|
1083 | - 'QST_admin_only' => 0, |
|
1084 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1085 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1086 | - 'QST_deleted' => 0, |
|
1087 | - ); |
|
1088 | - break; |
|
1089 | - } |
|
1090 | - if (! empty($QST_values)) { |
|
1091 | - // insert system question |
|
1092 | - $wpdb->insert( |
|
1093 | - $table_name, |
|
1094 | - $QST_values, |
|
1095 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1096 | - ); |
|
1097 | - $QST_ID = $wpdb->insert_id; |
|
1098 | - // QUESTION GROUP QUESTIONS |
|
1099 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1100 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
1101 | - } else { |
|
1102 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
1103 | - } |
|
1104 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
1105 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1106 | - } else { |
|
1107 | - $id_col = EEM_Question_Group::instance() |
|
1108 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | - if (is_array($id_col)) { |
|
1110 | - $QSG_ID = reset($id_col); |
|
1111 | - } else { |
|
1112 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | - EE_Log::instance()->log( |
|
1114 | - __FILE__, |
|
1115 | - __FUNCTION__, |
|
1116 | - sprintf( |
|
1117 | - __( |
|
1118 | - 'Could not associate question %1$s to a question group because no system question |
|
835 | + 'event_espresso' |
|
836 | + ), |
|
837 | + __FILE__, |
|
838 | + __FUNCTION__, |
|
839 | + __LINE__ |
|
840 | + ); |
|
841 | + return false; |
|
842 | + } |
|
843 | + return true; |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + |
|
848 | + /** |
|
849 | + * initialize_system_questions |
|
850 | + * |
|
851 | + * @access public |
|
852 | + * @static |
|
853 | + * @return void |
|
854 | + */ |
|
855 | + public static function initialize_system_questions() |
|
856 | + { |
|
857 | + // QUESTION GROUPS |
|
858 | + global $wpdb; |
|
859 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
860 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
861 | + // what we have |
|
862 | + $question_groups = $wpdb->get_col($SQL); |
|
863 | + // check the response |
|
864 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
865 | + // what we should have |
|
866 | + $QSG_systems = array(1, 2); |
|
867 | + // loop thru what we should have and compare to what we have |
|
868 | + foreach ($QSG_systems as $QSG_system) { |
|
869 | + // reset values array |
|
870 | + $QSG_values = array(); |
|
871 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
872 | + if (! in_array("$QSG_system", $question_groups)) { |
|
873 | + // add it |
|
874 | + switch ($QSG_system) { |
|
875 | + case 1: |
|
876 | + $QSG_values = array( |
|
877 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
878 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
879 | + 'QSG_desc' => '', |
|
880 | + 'QSG_order' => 1, |
|
881 | + 'QSG_show_group_name' => 1, |
|
882 | + 'QSG_show_group_desc' => 1, |
|
883 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
884 | + 'QSG_deleted' => 0, |
|
885 | + ); |
|
886 | + break; |
|
887 | + case 2: |
|
888 | + $QSG_values = array( |
|
889 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
890 | + 'QSG_identifier' => 'address-information-' . time(), |
|
891 | + 'QSG_desc' => '', |
|
892 | + 'QSG_order' => 2, |
|
893 | + 'QSG_show_group_name' => 1, |
|
894 | + 'QSG_show_group_desc' => 1, |
|
895 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
896 | + 'QSG_deleted' => 0, |
|
897 | + ); |
|
898 | + break; |
|
899 | + } |
|
900 | + // make sure we have some values before inserting them |
|
901 | + if (! empty($QSG_values)) { |
|
902 | + // insert system question |
|
903 | + $wpdb->insert( |
|
904 | + $table_name, |
|
905 | + $QSG_values, |
|
906 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
907 | + ); |
|
908 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
909 | + } |
|
910 | + } |
|
911 | + } |
|
912 | + // QUESTIONS |
|
913 | + global $wpdb; |
|
914 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
915 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
916 | + // what we have |
|
917 | + $questions = $wpdb->get_col($SQL); |
|
918 | + // what we should have |
|
919 | + $QST_systems = array( |
|
920 | + 'fname', |
|
921 | + 'lname', |
|
922 | + 'email', |
|
923 | + 'address', |
|
924 | + 'address2', |
|
925 | + 'city', |
|
926 | + 'country', |
|
927 | + 'state', |
|
928 | + 'zip', |
|
929 | + 'phone', |
|
930 | + ); |
|
931 | + $order_for_group_1 = 1; |
|
932 | + $order_for_group_2 = 1; |
|
933 | + // loop thru what we should have and compare to what we have |
|
934 | + foreach ($QST_systems as $QST_system) { |
|
935 | + // reset values array |
|
936 | + $QST_values = array(); |
|
937 | + // if we don't have what we should have |
|
938 | + if (! in_array($QST_system, $questions)) { |
|
939 | + // add it |
|
940 | + switch ($QST_system) { |
|
941 | + case 'fname': |
|
942 | + $QST_values = array( |
|
943 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
944 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
945 | + 'QST_system' => 'fname', |
|
946 | + 'QST_type' => 'TEXT', |
|
947 | + 'QST_required' => 1, |
|
948 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
949 | + 'QST_order' => 1, |
|
950 | + 'QST_admin_only' => 0, |
|
951 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
952 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
953 | + 'QST_deleted' => 0, |
|
954 | + ); |
|
955 | + break; |
|
956 | + case 'lname': |
|
957 | + $QST_values = array( |
|
958 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
959 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
960 | + 'QST_system' => 'lname', |
|
961 | + 'QST_type' => 'TEXT', |
|
962 | + 'QST_required' => 1, |
|
963 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
964 | + 'QST_order' => 2, |
|
965 | + 'QST_admin_only' => 0, |
|
966 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
967 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
968 | + 'QST_deleted' => 0, |
|
969 | + ); |
|
970 | + break; |
|
971 | + case 'email': |
|
972 | + $QST_values = array( |
|
973 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
974 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
975 | + 'QST_system' => 'email', |
|
976 | + 'QST_type' => 'EMAIL', |
|
977 | + 'QST_required' => 1, |
|
978 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
979 | + 'QST_order' => 3, |
|
980 | + 'QST_admin_only' => 0, |
|
981 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
982 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
983 | + 'QST_deleted' => 0, |
|
984 | + ); |
|
985 | + break; |
|
986 | + case 'address': |
|
987 | + $QST_values = array( |
|
988 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
989 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
990 | + 'QST_system' => 'address', |
|
991 | + 'QST_type' => 'TEXT', |
|
992 | + 'QST_required' => 0, |
|
993 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
994 | + 'QST_order' => 4, |
|
995 | + 'QST_admin_only' => 0, |
|
996 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
997 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
998 | + 'QST_deleted' => 0, |
|
999 | + ); |
|
1000 | + break; |
|
1001 | + case 'address2': |
|
1002 | + $QST_values = array( |
|
1003 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1004 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1005 | + 'QST_system' => 'address2', |
|
1006 | + 'QST_type' => 'TEXT', |
|
1007 | + 'QST_required' => 0, |
|
1008 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1009 | + 'QST_order' => 5, |
|
1010 | + 'QST_admin_only' => 0, |
|
1011 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1012 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1013 | + 'QST_deleted' => 0, |
|
1014 | + ); |
|
1015 | + break; |
|
1016 | + case 'city': |
|
1017 | + $QST_values = array( |
|
1018 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
1019 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1020 | + 'QST_system' => 'city', |
|
1021 | + 'QST_type' => 'TEXT', |
|
1022 | + 'QST_required' => 0, |
|
1023 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1024 | + 'QST_order' => 6, |
|
1025 | + 'QST_admin_only' => 0, |
|
1026 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1027 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1028 | + 'QST_deleted' => 0, |
|
1029 | + ); |
|
1030 | + break; |
|
1031 | + case 'country': |
|
1032 | + $QST_values = array( |
|
1033 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
1034 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1035 | + 'QST_system' => 'country', |
|
1036 | + 'QST_type' => 'COUNTRY', |
|
1037 | + 'QST_required' => 0, |
|
1038 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1039 | + 'QST_order' => 7, |
|
1040 | + 'QST_admin_only' => 0, |
|
1041 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1042 | + 'QST_deleted' => 0, |
|
1043 | + ); |
|
1044 | + break; |
|
1045 | + case 'state': |
|
1046 | + $QST_values = array( |
|
1047 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1048 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1049 | + 'QST_system' => 'state', |
|
1050 | + 'QST_type' => 'STATE', |
|
1051 | + 'QST_required' => 0, |
|
1052 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1053 | + 'QST_order' => 8, |
|
1054 | + 'QST_admin_only' => 0, |
|
1055 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1056 | + 'QST_deleted' => 0, |
|
1057 | + ); |
|
1058 | + break; |
|
1059 | + case 'zip': |
|
1060 | + $QST_values = array( |
|
1061 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1062 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1063 | + 'QST_system' => 'zip', |
|
1064 | + 'QST_type' => 'TEXT', |
|
1065 | + 'QST_required' => 0, |
|
1066 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1067 | + 'QST_order' => 9, |
|
1068 | + 'QST_admin_only' => 0, |
|
1069 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1070 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1071 | + 'QST_deleted' => 0, |
|
1072 | + ); |
|
1073 | + break; |
|
1074 | + case 'phone': |
|
1075 | + $QST_values = array( |
|
1076 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1077 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1078 | + 'QST_system' => 'phone', |
|
1079 | + 'QST_type' => 'TEXT', |
|
1080 | + 'QST_required' => 0, |
|
1081 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1082 | + 'QST_order' => 10, |
|
1083 | + 'QST_admin_only' => 0, |
|
1084 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1085 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1086 | + 'QST_deleted' => 0, |
|
1087 | + ); |
|
1088 | + break; |
|
1089 | + } |
|
1090 | + if (! empty($QST_values)) { |
|
1091 | + // insert system question |
|
1092 | + $wpdb->insert( |
|
1093 | + $table_name, |
|
1094 | + $QST_values, |
|
1095 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1096 | + ); |
|
1097 | + $QST_ID = $wpdb->insert_id; |
|
1098 | + // QUESTION GROUP QUESTIONS |
|
1099 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1100 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
1101 | + } else { |
|
1102 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
1103 | + } |
|
1104 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
1105 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1106 | + } else { |
|
1107 | + $id_col = EEM_Question_Group::instance() |
|
1108 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | + if (is_array($id_col)) { |
|
1110 | + $QSG_ID = reset($id_col); |
|
1111 | + } else { |
|
1112 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | + EE_Log::instance()->log( |
|
1114 | + __FILE__, |
|
1115 | + __FUNCTION__, |
|
1116 | + sprintf( |
|
1117 | + __( |
|
1118 | + 'Could not associate question %1$s to a question group because no system question |
|
1119 | 1119 | group existed', |
1120 | - 'event_espresso' |
|
1121 | - ), |
|
1122 | - $QST_ID), |
|
1123 | - 'error'); |
|
1124 | - continue; |
|
1125 | - } |
|
1126 | - } |
|
1127 | - // add system questions to groups |
|
1128 | - $wpdb->insert( |
|
1129 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1130 | - array( |
|
1131 | - 'QSG_ID' => $QSG_ID, |
|
1132 | - 'QST_ID' => $QST_ID, |
|
1133 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1134 | - ), |
|
1135 | - array('%d', '%d', '%d') |
|
1136 | - ); |
|
1137 | - } |
|
1138 | - } |
|
1139 | - } |
|
1140 | - } |
|
1141 | - |
|
1142 | - |
|
1143 | - /** |
|
1144 | - * Makes sure the default payment method (Invoice) is active. |
|
1145 | - * This used to be done automatically as part of constructing the old gateways config |
|
1146 | - * |
|
1147 | - * @throws \EE_Error |
|
1148 | - */ |
|
1149 | - public static function insert_default_payment_methods() |
|
1150 | - { |
|
1151 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1153 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1154 | - } else { |
|
1155 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
1156 | - } |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * insert_default_status_codes |
|
1161 | - * |
|
1162 | - * @access public |
|
1163 | - * @static |
|
1164 | - * @return void |
|
1165 | - */ |
|
1166 | - public static function insert_default_status_codes() |
|
1167 | - { |
|
1168 | - |
|
1169 | - global $wpdb; |
|
1170 | - |
|
1171 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1172 | - |
|
1173 | - $table_name = EEM_Status::instance()->table(); |
|
1174 | - |
|
1175 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1176 | - $wpdb->query($SQL); |
|
1177 | - |
|
1178 | - $SQL = "INSERT INTO $table_name |
|
1120 | + 'event_espresso' |
|
1121 | + ), |
|
1122 | + $QST_ID), |
|
1123 | + 'error'); |
|
1124 | + continue; |
|
1125 | + } |
|
1126 | + } |
|
1127 | + // add system questions to groups |
|
1128 | + $wpdb->insert( |
|
1129 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1130 | + array( |
|
1131 | + 'QSG_ID' => $QSG_ID, |
|
1132 | + 'QST_ID' => $QST_ID, |
|
1133 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1134 | + ), |
|
1135 | + array('%d', '%d', '%d') |
|
1136 | + ); |
|
1137 | + } |
|
1138 | + } |
|
1139 | + } |
|
1140 | + } |
|
1141 | + |
|
1142 | + |
|
1143 | + /** |
|
1144 | + * Makes sure the default payment method (Invoice) is active. |
|
1145 | + * This used to be done automatically as part of constructing the old gateways config |
|
1146 | + * |
|
1147 | + * @throws \EE_Error |
|
1148 | + */ |
|
1149 | + public static function insert_default_payment_methods() |
|
1150 | + { |
|
1151 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1153 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1154 | + } else { |
|
1155 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
1156 | + } |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * insert_default_status_codes |
|
1161 | + * |
|
1162 | + * @access public |
|
1163 | + * @static |
|
1164 | + * @return void |
|
1165 | + */ |
|
1166 | + public static function insert_default_status_codes() |
|
1167 | + { |
|
1168 | + |
|
1169 | + global $wpdb; |
|
1170 | + |
|
1171 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1172 | + |
|
1173 | + $table_name = EEM_Status::instance()->table(); |
|
1174 | + |
|
1175 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1176 | + $wpdb->query($SQL); |
|
1177 | + |
|
1178 | + $SQL = "INSERT INTO $table_name |
|
1179 | 1179 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
1180 | 1180 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
1181 | 1181 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1215,521 +1215,521 @@ discard block |
||
1215 | 1215 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
1216 | 1216 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
1217 | 1217 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
1218 | - $wpdb->query($SQL); |
|
1219 | - |
|
1220 | - } |
|
1221 | - |
|
1222 | - } |
|
1223 | - |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * create_upload_directories |
|
1227 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
1228 | - * |
|
1229 | - * @access public |
|
1230 | - * @static |
|
1231 | - * @return boolean success of verifying upload directories exist |
|
1232 | - */ |
|
1233 | - public static function create_upload_directories() |
|
1234 | - { |
|
1235 | - // Create the required folders |
|
1236 | - $folders = array( |
|
1237 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
1238 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1242 | - ); |
|
1243 | - foreach ($folders as $folder) { |
|
1244 | - try { |
|
1245 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1246 | - @ chmod($folder, 0755); |
|
1247 | - } catch (EE_Error $e) { |
|
1248 | - EE_Error::add_error( |
|
1249 | - sprintf( |
|
1250 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1251 | - $folder, |
|
1252 | - '<br />' . $e->getMessage() |
|
1253 | - ), |
|
1254 | - __FILE__, __FUNCTION__, __LINE__ |
|
1255 | - ); |
|
1256 | - //indicate we'll need to fix this later |
|
1257 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1258 | - return false; |
|
1259 | - } |
|
1260 | - } |
|
1261 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
1262 | - //is disabled, there might be activation errors recorded in there |
|
1263 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1264 | - //remember EE's folders are all good |
|
1265 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1266 | - return true; |
|
1267 | - } |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Whether the upload directories need to be fixed or not. |
|
1271 | - * If EE is installed but filesystem access isn't initially available, |
|
1272 | - * we need to get the user's filesystem credentials and THEN create them, |
|
1273 | - * so there might be period of time when EE is installed but its |
|
1274 | - * upload directories aren't available. This indicates such a state |
|
1275 | - * |
|
1276 | - * @return boolean |
|
1277 | - */ |
|
1278 | - public static function upload_directories_incomplete() |
|
1279 | - { |
|
1280 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1281 | - } |
|
1282 | - |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * generate_default_message_templates |
|
1286 | - * |
|
1287 | - * @static |
|
1288 | - * @throws EE_Error |
|
1289 | - * @return bool true means new templates were created. |
|
1290 | - * false means no templates were created. |
|
1291 | - * This is NOT an error flag. To check for errors you will want |
|
1292 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
1293 | - */ |
|
1294 | - public static function generate_default_message_templates() |
|
1295 | - { |
|
1296 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1297 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1298 | - /* |
|
1218 | + $wpdb->query($SQL); |
|
1219 | + |
|
1220 | + } |
|
1221 | + |
|
1222 | + } |
|
1223 | + |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * create_upload_directories |
|
1227 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
1228 | + * |
|
1229 | + * @access public |
|
1230 | + * @static |
|
1231 | + * @return boolean success of verifying upload directories exist |
|
1232 | + */ |
|
1233 | + public static function create_upload_directories() |
|
1234 | + { |
|
1235 | + // Create the required folders |
|
1236 | + $folders = array( |
|
1237 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
1238 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
1239 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1242 | + ); |
|
1243 | + foreach ($folders as $folder) { |
|
1244 | + try { |
|
1245 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1246 | + @ chmod($folder, 0755); |
|
1247 | + } catch (EE_Error $e) { |
|
1248 | + EE_Error::add_error( |
|
1249 | + sprintf( |
|
1250 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1251 | + $folder, |
|
1252 | + '<br />' . $e->getMessage() |
|
1253 | + ), |
|
1254 | + __FILE__, __FUNCTION__, __LINE__ |
|
1255 | + ); |
|
1256 | + //indicate we'll need to fix this later |
|
1257 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1258 | + return false; |
|
1259 | + } |
|
1260 | + } |
|
1261 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
1262 | + //is disabled, there might be activation errors recorded in there |
|
1263 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1264 | + //remember EE's folders are all good |
|
1265 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1266 | + return true; |
|
1267 | + } |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Whether the upload directories need to be fixed or not. |
|
1271 | + * If EE is installed but filesystem access isn't initially available, |
|
1272 | + * we need to get the user's filesystem credentials and THEN create them, |
|
1273 | + * so there might be period of time when EE is installed but its |
|
1274 | + * upload directories aren't available. This indicates such a state |
|
1275 | + * |
|
1276 | + * @return boolean |
|
1277 | + */ |
|
1278 | + public static function upload_directories_incomplete() |
|
1279 | + { |
|
1280 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1281 | + } |
|
1282 | + |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * generate_default_message_templates |
|
1286 | + * |
|
1287 | + * @static |
|
1288 | + * @throws EE_Error |
|
1289 | + * @return bool true means new templates were created. |
|
1290 | + * false means no templates were created. |
|
1291 | + * This is NOT an error flag. To check for errors you will want |
|
1292 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
1293 | + */ |
|
1294 | + public static function generate_default_message_templates() |
|
1295 | + { |
|
1296 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1297 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1298 | + /* |
|
1299 | 1299 | * This first method is taking care of ensuring any default messengers |
1300 | 1300 | * that should be made active and have templates generated are done. |
1301 | 1301 | */ |
1302 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1303 | - $message_resource_manager |
|
1304 | - ); |
|
1305 | - /** |
|
1306 | - * This method is verifying there are no NEW default message types |
|
1307 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1308 | - */ |
|
1309 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1310 | - $message_resource_manager |
|
1311 | - ); |
|
1312 | - //after all is done, let's persist these changes to the db. |
|
1313 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
1314 | - $message_resource_manager->update_active_messengers_option(); |
|
1315 | - // will return true if either of these are true. Otherwise will return false. |
|
1316 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1317 | - } |
|
1318 | - |
|
1319 | - |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1323 | - * @return array|bool |
|
1324 | - * @throws \EE_Error |
|
1325 | - */ |
|
1326 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1327 | - EE_Message_Resource_Manager $message_resource_manager |
|
1328 | - ) { |
|
1329 | - /** @type EE_messenger[] $active_messengers */ |
|
1330 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1331 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | - $templates_created = false; |
|
1333 | - foreach ($active_messengers as $active_messenger) { |
|
1334 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1335 | - $default_message_type_names_to_activate = array(); |
|
1336 | - // looping through each default message type reported by the messenger |
|
1337 | - // and setup the actual message types to activate. |
|
1338 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1339 | - // if already active or has already been activated before we skip |
|
1340 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1341 | - // we also skip if the message type is not installed. |
|
1342 | - if ( |
|
1343 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1344 | - $default_message_type_name_for_messenger, |
|
1345 | - $active_messenger->name |
|
1346 | - ) |
|
1347 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
1348 | - $active_messenger->name, |
|
1349 | - $default_message_type_name_for_messenger |
|
1350 | - ) |
|
1351 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1352 | - ) { |
|
1353 | - continue; |
|
1354 | - } |
|
1355 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1356 | - } |
|
1357 | - //let's activate! |
|
1358 | - $message_resource_manager->ensure_message_types_are_active( |
|
1359 | - $default_message_type_names_to_activate, |
|
1360 | - $active_messenger->name, |
|
1361 | - false |
|
1362 | - ); |
|
1363 | - //activate the templates for these message types |
|
1364 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
1365 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1366 | - $active_messenger->name, |
|
1367 | - $default_message_type_names_for_messenger, |
|
1368 | - '', |
|
1369 | - true |
|
1370 | - ); |
|
1371 | - } |
|
1372 | - } |
|
1373 | - return $templates_created; |
|
1374 | - } |
|
1375 | - |
|
1376 | - |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * This will activate and generate default messengers and default message types for those messengers. |
|
1380 | - * |
|
1381 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
1382 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
1383 | - * False means that there were no templates generated |
|
1384 | - * (which could simply mean there are no default message types for a messenger). |
|
1385 | - * @throws EE_Error |
|
1386 | - */ |
|
1387 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1388 | - EE_Message_Resource_Manager $message_resource_manager |
|
1389 | - ) { |
|
1390 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
1391 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1392 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1393 | - $templates_generated = false; |
|
1394 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1395 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1396 | - //verify the default message types match an installed message type. |
|
1397 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1398 | - if ( |
|
1399 | - ! isset($installed_message_types[$name]) |
|
1400 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1401 | - $name, |
|
1402 | - $messenger_to_generate->name |
|
1403 | - ) |
|
1404 | - ) { |
|
1405 | - unset($default_message_type_names_for_messenger[$key]); |
|
1406 | - } |
|
1407 | - } |
|
1408 | - // in previous iterations, the active_messengers option in the db |
|
1409 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1410 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
1411 | - // passing off to create templates (after the refactor is done). |
|
1412 | - // @todo remove this comment when determined not necessary. |
|
1413 | - $message_resource_manager->activate_messenger( |
|
1414 | - $messenger_to_generate->name, |
|
1415 | - $default_message_type_names_for_messenger, |
|
1416 | - false |
|
1417 | - ); |
|
1418 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
1419 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
1420 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1421 | - $messenger_to_generate->name, |
|
1422 | - $default_message_type_names_for_messenger, |
|
1423 | - '', |
|
1424 | - true |
|
1425 | - ); |
|
1426 | - } |
|
1427 | - } |
|
1428 | - return $templates_generated; |
|
1429 | - } |
|
1430 | - |
|
1431 | - |
|
1432 | - /** |
|
1433 | - * This returns the default messengers to generate templates for on activation of EE. |
|
1434 | - * It considers: |
|
1435 | - * - whether a messenger is already active in the db. |
|
1436 | - * - whether a messenger has been made active at any time in the past. |
|
1437 | - * |
|
1438 | - * @static |
|
1439 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
1440 | - * @return EE_messenger[] |
|
1441 | - */ |
|
1442 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
1443 | - EE_Message_Resource_Manager $message_resource_manager |
|
1444 | - ) { |
|
1445 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1446 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1447 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1448 | - |
|
1449 | - $messengers_to_generate = array(); |
|
1450 | - foreach ($installed_messengers as $installed_messenger) { |
|
1451 | - //if installed messenger is a messenger that should be activated on install |
|
1452 | - //and is not already active |
|
1453 | - //and has never been activated |
|
1454 | - if ( |
|
1455 | - ! $installed_messenger->activate_on_install |
|
1456 | - || isset($active_messengers[$installed_messenger->name]) |
|
1457 | - || isset($has_activated[$installed_messenger->name]) |
|
1458 | - ) { |
|
1459 | - continue; |
|
1460 | - } |
|
1461 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1462 | - } |
|
1463 | - return $messengers_to_generate; |
|
1464 | - } |
|
1465 | - |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * This simply validates active message types to ensure they actually match installed |
|
1469 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1470 | - * rows are set inactive. |
|
1471 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1472 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1473 | - * are still handled in here. |
|
1474 | - * |
|
1475 | - * @since 4.3.1 |
|
1476 | - * @return void |
|
1477 | - */ |
|
1478 | - public static function validate_messages_system() |
|
1479 | - { |
|
1480 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1481 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1482 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
1483 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1484 | - } |
|
1485 | - |
|
1486 | - |
|
1487 | - /** |
|
1488 | - * create_no_ticket_prices_array |
|
1489 | - * |
|
1490 | - * @access public |
|
1491 | - * @static |
|
1492 | - * @return void |
|
1493 | - */ |
|
1494 | - public static function create_no_ticket_prices_array() |
|
1495 | - { |
|
1496 | - // this creates an array for tracking events that have no active ticket prices created |
|
1497 | - // this allows us to warn admins of the situation so that it can be corrected |
|
1498 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1499 | - if (! $espresso_no_ticket_prices) { |
|
1500 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
1501 | - } |
|
1502 | - } |
|
1503 | - |
|
1504 | - |
|
1505 | - /** |
|
1506 | - * plugin_deactivation |
|
1507 | - * |
|
1508 | - * @access public |
|
1509 | - * @static |
|
1510 | - * @return void |
|
1511 | - */ |
|
1512 | - public static function plugin_deactivation() |
|
1513 | - { |
|
1514 | - } |
|
1515 | - |
|
1516 | - |
|
1517 | - /** |
|
1518 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1519 | - * (like post meta or term relations) |
|
1520 | - * |
|
1521 | - * @global wpdb $wpdb |
|
1522 | - * @throws \EE_Error |
|
1523 | - */ |
|
1524 | - public static function delete_all_espresso_cpt_data() |
|
1525 | - { |
|
1526 | - global $wpdb; |
|
1527 | - //get all the CPT post_types |
|
1528 | - $ee_post_types = array(); |
|
1529 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1530 | - if (method_exists($model_name, 'instance')) { |
|
1531 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1532 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
1533 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1534 | - } |
|
1535 | - } |
|
1536 | - } |
|
1537 | - //get all our CPTs |
|
1538 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1539 | - $cpt_ids = $wpdb->get_col($query); |
|
1540 | - //delete each post meta and term relations too |
|
1541 | - foreach ($cpt_ids as $post_id) { |
|
1542 | - wp_delete_post($post_id, true); |
|
1543 | - } |
|
1544 | - } |
|
1545 | - |
|
1546 | - /** |
|
1547 | - * Deletes all EE custom tables |
|
1548 | - * |
|
1549 | - * @return array |
|
1550 | - */ |
|
1551 | - public static function drop_espresso_tables() |
|
1552 | - { |
|
1553 | - $tables = array(); |
|
1554 | - // load registry |
|
1555 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1556 | - if (method_exists($model_name, 'instance')) { |
|
1557 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1558 | - if ($model_obj instanceof EEM_Base) { |
|
1559 | - foreach ($model_obj->get_tables() as $table) { |
|
1560 | - if (strpos($table->get_table_name(), 'esp_') |
|
1561 | - && |
|
1562 | - ( |
|
1563 | - is_main_site()//main site? nuke them all |
|
1564 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
1565 | - ) |
|
1566 | - ) { |
|
1567 | - $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1568 | - } |
|
1569 | - } |
|
1570 | - } |
|
1571 | - } |
|
1572 | - } |
|
1573 | - |
|
1574 | - //there are some tables whose models were removed. |
|
1575 | - //they should be removed when removing all EE core's data |
|
1576 | - $tables_without_models = array( |
|
1577 | - 'esp_promotion', |
|
1578 | - 'esp_promotion_applied', |
|
1579 | - 'esp_promotion_object', |
|
1580 | - 'esp_promotion_rule', |
|
1581 | - 'esp_rule', |
|
1582 | - ); |
|
1583 | - foreach ($tables_without_models as $table) { |
|
1584 | - $tables[$table] = $table; |
|
1585 | - } |
|
1586 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1587 | - } |
|
1588 | - |
|
1589 | - |
|
1590 | - |
|
1591 | - /** |
|
1592 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1593 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
1594 | - * Returns the list actually deleted |
|
1595 | - * |
|
1596 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1597 | - * @global WPDB $wpdb |
|
1598 | - * @param array $table_names |
|
1599 | - * @return array of table names which we deleted |
|
1600 | - */ |
|
1601 | - public static function drop_tables($table_names) |
|
1602 | - { |
|
1603 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1604 | - } |
|
1605 | - |
|
1606 | - |
|
1607 | - |
|
1608 | - /** |
|
1609 | - * plugin_uninstall |
|
1610 | - * |
|
1611 | - * @access public |
|
1612 | - * @static |
|
1613 | - * @param bool $remove_all |
|
1614 | - * @return void |
|
1615 | - */ |
|
1616 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1617 | - { |
|
1618 | - global $wpdb; |
|
1619 | - self::drop_espresso_tables(); |
|
1620 | - $wp_options_to_delete = array( |
|
1621 | - 'ee_no_ticket_prices' => true, |
|
1622 | - 'ee_active_messengers' => true, |
|
1623 | - 'ee_has_activated_messenger' => true, |
|
1624 | - 'ee_flush_rewrite_rules' => true, |
|
1625 | - 'ee_config' => false, |
|
1626 | - 'ee_data_migration_current_db_state' => true, |
|
1627 | - 'ee_data_migration_mapping_' => false, |
|
1628 | - 'ee_data_migration_script_' => false, |
|
1629 | - 'ee_data_migrations' => true, |
|
1630 | - 'ee_dms_map' => false, |
|
1631 | - 'ee_notices' => true, |
|
1632 | - 'lang_file_check_' => false, |
|
1633 | - 'ee_maintenance_mode' => true, |
|
1634 | - 'ee_ueip_optin' => true, |
|
1635 | - 'ee_ueip_has_notified' => true, |
|
1636 | - 'ee_plugin_activation_errors' => true, |
|
1637 | - 'ee_id_mapping_from' => false, |
|
1638 | - 'espresso_persistent_admin_notices' => true, |
|
1639 | - 'ee_encryption_key' => true, |
|
1640 | - 'pue_force_upgrade_' => false, |
|
1641 | - 'pue_json_error_' => false, |
|
1642 | - 'pue_install_key_' => false, |
|
1643 | - 'pue_verification_error_' => false, |
|
1644 | - 'pu_dismissed_upgrade_' => false, |
|
1645 | - 'external_updates-' => false, |
|
1646 | - 'ee_extra_data' => true, |
|
1647 | - 'ee_ssn_' => false, |
|
1648 | - 'ee_rss_' => false, |
|
1649 | - 'ee_rte_n_tx_' => false, |
|
1650 | - 'ee_pers_admin_notices' => true, |
|
1651 | - 'ee_job_parameters_' => false, |
|
1652 | - 'ee_upload_directories_incomplete' => true, |
|
1653 | - 'ee_verified_db_collations' => true, |
|
1654 | - ); |
|
1655 | - if (is_main_site()) { |
|
1656 | - $wp_options_to_delete['ee_network_config'] = true; |
|
1657 | - } |
|
1658 | - $undeleted_options = array(); |
|
1659 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1660 | - if ($no_wildcard) { |
|
1661 | - if ( ! delete_option($option_name)) { |
|
1662 | - $undeleted_options[] = $option_name; |
|
1663 | - } |
|
1664 | - } else { |
|
1665 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1666 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1667 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
1668 | - $undeleted_options[] = $option_name_from_wildcard; |
|
1669 | - } |
|
1670 | - } |
|
1671 | - } |
|
1672 | - } |
|
1673 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1674 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1675 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1676 | - $db_update_sans_ee4 = array(); |
|
1677 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
1678 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
1679 | - $db_update_sans_ee4[$version] = $times_activated; |
|
1680 | - } |
|
1681 | - } |
|
1682 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
1683 | - } |
|
1684 | - $errors = ''; |
|
1685 | - if ( ! empty($undeleted_options)) { |
|
1686 | - $errors .= sprintf( |
|
1687 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1688 | - '<br/>', |
|
1689 | - implode(',<br/>', $undeleted_options) |
|
1690 | - ); |
|
1691 | - } |
|
1692 | - if ( ! empty($errors)) { |
|
1693 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1694 | - } |
|
1695 | - } |
|
1696 | - |
|
1697 | - /** |
|
1698 | - * Gets the mysql error code from the last used query by wpdb |
|
1699 | - * |
|
1700 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1701 | - */ |
|
1702 | - public static function last_wpdb_error_code() |
|
1703 | - { |
|
1704 | - global $wpdb; |
|
1705 | - if ($wpdb->use_mysqli) { |
|
1706 | - return mysqli_errno($wpdb->dbh); |
|
1707 | - } else { |
|
1708 | - return mysql_errno($wpdb->dbh); |
|
1709 | - } |
|
1710 | - } |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1714 | - * |
|
1715 | - * @global wpdb $wpdb |
|
1716 | - * @deprecated instead use TableAnalysis::tableExists() |
|
1717 | - * @param string $table_name with or without $wpdb->prefix |
|
1718 | - * @return boolean |
|
1719 | - */ |
|
1720 | - public static function table_exists($table_name) |
|
1721 | - { |
|
1722 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1723 | - } |
|
1724 | - |
|
1725 | - /** |
|
1726 | - * Resets the cache on EEH_Activation |
|
1727 | - */ |
|
1728 | - public static function reset() |
|
1729 | - { |
|
1730 | - self::$_default_creator_id = null; |
|
1731 | - self::$_initialized_db_content_already_in_this_request = false; |
|
1732 | - } |
|
1302 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1303 | + $message_resource_manager |
|
1304 | + ); |
|
1305 | + /** |
|
1306 | + * This method is verifying there are no NEW default message types |
|
1307 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1308 | + */ |
|
1309 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1310 | + $message_resource_manager |
|
1311 | + ); |
|
1312 | + //after all is done, let's persist these changes to the db. |
|
1313 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
1314 | + $message_resource_manager->update_active_messengers_option(); |
|
1315 | + // will return true if either of these are true. Otherwise will return false. |
|
1316 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1317 | + } |
|
1318 | + |
|
1319 | + |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1323 | + * @return array|bool |
|
1324 | + * @throws \EE_Error |
|
1325 | + */ |
|
1326 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1327 | + EE_Message_Resource_Manager $message_resource_manager |
|
1328 | + ) { |
|
1329 | + /** @type EE_messenger[] $active_messengers */ |
|
1330 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1331 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | + $templates_created = false; |
|
1333 | + foreach ($active_messengers as $active_messenger) { |
|
1334 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1335 | + $default_message_type_names_to_activate = array(); |
|
1336 | + // looping through each default message type reported by the messenger |
|
1337 | + // and setup the actual message types to activate. |
|
1338 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1339 | + // if already active or has already been activated before we skip |
|
1340 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1341 | + // we also skip if the message type is not installed. |
|
1342 | + if ( |
|
1343 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1344 | + $default_message_type_name_for_messenger, |
|
1345 | + $active_messenger->name |
|
1346 | + ) |
|
1347 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
1348 | + $active_messenger->name, |
|
1349 | + $default_message_type_name_for_messenger |
|
1350 | + ) |
|
1351 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1352 | + ) { |
|
1353 | + continue; |
|
1354 | + } |
|
1355 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1356 | + } |
|
1357 | + //let's activate! |
|
1358 | + $message_resource_manager->ensure_message_types_are_active( |
|
1359 | + $default_message_type_names_to_activate, |
|
1360 | + $active_messenger->name, |
|
1361 | + false |
|
1362 | + ); |
|
1363 | + //activate the templates for these message types |
|
1364 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
1365 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1366 | + $active_messenger->name, |
|
1367 | + $default_message_type_names_for_messenger, |
|
1368 | + '', |
|
1369 | + true |
|
1370 | + ); |
|
1371 | + } |
|
1372 | + } |
|
1373 | + return $templates_created; |
|
1374 | + } |
|
1375 | + |
|
1376 | + |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * This will activate and generate default messengers and default message types for those messengers. |
|
1380 | + * |
|
1381 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
1382 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
1383 | + * False means that there were no templates generated |
|
1384 | + * (which could simply mean there are no default message types for a messenger). |
|
1385 | + * @throws EE_Error |
|
1386 | + */ |
|
1387 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1388 | + EE_Message_Resource_Manager $message_resource_manager |
|
1389 | + ) { |
|
1390 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
1391 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1392 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1393 | + $templates_generated = false; |
|
1394 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1395 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1396 | + //verify the default message types match an installed message type. |
|
1397 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1398 | + if ( |
|
1399 | + ! isset($installed_message_types[$name]) |
|
1400 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1401 | + $name, |
|
1402 | + $messenger_to_generate->name |
|
1403 | + ) |
|
1404 | + ) { |
|
1405 | + unset($default_message_type_names_for_messenger[$key]); |
|
1406 | + } |
|
1407 | + } |
|
1408 | + // in previous iterations, the active_messengers option in the db |
|
1409 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1410 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
1411 | + // passing off to create templates (after the refactor is done). |
|
1412 | + // @todo remove this comment when determined not necessary. |
|
1413 | + $message_resource_manager->activate_messenger( |
|
1414 | + $messenger_to_generate->name, |
|
1415 | + $default_message_type_names_for_messenger, |
|
1416 | + false |
|
1417 | + ); |
|
1418 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
1419 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
1420 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1421 | + $messenger_to_generate->name, |
|
1422 | + $default_message_type_names_for_messenger, |
|
1423 | + '', |
|
1424 | + true |
|
1425 | + ); |
|
1426 | + } |
|
1427 | + } |
|
1428 | + return $templates_generated; |
|
1429 | + } |
|
1430 | + |
|
1431 | + |
|
1432 | + /** |
|
1433 | + * This returns the default messengers to generate templates for on activation of EE. |
|
1434 | + * It considers: |
|
1435 | + * - whether a messenger is already active in the db. |
|
1436 | + * - whether a messenger has been made active at any time in the past. |
|
1437 | + * |
|
1438 | + * @static |
|
1439 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
1440 | + * @return EE_messenger[] |
|
1441 | + */ |
|
1442 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
1443 | + EE_Message_Resource_Manager $message_resource_manager |
|
1444 | + ) { |
|
1445 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1446 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1447 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1448 | + |
|
1449 | + $messengers_to_generate = array(); |
|
1450 | + foreach ($installed_messengers as $installed_messenger) { |
|
1451 | + //if installed messenger is a messenger that should be activated on install |
|
1452 | + //and is not already active |
|
1453 | + //and has never been activated |
|
1454 | + if ( |
|
1455 | + ! $installed_messenger->activate_on_install |
|
1456 | + || isset($active_messengers[$installed_messenger->name]) |
|
1457 | + || isset($has_activated[$installed_messenger->name]) |
|
1458 | + ) { |
|
1459 | + continue; |
|
1460 | + } |
|
1461 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1462 | + } |
|
1463 | + return $messengers_to_generate; |
|
1464 | + } |
|
1465 | + |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * This simply validates active message types to ensure they actually match installed |
|
1469 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1470 | + * rows are set inactive. |
|
1471 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1472 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1473 | + * are still handled in here. |
|
1474 | + * |
|
1475 | + * @since 4.3.1 |
|
1476 | + * @return void |
|
1477 | + */ |
|
1478 | + public static function validate_messages_system() |
|
1479 | + { |
|
1480 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1481 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1482 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
1483 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1484 | + } |
|
1485 | + |
|
1486 | + |
|
1487 | + /** |
|
1488 | + * create_no_ticket_prices_array |
|
1489 | + * |
|
1490 | + * @access public |
|
1491 | + * @static |
|
1492 | + * @return void |
|
1493 | + */ |
|
1494 | + public static function create_no_ticket_prices_array() |
|
1495 | + { |
|
1496 | + // this creates an array for tracking events that have no active ticket prices created |
|
1497 | + // this allows us to warn admins of the situation so that it can be corrected |
|
1498 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1499 | + if (! $espresso_no_ticket_prices) { |
|
1500 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
1501 | + } |
|
1502 | + } |
|
1503 | + |
|
1504 | + |
|
1505 | + /** |
|
1506 | + * plugin_deactivation |
|
1507 | + * |
|
1508 | + * @access public |
|
1509 | + * @static |
|
1510 | + * @return void |
|
1511 | + */ |
|
1512 | + public static function plugin_deactivation() |
|
1513 | + { |
|
1514 | + } |
|
1515 | + |
|
1516 | + |
|
1517 | + /** |
|
1518 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1519 | + * (like post meta or term relations) |
|
1520 | + * |
|
1521 | + * @global wpdb $wpdb |
|
1522 | + * @throws \EE_Error |
|
1523 | + */ |
|
1524 | + public static function delete_all_espresso_cpt_data() |
|
1525 | + { |
|
1526 | + global $wpdb; |
|
1527 | + //get all the CPT post_types |
|
1528 | + $ee_post_types = array(); |
|
1529 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1530 | + if (method_exists($model_name, 'instance')) { |
|
1531 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1532 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1533 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1534 | + } |
|
1535 | + } |
|
1536 | + } |
|
1537 | + //get all our CPTs |
|
1538 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1539 | + $cpt_ids = $wpdb->get_col($query); |
|
1540 | + //delete each post meta and term relations too |
|
1541 | + foreach ($cpt_ids as $post_id) { |
|
1542 | + wp_delete_post($post_id, true); |
|
1543 | + } |
|
1544 | + } |
|
1545 | + |
|
1546 | + /** |
|
1547 | + * Deletes all EE custom tables |
|
1548 | + * |
|
1549 | + * @return array |
|
1550 | + */ |
|
1551 | + public static function drop_espresso_tables() |
|
1552 | + { |
|
1553 | + $tables = array(); |
|
1554 | + // load registry |
|
1555 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1556 | + if (method_exists($model_name, 'instance')) { |
|
1557 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1558 | + if ($model_obj instanceof EEM_Base) { |
|
1559 | + foreach ($model_obj->get_tables() as $table) { |
|
1560 | + if (strpos($table->get_table_name(), 'esp_') |
|
1561 | + && |
|
1562 | + ( |
|
1563 | + is_main_site()//main site? nuke them all |
|
1564 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
1565 | + ) |
|
1566 | + ) { |
|
1567 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1568 | + } |
|
1569 | + } |
|
1570 | + } |
|
1571 | + } |
|
1572 | + } |
|
1573 | + |
|
1574 | + //there are some tables whose models were removed. |
|
1575 | + //they should be removed when removing all EE core's data |
|
1576 | + $tables_without_models = array( |
|
1577 | + 'esp_promotion', |
|
1578 | + 'esp_promotion_applied', |
|
1579 | + 'esp_promotion_object', |
|
1580 | + 'esp_promotion_rule', |
|
1581 | + 'esp_rule', |
|
1582 | + ); |
|
1583 | + foreach ($tables_without_models as $table) { |
|
1584 | + $tables[$table] = $table; |
|
1585 | + } |
|
1586 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1587 | + } |
|
1588 | + |
|
1589 | + |
|
1590 | + |
|
1591 | + /** |
|
1592 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1593 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
1594 | + * Returns the list actually deleted |
|
1595 | + * |
|
1596 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1597 | + * @global WPDB $wpdb |
|
1598 | + * @param array $table_names |
|
1599 | + * @return array of table names which we deleted |
|
1600 | + */ |
|
1601 | + public static function drop_tables($table_names) |
|
1602 | + { |
|
1603 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1604 | + } |
|
1605 | + |
|
1606 | + |
|
1607 | + |
|
1608 | + /** |
|
1609 | + * plugin_uninstall |
|
1610 | + * |
|
1611 | + * @access public |
|
1612 | + * @static |
|
1613 | + * @param bool $remove_all |
|
1614 | + * @return void |
|
1615 | + */ |
|
1616 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1617 | + { |
|
1618 | + global $wpdb; |
|
1619 | + self::drop_espresso_tables(); |
|
1620 | + $wp_options_to_delete = array( |
|
1621 | + 'ee_no_ticket_prices' => true, |
|
1622 | + 'ee_active_messengers' => true, |
|
1623 | + 'ee_has_activated_messenger' => true, |
|
1624 | + 'ee_flush_rewrite_rules' => true, |
|
1625 | + 'ee_config' => false, |
|
1626 | + 'ee_data_migration_current_db_state' => true, |
|
1627 | + 'ee_data_migration_mapping_' => false, |
|
1628 | + 'ee_data_migration_script_' => false, |
|
1629 | + 'ee_data_migrations' => true, |
|
1630 | + 'ee_dms_map' => false, |
|
1631 | + 'ee_notices' => true, |
|
1632 | + 'lang_file_check_' => false, |
|
1633 | + 'ee_maintenance_mode' => true, |
|
1634 | + 'ee_ueip_optin' => true, |
|
1635 | + 'ee_ueip_has_notified' => true, |
|
1636 | + 'ee_plugin_activation_errors' => true, |
|
1637 | + 'ee_id_mapping_from' => false, |
|
1638 | + 'espresso_persistent_admin_notices' => true, |
|
1639 | + 'ee_encryption_key' => true, |
|
1640 | + 'pue_force_upgrade_' => false, |
|
1641 | + 'pue_json_error_' => false, |
|
1642 | + 'pue_install_key_' => false, |
|
1643 | + 'pue_verification_error_' => false, |
|
1644 | + 'pu_dismissed_upgrade_' => false, |
|
1645 | + 'external_updates-' => false, |
|
1646 | + 'ee_extra_data' => true, |
|
1647 | + 'ee_ssn_' => false, |
|
1648 | + 'ee_rss_' => false, |
|
1649 | + 'ee_rte_n_tx_' => false, |
|
1650 | + 'ee_pers_admin_notices' => true, |
|
1651 | + 'ee_job_parameters_' => false, |
|
1652 | + 'ee_upload_directories_incomplete' => true, |
|
1653 | + 'ee_verified_db_collations' => true, |
|
1654 | + ); |
|
1655 | + if (is_main_site()) { |
|
1656 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1657 | + } |
|
1658 | + $undeleted_options = array(); |
|
1659 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1660 | + if ($no_wildcard) { |
|
1661 | + if ( ! delete_option($option_name)) { |
|
1662 | + $undeleted_options[] = $option_name; |
|
1663 | + } |
|
1664 | + } else { |
|
1665 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1666 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1667 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
1668 | + $undeleted_options[] = $option_name_from_wildcard; |
|
1669 | + } |
|
1670 | + } |
|
1671 | + } |
|
1672 | + } |
|
1673 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1674 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1675 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1676 | + $db_update_sans_ee4 = array(); |
|
1677 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1678 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
1679 | + $db_update_sans_ee4[$version] = $times_activated; |
|
1680 | + } |
|
1681 | + } |
|
1682 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1683 | + } |
|
1684 | + $errors = ''; |
|
1685 | + if ( ! empty($undeleted_options)) { |
|
1686 | + $errors .= sprintf( |
|
1687 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1688 | + '<br/>', |
|
1689 | + implode(',<br/>', $undeleted_options) |
|
1690 | + ); |
|
1691 | + } |
|
1692 | + if ( ! empty($errors)) { |
|
1693 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1694 | + } |
|
1695 | + } |
|
1696 | + |
|
1697 | + /** |
|
1698 | + * Gets the mysql error code from the last used query by wpdb |
|
1699 | + * |
|
1700 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1701 | + */ |
|
1702 | + public static function last_wpdb_error_code() |
|
1703 | + { |
|
1704 | + global $wpdb; |
|
1705 | + if ($wpdb->use_mysqli) { |
|
1706 | + return mysqli_errno($wpdb->dbh); |
|
1707 | + } else { |
|
1708 | + return mysql_errno($wpdb->dbh); |
|
1709 | + } |
|
1710 | + } |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1714 | + * |
|
1715 | + * @global wpdb $wpdb |
|
1716 | + * @deprecated instead use TableAnalysis::tableExists() |
|
1717 | + * @param string $table_name with or without $wpdb->prefix |
|
1718 | + * @return boolean |
|
1719 | + */ |
|
1720 | + public static function table_exists($table_name) |
|
1721 | + { |
|
1722 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1723 | + } |
|
1724 | + |
|
1725 | + /** |
|
1726 | + * Resets the cache on EEH_Activation |
|
1727 | + */ |
|
1728 | + public static function reset() |
|
1729 | + { |
|
1730 | + self::$_default_creator_id = null; |
|
1731 | + self::$_initialized_db_content_already_in_this_request = false; |
|
1732 | + } |
|
1733 | 1733 | } |
1734 | 1734 | // End of file EEH_Activation.helper.php |
1735 | 1735 | // Location: /helpers/EEH_Activation.core.php |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public static function getTableAnalysis() |
67 | 67 | { |
68 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
68 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
69 | 69 | self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
70 | 70 | } |
71 | 71 | return self::$table_analysis; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public static function getTableManager() |
79 | 79 | { |
80 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
80 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
81 | 81 | self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
82 | 82 | } |
83 | 83 | return self::$table_manager; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | if ($which_to_include === 'old') { |
194 | 194 | $cron_tasks = array_filter( |
195 | 195 | $cron_tasks, |
196 | - function ($value) { |
|
196 | + function($value) { |
|
197 | 197 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
198 | 198 | } |
199 | 199 | ); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | { |
224 | 224 | |
225 | 225 | foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
226 | - if (! wp_next_scheduled($hook_name)) { |
|
226 | + if ( ! wp_next_scheduled($hook_name)) { |
|
227 | 227 | /** |
228 | 228 | * This allows client code to define the initial start timestamp for this schedule. |
229 | 229 | */ |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | 3 |
329 | 329 | ); |
330 | 330 | //EE_Config::reset(); |
331 | - if (! EE_Config::logging_enabled()) { |
|
331 | + if ( ! EE_Config::logging_enabled()) { |
|
332 | 332 | delete_option(EE_Config::LOG_NAME); |
333 | 333 | } |
334 | 334 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | public static function load_calendar_config() |
344 | 344 | { |
345 | 345 | // grab array of all plugin folders and loop thru it |
346 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
346 | + $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR); |
|
347 | 347 | if (empty($plugins)) { |
348 | 348 | return; |
349 | 349 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | || strpos($plugin, 'calendar') !== false |
361 | 361 | ) { |
362 | 362 | // this is what we are looking for |
363 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
363 | + $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php'; |
|
364 | 364 | // does it exist in this folder ? |
365 | 365 | if (is_readable($calendar_config)) { |
366 | 366 | // YEAH! let's load it |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | ) { |
489 | 489 | //update Config with post ID |
490 | 490 | $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
491 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
491 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | 492 | $msg = __( |
493 | 493 | 'The Event Espresso critical page configuration settings could not be updated.', |
494 | 494 | 'event_espresso' |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
512 | 512 | 'event_espresso' |
513 | 513 | ), |
514 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
514 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">' |
|
515 | 515 | . __('Event Espresso Critical Pages Settings', 'event_espresso') |
516 | 516 | . '</a>' |
517 | 517 | ) |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | public static function get_page_by_ee_shortcode($ee_shortcode) |
538 | 538 | { |
539 | 539 | global $wpdb; |
540 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
540 | + $shortcode_and_opening_bracket = '['.$ee_shortcode; |
|
541 | 541 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
542 | 542 | if ($post_id) { |
543 | 543 | return get_post($post_id); |
@@ -563,11 +563,11 @@ discard block |
||
563 | 563 | 'post_status' => 'publish', |
564 | 564 | 'post_type' => 'page', |
565 | 565 | 'comment_status' => 'closed', |
566 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
566 | + 'post_content' => '['.$critical_page['code'].']', |
|
567 | 567 | ); |
568 | 568 | |
569 | 569 | $post_id = wp_insert_post($post_args); |
570 | - if (! $post_id) { |
|
570 | + if ( ! $post_id) { |
|
571 | 571 | $msg = sprintf( |
572 | 572 | __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
573 | 573 | $critical_page['name'] |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | return $critical_page; |
577 | 577 | } |
578 | 578 | // get newly created post's details |
579 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
579 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
580 | 580 | $msg = sprintf( |
581 | 581 | __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
582 | 582 | $critical_page['name'] |
@@ -613,17 +613,17 @@ discard block |
||
613 | 613 | $role_to_check |
614 | 614 | ); |
615 | 615 | if ($pre_filtered_id !== false) { |
616 | - return (int)$pre_filtered_id; |
|
616 | + return (int) $pre_filtered_id; |
|
617 | 617 | } |
618 | 618 | $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
619 | 619 | $query = $wpdb->prepare( |
620 | 620 | "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
621 | - '%' . $role_to_check . '%' |
|
621 | + '%'.$role_to_check.'%' |
|
622 | 622 | ); |
623 | 623 | $user_id = $wpdb->get_var($query); |
624 | 624 | $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
625 | - if ($user_id && (int)$user_id) { |
|
626 | - self::$_default_creator_id = (int)$user_id; |
|
625 | + if ($user_id && (int) $user_id) { |
|
626 | + self::$_default_creator_id = (int) $user_id; |
|
627 | 627 | return self::$_default_creator_id; |
628 | 628 | } else { |
629 | 629 | return null; |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | } |
659 | 659 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
660 | 660 | if ( ! function_exists('dbDelta')) { |
661 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
661 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
662 | 662 | } |
663 | 663 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
664 | 664 | $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
@@ -869,13 +869,13 @@ discard block |
||
869 | 869 | // reset values array |
870 | 870 | $QSG_values = array(); |
871 | 871 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
872 | - if (! in_array("$QSG_system", $question_groups)) { |
|
872 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
873 | 873 | // add it |
874 | 874 | switch ($QSG_system) { |
875 | 875 | case 1: |
876 | 876 | $QSG_values = array( |
877 | 877 | 'QSG_name' => __('Personal Information', 'event_espresso'), |
878 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
878 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
879 | 879 | 'QSG_desc' => '', |
880 | 880 | 'QSG_order' => 1, |
881 | 881 | 'QSG_show_group_name' => 1, |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | case 2: |
888 | 888 | $QSG_values = array( |
889 | 889 | 'QSG_name' => __('Address Information', 'event_espresso'), |
890 | - 'QSG_identifier' => 'address-information-' . time(), |
|
890 | + 'QSG_identifier' => 'address-information-'.time(), |
|
891 | 891 | 'QSG_desc' => '', |
892 | 892 | 'QSG_order' => 2, |
893 | 893 | 'QSG_show_group_name' => 1, |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | break; |
899 | 899 | } |
900 | 900 | // make sure we have some values before inserting them |
901 | - if (! empty($QSG_values)) { |
|
901 | + if ( ! empty($QSG_values)) { |
|
902 | 902 | // insert system question |
903 | 903 | $wpdb->insert( |
904 | 904 | $table_name, |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | // reset values array |
936 | 936 | $QST_values = array(); |
937 | 937 | // if we don't have what we should have |
938 | - if (! in_array($QST_system, $questions)) { |
|
938 | + if ( ! in_array($QST_system, $questions)) { |
|
939 | 939 | // add it |
940 | 940 | switch ($QST_system) { |
941 | 941 | case 'fname': |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | ); |
1088 | 1088 | break; |
1089 | 1089 | } |
1090 | - if (! empty($QST_values)) { |
|
1090 | + if ( ! empty($QST_values)) { |
|
1091 | 1091 | // insert system question |
1092 | 1092 | $wpdb->insert( |
1093 | 1093 | $table_name, |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | */ |
1149 | 1149 | public static function insert_default_payment_methods() |
1150 | 1150 | { |
1151 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1151 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | 1152 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
1153 | 1153 | EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
1154 | 1154 | } else { |
@@ -1236,9 +1236,9 @@ discard block |
||
1236 | 1236 | $folders = array( |
1237 | 1237 | EVENT_ESPRESSO_TEMPLATE_DIR, |
1238 | 1238 | EVENT_ESPRESSO_GATEWAY_DIR, |
1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1239 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/', |
|
1240 | + EVENT_ESPRESSO_UPLOAD_DIR.'css/', |
|
1241 | + EVENT_ESPRESSO_UPLOAD_DIR.'tickets/', |
|
1242 | 1242 | ); |
1243 | 1243 | foreach ($folders as $folder) { |
1244 | 1244 | try { |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | sprintf( |
1250 | 1250 | __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
1251 | 1251 | $folder, |
1252 | - '<br />' . $e->getMessage() |
|
1252 | + '<br />'.$e->getMessage() |
|
1253 | 1253 | ), |
1254 | 1254 | __FILE__, __FUNCTION__, __LINE__ |
1255 | 1255 | ); |
@@ -1260,7 +1260,7 @@ discard block |
||
1260 | 1260 | } |
1261 | 1261 | //just add the .htaccess file to the logs directory to begin with. Even if logging |
1262 | 1262 | //is disabled, there might be activation errors recorded in there |
1263 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1263 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/'); |
|
1264 | 1264 | //remember EE's folders are all good |
1265 | 1265 | delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
1266 | 1266 | return true; |
@@ -1496,7 +1496,7 @@ discard block |
||
1496 | 1496 | // this creates an array for tracking events that have no active ticket prices created |
1497 | 1497 | // this allows us to warn admins of the situation so that it can be corrected |
1498 | 1498 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
1499 | - if (! $espresso_no_ticket_prices) { |
|
1499 | + if ( ! $espresso_no_ticket_prices) { |
|
1500 | 1500 | add_option('ee_no_ticket_prices', array(), '', false); |
1501 | 1501 | } |
1502 | 1502 | } |
@@ -1535,7 +1535,7 @@ discard block |
||
1535 | 1535 | } |
1536 | 1536 | } |
1537 | 1537 | //get all our CPTs |
1538 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1538 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
1539 | 1539 | $cpt_ids = $wpdb->get_col($query); |
1540 | 1540 | //delete each post meta and term relations too |
1541 | 1541 | foreach ($cpt_ids as $post_id) { |
@@ -1675,7 +1675,7 @@ discard block |
||
1675 | 1675 | if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
1676 | 1676 | $db_update_sans_ee4 = array(); |
1677 | 1677 | foreach ($espresso_db_update as $version => $times_activated) { |
1678 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
1678 | + if ((string) $version[0] === '3') {//if its NON EE4 |
|
1679 | 1679 | $db_update_sans_ee4[$version] = $times_activated; |
1680 | 1680 | } |
1681 | 1681 | } |
@@ -22,744 +22,744 @@ |
||
22 | 22 | |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @return EED_Module|EED_Add_New_State |
|
27 | - */ |
|
28 | - public static function instance() |
|
29 | - { |
|
30 | - return parent::get_instance(__CLASS__); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
37 | - * |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public static function set_hooks() |
|
41 | - { |
|
42 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
43 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
44 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
46 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
48 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
49 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
50 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
51 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
52 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
53 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
54 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
55 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
56 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
57 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
58 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
65 | - * |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public static function set_hooks_admin() |
|
69 | - { |
|
70 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
71 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
72 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
73 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
74 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
75 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
76 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
77 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
78 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
79 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
80 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
81 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
82 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
83 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
84 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
85 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
86 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
87 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
88 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
89 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
90 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
91 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
92 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public static function set_definitions() |
|
101 | - { |
|
102 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
103 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
104 | - '\\', |
|
105 | - DS, |
|
106 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
107 | - ); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @param WP $WP |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - public function run($WP) |
|
117 | - { |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public static function translate_js_strings() |
|
126 | - { |
|
127 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
128 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
129 | - 'event_espresso' |
|
130 | - ); |
|
131 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
132 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
133 | - 'event_espresso' |
|
134 | - ); |
|
135 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
136 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
137 | - 'event_espresso' |
|
138 | - ); |
|
139 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
140 | - 'The new state was successfully saved to the database.', |
|
141 | - 'event_espresso' |
|
142 | - ); |
|
143 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
144 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
145 | - 'event_espresso' |
|
146 | - ); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - public static function wp_enqueue_scripts() |
|
155 | - { |
|
156 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
157 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
158 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
159 | - wp_enqueue_script('add_new_state'); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * display_add_new_state_micro_form |
|
167 | - * |
|
168 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
169 | - * @return string |
|
170 | - * @throws EE_Error |
|
171 | - * @throws InvalidArgumentException |
|
172 | - * @throws InvalidDataTypeException |
|
173 | - * @throws InvalidInterfaceException |
|
174 | - */ |
|
175 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
176 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
177 | - { |
|
178 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
179 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
180 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
181 | - // is the "state" question in this form section? |
|
182 | - $input = $question_group_reg_form->get_subsection('state'); |
|
183 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
184 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
185 | - //by forcing it to set it now, like it did while getting the form for display |
|
186 | - if ($input instanceof EE_State_Select_Input) { |
|
187 | - $input->html_name(); |
|
188 | - } |
|
189 | - return $question_group_reg_form; |
|
190 | - } |
|
191 | - // we're only doing this for state select inputs |
|
192 | - if ($input instanceof EE_State_Select_Input) { |
|
193 | - // grab any set values from the request |
|
194 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
195 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
196 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
197 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
198 | - $country_options = array(); |
|
199 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
200 | - if (! empty($countries)) { |
|
201 | - foreach ($countries as $country) { |
|
202 | - if ($country instanceof EE_Country) { |
|
203 | - $country_options[$country->ID()] = $country->name(); |
|
204 | - } |
|
205 | - } |
|
206 | - } |
|
207 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
208 | - array( |
|
209 | - 'name' => 'new_state_micro_form', |
|
210 | - 'html_id' => 'new_state_micro_form', |
|
211 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
212 | - 'subsections' => array( |
|
213 | - // add hidden input to indicate that a new state is being added |
|
214 | - 'add_new_state' => new EE_Hidden_Input( |
|
215 | - array( |
|
216 | - 'html_name' => str_replace( |
|
217 | - 'state', |
|
218 | - 'nsmf_add_new_state', |
|
219 | - $input->html_name() |
|
220 | - ), |
|
221 | - 'html_id' => str_replace( |
|
222 | - 'state', |
|
223 | - 'nsmf_add_new_state', |
|
224 | - $input->html_id() |
|
225 | - ), |
|
226 | - 'default' => 0, |
|
227 | - ) |
|
228 | - ), |
|
229 | - // add link for displaying hidden container |
|
230 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
231 | - apply_filters( |
|
232 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
233 | - EEH_HTML::link( |
|
234 | - '', |
|
235 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
236 | - '', |
|
237 | - 'display-' . $input->html_id(), |
|
238 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
239 | - '', |
|
240 | - 'data-target="' . $input->html_id() . '"' |
|
241 | - ) |
|
242 | - ) |
|
243 | - ), |
|
244 | - // add initial html for hidden container |
|
245 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
246 | - apply_filters( |
|
247 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
248 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
249 | - 'display: none;') . |
|
250 | - EEH_HTML::h6( |
|
251 | - esc_html__( |
|
252 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
253 | - 'event_espresso' |
|
254 | - ) |
|
255 | - ) . |
|
256 | - EEH_HTML::ul() . |
|
257 | - EEH_HTML::li( |
|
258 | - esc_html__( |
|
259 | - 'first select the Country that your State/Province belongs to', |
|
260 | - 'event_espresso' |
|
261 | - ) |
|
262 | - ) . |
|
263 | - EEH_HTML::li( |
|
264 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
265 | - ) . |
|
266 | - EEH_HTML::li( |
|
267 | - esc_html__( |
|
268 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
269 | - 'event_espresso' |
|
270 | - ) |
|
271 | - ) . |
|
272 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
273 | - EEH_HTML::ulx() |
|
274 | - ) |
|
275 | - ), |
|
276 | - // NEW STATE COUNTRY |
|
277 | - 'new_state_country' => new EE_Country_Select_Input( |
|
278 | - $country_options, |
|
279 | - array( |
|
280 | - 'html_name' => $country_name, |
|
281 | - 'html_id' => str_replace( |
|
282 | - 'state', |
|
283 | - 'nsmf_new_state_country', $input->html_id() |
|
284 | - ), |
|
285 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
286 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
287 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
288 | - 'required' => false, |
|
289 | - ) |
|
290 | - ), |
|
291 | - // NEW STATE NAME |
|
292 | - 'new_state_name' => new EE_Text_Input( |
|
293 | - array( |
|
294 | - 'html_name' => $state_name, |
|
295 | - 'html_id' => str_replace( |
|
296 | - 'state', |
|
297 | - 'nsmf_new_state_name', $input->html_id() |
|
298 | - ), |
|
299 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
300 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
301 | - 'event_espresso'), |
|
302 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
303 | - 'required' => false, |
|
304 | - ) |
|
305 | - ), |
|
306 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
307 | - // NEW STATE NAME |
|
308 | - 'new_state_abbrv' => new EE_Text_Input( |
|
309 | - array( |
|
310 | - 'html_name' => $abbrv_name, |
|
311 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
312 | - $input->html_id()), |
|
313 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
314 | - 'html_label_text' => esc_html__( |
|
315 | - 'New State/Province Abbreviation', |
|
316 | - 'event_espresso' |
|
317 | - ) . ' *', |
|
318 | - 'html_other_attributes' => 'size="24"', |
|
319 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
320 | - 'required' => false, |
|
321 | - ) |
|
322 | - ), |
|
323 | - // "submit" button |
|
324 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
325 | - apply_filters( |
|
326 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
327 | - EEH_HTML::nbsp(3) . |
|
328 | - EEH_HTML::link( |
|
329 | - '', |
|
330 | - esc_html__('ADD', 'event_espresso'), |
|
331 | - '', |
|
332 | - 'submit-' . $new_state_submit_id, |
|
333 | - 'ee-form-add-new-state-submit button button-secondary', |
|
334 | - '', |
|
335 | - 'data-target="' . $new_state_submit_id . '"' |
|
336 | - ) |
|
337 | - ) |
|
338 | - ), |
|
339 | - // extra info |
|
340 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
341 | - apply_filters( |
|
342 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
343 | - EEH_HTML::br(2) |
|
344 | - . |
|
345 | - EEH_HTML::div('', '', 'small-text') |
|
346 | - . |
|
347 | - EEH_HTML::strong( |
|
348 | - '* ' . |
|
349 | - esc_html__( |
|
350 | - 'Don\'t know your State/Province Abbreviation?', |
|
351 | - 'event_espresso' |
|
352 | - ) |
|
353 | - ) |
|
354 | - . |
|
355 | - EEH_HTML::br() |
|
356 | - . |
|
357 | - sprintf( |
|
358 | - esc_html__( |
|
359 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
360 | - 'event_espresso' |
|
361 | - ), |
|
362 | - EEH_HTML::link( |
|
363 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
364 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
365 | - '', |
|
366 | - '', |
|
367 | - 'ee-form-add-new-state-wiki-lnk', |
|
368 | - '', |
|
369 | - 'target="_blank"' |
|
370 | - ) |
|
371 | - ) |
|
372 | - . |
|
373 | - EEH_HTML::divx() |
|
374 | - . |
|
375 | - EEH_HTML::br() |
|
376 | - . |
|
377 | - EEH_HTML::link( |
|
378 | - '', |
|
379 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
380 | - '', |
|
381 | - 'hide-' . $input->html_id(), |
|
382 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
383 | - '', |
|
384 | - 'data-target="' . $input->html_id() . '"' |
|
385 | - ) |
|
386 | - . |
|
387 | - EEH_HTML::divx() |
|
388 | - . |
|
389 | - EEH_HTML::br() |
|
390 | - ) |
|
391 | - ), |
|
392 | - ), |
|
393 | - ) |
|
394 | - ); |
|
395 | - $question_group_reg_form->add_subsections( |
|
396 | - array('new_state_micro_form' => $new_state_micro_form), |
|
397 | - 'state', |
|
398 | - false |
|
399 | - ); |
|
400 | - } |
|
401 | - return $question_group_reg_form; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * set_new_state_input_width |
|
408 | - * |
|
409 | - * @return int|string |
|
410 | - * @throws EE_Error |
|
411 | - * @throws InvalidArgumentException |
|
412 | - * @throws InvalidDataTypeException |
|
413 | - * @throws InvalidInterfaceException |
|
414 | - * @throws ReflectionException |
|
415 | - */ |
|
416 | - public static function add_new_state() |
|
417 | - { |
|
418 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
419 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
420 | - EE_Registry::instance()->load_model('State'); |
|
421 | - // grab country ISO code, new state name, and new state abbreviation |
|
422 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
423 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
424 | - : false; |
|
425 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
426 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
427 | - : false; |
|
428 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
429 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
430 | - : false; |
|
431 | - if ($state_country && $state_name && $state_abbr) { |
|
432 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
433 | - 'CNT_ISO' => strtoupper($state_country), |
|
434 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
435 | - 'STA_name' => ucwords($state_name), |
|
436 | - 'STA_active' => false, |
|
437 | - )); |
|
438 | - if ($new_state instanceof EE_State) { |
|
439 | - // clean house |
|
440 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
441 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
442 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
443 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
444 | - // get any existing new states |
|
445 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
446 | - 'nsmf_new_states' |
|
447 | - ); |
|
448 | - $new_states[$new_state->ID()] = $new_state; |
|
449 | - EE_Registry::instance()->SSN->set_session_data( |
|
450 | - array('nsmf_new_states' => $new_states) |
|
451 | - ); |
|
452 | - if (EE_Registry::instance()->REQ->ajax) { |
|
453 | - echo wp_json_encode(array( |
|
454 | - 'success' => true, |
|
455 | - 'id' => $new_state->ID(), |
|
456 | - 'name' => $new_state->name(), |
|
457 | - 'abbrev' => $new_state->abbrev(), |
|
458 | - 'country_iso' => $new_state->country_iso(), |
|
459 | - 'country_name' => $new_state->country()->name(), |
|
460 | - )); |
|
461 | - exit(); |
|
462 | - } |
|
463 | - return $new_state->ID(); |
|
464 | - } |
|
465 | - } else { |
|
466 | - $error = esc_html__( |
|
467 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
468 | - 'event_espresso' |
|
469 | - ); |
|
470 | - if (EE_Registry::instance()->REQ->ajax) { |
|
471 | - echo wp_json_encode(array('error' => $error)); |
|
472 | - exit(); |
|
473 | - } |
|
474 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
475 | - } |
|
476 | - } |
|
477 | - return false; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * recursively drills down through request params to remove any that were added by this module |
|
484 | - * |
|
485 | - * @param array $request_params |
|
486 | - * @return array |
|
487 | - */ |
|
488 | - public static function filter_checkout_request_params($request_params) |
|
489 | - { |
|
490 | - foreach ($request_params as $form_section) { |
|
491 | - if (is_array($form_section)) { |
|
492 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
493 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
494 | - } |
|
495 | - } |
|
496 | - return $request_params; |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * @param array $request_params |
|
503 | - * @return array |
|
504 | - */ |
|
505 | - public static function unset_new_state_request_params($request_params) |
|
506 | - { |
|
507 | - unset( |
|
508 | - $request_params['new_state_micro_form'], |
|
509 | - $request_params['new_state_micro_add_new_state'], |
|
510 | - $request_params['new_state_micro_new_state_country'], |
|
511 | - $request_params['new_state_micro_new_state_name'], |
|
512 | - $request_params['new_state_micro_new_state_abbrv'] |
|
513 | - ); |
|
514 | - return $request_params; |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * @param array $props_n_values |
|
521 | - * @return bool |
|
522 | - * @throws EE_Error |
|
523 | - * @throws InvalidArgumentException |
|
524 | - * @throws InvalidDataTypeException |
|
525 | - * @throws InvalidInterfaceException |
|
526 | - */ |
|
527 | - public static function save_new_state_to_db($props_n_values = array()) |
|
528 | - { |
|
529 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
530 | - if (! empty($existing_state)) { |
|
531 | - return array_pop($existing_state); |
|
532 | - } |
|
533 | - $new_state = EE_State::new_instance($props_n_values); |
|
534 | - if ($new_state instanceof EE_State) { |
|
535 | - $country_settings_url = add_query_arg( |
|
536 | - array( |
|
537 | - 'page' => 'espresso_general_settings', |
|
538 | - 'action' => 'country_settings', |
|
539 | - 'country' => $new_state->country_iso(), |
|
540 | - ), |
|
541 | - admin_url('admin.php') |
|
542 | - ); |
|
543 | - // if not non-ajax admin |
|
544 | - new PersistentAdminNotice( |
|
545 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
546 | - sprintf( |
|
547 | - esc_html__( |
|
548 | - '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.', |
|
549 | - 'event_espresso' |
|
550 | - ), |
|
551 | - '<b>' . $new_state->name() . '</b>', |
|
552 | - '<b>' . $new_state->abbrev() . '</b>', |
|
553 | - '<b>' . $new_state->country()->name() . '</b>', |
|
554 | - '<a href="' |
|
555 | - . $country_settings_url |
|
556 | - . '">' |
|
557 | - . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
558 | - 'event_espresso') |
|
559 | - . '</a>', |
|
560 | - '<br />' |
|
561 | - ) |
|
562 | - ); |
|
563 | - $new_state->save(); |
|
564 | - EEM_State::instance()->reset_cached_states(); |
|
565 | - return $new_state; |
|
566 | - } |
|
567 | - return false; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * @param string $CNT_ISO |
|
574 | - * @param string $STA_ID |
|
575 | - * @param array $cols_n_values |
|
576 | - * @return void |
|
577 | - * @throws DomainException |
|
578 | - * @throws EE_Error |
|
579 | - * @throws InvalidArgumentException |
|
580 | - * @throws InvalidDataTypeException |
|
581 | - * @throws InvalidInterfaceException |
|
582 | - */ |
|
583 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
584 | - { |
|
585 | - if (! $CNT_ISO) { |
|
586 | - EE_Error::add_error( |
|
587 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
588 | - __FILE__, |
|
589 | - __FUNCTION__, |
|
590 | - __LINE__ |
|
591 | - ); |
|
592 | - } |
|
593 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
594 | - : false; |
|
595 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
596 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
597 | - if ($state instanceof EE_State) { |
|
598 | - $STA_abbrev = $state->abbrev(); |
|
599 | - } |
|
600 | - } |
|
601 | - if (! $STA_abbrev) { |
|
602 | - EE_Error::add_error( |
|
603 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
604 | - __FILE__, |
|
605 | - __FUNCTION__, |
|
606 | - __LINE__ |
|
607 | - ); |
|
608 | - } |
|
609 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
610 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
611 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
612 | - ); |
|
613 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * @param EE_State[] $state_options |
|
620 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
621 | - * @param EE_Registration $registration |
|
622 | - * @param EE_Question $question |
|
623 | - * @param $answer |
|
624 | - * @return array |
|
625 | - * @throws EE_Error |
|
626 | - * @throws InvalidArgumentException |
|
627 | - * @throws InvalidDataTypeException |
|
628 | - * @throws InvalidInterfaceException |
|
629 | - */ |
|
630 | - public static function inject_new_reg_state_into_options( |
|
631 | - $state_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() === EEM_Question::QST_type_state |
|
639 | - ) { |
|
640 | - $STA_ID = $answer->value(); |
|
641 | - if (! empty($STA_ID)) { |
|
642 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
643 | - if ($state instanceof EE_State) { |
|
644 | - $country = $state->country(); |
|
645 | - if ($country instanceof EE_Country) { |
|
646 | - if (! isset($state_options[$country->name()])) { |
|
647 | - $state_options[$country->name()] = array(); |
|
648 | - } |
|
649 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
650 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
651 | - } |
|
652 | - } |
|
653 | - } |
|
654 | - } |
|
655 | - } |
|
656 | - return $state_options; |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * @param EE_Country[] $country_options |
|
663 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
664 | - * @param EE_Registration $registration |
|
665 | - * @param EE_Question $question |
|
666 | - * @param $answer |
|
667 | - * @return array |
|
668 | - * @throws EE_Error |
|
669 | - * @throws InvalidArgumentException |
|
670 | - * @throws InvalidDataTypeException |
|
671 | - * @throws InvalidInterfaceException |
|
672 | - */ |
|
673 | - public static function inject_new_reg_country_into_options( |
|
674 | - $country_options = array(), |
|
675 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
676 | - EE_Registration $registration, |
|
677 | - EE_Question $question, |
|
678 | - $answer |
|
679 | - ) { |
|
680 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
681 | - && $question->type() |
|
682 | - === EEM_Question::QST_type_country |
|
683 | - ) { |
|
684 | - $CNT_ISO = $answer->value(); |
|
685 | - if (! empty($CNT_ISO)) { |
|
686 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
687 | - if ($country instanceof EE_Country) { |
|
688 | - if (! isset($country_options[$CNT_ISO])) { |
|
689 | - $country_options[$CNT_ISO] = $country->name(); |
|
690 | - } |
|
691 | - } |
|
692 | - } |
|
693 | - } |
|
694 | - return $country_options; |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * @param EE_State[] $state_options |
|
701 | - * @return array |
|
702 | - * @throws EE_Error |
|
703 | - * @throws InvalidArgumentException |
|
704 | - * @throws InvalidDataTypeException |
|
705 | - * @throws InvalidInterfaceException |
|
706 | - */ |
|
707 | - public static function state_options($state_options = array()) |
|
708 | - { |
|
709 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
710 | - foreach ($new_states as $new_state) { |
|
711 | - if ( |
|
712 | - $new_state instanceof EE_State |
|
713 | - && $new_state->country() instanceof EE_Country |
|
714 | - ) { |
|
715 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
716 | - } |
|
717 | - } |
|
718 | - return $state_options; |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * @return array |
|
725 | - * @throws InvalidArgumentException |
|
726 | - * @throws InvalidDataTypeException |
|
727 | - * @throws InvalidInterfaceException |
|
728 | - */ |
|
729 | - protected static function _get_new_states() |
|
730 | - { |
|
731 | - $new_states = array(); |
|
732 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
733 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
734 | - 'nsmf_new_states' |
|
735 | - ); |
|
736 | - } |
|
737 | - return is_array($new_states) ? $new_states : array(); |
|
738 | - } |
|
739 | - |
|
740 | - |
|
741 | - |
|
742 | - /** |
|
743 | - * @param EE_Country[] $country_options |
|
744 | - * @return array |
|
745 | - * @throws EE_Error |
|
746 | - * @throws InvalidArgumentException |
|
747 | - * @throws InvalidDataTypeException |
|
748 | - * @throws InvalidInterfaceException |
|
749 | - */ |
|
750 | - public static function country_options($country_options = array()) |
|
751 | - { |
|
752 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
753 | - foreach ($new_states as $new_state) { |
|
754 | - if ( |
|
755 | - $new_state instanceof EE_State |
|
756 | - && $new_state->country() instanceof EE_Country |
|
757 | - ) { |
|
758 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
759 | - } |
|
760 | - } |
|
761 | - return $country_options; |
|
762 | - } |
|
25 | + /** |
|
26 | + * @return EED_Module|EED_Add_New_State |
|
27 | + */ |
|
28 | + public static function instance() |
|
29 | + { |
|
30 | + return parent::get_instance(__CLASS__); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
37 | + * |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public static function set_hooks() |
|
41 | + { |
|
42 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
43 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
44 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
46 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
48 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
49 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
50 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
51 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
52 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
53 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
54 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
55 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
56 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
57 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
58 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
65 | + * |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public static function set_hooks_admin() |
|
69 | + { |
|
70 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
71 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
72 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
73 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
74 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
75 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
76 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
77 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
78 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
79 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
80 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
81 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
82 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
83 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
84 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
85 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
86 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
87 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
88 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
89 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
90 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
91 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
92 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public static function set_definitions() |
|
101 | + { |
|
102 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
103 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
104 | + '\\', |
|
105 | + DS, |
|
106 | + plugin_dir_path(__FILE__)) . 'templates' . DS |
|
107 | + ); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @param WP $WP |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + public function run($WP) |
|
117 | + { |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public static function translate_js_strings() |
|
126 | + { |
|
127 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
128 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
129 | + 'event_espresso' |
|
130 | + ); |
|
131 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
132 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
133 | + 'event_espresso' |
|
134 | + ); |
|
135 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
136 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
137 | + 'event_espresso' |
|
138 | + ); |
|
139 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
140 | + 'The new state was successfully saved to the database.', |
|
141 | + 'event_espresso' |
|
142 | + ); |
|
143 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
144 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
145 | + 'event_espresso' |
|
146 | + ); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + public static function wp_enqueue_scripts() |
|
155 | + { |
|
156 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
157 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
158 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
159 | + wp_enqueue_script('add_new_state'); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * display_add_new_state_micro_form |
|
167 | + * |
|
168 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
169 | + * @return string |
|
170 | + * @throws EE_Error |
|
171 | + * @throws InvalidArgumentException |
|
172 | + * @throws InvalidDataTypeException |
|
173 | + * @throws InvalidInterfaceException |
|
174 | + */ |
|
175 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
176 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
177 | + { |
|
178 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
179 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
180 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
181 | + // is the "state" question in this form section? |
|
182 | + $input = $question_group_reg_form->get_subsection('state'); |
|
183 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
184 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
185 | + //by forcing it to set it now, like it did while getting the form for display |
|
186 | + if ($input instanceof EE_State_Select_Input) { |
|
187 | + $input->html_name(); |
|
188 | + } |
|
189 | + return $question_group_reg_form; |
|
190 | + } |
|
191 | + // we're only doing this for state select inputs |
|
192 | + if ($input instanceof EE_State_Select_Input) { |
|
193 | + // grab any set values from the request |
|
194 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
195 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
196 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
197 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
198 | + $country_options = array(); |
|
199 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
200 | + if (! empty($countries)) { |
|
201 | + foreach ($countries as $country) { |
|
202 | + if ($country instanceof EE_Country) { |
|
203 | + $country_options[$country->ID()] = $country->name(); |
|
204 | + } |
|
205 | + } |
|
206 | + } |
|
207 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
208 | + array( |
|
209 | + 'name' => 'new_state_micro_form', |
|
210 | + 'html_id' => 'new_state_micro_form', |
|
211 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
212 | + 'subsections' => array( |
|
213 | + // add hidden input to indicate that a new state is being added |
|
214 | + 'add_new_state' => new EE_Hidden_Input( |
|
215 | + array( |
|
216 | + 'html_name' => str_replace( |
|
217 | + 'state', |
|
218 | + 'nsmf_add_new_state', |
|
219 | + $input->html_name() |
|
220 | + ), |
|
221 | + 'html_id' => str_replace( |
|
222 | + 'state', |
|
223 | + 'nsmf_add_new_state', |
|
224 | + $input->html_id() |
|
225 | + ), |
|
226 | + 'default' => 0, |
|
227 | + ) |
|
228 | + ), |
|
229 | + // add link for displaying hidden container |
|
230 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
231 | + apply_filters( |
|
232 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
233 | + EEH_HTML::link( |
|
234 | + '', |
|
235 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
236 | + '', |
|
237 | + 'display-' . $input->html_id(), |
|
238 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
239 | + '', |
|
240 | + 'data-target="' . $input->html_id() . '"' |
|
241 | + ) |
|
242 | + ) |
|
243 | + ), |
|
244 | + // add initial html for hidden container |
|
245 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
246 | + apply_filters( |
|
247 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
248 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
249 | + 'display: none;') . |
|
250 | + EEH_HTML::h6( |
|
251 | + esc_html__( |
|
252 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
253 | + 'event_espresso' |
|
254 | + ) |
|
255 | + ) . |
|
256 | + EEH_HTML::ul() . |
|
257 | + EEH_HTML::li( |
|
258 | + esc_html__( |
|
259 | + 'first select the Country that your State/Province belongs to', |
|
260 | + 'event_espresso' |
|
261 | + ) |
|
262 | + ) . |
|
263 | + EEH_HTML::li( |
|
264 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
265 | + ) . |
|
266 | + EEH_HTML::li( |
|
267 | + esc_html__( |
|
268 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
269 | + 'event_espresso' |
|
270 | + ) |
|
271 | + ) . |
|
272 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
273 | + EEH_HTML::ulx() |
|
274 | + ) |
|
275 | + ), |
|
276 | + // NEW STATE COUNTRY |
|
277 | + 'new_state_country' => new EE_Country_Select_Input( |
|
278 | + $country_options, |
|
279 | + array( |
|
280 | + 'html_name' => $country_name, |
|
281 | + 'html_id' => str_replace( |
|
282 | + 'state', |
|
283 | + 'nsmf_new_state_country', $input->html_id() |
|
284 | + ), |
|
285 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
286 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
287 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
288 | + 'required' => false, |
|
289 | + ) |
|
290 | + ), |
|
291 | + // NEW STATE NAME |
|
292 | + 'new_state_name' => new EE_Text_Input( |
|
293 | + array( |
|
294 | + 'html_name' => $state_name, |
|
295 | + 'html_id' => str_replace( |
|
296 | + 'state', |
|
297 | + 'nsmf_new_state_name', $input->html_id() |
|
298 | + ), |
|
299 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
300 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
301 | + 'event_espresso'), |
|
302 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
303 | + 'required' => false, |
|
304 | + ) |
|
305 | + ), |
|
306 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
307 | + // NEW STATE NAME |
|
308 | + 'new_state_abbrv' => new EE_Text_Input( |
|
309 | + array( |
|
310 | + 'html_name' => $abbrv_name, |
|
311 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
312 | + $input->html_id()), |
|
313 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
314 | + 'html_label_text' => esc_html__( |
|
315 | + 'New State/Province Abbreviation', |
|
316 | + 'event_espresso' |
|
317 | + ) . ' *', |
|
318 | + 'html_other_attributes' => 'size="24"', |
|
319 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
320 | + 'required' => false, |
|
321 | + ) |
|
322 | + ), |
|
323 | + // "submit" button |
|
324 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
325 | + apply_filters( |
|
326 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
327 | + EEH_HTML::nbsp(3) . |
|
328 | + EEH_HTML::link( |
|
329 | + '', |
|
330 | + esc_html__('ADD', 'event_espresso'), |
|
331 | + '', |
|
332 | + 'submit-' . $new_state_submit_id, |
|
333 | + 'ee-form-add-new-state-submit button button-secondary', |
|
334 | + '', |
|
335 | + 'data-target="' . $new_state_submit_id . '"' |
|
336 | + ) |
|
337 | + ) |
|
338 | + ), |
|
339 | + // extra info |
|
340 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
341 | + apply_filters( |
|
342 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
343 | + EEH_HTML::br(2) |
|
344 | + . |
|
345 | + EEH_HTML::div('', '', 'small-text') |
|
346 | + . |
|
347 | + EEH_HTML::strong( |
|
348 | + '* ' . |
|
349 | + esc_html__( |
|
350 | + 'Don\'t know your State/Province Abbreviation?', |
|
351 | + 'event_espresso' |
|
352 | + ) |
|
353 | + ) |
|
354 | + . |
|
355 | + EEH_HTML::br() |
|
356 | + . |
|
357 | + sprintf( |
|
358 | + esc_html__( |
|
359 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
360 | + 'event_espresso' |
|
361 | + ), |
|
362 | + EEH_HTML::link( |
|
363 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
364 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
365 | + '', |
|
366 | + '', |
|
367 | + 'ee-form-add-new-state-wiki-lnk', |
|
368 | + '', |
|
369 | + 'target="_blank"' |
|
370 | + ) |
|
371 | + ) |
|
372 | + . |
|
373 | + EEH_HTML::divx() |
|
374 | + . |
|
375 | + EEH_HTML::br() |
|
376 | + . |
|
377 | + EEH_HTML::link( |
|
378 | + '', |
|
379 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
380 | + '', |
|
381 | + 'hide-' . $input->html_id(), |
|
382 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
383 | + '', |
|
384 | + 'data-target="' . $input->html_id() . '"' |
|
385 | + ) |
|
386 | + . |
|
387 | + EEH_HTML::divx() |
|
388 | + . |
|
389 | + EEH_HTML::br() |
|
390 | + ) |
|
391 | + ), |
|
392 | + ), |
|
393 | + ) |
|
394 | + ); |
|
395 | + $question_group_reg_form->add_subsections( |
|
396 | + array('new_state_micro_form' => $new_state_micro_form), |
|
397 | + 'state', |
|
398 | + false |
|
399 | + ); |
|
400 | + } |
|
401 | + return $question_group_reg_form; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * set_new_state_input_width |
|
408 | + * |
|
409 | + * @return int|string |
|
410 | + * @throws EE_Error |
|
411 | + * @throws InvalidArgumentException |
|
412 | + * @throws InvalidDataTypeException |
|
413 | + * @throws InvalidInterfaceException |
|
414 | + * @throws ReflectionException |
|
415 | + */ |
|
416 | + public static function add_new_state() |
|
417 | + { |
|
418 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
419 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
420 | + EE_Registry::instance()->load_model('State'); |
|
421 | + // grab country ISO code, new state name, and new state abbreviation |
|
422 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
423 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
424 | + : false; |
|
425 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
426 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
427 | + : false; |
|
428 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
429 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
430 | + : false; |
|
431 | + if ($state_country && $state_name && $state_abbr) { |
|
432 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
433 | + 'CNT_ISO' => strtoupper($state_country), |
|
434 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
435 | + 'STA_name' => ucwords($state_name), |
|
436 | + 'STA_active' => false, |
|
437 | + )); |
|
438 | + if ($new_state instanceof EE_State) { |
|
439 | + // clean house |
|
440 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
441 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
442 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
443 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
444 | + // get any existing new states |
|
445 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
446 | + 'nsmf_new_states' |
|
447 | + ); |
|
448 | + $new_states[$new_state->ID()] = $new_state; |
|
449 | + EE_Registry::instance()->SSN->set_session_data( |
|
450 | + array('nsmf_new_states' => $new_states) |
|
451 | + ); |
|
452 | + if (EE_Registry::instance()->REQ->ajax) { |
|
453 | + echo wp_json_encode(array( |
|
454 | + 'success' => true, |
|
455 | + 'id' => $new_state->ID(), |
|
456 | + 'name' => $new_state->name(), |
|
457 | + 'abbrev' => $new_state->abbrev(), |
|
458 | + 'country_iso' => $new_state->country_iso(), |
|
459 | + 'country_name' => $new_state->country()->name(), |
|
460 | + )); |
|
461 | + exit(); |
|
462 | + } |
|
463 | + return $new_state->ID(); |
|
464 | + } |
|
465 | + } else { |
|
466 | + $error = esc_html__( |
|
467 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
468 | + 'event_espresso' |
|
469 | + ); |
|
470 | + if (EE_Registry::instance()->REQ->ajax) { |
|
471 | + echo wp_json_encode(array('error' => $error)); |
|
472 | + exit(); |
|
473 | + } |
|
474 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
475 | + } |
|
476 | + } |
|
477 | + return false; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * recursively drills down through request params to remove any that were added by this module |
|
484 | + * |
|
485 | + * @param array $request_params |
|
486 | + * @return array |
|
487 | + */ |
|
488 | + public static function filter_checkout_request_params($request_params) |
|
489 | + { |
|
490 | + foreach ($request_params as $form_section) { |
|
491 | + if (is_array($form_section)) { |
|
492 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
493 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
494 | + } |
|
495 | + } |
|
496 | + return $request_params; |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * @param array $request_params |
|
503 | + * @return array |
|
504 | + */ |
|
505 | + public static function unset_new_state_request_params($request_params) |
|
506 | + { |
|
507 | + unset( |
|
508 | + $request_params['new_state_micro_form'], |
|
509 | + $request_params['new_state_micro_add_new_state'], |
|
510 | + $request_params['new_state_micro_new_state_country'], |
|
511 | + $request_params['new_state_micro_new_state_name'], |
|
512 | + $request_params['new_state_micro_new_state_abbrv'] |
|
513 | + ); |
|
514 | + return $request_params; |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * @param array $props_n_values |
|
521 | + * @return bool |
|
522 | + * @throws EE_Error |
|
523 | + * @throws InvalidArgumentException |
|
524 | + * @throws InvalidDataTypeException |
|
525 | + * @throws InvalidInterfaceException |
|
526 | + */ |
|
527 | + public static function save_new_state_to_db($props_n_values = array()) |
|
528 | + { |
|
529 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
530 | + if (! empty($existing_state)) { |
|
531 | + return array_pop($existing_state); |
|
532 | + } |
|
533 | + $new_state = EE_State::new_instance($props_n_values); |
|
534 | + if ($new_state instanceof EE_State) { |
|
535 | + $country_settings_url = add_query_arg( |
|
536 | + array( |
|
537 | + 'page' => 'espresso_general_settings', |
|
538 | + 'action' => 'country_settings', |
|
539 | + 'country' => $new_state->country_iso(), |
|
540 | + ), |
|
541 | + admin_url('admin.php') |
|
542 | + ); |
|
543 | + // if not non-ajax admin |
|
544 | + new PersistentAdminNotice( |
|
545 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
546 | + sprintf( |
|
547 | + esc_html__( |
|
548 | + '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.', |
|
549 | + 'event_espresso' |
|
550 | + ), |
|
551 | + '<b>' . $new_state->name() . '</b>', |
|
552 | + '<b>' . $new_state->abbrev() . '</b>', |
|
553 | + '<b>' . $new_state->country()->name() . '</b>', |
|
554 | + '<a href="' |
|
555 | + . $country_settings_url |
|
556 | + . '">' |
|
557 | + . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
558 | + 'event_espresso') |
|
559 | + . '</a>', |
|
560 | + '<br />' |
|
561 | + ) |
|
562 | + ); |
|
563 | + $new_state->save(); |
|
564 | + EEM_State::instance()->reset_cached_states(); |
|
565 | + return $new_state; |
|
566 | + } |
|
567 | + return false; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * @param string $CNT_ISO |
|
574 | + * @param string $STA_ID |
|
575 | + * @param array $cols_n_values |
|
576 | + * @return void |
|
577 | + * @throws DomainException |
|
578 | + * @throws EE_Error |
|
579 | + * @throws InvalidArgumentException |
|
580 | + * @throws InvalidDataTypeException |
|
581 | + * @throws InvalidInterfaceException |
|
582 | + */ |
|
583 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
584 | + { |
|
585 | + if (! $CNT_ISO) { |
|
586 | + EE_Error::add_error( |
|
587 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
588 | + __FILE__, |
|
589 | + __FUNCTION__, |
|
590 | + __LINE__ |
|
591 | + ); |
|
592 | + } |
|
593 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
594 | + : false; |
|
595 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
596 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
597 | + if ($state instanceof EE_State) { |
|
598 | + $STA_abbrev = $state->abbrev(); |
|
599 | + } |
|
600 | + } |
|
601 | + if (! $STA_abbrev) { |
|
602 | + EE_Error::add_error( |
|
603 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
604 | + __FILE__, |
|
605 | + __FUNCTION__, |
|
606 | + __LINE__ |
|
607 | + ); |
|
608 | + } |
|
609 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
610 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
611 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
612 | + ); |
|
613 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * @param EE_State[] $state_options |
|
620 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
621 | + * @param EE_Registration $registration |
|
622 | + * @param EE_Question $question |
|
623 | + * @param $answer |
|
624 | + * @return array |
|
625 | + * @throws EE_Error |
|
626 | + * @throws InvalidArgumentException |
|
627 | + * @throws InvalidDataTypeException |
|
628 | + * @throws InvalidInterfaceException |
|
629 | + */ |
|
630 | + public static function inject_new_reg_state_into_options( |
|
631 | + $state_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() === EEM_Question::QST_type_state |
|
639 | + ) { |
|
640 | + $STA_ID = $answer->value(); |
|
641 | + if (! empty($STA_ID)) { |
|
642 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
643 | + if ($state instanceof EE_State) { |
|
644 | + $country = $state->country(); |
|
645 | + if ($country instanceof EE_Country) { |
|
646 | + if (! isset($state_options[$country->name()])) { |
|
647 | + $state_options[$country->name()] = array(); |
|
648 | + } |
|
649 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
650 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
651 | + } |
|
652 | + } |
|
653 | + } |
|
654 | + } |
|
655 | + } |
|
656 | + return $state_options; |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * @param EE_Country[] $country_options |
|
663 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
664 | + * @param EE_Registration $registration |
|
665 | + * @param EE_Question $question |
|
666 | + * @param $answer |
|
667 | + * @return array |
|
668 | + * @throws EE_Error |
|
669 | + * @throws InvalidArgumentException |
|
670 | + * @throws InvalidDataTypeException |
|
671 | + * @throws InvalidInterfaceException |
|
672 | + */ |
|
673 | + public static function inject_new_reg_country_into_options( |
|
674 | + $country_options = array(), |
|
675 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
676 | + EE_Registration $registration, |
|
677 | + EE_Question $question, |
|
678 | + $answer |
|
679 | + ) { |
|
680 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
681 | + && $question->type() |
|
682 | + === EEM_Question::QST_type_country |
|
683 | + ) { |
|
684 | + $CNT_ISO = $answer->value(); |
|
685 | + if (! empty($CNT_ISO)) { |
|
686 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
687 | + if ($country instanceof EE_Country) { |
|
688 | + if (! isset($country_options[$CNT_ISO])) { |
|
689 | + $country_options[$CNT_ISO] = $country->name(); |
|
690 | + } |
|
691 | + } |
|
692 | + } |
|
693 | + } |
|
694 | + return $country_options; |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * @param EE_State[] $state_options |
|
701 | + * @return array |
|
702 | + * @throws EE_Error |
|
703 | + * @throws InvalidArgumentException |
|
704 | + * @throws InvalidDataTypeException |
|
705 | + * @throws InvalidInterfaceException |
|
706 | + */ |
|
707 | + public static function state_options($state_options = array()) |
|
708 | + { |
|
709 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
710 | + foreach ($new_states as $new_state) { |
|
711 | + if ( |
|
712 | + $new_state instanceof EE_State |
|
713 | + && $new_state->country() instanceof EE_Country |
|
714 | + ) { |
|
715 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
716 | + } |
|
717 | + } |
|
718 | + return $state_options; |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * @return array |
|
725 | + * @throws InvalidArgumentException |
|
726 | + * @throws InvalidDataTypeException |
|
727 | + * @throws InvalidInterfaceException |
|
728 | + */ |
|
729 | + protected static function _get_new_states() |
|
730 | + { |
|
731 | + $new_states = array(); |
|
732 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
733 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
734 | + 'nsmf_new_states' |
|
735 | + ); |
|
736 | + } |
|
737 | + return is_array($new_states) ? $new_states : array(); |
|
738 | + } |
|
739 | + |
|
740 | + |
|
741 | + |
|
742 | + /** |
|
743 | + * @param EE_Country[] $country_options |
|
744 | + * @return array |
|
745 | + * @throws EE_Error |
|
746 | + * @throws InvalidArgumentException |
|
747 | + * @throws InvalidDataTypeException |
|
748 | + * @throws InvalidInterfaceException |
|
749 | + */ |
|
750 | + public static function country_options($country_options = array()) |
|
751 | + { |
|
752 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
753 | + foreach ($new_states as $new_state) { |
|
754 | + if ( |
|
755 | + $new_state instanceof EE_State |
|
756 | + && $new_state->country() instanceof EE_Country |
|
757 | + ) { |
|
758 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
759 | + } |
|
760 | + } |
|
761 | + return $country_options; |
|
762 | + } |
|
763 | 763 | |
764 | 764 | |
765 | 765 |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public static function set_definitions() |
101 | 101 | { |
102 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
102 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
103 | 103 | define('ANS_TEMPLATES_PATH', str_replace( |
104 | 104 | '\\', |
105 | 105 | DS, |
106 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
106 | + plugin_dir_path(__FILE__)).'templates'.DS |
|
107 | 107 | ); |
108 | 108 | } |
109 | 109 | |
@@ -124,19 +124,19 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public static function translate_js_strings() |
126 | 126 | { |
127 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
127 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
128 | 128 | 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
129 | 129 | 'event_espresso' |
130 | 130 | ); |
131 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
131 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
132 | 132 | 'In order to proceed, you need to enter the name of your State/Province.', |
133 | 133 | 'event_espresso' |
134 | 134 | ); |
135 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
135 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
136 | 136 | 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
137 | 137 | 'event_espresso' |
138 | 138 | ); |
139 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
139 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
140 | 140 | 'The new state was successfully saved to the database.', |
141 | 141 | 'event_espresso' |
142 | 142 | ); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | public static function wp_enqueue_scripts() |
155 | 155 | { |
156 | 156 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
157 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
157 | + wp_register_script('add_new_state', ANS_ASSETS_URL.'add_new_state.js', |
|
158 | 158 | array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
159 | 159 | wp_enqueue_script('add_new_state'); |
160 | 160 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
198 | 198 | $country_options = array(); |
199 | 199 | $countries = EEM_Country::instance()->get_all_countries(); |
200 | - if (! empty($countries)) { |
|
200 | + if ( ! empty($countries)) { |
|
201 | 201 | foreach ($countries as $country) { |
202 | 202 | if ($country instanceof EE_Country) { |
203 | 203 | $country_options[$country->ID()] = $country->name(); |
@@ -234,10 +234,10 @@ discard block |
||
234 | 234 | '', |
235 | 235 | esc_html__('click here to add a new state/province', 'event_espresso'), |
236 | 236 | '', |
237 | - 'display-' . $input->html_id(), |
|
237 | + 'display-'.$input->html_id(), |
|
238 | 238 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
239 | 239 | '', |
240 | - 'data-target="' . $input->html_id() . '"' |
|
240 | + 'data-target="'.$input->html_id().'"' |
|
241 | 241 | ) |
242 | 242 | ) |
243 | 243 | ), |
@@ -245,31 +245,31 @@ discard block |
||
245 | 245 | 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
246 | 246 | apply_filters( |
247 | 247 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
248 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
249 | - 'display: none;') . |
|
248 | + EEH_HTML::div('', $input->html_id().'-dv', 'ee-form-add-new-state-dv', |
|
249 | + 'display: none;'). |
|
250 | 250 | EEH_HTML::h6( |
251 | 251 | esc_html__( |
252 | 252 | 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
253 | 253 | 'event_espresso' |
254 | 254 | ) |
255 | - ) . |
|
256 | - EEH_HTML::ul() . |
|
255 | + ). |
|
256 | + EEH_HTML::ul(). |
|
257 | 257 | EEH_HTML::li( |
258 | 258 | esc_html__( |
259 | 259 | 'first select the Country that your State/Province belongs to', |
260 | 260 | 'event_espresso' |
261 | 261 | ) |
262 | - ) . |
|
262 | + ). |
|
263 | 263 | EEH_HTML::li( |
264 | 264 | esc_html__('enter the name of your State/Province', 'event_espresso') |
265 | - ) . |
|
265 | + ). |
|
266 | 266 | EEH_HTML::li( |
267 | 267 | esc_html__( |
268 | 268 | 'enter a two to six letter abbreviation for the name of your State/Province', |
269 | 269 | 'event_espresso' |
270 | 270 | ) |
271 | - ) . |
|
272 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
271 | + ). |
|
272 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')). |
|
273 | 273 | EEH_HTML::ulx() |
274 | 274 | ) |
275 | 275 | ), |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | 'state', |
283 | 283 | 'nsmf_new_state_country', $input->html_id() |
284 | 284 | ), |
285 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
285 | + 'html_class' => $input->html_class().' new-state-country', |
|
286 | 286 | 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
287 | 287 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
288 | 288 | 'required' => false, |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | 'state', |
297 | 297 | 'nsmf_new_state_name', $input->html_id() |
298 | 298 | ), |
299 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
299 | + 'html_class' => $input->html_class().' new-state-state', |
|
300 | 300 | 'html_label_text' => esc_html__('New State/Province Name', |
301 | 301 | 'event_espresso'), |
302 | 302 | 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
@@ -310,11 +310,11 @@ discard block |
||
310 | 310 | 'html_name' => $abbrv_name, |
311 | 311 | 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
312 | 312 | $input->html_id()), |
313 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
313 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
314 | 314 | 'html_label_text' => esc_html__( |
315 | 315 | 'New State/Province Abbreviation', |
316 | 316 | 'event_espresso' |
317 | - ) . ' *', |
|
317 | + ).' *', |
|
318 | 318 | 'html_other_attributes' => 'size="24"', |
319 | 319 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
320 | 320 | 'required' => false, |
@@ -324,15 +324,15 @@ discard block |
||
324 | 324 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
325 | 325 | apply_filters( |
326 | 326 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
327 | - EEH_HTML::nbsp(3) . |
|
327 | + EEH_HTML::nbsp(3). |
|
328 | 328 | EEH_HTML::link( |
329 | 329 | '', |
330 | 330 | esc_html__('ADD', 'event_espresso'), |
331 | 331 | '', |
332 | - 'submit-' . $new_state_submit_id, |
|
332 | + 'submit-'.$new_state_submit_id, |
|
333 | 333 | 'ee-form-add-new-state-submit button button-secondary', |
334 | 334 | '', |
335 | - 'data-target="' . $new_state_submit_id . '"' |
|
335 | + 'data-target="'.$new_state_submit_id.'"' |
|
336 | 336 | ) |
337 | 337 | ) |
338 | 338 | ), |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | EEH_HTML::div('', '', 'small-text') |
346 | 346 | . |
347 | 347 | EEH_HTML::strong( |
348 | - '* ' . |
|
348 | + '* '. |
|
349 | 349 | esc_html__( |
350 | 350 | 'Don\'t know your State/Province Abbreviation?', |
351 | 351 | 'event_espresso' |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | '', |
379 | 379 | esc_html__('cancel new State/Province', 'event_espresso'), |
380 | 380 | '', |
381 | - 'hide-' . $input->html_id(), |
|
381 | + 'hide-'.$input->html_id(), |
|
382 | 382 | 'ee-form-cancel-new-state-lnk smaller-text', |
383 | 383 | '', |
384 | - 'data-target="' . $input->html_id() . '"' |
|
384 | + 'data-target="'.$input->html_id().'"' |
|
385 | 385 | ) |
386 | 386 | . |
387 | 387 | EEH_HTML::divx() |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | public static function save_new_state_to_db($props_n_values = array()) |
528 | 528 | { |
529 | 529 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
530 | - if (! empty($existing_state)) { |
|
530 | + if ( ! empty($existing_state)) { |
|
531 | 531 | return array_pop($existing_state); |
532 | 532 | } |
533 | 533 | $new_state = EE_State::new_instance($props_n_values); |
@@ -542,15 +542,15 @@ discard block |
||
542 | 542 | ); |
543 | 543 | // if not non-ajax admin |
544 | 544 | new PersistentAdminNotice( |
545 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
545 | + 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(), |
|
546 | 546 | sprintf( |
547 | 547 | esc_html__( |
548 | 548 | '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.', |
549 | 549 | 'event_espresso' |
550 | 550 | ), |
551 | - '<b>' . $new_state->name() . '</b>', |
|
552 | - '<b>' . $new_state->abbrev() . '</b>', |
|
553 | - '<b>' . $new_state->country()->name() . '</b>', |
|
551 | + '<b>'.$new_state->name().'</b>', |
|
552 | + '<b>'.$new_state->abbrev().'</b>', |
|
553 | + '<b>'.$new_state->country()->name().'</b>', |
|
554 | 554 | '<a href="' |
555 | 555 | . $country_settings_url |
556 | 556 | . '">' |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | */ |
583 | 583 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
584 | 584 | { |
585 | - if (! $CNT_ISO) { |
|
585 | + if ( ! $CNT_ISO) { |
|
586 | 586 | EE_Error::add_error( |
587 | 587 | esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
588 | 588 | __FILE__, |
@@ -592,13 +592,13 @@ discard block |
||
592 | 592 | } |
593 | 593 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
594 | 594 | : false; |
595 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
595 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
596 | 596 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
597 | 597 | if ($state instanceof EE_State) { |
598 | 598 | $STA_abbrev = $state->abbrev(); |
599 | 599 | } |
600 | 600 | } |
601 | - if (! $STA_abbrev) { |
|
601 | + if ( ! $STA_abbrev) { |
|
602 | 602 | EE_Error::add_error( |
603 | 603 | esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
604 | 604 | __FILE__, |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
611 | 611 | 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
612 | 612 | ); |
613 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
613 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | |
@@ -638,15 +638,15 @@ discard block |
||
638 | 638 | && $question->type() === EEM_Question::QST_type_state |
639 | 639 | ) { |
640 | 640 | $STA_ID = $answer->value(); |
641 | - if (! empty($STA_ID)) { |
|
641 | + if ( ! empty($STA_ID)) { |
|
642 | 642 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
643 | 643 | if ($state instanceof EE_State) { |
644 | 644 | $country = $state->country(); |
645 | 645 | if ($country instanceof EE_Country) { |
646 | - if (! isset($state_options[$country->name()])) { |
|
646 | + if ( ! isset($state_options[$country->name()])) { |
|
647 | 647 | $state_options[$country->name()] = array(); |
648 | 648 | } |
649 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
649 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
650 | 650 | $state_options[$country->name()][$STA_ID] = $state->name(); |
651 | 651 | } |
652 | 652 | } |
@@ -682,10 +682,10 @@ discard block |
||
682 | 682 | === EEM_Question::QST_type_country |
683 | 683 | ) { |
684 | 684 | $CNT_ISO = $answer->value(); |
685 | - if (! empty($CNT_ISO)) { |
|
685 | + if ( ! empty($CNT_ISO)) { |
|
686 | 686 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
687 | 687 | if ($country instanceof EE_Country) { |
688 | - if (! isset($country_options[$CNT_ISO])) { |
|
688 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
689 | 689 | $country_options[$CNT_ISO] = $country->name(); |
690 | 690 | } |
691 | 691 | } |