@@ -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 | } |
@@ -21,571 +21,571 @@ |
||
21 | 21 | class EE_Payment_Method_Manager implements ResettableInterface |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * prefix added to all payment method capabilities names |
|
26 | - */ |
|
27 | - const CAPABILITIES_PREFIX= 'ee_payment_method_'; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var EE_Payment_Method_Manager $_instance |
|
31 | - */ |
|
32 | - private static $_instance; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var boolean |
|
36 | - */ |
|
37 | - protected $payment_method_caps_initialized = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var array keys are class names without 'EE_PMT_', values are their filepaths |
|
41 | - */ |
|
42 | - protected $_payment_method_types = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * @var EE_PMT_Base[] |
|
46 | - */ |
|
47 | - protected $payment_method_objects = array(); |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * EE_Payment_Method_Manager constructor. |
|
53 | - * |
|
54 | - * @throws EE_Error |
|
55 | - * @throws DomainException |
|
56 | - */ |
|
57 | - public function __construct() |
|
58 | - { |
|
59 | - // if in admin lets ensure caps are set. |
|
60 | - if (is_admin()) { |
|
61 | - $this->_register_payment_methods(); |
|
62 | - // set them immediately |
|
63 | - $this->initializePaymentMethodCaps(); |
|
64 | - // plus any time they get reset |
|
65 | - add_filter( |
|
66 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
67 | - array($this, 'addPaymentMethodCapsDuringReset') |
|
68 | - ); |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @singleton method used to instantiate class object |
|
76 | - * @return EE_Payment_Method_Manager instance |
|
77 | - * @throws DomainException |
|
78 | - * @throws EE_Error |
|
79 | - */ |
|
80 | - public static function instance() |
|
81 | - { |
|
82 | - // check if class object is instantiated, and instantiated properly |
|
83 | - if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
84 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
85 | - self::$_instance = new self(); |
|
86 | - } |
|
87 | - return self::$_instance; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Resets the instance and returns a new one |
|
94 | - * |
|
95 | - * @return EE_Payment_Method_Manager |
|
96 | - * @throws DomainException |
|
97 | - * @throws EE_Error |
|
98 | - */ |
|
99 | - public static function reset() |
|
100 | - { |
|
101 | - self::$_instance = null; |
|
102 | - return self::instance(); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * If necessary, re-register payment methods |
|
109 | - * |
|
110 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
111 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
112 | - * we have not yet checked during this request, then we need to check anyways) |
|
113 | - */ |
|
114 | - public function maybe_register_payment_methods($force_recheck = false) |
|
115 | - { |
|
116 | - if (! $this->_payment_method_types || $force_recheck) { |
|
117 | - $this->_register_payment_methods(); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * register_payment_methods |
|
125 | - * |
|
126 | - * @return array |
|
127 | - */ |
|
128 | - protected function _register_payment_methods() |
|
129 | - { |
|
130 | - // grab list of installed modules |
|
131 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
132 | - // filter list of modules to register |
|
133 | - $pm_to_register = apply_filters( |
|
134 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
135 | - $pm_to_register |
|
136 | - ); |
|
137 | - // remove any duplicates if that should happen for some reason |
|
138 | - $pm_to_register = array_unique($pm_to_register); |
|
139 | - // loop through folders |
|
140 | - foreach ($pm_to_register as $pm_path) { |
|
141 | - $this->register_payment_method($pm_path); |
|
142 | - } |
|
143 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
144 | - // filter list of installed modules |
|
145 | - //keep them organized alphabetically by the payment method type's name |
|
146 | - ksort($this->_payment_method_types); |
|
147 | - return apply_filters( |
|
148 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
149 | - $this->_payment_method_types |
|
150 | - ); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * register_payment_method- makes core aware of this payment method |
|
157 | - * |
|
158 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
159 | - * @return boolean |
|
160 | - */ |
|
161 | - public function register_payment_method($payment_method_path = '') |
|
162 | - { |
|
163 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
164 | - $module_ext = '.pm.php'; |
|
165 | - // make all separators match |
|
166 | - $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
167 | - // grab and sanitize module name |
|
168 | - $module_dir = basename($payment_method_path); |
|
169 | - // create class name from module directory name |
|
170 | - $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
|
171 | - // add class prefix |
|
172 | - $module_class = 'EE_PMT_' . $module; |
|
173 | - // does the module exist ? |
|
174 | - if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
175 | - $msg = sprintf( |
|
176 | - esc_html__( |
|
177 | - 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
178 | - 'event_espresso' |
|
179 | - ), $module |
|
180 | - ); |
|
181 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
182 | - return false; |
|
183 | - } |
|
184 | - // load the module class file |
|
185 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
186 | - // verify that class exists |
|
187 | - if (! class_exists($module_class)) { |
|
188 | - $msg = sprintf( |
|
189 | - esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
|
190 | - $module_class |
|
191 | - ); |
|
192 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
193 | - return false; |
|
194 | - } |
|
195 | - // add to array of registered modules |
|
196 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
197 | - return true; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Checks if a payment method has been registered, and if so includes it |
|
204 | - * |
|
205 | - * @param string $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_') |
|
206 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
207 | - * @return boolean |
|
208 | - */ |
|
209 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
210 | - { |
|
211 | - if ( |
|
212 | - $force_recheck |
|
213 | - || ! is_array($this->_payment_method_types) |
|
214 | - || ! isset($this->_payment_method_types[$payment_method_name]) |
|
215 | - ) { |
|
216 | - $this->maybe_register_payment_methods($force_recheck); |
|
217 | - } |
|
218 | - if (isset($this->_payment_method_types[$payment_method_name])) { |
|
219 | - require_once($this->_payment_method_types[$payment_method_name]); |
|
220 | - return true; |
|
221 | - } |
|
222 | - return false; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * Returns all the class names of the various payment method types |
|
229 | - * |
|
230 | - * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names' |
|
231 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
232 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
233 | - * @return array |
|
234 | - */ |
|
235 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
236 | - { |
|
237 | - $this->maybe_register_payment_methods($force_recheck); |
|
238 | - if ($with_prefixes) { |
|
239 | - $classnames = array_keys($this->_payment_method_types); |
|
240 | - $payment_methods = array(); |
|
241 | - foreach ($classnames as $classname) { |
|
242 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
243 | - } |
|
244 | - return $payment_methods; |
|
245 | - } |
|
246 | - return array_keys($this->_payment_method_types); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Gets an object of each payment method type, none of which are bound to a |
|
253 | - * payment method instance |
|
254 | - * |
|
255 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
256 | - * @return EE_PMT_Base[] |
|
257 | - */ |
|
258 | - public function payment_method_types($force_recheck = false) |
|
259 | - { |
|
260 | - if ($force_recheck || empty($this->payment_method_objects)) { |
|
261 | - $this->maybe_register_payment_methods($force_recheck); |
|
262 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
263 | - if (! isset($this->payment_method_objects[$classname])) { |
|
264 | - $this->payment_method_objects[$classname] = new $classname; |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
268 | - return $this->payment_method_objects; |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Changes the payment method's class name into the payment method type's name |
|
275 | - * (as used on the payment method's table's PMD_type field) |
|
276 | - * |
|
277 | - * @param string $classname |
|
278 | - * @return string |
|
279 | - */ |
|
280 | - public function payment_method_type_sans_class_prefix($classname) |
|
281 | - { |
|
282 | - return str_replace('EE_PMT_', '', $classname); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * Does the opposite of payment-method_type_sans_prefix |
|
289 | - * |
|
290 | - * @param string $type |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - public function payment_method_class_from_type($type) |
|
294 | - { |
|
295 | - return 'EE_PMT_' . $type; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * Activates a payment method of the given type. |
|
302 | - * |
|
303 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
304 | - * @return EE_Payment_Method |
|
305 | - * @throws InvalidDataTypeException |
|
306 | - * @throws EE_Error |
|
307 | - */ |
|
308 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
309 | - { |
|
310 | - $this->maybe_register_payment_methods(); |
|
311 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
312 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
313 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
314 | - if (class_exists($pm_type_class)) { |
|
315 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
316 | - $pm_type_obj = new $pm_type_class; |
|
317 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
318 | - if (! $payment_method) { |
|
319 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
320 | - } |
|
321 | - $payment_method->set_type($payment_method_type); |
|
322 | - $this->initialize_payment_method($payment_method); |
|
323 | - } else { |
|
324 | - throw new EE_Error( |
|
325 | - sprintf( |
|
326 | - esc_html__( |
|
327 | - 'There is no payment method of type %1$s, so it could not be activated', |
|
328 | - 'event_espresso' |
|
329 | - ), |
|
330 | - $pm_type_class |
|
331 | - ) |
|
332 | - ); |
|
333 | - } |
|
334 | - } |
|
335 | - $payment_method->set_active(); |
|
336 | - $payment_method->save(); |
|
337 | - if ($payment_method->type() === 'Invoice') { |
|
338 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
339 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
340 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
341 | - $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
342 | - new PersistentAdminNotice( |
|
343 | - 'invoice_pm_requirements_notice', |
|
344 | - sprintf( |
|
345 | - esc_html__( |
|
346 | - 'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
347 | - 'event_espresso' |
|
348 | - ), |
|
349 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
350 | - '</a>' |
|
351 | - ), |
|
352 | - true |
|
353 | - ); |
|
354 | - } |
|
355 | - return $payment_method; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Creates a payment method of the specified type. Does not save it. |
|
362 | - * |
|
363 | - * @global WP_User $current_user |
|
364 | - * @param EE_PMT_Base $pm_type_obj |
|
365 | - * @return EE_Payment_Method |
|
366 | - * @throws EE_Error |
|
367 | - */ |
|
368 | - public function create_payment_method_of_type($pm_type_obj) |
|
369 | - { |
|
370 | - global $current_user; |
|
371 | - $payment_method = EE_Payment_Method::new_instance( |
|
372 | - array( |
|
373 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
374 | - 'PMD_name' => $pm_type_obj->pretty_name(), |
|
375 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
376 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
377 | - 'PMD_wp_user' => $current_user->ID, |
|
378 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
379 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
380 | - ) * 10, |
|
381 | - ) |
|
382 | - ); |
|
383 | - return $payment_method; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Sets the initial payment method properties (including extra meta) |
|
390 | - * |
|
391 | - * @param EE_Payment_Method $payment_method |
|
392 | - * @return EE_Payment_Method |
|
393 | - * @throws EE_Error |
|
394 | - */ |
|
395 | - public function initialize_payment_method($payment_method) |
|
396 | - { |
|
397 | - $pm_type_obj = $payment_method->type_obj(); |
|
398 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
399 | - if (! $payment_method->button_url()) { |
|
400 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
401 | - } |
|
402 | - //now add setup its default extra meta properties |
|
403 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
404 | - if (! empty($extra_metas)) { |
|
405 | - //verify the payment method has an ID before adding extra meta |
|
406 | - if (! $payment_method->ID()) { |
|
407 | - $payment_method->save(); |
|
408 | - } |
|
409 | - foreach ($extra_metas as $meta_name => $input) { |
|
410 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
411 | - } |
|
412 | - } |
|
413 | - return $payment_method; |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * Makes sure the payment method is related to the specified payment method |
|
420 | - * |
|
421 | - * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
422 | - * @param EE_Payment_Method $payment_method |
|
423 | - * @return EE_Payment_Method |
|
424 | - * @throws EE_Error |
|
425 | - */ |
|
426 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
427 | - { |
|
428 | - EE_Error::doing_it_wrong( |
|
429 | - 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
430 | - esc_html__( |
|
431 | - 'We no longer define what currencies are usable by payment methods. Its not used nor efficient.', |
|
432 | - 'event_espresso' |
|
433 | - ), |
|
434 | - '4.9.40' |
|
435 | - ); |
|
436 | - return $payment_method; |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * Deactivates a payment method of the given payment method slug. |
|
443 | - * |
|
444 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
445 | - * @return int count of rows updated. |
|
446 | - * @throws EE_Error |
|
447 | - */ |
|
448 | - public function deactivate_payment_method($payment_method_slug) |
|
449 | - { |
|
450 | - EE_Log::instance()->log( |
|
451 | - __FILE__, |
|
452 | - __FUNCTION__, |
|
453 | - sprintf( |
|
454 | - esc_html__( |
|
455 | - 'Payment method with slug %1$s is being deactivated by site admin', |
|
456 | - 'event_espresso' |
|
457 | - ), |
|
458 | - $payment_method_slug |
|
459 | - ), |
|
460 | - 'payment_method_change' |
|
461 | - ); |
|
462 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
463 | - array('PMD_scope' => array()), |
|
464 | - array(array('PMD_slug' => $payment_method_slug)) |
|
465 | - ); |
|
466 | - return $count_updated; |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * initializes payment method access caps via EE_Capabilities::init_role_caps() |
|
473 | - * upon EE_Payment_Method_Manager construction |
|
474 | - * |
|
475 | - * @throws EE_Error |
|
476 | - * @throws DomainException |
|
477 | - */ |
|
478 | - protected function initializePaymentMethodCaps() |
|
479 | - { |
|
480 | - // don't do this twice |
|
481 | - if ($this->payment_method_caps_initialized) { |
|
482 | - return; |
|
483 | - } |
|
484 | - EE_Capabilities::instance()->addCaps( |
|
485 | - $this->getPaymentMethodCaps() |
|
486 | - ); |
|
487 | - $this->payment_method_caps_initialized = true; |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * array of dynamic payment method access caps. |
|
494 | - * at the time of writing, october 20 2014, these are the caps added: |
|
495 | - * ee_payment_method_admin_only |
|
496 | - * ee_payment_method_aim |
|
497 | - * ee_payment_method_bank |
|
498 | - * ee_payment_method_check |
|
499 | - * ee_payment_method_invoice |
|
500 | - * ee_payment_method_mijireh |
|
501 | - * ee_payment_method_paypal_pro |
|
502 | - * ee_payment_method_paypal_standard |
|
503 | - * Any other payment methods added to core or via addons will also get |
|
504 | - * their related capability automatically added too, so long as they are |
|
505 | - * registered properly using EE_Register_Payment_Method::register() |
|
506 | - * |
|
507 | - * @return array |
|
508 | - * @throws DomainException |
|
509 | - */ |
|
510 | - protected function getPaymentMethodCaps() |
|
511 | - { |
|
512 | - $caps = array(); |
|
513 | - foreach ($this->payment_method_type_names() as $payment_method_name) { |
|
514 | - $caps = $this->addPaymentMethodCap($payment_method_name,$caps); |
|
515 | - } |
|
516 | - return $caps; |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * @param string $payment_method_name |
|
523 | - * @param array $payment_method_caps |
|
524 | - * @param string $role |
|
525 | - * @return array |
|
526 | - * @throws DomainException |
|
527 | - */ |
|
528 | - public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator') |
|
529 | - { |
|
530 | - if (empty($payment_method_name)) { |
|
531 | - throw new DomainException( |
|
532 | - esc_html__( |
|
533 | - 'The name of a payment method must be specified to add capabilities.', |
|
534 | - 'event_espresso' |
|
535 | - ) |
|
536 | - ); |
|
537 | - } |
|
538 | - if (empty($role)) { |
|
539 | - throw new DomainException( |
|
540 | - sprintf( |
|
541 | - esc_html__( |
|
542 | - 'No role was supplied while trying to add capabilities for the %1$s payment method.', |
|
543 | - 'event_espresso' |
|
544 | - ), |
|
545 | - $payment_method_name |
|
546 | - ) |
|
547 | - ); |
|
548 | - } |
|
549 | - if(! isset($payment_method_caps[$role])) { |
|
550 | - $payment_method_caps[$role] = array(); |
|
551 | - } |
|
552 | - $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
553 | - . strtolower($payment_method_name); |
|
554 | - return $payment_method_caps; |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter |
|
561 | - * to add dynamic payment method access caps when capabilities are reset |
|
562 | - * (or if that filter is called and PM caps are not already set) |
|
563 | - * |
|
564 | - * @param array $caps capabilities being filtered |
|
565 | - * @param bool $reset |
|
566 | - * @return array |
|
567 | - * @throws DomainException |
|
568 | - */ |
|
569 | - public function addPaymentMethodCapsDuringReset(array $caps, $reset = false) |
|
570 | - { |
|
571 | - if ($reset || ! $this->payment_method_caps_initialized) { |
|
572 | - $this->payment_method_caps_initialized = true; |
|
573 | - $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps()); |
|
574 | - } |
|
575 | - return $caps; |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * @deprecated 4.9.42 |
|
582 | - * @param $caps |
|
583 | - * @return mixed |
|
584 | - */ |
|
585 | - public function add_payment_method_caps($caps) |
|
586 | - { |
|
587 | - return $caps; |
|
588 | - } |
|
24 | + /** |
|
25 | + * prefix added to all payment method capabilities names |
|
26 | + */ |
|
27 | + const CAPABILITIES_PREFIX= 'ee_payment_method_'; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var EE_Payment_Method_Manager $_instance |
|
31 | + */ |
|
32 | + private static $_instance; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var boolean |
|
36 | + */ |
|
37 | + protected $payment_method_caps_initialized = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var array keys are class names without 'EE_PMT_', values are their filepaths |
|
41 | + */ |
|
42 | + protected $_payment_method_types = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * @var EE_PMT_Base[] |
|
46 | + */ |
|
47 | + protected $payment_method_objects = array(); |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * EE_Payment_Method_Manager constructor. |
|
53 | + * |
|
54 | + * @throws EE_Error |
|
55 | + * @throws DomainException |
|
56 | + */ |
|
57 | + public function __construct() |
|
58 | + { |
|
59 | + // if in admin lets ensure caps are set. |
|
60 | + if (is_admin()) { |
|
61 | + $this->_register_payment_methods(); |
|
62 | + // set them immediately |
|
63 | + $this->initializePaymentMethodCaps(); |
|
64 | + // plus any time they get reset |
|
65 | + add_filter( |
|
66 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
67 | + array($this, 'addPaymentMethodCapsDuringReset') |
|
68 | + ); |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @singleton method used to instantiate class object |
|
76 | + * @return EE_Payment_Method_Manager instance |
|
77 | + * @throws DomainException |
|
78 | + * @throws EE_Error |
|
79 | + */ |
|
80 | + public static function instance() |
|
81 | + { |
|
82 | + // check if class object is instantiated, and instantiated properly |
|
83 | + if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
84 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
85 | + self::$_instance = new self(); |
|
86 | + } |
|
87 | + return self::$_instance; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Resets the instance and returns a new one |
|
94 | + * |
|
95 | + * @return EE_Payment_Method_Manager |
|
96 | + * @throws DomainException |
|
97 | + * @throws EE_Error |
|
98 | + */ |
|
99 | + public static function reset() |
|
100 | + { |
|
101 | + self::$_instance = null; |
|
102 | + return self::instance(); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * If necessary, re-register payment methods |
|
109 | + * |
|
110 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
111 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
112 | + * we have not yet checked during this request, then we need to check anyways) |
|
113 | + */ |
|
114 | + public function maybe_register_payment_methods($force_recheck = false) |
|
115 | + { |
|
116 | + if (! $this->_payment_method_types || $force_recheck) { |
|
117 | + $this->_register_payment_methods(); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * register_payment_methods |
|
125 | + * |
|
126 | + * @return array |
|
127 | + */ |
|
128 | + protected function _register_payment_methods() |
|
129 | + { |
|
130 | + // grab list of installed modules |
|
131 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
132 | + // filter list of modules to register |
|
133 | + $pm_to_register = apply_filters( |
|
134 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
135 | + $pm_to_register |
|
136 | + ); |
|
137 | + // remove any duplicates if that should happen for some reason |
|
138 | + $pm_to_register = array_unique($pm_to_register); |
|
139 | + // loop through folders |
|
140 | + foreach ($pm_to_register as $pm_path) { |
|
141 | + $this->register_payment_method($pm_path); |
|
142 | + } |
|
143 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
144 | + // filter list of installed modules |
|
145 | + //keep them organized alphabetically by the payment method type's name |
|
146 | + ksort($this->_payment_method_types); |
|
147 | + return apply_filters( |
|
148 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
149 | + $this->_payment_method_types |
|
150 | + ); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * register_payment_method- makes core aware of this payment method |
|
157 | + * |
|
158 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
159 | + * @return boolean |
|
160 | + */ |
|
161 | + public function register_payment_method($payment_method_path = '') |
|
162 | + { |
|
163 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
164 | + $module_ext = '.pm.php'; |
|
165 | + // make all separators match |
|
166 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
167 | + // grab and sanitize module name |
|
168 | + $module_dir = basename($payment_method_path); |
|
169 | + // create class name from module directory name |
|
170 | + $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
|
171 | + // add class prefix |
|
172 | + $module_class = 'EE_PMT_' . $module; |
|
173 | + // does the module exist ? |
|
174 | + if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
175 | + $msg = sprintf( |
|
176 | + esc_html__( |
|
177 | + 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
178 | + 'event_espresso' |
|
179 | + ), $module |
|
180 | + ); |
|
181 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
182 | + return false; |
|
183 | + } |
|
184 | + // load the module class file |
|
185 | + require_once($payment_method_path . DS . $module_class . $module_ext); |
|
186 | + // verify that class exists |
|
187 | + if (! class_exists($module_class)) { |
|
188 | + $msg = sprintf( |
|
189 | + esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
|
190 | + $module_class |
|
191 | + ); |
|
192 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
193 | + return false; |
|
194 | + } |
|
195 | + // add to array of registered modules |
|
196 | + $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
197 | + return true; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Checks if a payment method has been registered, and if so includes it |
|
204 | + * |
|
205 | + * @param string $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_') |
|
206 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
207 | + * @return boolean |
|
208 | + */ |
|
209 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
210 | + { |
|
211 | + if ( |
|
212 | + $force_recheck |
|
213 | + || ! is_array($this->_payment_method_types) |
|
214 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
215 | + ) { |
|
216 | + $this->maybe_register_payment_methods($force_recheck); |
|
217 | + } |
|
218 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
219 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
220 | + return true; |
|
221 | + } |
|
222 | + return false; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * Returns all the class names of the various payment method types |
|
229 | + * |
|
230 | + * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names' |
|
231 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
232 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
233 | + * @return array |
|
234 | + */ |
|
235 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
236 | + { |
|
237 | + $this->maybe_register_payment_methods($force_recheck); |
|
238 | + if ($with_prefixes) { |
|
239 | + $classnames = array_keys($this->_payment_method_types); |
|
240 | + $payment_methods = array(); |
|
241 | + foreach ($classnames as $classname) { |
|
242 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
243 | + } |
|
244 | + return $payment_methods; |
|
245 | + } |
|
246 | + return array_keys($this->_payment_method_types); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Gets an object of each payment method type, none of which are bound to a |
|
253 | + * payment method instance |
|
254 | + * |
|
255 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
256 | + * @return EE_PMT_Base[] |
|
257 | + */ |
|
258 | + public function payment_method_types($force_recheck = false) |
|
259 | + { |
|
260 | + if ($force_recheck || empty($this->payment_method_objects)) { |
|
261 | + $this->maybe_register_payment_methods($force_recheck); |
|
262 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
263 | + if (! isset($this->payment_method_objects[$classname])) { |
|
264 | + $this->payment_method_objects[$classname] = new $classname; |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | + return $this->payment_method_objects; |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Changes the payment method's class name into the payment method type's name |
|
275 | + * (as used on the payment method's table's PMD_type field) |
|
276 | + * |
|
277 | + * @param string $classname |
|
278 | + * @return string |
|
279 | + */ |
|
280 | + public function payment_method_type_sans_class_prefix($classname) |
|
281 | + { |
|
282 | + return str_replace('EE_PMT_', '', $classname); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * Does the opposite of payment-method_type_sans_prefix |
|
289 | + * |
|
290 | + * @param string $type |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + public function payment_method_class_from_type($type) |
|
294 | + { |
|
295 | + return 'EE_PMT_' . $type; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * Activates a payment method of the given type. |
|
302 | + * |
|
303 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
304 | + * @return EE_Payment_Method |
|
305 | + * @throws InvalidDataTypeException |
|
306 | + * @throws EE_Error |
|
307 | + */ |
|
308 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
309 | + { |
|
310 | + $this->maybe_register_payment_methods(); |
|
311 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
312 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
313 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
314 | + if (class_exists($pm_type_class)) { |
|
315 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
316 | + $pm_type_obj = new $pm_type_class; |
|
317 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
318 | + if (! $payment_method) { |
|
319 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
320 | + } |
|
321 | + $payment_method->set_type($payment_method_type); |
|
322 | + $this->initialize_payment_method($payment_method); |
|
323 | + } else { |
|
324 | + throw new EE_Error( |
|
325 | + sprintf( |
|
326 | + esc_html__( |
|
327 | + 'There is no payment method of type %1$s, so it could not be activated', |
|
328 | + 'event_espresso' |
|
329 | + ), |
|
330 | + $pm_type_class |
|
331 | + ) |
|
332 | + ); |
|
333 | + } |
|
334 | + } |
|
335 | + $payment_method->set_active(); |
|
336 | + $payment_method->save(); |
|
337 | + if ($payment_method->type() === 'Invoice') { |
|
338 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
339 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
340 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
341 | + $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
342 | + new PersistentAdminNotice( |
|
343 | + 'invoice_pm_requirements_notice', |
|
344 | + sprintf( |
|
345 | + esc_html__( |
|
346 | + 'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
347 | + 'event_espresso' |
|
348 | + ), |
|
349 | + '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
350 | + '</a>' |
|
351 | + ), |
|
352 | + true |
|
353 | + ); |
|
354 | + } |
|
355 | + return $payment_method; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Creates a payment method of the specified type. Does not save it. |
|
362 | + * |
|
363 | + * @global WP_User $current_user |
|
364 | + * @param EE_PMT_Base $pm_type_obj |
|
365 | + * @return EE_Payment_Method |
|
366 | + * @throws EE_Error |
|
367 | + */ |
|
368 | + public function create_payment_method_of_type($pm_type_obj) |
|
369 | + { |
|
370 | + global $current_user; |
|
371 | + $payment_method = EE_Payment_Method::new_instance( |
|
372 | + array( |
|
373 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
374 | + 'PMD_name' => $pm_type_obj->pretty_name(), |
|
375 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
376 | + 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
377 | + 'PMD_wp_user' => $current_user->ID, |
|
378 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
379 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
380 | + ) * 10, |
|
381 | + ) |
|
382 | + ); |
|
383 | + return $payment_method; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Sets the initial payment method properties (including extra meta) |
|
390 | + * |
|
391 | + * @param EE_Payment_Method $payment_method |
|
392 | + * @return EE_Payment_Method |
|
393 | + * @throws EE_Error |
|
394 | + */ |
|
395 | + public function initialize_payment_method($payment_method) |
|
396 | + { |
|
397 | + $pm_type_obj = $payment_method->type_obj(); |
|
398 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
399 | + if (! $payment_method->button_url()) { |
|
400 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
401 | + } |
|
402 | + //now add setup its default extra meta properties |
|
403 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
404 | + if (! empty($extra_metas)) { |
|
405 | + //verify the payment method has an ID before adding extra meta |
|
406 | + if (! $payment_method->ID()) { |
|
407 | + $payment_method->save(); |
|
408 | + } |
|
409 | + foreach ($extra_metas as $meta_name => $input) { |
|
410 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
411 | + } |
|
412 | + } |
|
413 | + return $payment_method; |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * Makes sure the payment method is related to the specified payment method |
|
420 | + * |
|
421 | + * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
422 | + * @param EE_Payment_Method $payment_method |
|
423 | + * @return EE_Payment_Method |
|
424 | + * @throws EE_Error |
|
425 | + */ |
|
426 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
427 | + { |
|
428 | + EE_Error::doing_it_wrong( |
|
429 | + 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
430 | + esc_html__( |
|
431 | + 'We no longer define what currencies are usable by payment methods. Its not used nor efficient.', |
|
432 | + 'event_espresso' |
|
433 | + ), |
|
434 | + '4.9.40' |
|
435 | + ); |
|
436 | + return $payment_method; |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * Deactivates a payment method of the given payment method slug. |
|
443 | + * |
|
444 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
445 | + * @return int count of rows updated. |
|
446 | + * @throws EE_Error |
|
447 | + */ |
|
448 | + public function deactivate_payment_method($payment_method_slug) |
|
449 | + { |
|
450 | + EE_Log::instance()->log( |
|
451 | + __FILE__, |
|
452 | + __FUNCTION__, |
|
453 | + sprintf( |
|
454 | + esc_html__( |
|
455 | + 'Payment method with slug %1$s is being deactivated by site admin', |
|
456 | + 'event_espresso' |
|
457 | + ), |
|
458 | + $payment_method_slug |
|
459 | + ), |
|
460 | + 'payment_method_change' |
|
461 | + ); |
|
462 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
463 | + array('PMD_scope' => array()), |
|
464 | + array(array('PMD_slug' => $payment_method_slug)) |
|
465 | + ); |
|
466 | + return $count_updated; |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * initializes payment method access caps via EE_Capabilities::init_role_caps() |
|
473 | + * upon EE_Payment_Method_Manager construction |
|
474 | + * |
|
475 | + * @throws EE_Error |
|
476 | + * @throws DomainException |
|
477 | + */ |
|
478 | + protected function initializePaymentMethodCaps() |
|
479 | + { |
|
480 | + // don't do this twice |
|
481 | + if ($this->payment_method_caps_initialized) { |
|
482 | + return; |
|
483 | + } |
|
484 | + EE_Capabilities::instance()->addCaps( |
|
485 | + $this->getPaymentMethodCaps() |
|
486 | + ); |
|
487 | + $this->payment_method_caps_initialized = true; |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * array of dynamic payment method access caps. |
|
494 | + * at the time of writing, october 20 2014, these are the caps added: |
|
495 | + * ee_payment_method_admin_only |
|
496 | + * ee_payment_method_aim |
|
497 | + * ee_payment_method_bank |
|
498 | + * ee_payment_method_check |
|
499 | + * ee_payment_method_invoice |
|
500 | + * ee_payment_method_mijireh |
|
501 | + * ee_payment_method_paypal_pro |
|
502 | + * ee_payment_method_paypal_standard |
|
503 | + * Any other payment methods added to core or via addons will also get |
|
504 | + * their related capability automatically added too, so long as they are |
|
505 | + * registered properly using EE_Register_Payment_Method::register() |
|
506 | + * |
|
507 | + * @return array |
|
508 | + * @throws DomainException |
|
509 | + */ |
|
510 | + protected function getPaymentMethodCaps() |
|
511 | + { |
|
512 | + $caps = array(); |
|
513 | + foreach ($this->payment_method_type_names() as $payment_method_name) { |
|
514 | + $caps = $this->addPaymentMethodCap($payment_method_name,$caps); |
|
515 | + } |
|
516 | + return $caps; |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * @param string $payment_method_name |
|
523 | + * @param array $payment_method_caps |
|
524 | + * @param string $role |
|
525 | + * @return array |
|
526 | + * @throws DomainException |
|
527 | + */ |
|
528 | + public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator') |
|
529 | + { |
|
530 | + if (empty($payment_method_name)) { |
|
531 | + throw new DomainException( |
|
532 | + esc_html__( |
|
533 | + 'The name of a payment method must be specified to add capabilities.', |
|
534 | + 'event_espresso' |
|
535 | + ) |
|
536 | + ); |
|
537 | + } |
|
538 | + if (empty($role)) { |
|
539 | + throw new DomainException( |
|
540 | + sprintf( |
|
541 | + esc_html__( |
|
542 | + 'No role was supplied while trying to add capabilities for the %1$s payment method.', |
|
543 | + 'event_espresso' |
|
544 | + ), |
|
545 | + $payment_method_name |
|
546 | + ) |
|
547 | + ); |
|
548 | + } |
|
549 | + if(! isset($payment_method_caps[$role])) { |
|
550 | + $payment_method_caps[$role] = array(); |
|
551 | + } |
|
552 | + $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
553 | + . strtolower($payment_method_name); |
|
554 | + return $payment_method_caps; |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter |
|
561 | + * to add dynamic payment method access caps when capabilities are reset |
|
562 | + * (or if that filter is called and PM caps are not already set) |
|
563 | + * |
|
564 | + * @param array $caps capabilities being filtered |
|
565 | + * @param bool $reset |
|
566 | + * @return array |
|
567 | + * @throws DomainException |
|
568 | + */ |
|
569 | + public function addPaymentMethodCapsDuringReset(array $caps, $reset = false) |
|
570 | + { |
|
571 | + if ($reset || ! $this->payment_method_caps_initialized) { |
|
572 | + $this->payment_method_caps_initialized = true; |
|
573 | + $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps()); |
|
574 | + } |
|
575 | + return $caps; |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * @deprecated 4.9.42 |
|
582 | + * @param $caps |
|
583 | + * @return mixed |
|
584 | + */ |
|
585 | + public function add_payment_method_caps($caps) |
|
586 | + { |
|
587 | + return $caps; |
|
588 | + } |
|
589 | 589 | |
590 | 590 | |
591 | 591 |
@@ -101,14 +101,14 @@ discard block |
||
101 | 101 | default : |
102 | 102 | $to = get_option('admin_email'); |
103 | 103 | } |
104 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
104 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
105 | 105 | $msg = EE_Error::_format_error($type, $message, $file, $line); |
106 | 106 | if (function_exists('wp_mail')) { |
107 | 107 | add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
108 | 108 | wp_mail($to, $subject, $msg); |
109 | 109 | } |
110 | 110 | echo '<div id="message" class="espresso-notices error"><p>'; |
111 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
111 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
112 | 112 | echo '<br /></p></div>'; |
113 | 113 | } |
114 | 114 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | ? true |
256 | 256 | : false; |
257 | 257 | if ($check_stored && ! $has_error) { |
258 | - $notices = (array)get_option('ee_notices', array()); |
|
258 | + $notices = (array) get_option('ee_notices', array()); |
|
259 | 259 | foreach ($notices as $type => $notice) { |
260 | 260 | if ($type === $type_to_check && $notice) { |
261 | 261 | return true; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | } |
331 | 331 | </style> |
332 | 332 | <div id="ee-error-message" class="error">'; |
333 | - if (! WP_DEBUG) { |
|
333 | + if ( ! WP_DEBUG) { |
|
334 | 334 | $output .= ' |
335 | 335 | <p>'; |
336 | 336 | } |
@@ -387,14 +387,14 @@ discard block |
||
387 | 387 | $class_dsply = ! empty($class) ? $class : ' '; |
388 | 388 | $type_dsply = ! empty($type) ? $type : ' '; |
389 | 389 | $function_dsply = ! empty($function) ? $function : ' '; |
390 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
390 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
391 | 391 | $trace_details .= ' |
392 | 392 | <tr> |
393 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
394 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
395 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
396 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
397 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
393 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
394 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
395 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
396 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
397 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
398 | 398 | </tr>'; |
399 | 399 | } |
400 | 400 | $trace_details .= ' |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | } |
404 | 404 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
405 | 405 | // add generic non-identifying messages for non-privileged users |
406 | - if (! WP_DEBUG) { |
|
406 | + if ( ! WP_DEBUG) { |
|
407 | 407 | $output .= '<span class="ee-error-user-msg-spn">' |
408 | 408 | . trim($ex['msg']) |
409 | 409 | . '</span> <sup>' |
@@ -445,14 +445,14 @@ discard block |
||
445 | 445 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
446 | 446 | ' |
447 | 447 | . $trace_details; |
448 | - if (! empty($class)) { |
|
448 | + if ( ! empty($class)) { |
|
449 | 449 | $output .= ' |
450 | 450 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
451 | 451 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
452 | 452 | <h3>Class Details</h3>'; |
453 | 453 | $a = new ReflectionClass($class); |
454 | 454 | $output .= ' |
455 | - <pre>' . $a . '</pre> |
|
455 | + <pre>' . $a.'</pre> |
|
456 | 456 | </div> |
457 | 457 | </div>'; |
458 | 458 | } |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | } |
466 | 466 | // remove last linebreak |
467 | 467 | $output = substr($output, 0, -6); |
468 | - if (! WP_DEBUG) { |
|
468 | + if ( ! WP_DEBUG) { |
|
469 | 469 | $output .= ' |
470 | 470 | </p>'; |
471 | 471 | } |
@@ -492,20 +492,20 @@ discard block |
||
492 | 492 | private function _convert_args_to_string($arguments = array(), $array = false) |
493 | 493 | { |
494 | 494 | $arg_string = ''; |
495 | - if (! empty($arguments)) { |
|
495 | + if ( ! empty($arguments)) { |
|
496 | 496 | $args = array(); |
497 | 497 | foreach ($arguments as $arg) { |
498 | - if (! empty($arg)) { |
|
498 | + if ( ! empty($arg)) { |
|
499 | 499 | if (is_string($arg)) { |
500 | - $args[] = " '" . $arg . "'"; |
|
500 | + $args[] = " '".$arg."'"; |
|
501 | 501 | } elseif (is_array($arg)) { |
502 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
502 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true); |
|
503 | 503 | } elseif ($arg === null) { |
504 | 504 | $args[] = ' NULL'; |
505 | 505 | } elseif (is_bool($arg)) { |
506 | 506 | $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
507 | 507 | } elseif (is_object($arg)) { |
508 | - $args[] = ' OBJECT ' . get_class($arg); |
|
508 | + $args[] = ' OBJECT '.get_class($arg); |
|
509 | 509 | } elseif (is_resource($arg)) { |
510 | 510 | $args[] = get_resource_type($arg); |
511 | 511 | } else { |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | { |
609 | 609 | if (empty($msg)) { |
610 | 610 | EE_Error::doing_it_wrong( |
611 | - 'EE_Error::add_' . $type . '()', |
|
611 | + 'EE_Error::add_'.$type.'()', |
|
612 | 612 | sprintf( |
613 | 613 | __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
614 | 614 | 'event_espresso'), |
@@ -644,11 +644,11 @@ discard block |
||
644 | 644 | do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
645 | 645 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
646 | 646 | // add notice if message exists |
647 | - if (! empty($msg)) { |
|
647 | + if ( ! empty($msg)) { |
|
648 | 648 | // get error code |
649 | 649 | $notice_code = EE_Error::generate_error_code($file, $func, $line); |
650 | 650 | if (WP_DEBUG && $type === 'errors') { |
651 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
651 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
652 | 652 | } |
653 | 653 | // add notice. Index by code if it's not blank |
654 | 654 | if ($notice_code) { |
@@ -789,13 +789,13 @@ discard block |
||
789 | 789 | if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
790 | 790 | // combine messages |
791 | 791 | $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
792 | - $print_scripts = true; |
|
792 | + $print_scripts = true; |
|
793 | 793 | } |
794 | 794 | // check for attention messages |
795 | 795 | if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
796 | 796 | // combine messages |
797 | 797 | $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
798 | - $print_scripts = true; |
|
798 | + $print_scripts = true; |
|
799 | 799 | } |
800 | 800 | // check for error messages |
801 | 801 | if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
@@ -804,7 +804,7 @@ discard block |
||
804 | 804 | : __('An error has occurred:<br />', 'event_espresso'); |
805 | 805 | // combine messages |
806 | 806 | $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
807 | - $print_scripts = true; |
|
807 | + $print_scripts = true; |
|
808 | 808 | } |
809 | 809 | if ($format_output) { |
810 | 810 | |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | */ |
887 | 887 | private static function _print_scripts($force_print = false) |
888 | 888 | { |
889 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
889 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
890 | 890 | if (wp_script_is('ee_error_js', 'enqueued')) { |
891 | 891 | return ''; |
892 | 892 | } |
@@ -900,12 +900,12 @@ discard block |
||
900 | 900 | return ' |
901 | 901 | <script> |
902 | 902 | /* <![CDATA[ */ |
903 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
903 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
904 | 904 | /* ]]> */ |
905 | 905 | </script> |
906 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
907 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
908 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
906 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
907 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
908 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
909 | 909 | '; |
910 | 910 | } |
911 | 911 | return ''; |
@@ -936,8 +936,8 @@ discard block |
||
936 | 936 | { |
937 | 937 | $file = explode('.', basename($file)); |
938 | 938 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
939 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
940 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
939 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
940 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
941 | 941 | return $error_code; |
942 | 942 | } |
943 | 943 | |
@@ -956,18 +956,18 @@ discard block |
||
956 | 956 | if (empty($ex)) { |
957 | 957 | return; |
958 | 958 | } |
959 | - if (! $time) { |
|
959 | + if ( ! $time) { |
|
960 | 960 | $time = time(); |
961 | 961 | } |
962 | 962 | $exception_log = '----------------------------------------------------------------------------------------' |
963 | 963 | . PHP_EOL; |
964 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
965 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
966 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
967 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
968 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
969 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
970 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
964 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
965 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
966 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
967 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
968 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
969 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
970 | + $exception_log .= $ex['string'].PHP_EOL; |
|
971 | 971 | $exception_log .= '----------------------------------------------------------------------------------------' |
972 | 972 | . PHP_EOL; |
973 | 973 | try { |
@@ -975,15 +975,15 @@ discard block |
||
975 | 975 | . 'logs' |
976 | 976 | . DS |
977 | 977 | . self::$_exception_log_file); |
978 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs'); |
|
979 | - if (! $clear) { |
|
978 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs'); |
|
979 | + if ( ! $clear) { |
|
980 | 980 | //get existing log file and append new log info |
981 | 981 | $exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR |
982 | 982 | . 'logs' |
983 | 983 | . DS |
984 | - . self::$_exception_log_file) . $exception_log; |
|
984 | + . self::$_exception_log_file).$exception_log; |
|
985 | 985 | } |
986 | - EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, |
|
986 | + EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file, |
|
987 | 987 | $exception_log); |
988 | 988 | } catch (EE_Error $e) { |
989 | 989 | EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
@@ -1153,14 +1153,14 @@ discard block |
||
1153 | 1153 | // js for error handling |
1154 | 1154 | wp_register_script( |
1155 | 1155 | 'espresso_core', |
1156 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1156 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
1157 | 1157 | array('jquery'), |
1158 | 1158 | EVENT_ESPRESSO_VERSION, |
1159 | 1159 | false |
1160 | 1160 | ); |
1161 | 1161 | wp_register_script( |
1162 | 1162 | 'ee_error_js', |
1163 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1163 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
1164 | 1164 | array('espresso_core'), |
1165 | 1165 | EVENT_ESPRESSO_VERSION, |
1166 | 1166 | false |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | // if you're a dev and want to receive all errors via email |
12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -28,253 +28,253 @@ discard block |
||
28 | 28 | { |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * name of the file to log exceptions to |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
37 | - |
|
38 | - /** |
|
39 | - * stores details for all exception |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - private static $_all_exceptions = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * tracks number of errors |
|
47 | - * |
|
48 | - * @var int |
|
49 | - */ |
|
50 | - private static $_error_count = 0; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array $_espresso_notices |
|
54 | - */ |
|
55 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @override default exception handling |
|
61 | - * @param string $message |
|
62 | - * @param int $code |
|
63 | - * @param Exception|null $previous |
|
64 | - */ |
|
65 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
66 | - { |
|
67 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
68 | - parent::__construct($message, $code); |
|
69 | - } else { |
|
70 | - parent::__construct($message, $code, $previous); |
|
71 | - } |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * error_handler |
|
78 | - * |
|
79 | - * @param $code |
|
80 | - * @param $message |
|
81 | - * @param $file |
|
82 | - * @param $line |
|
83 | - * @return void |
|
84 | - */ |
|
85 | - public static function error_handler($code, $message, $file, $line) |
|
86 | - { |
|
87 | - $type = EE_Error::error_type($code); |
|
88 | - $site = site_url(); |
|
89 | - switch ($site) { |
|
90 | - case 'http://ee4.eventespresso.com/' : |
|
91 | - case 'http://ee4decaf.eventespresso.com/' : |
|
92 | - case 'http://ee4hf.eventespresso.com/' : |
|
93 | - case 'http://ee4a.eventespresso.com/' : |
|
94 | - case 'http://ee4ad.eventespresso.com/' : |
|
95 | - case 'http://ee4b.eventespresso.com/' : |
|
96 | - case 'http://ee4bd.eventespresso.com/' : |
|
97 | - case 'http://ee4d.eventespresso.com/' : |
|
98 | - case 'http://ee4dd.eventespresso.com/' : |
|
99 | - $to = '[email protected]'; |
|
100 | - break; |
|
101 | - default : |
|
102 | - $to = get_option('admin_email'); |
|
103 | - } |
|
104 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
105 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
106 | - if (function_exists('wp_mail')) { |
|
107 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
108 | - wp_mail($to, $subject, $msg); |
|
109 | - } |
|
110 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
111 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
112 | - echo '<br /></p></div>'; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * error_type |
|
119 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
120 | - * |
|
121 | - * @param $code |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public static function error_type($code) |
|
125 | - { |
|
126 | - switch ($code) { |
|
127 | - case E_ERROR: // 1 // |
|
128 | - return 'E_ERROR'; |
|
129 | - case E_WARNING: // 2 // |
|
130 | - return 'E_WARNING'; |
|
131 | - case E_PARSE: // 4 // |
|
132 | - return 'E_PARSE'; |
|
133 | - case E_NOTICE: // 8 // |
|
134 | - return 'E_NOTICE'; |
|
135 | - case E_CORE_ERROR: // 16 // |
|
136 | - return 'E_CORE_ERROR'; |
|
137 | - case E_CORE_WARNING: // 32 // |
|
138 | - return 'E_CORE_WARNING'; |
|
139 | - case E_COMPILE_ERROR: // 64 // |
|
140 | - return 'E_COMPILE_ERROR'; |
|
141 | - case E_COMPILE_WARNING: // 128 // |
|
142 | - return 'E_COMPILE_WARNING'; |
|
143 | - case E_USER_ERROR: // 256 // |
|
144 | - return 'E_USER_ERROR'; |
|
145 | - case E_USER_WARNING: // 512 // |
|
146 | - return 'E_USER_WARNING'; |
|
147 | - case E_USER_NOTICE: // 1024 // |
|
148 | - return 'E_USER_NOTICE'; |
|
149 | - case E_STRICT: // 2048 // |
|
150 | - return 'E_STRICT'; |
|
151 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
152 | - return 'E_RECOVERABLE_ERROR'; |
|
153 | - case E_DEPRECATED: // 8192 // |
|
154 | - return 'E_DEPRECATED'; |
|
155 | - case E_USER_DEPRECATED: // 16384 // |
|
156 | - return 'E_USER_DEPRECATED'; |
|
157 | - case E_ALL: // 16384 // |
|
158 | - return 'E_ALL'; |
|
159 | - } |
|
160 | - return ''; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * fatal_error_handler |
|
167 | - * |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - public static function fatal_error_handler() |
|
171 | - { |
|
172 | - $last_error = error_get_last(); |
|
173 | - if ($last_error['type'] === E_ERROR) { |
|
174 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * _format_error |
|
182 | - * |
|
183 | - * @param $code |
|
184 | - * @param $message |
|
185 | - * @param $file |
|
186 | - * @param $line |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - private static function _format_error($code, $message, $file, $line) |
|
190 | - { |
|
191 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
192 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
193 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
194 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
195 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
196 | - $html .= '</tbody></table>'; |
|
197 | - return $html; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * set_content_type |
|
204 | - * |
|
205 | - * @param $content_type |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public static function set_content_type($content_type) |
|
209 | - { |
|
210 | - return 'text/html'; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * @return void |
|
217 | - * @throws EE_Error |
|
218 | - * @throws ReflectionException |
|
219 | - */ |
|
220 | - public function get_error() |
|
221 | - { |
|
222 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
223 | - throw $this; |
|
224 | - } |
|
225 | - // get separate user and developer messages if they exist |
|
226 | - $msg = explode('||', $this->getMessage()); |
|
227 | - $user_msg = $msg[0]; |
|
228 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
229 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
230 | - // add details to _all_exceptions array |
|
231 | - $x_time = time(); |
|
232 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
233 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
234 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
235 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
236 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
237 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
238 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
239 | - self::$_error_count++; |
|
240 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
241 | - $this->display_errors(); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @param bool $check_stored |
|
248 | - * @param string $type_to_check |
|
249 | - * @return bool |
|
250 | - */ |
|
251 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
252 | - { |
|
253 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
254 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
255 | - ? true |
|
256 | - : false; |
|
257 | - if ($check_stored && ! $has_error) { |
|
258 | - $notices = (array)get_option('ee_notices', array()); |
|
259 | - foreach ($notices as $type => $notice) { |
|
260 | - if ($type === $type_to_check && $notice) { |
|
261 | - return true; |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
265 | - return $has_error; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * @echo string |
|
272 | - * @throws \ReflectionException |
|
273 | - */ |
|
274 | - public function display_errors() |
|
275 | - { |
|
276 | - $trace_details = ''; |
|
277 | - $output = ' |
|
31 | + /** |
|
32 | + * name of the file to log exceptions to |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
37 | + |
|
38 | + /** |
|
39 | + * stores details for all exception |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + private static $_all_exceptions = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * tracks number of errors |
|
47 | + * |
|
48 | + * @var int |
|
49 | + */ |
|
50 | + private static $_error_count = 0; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array $_espresso_notices |
|
54 | + */ |
|
55 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @override default exception handling |
|
61 | + * @param string $message |
|
62 | + * @param int $code |
|
63 | + * @param Exception|null $previous |
|
64 | + */ |
|
65 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
66 | + { |
|
67 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
68 | + parent::__construct($message, $code); |
|
69 | + } else { |
|
70 | + parent::__construct($message, $code, $previous); |
|
71 | + } |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * error_handler |
|
78 | + * |
|
79 | + * @param $code |
|
80 | + * @param $message |
|
81 | + * @param $file |
|
82 | + * @param $line |
|
83 | + * @return void |
|
84 | + */ |
|
85 | + public static function error_handler($code, $message, $file, $line) |
|
86 | + { |
|
87 | + $type = EE_Error::error_type($code); |
|
88 | + $site = site_url(); |
|
89 | + switch ($site) { |
|
90 | + case 'http://ee4.eventespresso.com/' : |
|
91 | + case 'http://ee4decaf.eventespresso.com/' : |
|
92 | + case 'http://ee4hf.eventespresso.com/' : |
|
93 | + case 'http://ee4a.eventespresso.com/' : |
|
94 | + case 'http://ee4ad.eventespresso.com/' : |
|
95 | + case 'http://ee4b.eventespresso.com/' : |
|
96 | + case 'http://ee4bd.eventespresso.com/' : |
|
97 | + case 'http://ee4d.eventespresso.com/' : |
|
98 | + case 'http://ee4dd.eventespresso.com/' : |
|
99 | + $to = '[email protected]'; |
|
100 | + break; |
|
101 | + default : |
|
102 | + $to = get_option('admin_email'); |
|
103 | + } |
|
104 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
105 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
106 | + if (function_exists('wp_mail')) { |
|
107 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
108 | + wp_mail($to, $subject, $msg); |
|
109 | + } |
|
110 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
111 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
112 | + echo '<br /></p></div>'; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * error_type |
|
119 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
120 | + * |
|
121 | + * @param $code |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public static function error_type($code) |
|
125 | + { |
|
126 | + switch ($code) { |
|
127 | + case E_ERROR: // 1 // |
|
128 | + return 'E_ERROR'; |
|
129 | + case E_WARNING: // 2 // |
|
130 | + return 'E_WARNING'; |
|
131 | + case E_PARSE: // 4 // |
|
132 | + return 'E_PARSE'; |
|
133 | + case E_NOTICE: // 8 // |
|
134 | + return 'E_NOTICE'; |
|
135 | + case E_CORE_ERROR: // 16 // |
|
136 | + return 'E_CORE_ERROR'; |
|
137 | + case E_CORE_WARNING: // 32 // |
|
138 | + return 'E_CORE_WARNING'; |
|
139 | + case E_COMPILE_ERROR: // 64 // |
|
140 | + return 'E_COMPILE_ERROR'; |
|
141 | + case E_COMPILE_WARNING: // 128 // |
|
142 | + return 'E_COMPILE_WARNING'; |
|
143 | + case E_USER_ERROR: // 256 // |
|
144 | + return 'E_USER_ERROR'; |
|
145 | + case E_USER_WARNING: // 512 // |
|
146 | + return 'E_USER_WARNING'; |
|
147 | + case E_USER_NOTICE: // 1024 // |
|
148 | + return 'E_USER_NOTICE'; |
|
149 | + case E_STRICT: // 2048 // |
|
150 | + return 'E_STRICT'; |
|
151 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
152 | + return 'E_RECOVERABLE_ERROR'; |
|
153 | + case E_DEPRECATED: // 8192 // |
|
154 | + return 'E_DEPRECATED'; |
|
155 | + case E_USER_DEPRECATED: // 16384 // |
|
156 | + return 'E_USER_DEPRECATED'; |
|
157 | + case E_ALL: // 16384 // |
|
158 | + return 'E_ALL'; |
|
159 | + } |
|
160 | + return ''; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * fatal_error_handler |
|
167 | + * |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + public static function fatal_error_handler() |
|
171 | + { |
|
172 | + $last_error = error_get_last(); |
|
173 | + if ($last_error['type'] === E_ERROR) { |
|
174 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * _format_error |
|
182 | + * |
|
183 | + * @param $code |
|
184 | + * @param $message |
|
185 | + * @param $file |
|
186 | + * @param $line |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + private static function _format_error($code, $message, $file, $line) |
|
190 | + { |
|
191 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
192 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
193 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
194 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
195 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
196 | + $html .= '</tbody></table>'; |
|
197 | + return $html; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * set_content_type |
|
204 | + * |
|
205 | + * @param $content_type |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public static function set_content_type($content_type) |
|
209 | + { |
|
210 | + return 'text/html'; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * @return void |
|
217 | + * @throws EE_Error |
|
218 | + * @throws ReflectionException |
|
219 | + */ |
|
220 | + public function get_error() |
|
221 | + { |
|
222 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
223 | + throw $this; |
|
224 | + } |
|
225 | + // get separate user and developer messages if they exist |
|
226 | + $msg = explode('||', $this->getMessage()); |
|
227 | + $user_msg = $msg[0]; |
|
228 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
229 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
230 | + // add details to _all_exceptions array |
|
231 | + $x_time = time(); |
|
232 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
233 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
234 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
235 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
236 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
237 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
238 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
239 | + self::$_error_count++; |
|
240 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
241 | + $this->display_errors(); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @param bool $check_stored |
|
248 | + * @param string $type_to_check |
|
249 | + * @return bool |
|
250 | + */ |
|
251 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
252 | + { |
|
253 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
254 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
255 | + ? true |
|
256 | + : false; |
|
257 | + if ($check_stored && ! $has_error) { |
|
258 | + $notices = (array)get_option('ee_notices', array()); |
|
259 | + foreach ($notices as $type => $notice) { |
|
260 | + if ($type === $type_to_check && $notice) { |
|
261 | + return true; |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | + return $has_error; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * @echo string |
|
272 | + * @throws \ReflectionException |
|
273 | + */ |
|
274 | + public function display_errors() |
|
275 | + { |
|
276 | + $trace_details = ''; |
|
277 | + $output = ' |
|
278 | 278 | <style type="text/css"> |
279 | 279 | #ee-error-message { |
280 | 280 | max-width:90% !important; |
@@ -330,21 +330,21 @@ discard block |
||
330 | 330 | } |
331 | 331 | </style> |
332 | 332 | <div id="ee-error-message" class="error">'; |
333 | - if (! WP_DEBUG) { |
|
334 | - $output .= ' |
|
333 | + if (! WP_DEBUG) { |
|
334 | + $output .= ' |
|
335 | 335 | <p>'; |
336 | - } |
|
337 | - // cycle thru errors |
|
338 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
339 | - $error_code = ''; |
|
340 | - // process trace info |
|
341 | - if (empty($ex['trace'])) { |
|
342 | - $trace_details .= __( |
|
343 | - 'Sorry, but no trace information was available for this exception.', |
|
344 | - 'event_espresso' |
|
345 | - ); |
|
346 | - } else { |
|
347 | - $trace_details .= ' |
|
336 | + } |
|
337 | + // cycle thru errors |
|
338 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
339 | + $error_code = ''; |
|
340 | + // process trace info |
|
341 | + if (empty($ex['trace'])) { |
|
342 | + $trace_details .= __( |
|
343 | + 'Sorry, but no trace information was available for this exception.', |
|
344 | + 'event_espresso' |
|
345 | + ); |
|
346 | + } else { |
|
347 | + $trace_details .= ' |
|
348 | 348 | <div id="ee-trace-details"> |
349 | 349 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
350 | 350 | <tr> |
@@ -354,43 +354,43 @@ discard block |
||
354 | 354 | <th scope="col" align="left">Class</th> |
355 | 355 | <th scope="col" align="left">Method( arguments )</th> |
356 | 356 | </tr>'; |
357 | - $last_on_stack = count($ex['trace']) - 1; |
|
358 | - // reverse array so that stack is in proper chronological order |
|
359 | - $sorted_trace = array_reverse($ex['trace']); |
|
360 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
361 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
362 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
363 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
364 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
365 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
366 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
367 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
368 | - if (empty($file) && ! empty($class)) { |
|
369 | - $a = new ReflectionClass($class); |
|
370 | - $file = $a->getFileName(); |
|
371 | - if (empty($line) && ! empty($function)) { |
|
372 | - try { |
|
373 | - //if $function is a closure, this throws an exception |
|
374 | - $b = new ReflectionMethod($class, $function); |
|
375 | - $line = $b->getStartLine(); |
|
376 | - } catch (Exception $closure_exception) { |
|
377 | - $line = 'unknown'; |
|
378 | - } |
|
379 | - } |
|
380 | - } |
|
381 | - if ($nmbr === $last_on_stack) { |
|
382 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
383 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
384 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
385 | - } |
|
386 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
387 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
388 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
389 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
390 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
391 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
392 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
393 | - $trace_details .= ' |
|
357 | + $last_on_stack = count($ex['trace']) - 1; |
|
358 | + // reverse array so that stack is in proper chronological order |
|
359 | + $sorted_trace = array_reverse($ex['trace']); |
|
360 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
361 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
362 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
363 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
364 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
365 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
366 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
367 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
368 | + if (empty($file) && ! empty($class)) { |
|
369 | + $a = new ReflectionClass($class); |
|
370 | + $file = $a->getFileName(); |
|
371 | + if (empty($line) && ! empty($function)) { |
|
372 | + try { |
|
373 | + //if $function is a closure, this throws an exception |
|
374 | + $b = new ReflectionMethod($class, $function); |
|
375 | + $line = $b->getStartLine(); |
|
376 | + } catch (Exception $closure_exception) { |
|
377 | + $line = 'unknown'; |
|
378 | + } |
|
379 | + } |
|
380 | + } |
|
381 | + if ($nmbr === $last_on_stack) { |
|
382 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
383 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
384 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
385 | + } |
|
386 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
387 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
388 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
389 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
390 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
391 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
392 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
393 | + $trace_details .= ' |
|
394 | 394 | <tr> |
395 | 395 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
396 | 396 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -398,516 +398,516 @@ discard block |
||
398 | 398 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
399 | 399 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
400 | 400 | </tr>'; |
401 | - } |
|
402 | - $trace_details .= ' |
|
401 | + } |
|
402 | + $trace_details .= ' |
|
403 | 403 | </table> |
404 | 404 | </div>'; |
405 | - } |
|
406 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
407 | - // add generic non-identifying messages for non-privileged users |
|
408 | - if (! WP_DEBUG) { |
|
409 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
410 | - . trim($ex['msg']) |
|
411 | - . '</span> <sup>' |
|
412 | - . $ex['code'] |
|
413 | - . '</sup><br />'; |
|
414 | - } else { |
|
415 | - // or helpful developer messages if debugging is on |
|
416 | - $output .= ' |
|
405 | + } |
|
406 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
407 | + // add generic non-identifying messages for non-privileged users |
|
408 | + if (! WP_DEBUG) { |
|
409 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
410 | + . trim($ex['msg']) |
|
411 | + . '</span> <sup>' |
|
412 | + . $ex['code'] |
|
413 | + . '</sup><br />'; |
|
414 | + } else { |
|
415 | + // or helpful developer messages if debugging is on |
|
416 | + $output .= ' |
|
417 | 417 | <div class="ee-error-dev-msg-dv"> |
418 | 418 | <p class="ee-error-dev-msg-pg"> |
419 | 419 | <strong class="ee-error-dev-msg-str">An ' |
420 | - . $ex['name'] |
|
421 | - . ' exception was thrown!</strong> <span>code: ' |
|
422 | - . $ex['code'] |
|
423 | - . '</span><br /> |
|
420 | + . $ex['name'] |
|
421 | + . ' exception was thrown!</strong> <span>code: ' |
|
422 | + . $ex['code'] |
|
423 | + . '</span><br /> |
|
424 | 424 | <span class="big-text">"' |
425 | - . trim($ex['msg']) |
|
426 | - . '"</span><br/> |
|
425 | + . trim($ex['msg']) |
|
426 | + . '"</span><br/> |
|
427 | 427 | <a id="display-ee-error-trace-' |
428 | - . self::$_error_count |
|
429 | - . $time |
|
430 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
431 | - . self::$_error_count |
|
432 | - . $time |
|
433 | - . '"> |
|
428 | + . self::$_error_count |
|
429 | + . $time |
|
430 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
431 | + . self::$_error_count |
|
432 | + . $time |
|
433 | + . '"> |
|
434 | 434 | ' |
435 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
436 | - . ' |
|
435 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
436 | + . ' |
|
437 | 437 | </a><br /> |
438 | 438 | <span class="small-text lt-grey-text">' |
439 | - . $ex['file'] |
|
440 | - . ' ( line no: ' |
|
441 | - . $ex['line'] |
|
442 | - . ' )</span> |
|
439 | + . $ex['file'] |
|
440 | + . ' ( line no: ' |
|
441 | + . $ex['line'] |
|
442 | + . ' )</span> |
|
443 | 443 | </p> |
444 | 444 | <div id="ee-error-trace-' |
445 | - . self::$_error_count |
|
446 | - . $time |
|
447 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
445 | + . self::$_error_count |
|
446 | + . $time |
|
447 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
448 | 448 | ' |
449 | - . $trace_details; |
|
450 | - if (! empty($class)) { |
|
451 | - $output .= ' |
|
449 | + . $trace_details; |
|
450 | + if (! empty($class)) { |
|
451 | + $output .= ' |
|
452 | 452 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
453 | 453 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
454 | 454 | <h3>Class Details</h3>'; |
455 | - $a = new ReflectionClass($class); |
|
456 | - $output .= ' |
|
455 | + $a = new ReflectionClass($class); |
|
456 | + $output .= ' |
|
457 | 457 | <pre>' . $a . '</pre> |
458 | 458 | </div> |
459 | 459 | </div>'; |
460 | - } |
|
461 | - $output .= ' |
|
460 | + } |
|
461 | + $output .= ' |
|
462 | 462 | </div> |
463 | 463 | </div> |
464 | 464 | <br />'; |
465 | - } |
|
466 | - $this->write_to_error_log($time, $ex); |
|
467 | - } |
|
468 | - // remove last linebreak |
|
469 | - $output = substr($output, 0, -6); |
|
470 | - if (! WP_DEBUG) { |
|
471 | - $output .= ' |
|
465 | + } |
|
466 | + $this->write_to_error_log($time, $ex); |
|
467 | + } |
|
468 | + // remove last linebreak |
|
469 | + $output = substr($output, 0, -6); |
|
470 | + if (! WP_DEBUG) { |
|
471 | + $output .= ' |
|
472 | 472 | </p>'; |
473 | - } |
|
474 | - $output .= ' |
|
473 | + } |
|
474 | + $output .= ' |
|
475 | 475 | </div>'; |
476 | - $output .= self::_print_scripts(true); |
|
477 | - if (defined('DOING_AJAX')) { |
|
478 | - echo wp_json_encode(array('error' => $output)); |
|
479 | - exit(); |
|
480 | - } |
|
481 | - echo $output; |
|
482 | - die(); |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * generate string from exception trace args |
|
489 | - * |
|
490 | - * @param array $arguments |
|
491 | - * @param bool $array |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
495 | - { |
|
496 | - $arg_string = ''; |
|
497 | - if (! empty($arguments)) { |
|
498 | - $args = array(); |
|
499 | - foreach ($arguments as $arg) { |
|
500 | - if (! empty($arg)) { |
|
501 | - if (is_string($arg)) { |
|
502 | - $args[] = " '" . $arg . "'"; |
|
503 | - } elseif (is_array($arg)) { |
|
504 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
505 | - } elseif ($arg === null) { |
|
506 | - $args[] = ' NULL'; |
|
507 | - } elseif (is_bool($arg)) { |
|
508 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
509 | - } elseif (is_object($arg)) { |
|
510 | - $args[] = ' OBJECT ' . get_class($arg); |
|
511 | - } elseif (is_resource($arg)) { |
|
512 | - $args[] = get_resource_type($arg); |
|
513 | - } else { |
|
514 | - $args[] = $arg; |
|
515 | - } |
|
516 | - } |
|
517 | - } |
|
518 | - $arg_string = implode(', ', $args); |
|
519 | - } |
|
520 | - if ($array) { |
|
521 | - $arg_string .= ' )'; |
|
522 | - } |
|
523 | - return $arg_string; |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * add error message |
|
530 | - * |
|
531 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
532 | - * separate messages for user || dev |
|
533 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
534 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
535 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
536 | - * @return void |
|
537 | - */ |
|
538 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
539 | - { |
|
540 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
541 | - self::$_error_count++; |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
548 | - * adds an error |
|
549 | - * |
|
550 | - * @param string $msg |
|
551 | - * @param string $file |
|
552 | - * @param string $func |
|
553 | - * @param string $line |
|
554 | - * @throws EE_Error |
|
555 | - */ |
|
556 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
557 | - { |
|
558 | - if (WP_DEBUG) { |
|
559 | - throw new EE_Error($msg); |
|
560 | - } |
|
561 | - EE_Error::add_error($msg, $file, $func, $line); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * add success message |
|
568 | - * |
|
569 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
570 | - * separate messages for user || dev |
|
571 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
572 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
573 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
574 | - * @return void |
|
575 | - */ |
|
576 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
577 | - { |
|
578 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * add attention message |
|
585 | - * |
|
586 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
587 | - * separate messages for user || dev |
|
588 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
589 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
590 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
591 | - * @return void |
|
592 | - */ |
|
593 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
594 | - { |
|
595 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * @param string $type whether the message is for a success or error notification |
|
602 | - * @param string $msg the message to display to users or developers |
|
603 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
604 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
605 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
606 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
607 | - * @return void |
|
608 | - */ |
|
609 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
610 | - { |
|
611 | - if (empty($msg)) { |
|
612 | - EE_Error::doing_it_wrong( |
|
613 | - 'EE_Error::add_' . $type . '()', |
|
614 | - sprintf( |
|
615 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
616 | - 'event_espresso'), |
|
617 | - $type, |
|
618 | - $file, |
|
619 | - $line |
|
620 | - ), |
|
621 | - EVENT_ESPRESSO_VERSION |
|
622 | - ); |
|
623 | - } |
|
624 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
625 | - EE_Error::doing_it_wrong( |
|
626 | - 'EE_Error::add_error()', |
|
627 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
628 | - 'event_espresso'), |
|
629 | - EVENT_ESPRESSO_VERSION |
|
630 | - ); |
|
631 | - } |
|
632 | - // get separate user and developer messages if they exist |
|
633 | - $msg = explode('||', $msg); |
|
634 | - $user_msg = $msg[0]; |
|
635 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
636 | - /** |
|
637 | - * Do an action so other code can be triggered when a notice is created |
|
638 | - * |
|
639 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
640 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
641 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
642 | - * @param string $file file where error was generated |
|
643 | - * @param string $func function where error was generated |
|
644 | - * @param string $line line where error was generated |
|
645 | - */ |
|
646 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
647 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
648 | - // add notice if message exists |
|
649 | - if (! empty($msg)) { |
|
650 | - // get error code |
|
651 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
652 | - if (WP_DEBUG && $type === 'errors') { |
|
653 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
654 | - } |
|
655 | - // add notice. Index by code if it's not blank |
|
656 | - if ($notice_code) { |
|
657 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
658 | - } else { |
|
659 | - self::$_espresso_notices[$type][] = $msg; |
|
660 | - } |
|
661 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
662 | - } |
|
663 | - } |
|
664 | - |
|
665 | - |
|
666 | - /** |
|
667 | - * in some case it may be necessary to overwrite the existing success messages |
|
668 | - * |
|
669 | - * @return void |
|
670 | - */ |
|
671 | - public static function overwrite_success() |
|
672 | - { |
|
673 | - self::$_espresso_notices['success'] = false; |
|
674 | - } |
|
675 | - |
|
676 | - |
|
677 | - |
|
678 | - /** |
|
679 | - * in some case it may be necessary to overwrite the existing attention messages |
|
680 | - * |
|
681 | - * @return void |
|
682 | - */ |
|
683 | - public static function overwrite_attention() |
|
684 | - { |
|
685 | - self::$_espresso_notices['attention'] = false; |
|
686 | - } |
|
687 | - |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * in some case it may be necessary to overwrite the existing error messages |
|
692 | - * |
|
693 | - * @return void |
|
694 | - */ |
|
695 | - public static function overwrite_errors() |
|
696 | - { |
|
697 | - self::$_espresso_notices['errors'] = false; |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * @return void |
|
704 | - */ |
|
705 | - public static function reset_notices() |
|
706 | - { |
|
707 | - self::$_espresso_notices['success'] = false; |
|
708 | - self::$_espresso_notices['attention'] = false; |
|
709 | - self::$_espresso_notices['errors'] = false; |
|
710 | - } |
|
711 | - |
|
712 | - |
|
713 | - |
|
714 | - /** |
|
715 | - * @return int |
|
716 | - */ |
|
717 | - public static function has_notices() |
|
718 | - { |
|
719 | - $has_notices = 0; |
|
720 | - // check for success messages |
|
721 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
722 | - ? 3 |
|
723 | - : $has_notices; |
|
724 | - // check for attention messages |
|
725 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
726 | - ? 2 |
|
727 | - : $has_notices; |
|
728 | - // check for error messages |
|
729 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
730 | - ? 1 |
|
731 | - : $has_notices; |
|
732 | - return $has_notices; |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
738 | - * |
|
739 | - * @since 4.9.0 |
|
740 | - * @return array |
|
741 | - */ |
|
742 | - public static function get_vanilla_notices() |
|
743 | - { |
|
744 | - return array( |
|
745 | - 'success' => isset(self::$_espresso_notices['success']) |
|
746 | - ? self::$_espresso_notices['success'] |
|
747 | - : array(), |
|
748 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
749 | - ? self::$_espresso_notices['attention'] |
|
750 | - : array(), |
|
751 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
752 | - ? self::$_espresso_notices['errors'] |
|
753 | - : array(), |
|
754 | - ); |
|
755 | - } |
|
756 | - |
|
757 | - |
|
758 | - |
|
759 | - /** |
|
760 | - * compile all error or success messages into one string |
|
761 | - * |
|
762 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
763 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
764 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
765 | - * - ONLY do this just before redirecting |
|
766 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
767 | - * @return array |
|
768 | - */ |
|
769 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
770 | - { |
|
771 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
772 | - $success_messages = ''; |
|
773 | - $attention_messages = ''; |
|
774 | - $error_messages = ''; |
|
775 | - $print_scripts = false; |
|
776 | - // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
777 | - // either save notices to the db |
|
778 | - if ($save_to_transient) { |
|
779 | - update_option('ee_notices', self::$_espresso_notices); |
|
780 | - return array(); |
|
781 | - } |
|
782 | - // grab any notices that have been previously saved |
|
783 | - if ($notices = get_option('ee_notices', false)) { |
|
784 | - foreach ($notices as $type => $notice) { |
|
785 | - if (is_array($notice) && ! empty($notice)) { |
|
786 | - // make sure that existing notice type is an array |
|
787 | - self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
788 | - && ! empty(self::$_espresso_notices[$type]) |
|
789 | - ? self::$_espresso_notices[$type] : array(); |
|
790 | - // merge stored notices with any newly created ones |
|
791 | - self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
792 | - $print_scripts = true; |
|
793 | - } |
|
794 | - } |
|
795 | - // now clear any stored notices |
|
796 | - update_option('ee_notices', false); |
|
797 | - } |
|
798 | - // check for success messages |
|
799 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
800 | - // combine messages |
|
801 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
802 | - $print_scripts = true; |
|
803 | - } |
|
804 | - // check for attention messages |
|
805 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
806 | - // combine messages |
|
807 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
808 | - $print_scripts = true; |
|
809 | - } |
|
810 | - // check for error messages |
|
811 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
812 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
813 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
814 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
815 | - // combine messages |
|
816 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
817 | - $print_scripts = true; |
|
818 | - } |
|
819 | - if ($format_output) { |
|
820 | - |
|
821 | - $notices = '<div id="espresso-notices">'; |
|
822 | - $close = is_admin() ? '' |
|
823 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
824 | - if ($success_messages !== '') { |
|
825 | - $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
826 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
827 | - //showMessage( $success_messages ); |
|
828 | - $notices .= '<div id="' |
|
829 | - . $css_id |
|
830 | - . '" class="espresso-notices ' |
|
831 | - . $css_class |
|
832 | - . '" style="display:none;"><p>' |
|
833 | - . $success_messages |
|
834 | - . '</p>' |
|
835 | - . $close |
|
836 | - . '</div>'; |
|
837 | - } |
|
838 | - if ($attention_messages !== '') { |
|
839 | - $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
840 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
841 | - //showMessage( $error_messages, TRUE ); |
|
842 | - $notices .= '<div id="' |
|
843 | - . $css_id |
|
844 | - . '" class="espresso-notices ' |
|
845 | - . $css_class |
|
846 | - . '" style="display:none;"><p>' |
|
847 | - . $attention_messages |
|
848 | - . '</p>' |
|
849 | - . $close |
|
850 | - . '</div>'; |
|
851 | - } |
|
852 | - if ($error_messages !== '') { |
|
853 | - $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
854 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
855 | - //showMessage( $error_messages, TRUE ); |
|
856 | - $notices .= '<div id="' |
|
857 | - . $css_id |
|
858 | - . '" class="espresso-notices ' |
|
859 | - . $css_class |
|
860 | - . '" style="display:none;"><p>' |
|
861 | - . $error_messages |
|
862 | - . '</p>' |
|
863 | - . $close |
|
864 | - . '</div>'; |
|
865 | - } |
|
866 | - $notices .= '</div>'; |
|
867 | - } else { |
|
868 | - |
|
869 | - $notices = array( |
|
870 | - 'success' => $success_messages, |
|
871 | - 'attention' => $attention_messages, |
|
872 | - 'errors' => $error_messages, |
|
873 | - ); |
|
874 | - if ($remove_empty) { |
|
875 | - // remove empty notices |
|
876 | - foreach ($notices as $type => $notice) { |
|
877 | - if (empty($notice)) { |
|
878 | - unset($notices[$type]); |
|
879 | - } |
|
880 | - } |
|
881 | - } |
|
882 | - } |
|
883 | - if ($print_scripts) { |
|
884 | - self::_print_scripts(); |
|
885 | - } |
|
886 | - return $notices; |
|
887 | - } |
|
888 | - |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * _print_scripts |
|
893 | - * |
|
894 | - * @param bool $force_print |
|
895 | - * @return string |
|
896 | - */ |
|
897 | - private static function _print_scripts($force_print = false) |
|
898 | - { |
|
899 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
900 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
901 | - return ''; |
|
902 | - } |
|
903 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
904 | - wp_enqueue_style('espresso_default'); |
|
905 | - wp_enqueue_style('espresso_custom_css'); |
|
906 | - wp_enqueue_script('ee_error_js'); |
|
907 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
908 | - } |
|
909 | - } else { |
|
910 | - return ' |
|
476 | + $output .= self::_print_scripts(true); |
|
477 | + if (defined('DOING_AJAX')) { |
|
478 | + echo wp_json_encode(array('error' => $output)); |
|
479 | + exit(); |
|
480 | + } |
|
481 | + echo $output; |
|
482 | + die(); |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * generate string from exception trace args |
|
489 | + * |
|
490 | + * @param array $arguments |
|
491 | + * @param bool $array |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
495 | + { |
|
496 | + $arg_string = ''; |
|
497 | + if (! empty($arguments)) { |
|
498 | + $args = array(); |
|
499 | + foreach ($arguments as $arg) { |
|
500 | + if (! empty($arg)) { |
|
501 | + if (is_string($arg)) { |
|
502 | + $args[] = " '" . $arg . "'"; |
|
503 | + } elseif (is_array($arg)) { |
|
504 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
505 | + } elseif ($arg === null) { |
|
506 | + $args[] = ' NULL'; |
|
507 | + } elseif (is_bool($arg)) { |
|
508 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
509 | + } elseif (is_object($arg)) { |
|
510 | + $args[] = ' OBJECT ' . get_class($arg); |
|
511 | + } elseif (is_resource($arg)) { |
|
512 | + $args[] = get_resource_type($arg); |
|
513 | + } else { |
|
514 | + $args[] = $arg; |
|
515 | + } |
|
516 | + } |
|
517 | + } |
|
518 | + $arg_string = implode(', ', $args); |
|
519 | + } |
|
520 | + if ($array) { |
|
521 | + $arg_string .= ' )'; |
|
522 | + } |
|
523 | + return $arg_string; |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * add error message |
|
530 | + * |
|
531 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
532 | + * separate messages for user || dev |
|
533 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
534 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
535 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
536 | + * @return void |
|
537 | + */ |
|
538 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
539 | + { |
|
540 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
541 | + self::$_error_count++; |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
548 | + * adds an error |
|
549 | + * |
|
550 | + * @param string $msg |
|
551 | + * @param string $file |
|
552 | + * @param string $func |
|
553 | + * @param string $line |
|
554 | + * @throws EE_Error |
|
555 | + */ |
|
556 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
557 | + { |
|
558 | + if (WP_DEBUG) { |
|
559 | + throw new EE_Error($msg); |
|
560 | + } |
|
561 | + EE_Error::add_error($msg, $file, $func, $line); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * add success message |
|
568 | + * |
|
569 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
570 | + * separate messages for user || dev |
|
571 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
572 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
573 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
574 | + * @return void |
|
575 | + */ |
|
576 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
577 | + { |
|
578 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * add attention message |
|
585 | + * |
|
586 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
587 | + * separate messages for user || dev |
|
588 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
589 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
590 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
591 | + * @return void |
|
592 | + */ |
|
593 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
594 | + { |
|
595 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * @param string $type whether the message is for a success or error notification |
|
602 | + * @param string $msg the message to display to users or developers |
|
603 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
604 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
605 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
606 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
607 | + * @return void |
|
608 | + */ |
|
609 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
610 | + { |
|
611 | + if (empty($msg)) { |
|
612 | + EE_Error::doing_it_wrong( |
|
613 | + 'EE_Error::add_' . $type . '()', |
|
614 | + sprintf( |
|
615 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
616 | + 'event_espresso'), |
|
617 | + $type, |
|
618 | + $file, |
|
619 | + $line |
|
620 | + ), |
|
621 | + EVENT_ESPRESSO_VERSION |
|
622 | + ); |
|
623 | + } |
|
624 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
625 | + EE_Error::doing_it_wrong( |
|
626 | + 'EE_Error::add_error()', |
|
627 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
628 | + 'event_espresso'), |
|
629 | + EVENT_ESPRESSO_VERSION |
|
630 | + ); |
|
631 | + } |
|
632 | + // get separate user and developer messages if they exist |
|
633 | + $msg = explode('||', $msg); |
|
634 | + $user_msg = $msg[0]; |
|
635 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
636 | + /** |
|
637 | + * Do an action so other code can be triggered when a notice is created |
|
638 | + * |
|
639 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
640 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
641 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
642 | + * @param string $file file where error was generated |
|
643 | + * @param string $func function where error was generated |
|
644 | + * @param string $line line where error was generated |
|
645 | + */ |
|
646 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
647 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
648 | + // add notice if message exists |
|
649 | + if (! empty($msg)) { |
|
650 | + // get error code |
|
651 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
652 | + if (WP_DEBUG && $type === 'errors') { |
|
653 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
654 | + } |
|
655 | + // add notice. Index by code if it's not blank |
|
656 | + if ($notice_code) { |
|
657 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
658 | + } else { |
|
659 | + self::$_espresso_notices[$type][] = $msg; |
|
660 | + } |
|
661 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
662 | + } |
|
663 | + } |
|
664 | + |
|
665 | + |
|
666 | + /** |
|
667 | + * in some case it may be necessary to overwrite the existing success messages |
|
668 | + * |
|
669 | + * @return void |
|
670 | + */ |
|
671 | + public static function overwrite_success() |
|
672 | + { |
|
673 | + self::$_espresso_notices['success'] = false; |
|
674 | + } |
|
675 | + |
|
676 | + |
|
677 | + |
|
678 | + /** |
|
679 | + * in some case it may be necessary to overwrite the existing attention messages |
|
680 | + * |
|
681 | + * @return void |
|
682 | + */ |
|
683 | + public static function overwrite_attention() |
|
684 | + { |
|
685 | + self::$_espresso_notices['attention'] = false; |
|
686 | + } |
|
687 | + |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * in some case it may be necessary to overwrite the existing error messages |
|
692 | + * |
|
693 | + * @return void |
|
694 | + */ |
|
695 | + public static function overwrite_errors() |
|
696 | + { |
|
697 | + self::$_espresso_notices['errors'] = false; |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * @return void |
|
704 | + */ |
|
705 | + public static function reset_notices() |
|
706 | + { |
|
707 | + self::$_espresso_notices['success'] = false; |
|
708 | + self::$_espresso_notices['attention'] = false; |
|
709 | + self::$_espresso_notices['errors'] = false; |
|
710 | + } |
|
711 | + |
|
712 | + |
|
713 | + |
|
714 | + /** |
|
715 | + * @return int |
|
716 | + */ |
|
717 | + public static function has_notices() |
|
718 | + { |
|
719 | + $has_notices = 0; |
|
720 | + // check for success messages |
|
721 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
722 | + ? 3 |
|
723 | + : $has_notices; |
|
724 | + // check for attention messages |
|
725 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
726 | + ? 2 |
|
727 | + : $has_notices; |
|
728 | + // check for error messages |
|
729 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
730 | + ? 1 |
|
731 | + : $has_notices; |
|
732 | + return $has_notices; |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
738 | + * |
|
739 | + * @since 4.9.0 |
|
740 | + * @return array |
|
741 | + */ |
|
742 | + public static function get_vanilla_notices() |
|
743 | + { |
|
744 | + return array( |
|
745 | + 'success' => isset(self::$_espresso_notices['success']) |
|
746 | + ? self::$_espresso_notices['success'] |
|
747 | + : array(), |
|
748 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
749 | + ? self::$_espresso_notices['attention'] |
|
750 | + : array(), |
|
751 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
752 | + ? self::$_espresso_notices['errors'] |
|
753 | + : array(), |
|
754 | + ); |
|
755 | + } |
|
756 | + |
|
757 | + |
|
758 | + |
|
759 | + /** |
|
760 | + * compile all error or success messages into one string |
|
761 | + * |
|
762 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
763 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
764 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
765 | + * - ONLY do this just before redirecting |
|
766 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
767 | + * @return array |
|
768 | + */ |
|
769 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
770 | + { |
|
771 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
772 | + $success_messages = ''; |
|
773 | + $attention_messages = ''; |
|
774 | + $error_messages = ''; |
|
775 | + $print_scripts = false; |
|
776 | + // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
777 | + // either save notices to the db |
|
778 | + if ($save_to_transient) { |
|
779 | + update_option('ee_notices', self::$_espresso_notices); |
|
780 | + return array(); |
|
781 | + } |
|
782 | + // grab any notices that have been previously saved |
|
783 | + if ($notices = get_option('ee_notices', false)) { |
|
784 | + foreach ($notices as $type => $notice) { |
|
785 | + if (is_array($notice) && ! empty($notice)) { |
|
786 | + // make sure that existing notice type is an array |
|
787 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
788 | + && ! empty(self::$_espresso_notices[$type]) |
|
789 | + ? self::$_espresso_notices[$type] : array(); |
|
790 | + // merge stored notices with any newly created ones |
|
791 | + self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
792 | + $print_scripts = true; |
|
793 | + } |
|
794 | + } |
|
795 | + // now clear any stored notices |
|
796 | + update_option('ee_notices', false); |
|
797 | + } |
|
798 | + // check for success messages |
|
799 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
800 | + // combine messages |
|
801 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
802 | + $print_scripts = true; |
|
803 | + } |
|
804 | + // check for attention messages |
|
805 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
806 | + // combine messages |
|
807 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
808 | + $print_scripts = true; |
|
809 | + } |
|
810 | + // check for error messages |
|
811 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
812 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
813 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
814 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
815 | + // combine messages |
|
816 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
817 | + $print_scripts = true; |
|
818 | + } |
|
819 | + if ($format_output) { |
|
820 | + |
|
821 | + $notices = '<div id="espresso-notices">'; |
|
822 | + $close = is_admin() ? '' |
|
823 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
824 | + if ($success_messages !== '') { |
|
825 | + $css_id = is_admin() ? 'message' : 'espresso-notices-success'; |
|
826 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
827 | + //showMessage( $success_messages ); |
|
828 | + $notices .= '<div id="' |
|
829 | + . $css_id |
|
830 | + . '" class="espresso-notices ' |
|
831 | + . $css_class |
|
832 | + . '" style="display:none;"><p>' |
|
833 | + . $success_messages |
|
834 | + . '</p>' |
|
835 | + . $close |
|
836 | + . '</div>'; |
|
837 | + } |
|
838 | + if ($attention_messages !== '') { |
|
839 | + $css_id = is_admin() ? 'message' : 'espresso-notices-attention'; |
|
840 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
841 | + //showMessage( $error_messages, TRUE ); |
|
842 | + $notices .= '<div id="' |
|
843 | + . $css_id |
|
844 | + . '" class="espresso-notices ' |
|
845 | + . $css_class |
|
846 | + . '" style="display:none;"><p>' |
|
847 | + . $attention_messages |
|
848 | + . '</p>' |
|
849 | + . $close |
|
850 | + . '</div>'; |
|
851 | + } |
|
852 | + if ($error_messages !== '') { |
|
853 | + $css_id = is_admin() ? 'message' : 'espresso-notices-error'; |
|
854 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
855 | + //showMessage( $error_messages, TRUE ); |
|
856 | + $notices .= '<div id="' |
|
857 | + . $css_id |
|
858 | + . '" class="espresso-notices ' |
|
859 | + . $css_class |
|
860 | + . '" style="display:none;"><p>' |
|
861 | + . $error_messages |
|
862 | + . '</p>' |
|
863 | + . $close |
|
864 | + . '</div>'; |
|
865 | + } |
|
866 | + $notices .= '</div>'; |
|
867 | + } else { |
|
868 | + |
|
869 | + $notices = array( |
|
870 | + 'success' => $success_messages, |
|
871 | + 'attention' => $attention_messages, |
|
872 | + 'errors' => $error_messages, |
|
873 | + ); |
|
874 | + if ($remove_empty) { |
|
875 | + // remove empty notices |
|
876 | + foreach ($notices as $type => $notice) { |
|
877 | + if (empty($notice)) { |
|
878 | + unset($notices[$type]); |
|
879 | + } |
|
880 | + } |
|
881 | + } |
|
882 | + } |
|
883 | + if ($print_scripts) { |
|
884 | + self::_print_scripts(); |
|
885 | + } |
|
886 | + return $notices; |
|
887 | + } |
|
888 | + |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * _print_scripts |
|
893 | + * |
|
894 | + * @param bool $force_print |
|
895 | + * @return string |
|
896 | + */ |
|
897 | + private static function _print_scripts($force_print = false) |
|
898 | + { |
|
899 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
900 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
901 | + return ''; |
|
902 | + } |
|
903 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
904 | + wp_enqueue_style('espresso_default'); |
|
905 | + wp_enqueue_style('espresso_custom_css'); |
|
906 | + wp_enqueue_script('ee_error_js'); |
|
907 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
908 | + } |
|
909 | + } else { |
|
910 | + return ' |
|
911 | 911 | <script> |
912 | 912 | /* <![CDATA[ */ |
913 | 913 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -917,235 +917,235 @@ discard block |
||
917 | 917 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
918 | 918 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
919 | 919 | '; |
920 | - } |
|
921 | - return ''; |
|
922 | - } |
|
923 | - |
|
924 | - |
|
925 | - |
|
926 | - /** |
|
927 | - * @return void |
|
928 | - */ |
|
929 | - public static function enqueue_error_scripts() |
|
930 | - { |
|
931 | - self::_print_scripts(); |
|
932 | - } |
|
933 | - |
|
934 | - |
|
935 | - |
|
936 | - /** |
|
937 | - * create error code from filepath, function name, |
|
938 | - * and line number where exception or error was thrown |
|
939 | - * |
|
940 | - * @param string $file |
|
941 | - * @param string $func |
|
942 | - * @param string $line |
|
943 | - * @return string |
|
944 | - */ |
|
945 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
946 | - { |
|
947 | - $file = explode('.', basename($file)); |
|
948 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
949 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
950 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
951 | - return $error_code; |
|
952 | - } |
|
953 | - |
|
954 | - |
|
955 | - |
|
956 | - /** |
|
957 | - * write exception details to log file |
|
958 | - * |
|
959 | - * @param int $time |
|
960 | - * @param array $ex |
|
961 | - * @param bool $clear |
|
962 | - * @return void |
|
963 | - */ |
|
964 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
965 | - { |
|
966 | - if (empty($ex)) { |
|
967 | - return; |
|
968 | - } |
|
969 | - if (! $time) { |
|
970 | - $time = time(); |
|
971 | - } |
|
972 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
973 | - . PHP_EOL; |
|
974 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
975 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
976 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
977 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
978 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
979 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
980 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
981 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
982 | - . PHP_EOL; |
|
983 | - try { |
|
984 | - EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR |
|
985 | - . 'logs' |
|
986 | - . DS |
|
987 | - . self::$_exception_log_file); |
|
988 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs'); |
|
989 | - if (! $clear) { |
|
990 | - //get existing log file and append new log info |
|
991 | - $exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR |
|
992 | - . 'logs' |
|
993 | - . DS |
|
994 | - . self::$_exception_log_file) . $exception_log; |
|
995 | - } |
|
996 | - EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, |
|
997 | - $exception_log); |
|
998 | - } catch (EE_Error $e) { |
|
999 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
1000 | - 'event_espresso'), $e->getMessage())); |
|
1001 | - } |
|
1002 | - } |
|
1003 | - |
|
1004 | - |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1008 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1009 | - * but the code execution is done in a manner that could lead to unexpected results |
|
1010 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
1011 | - * A good test for knowing whether to use this method is: |
|
1012 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1013 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1014 | - * 2. If this is loaded before something else, it won't break anything, |
|
1015 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1016 | - * |
|
1017 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1018 | - * @param string $function The function that was called |
|
1019 | - * @param string $message A message explaining what has been done incorrectly |
|
1020 | - * @param string $version The version of Event Espresso where the error was added |
|
1021 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1022 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
1023 | - * but not have any notices appear until a later version. This allows developers |
|
1024 | - * extra time to update their code before notices appear. |
|
1025 | - * @param int $error_type |
|
1026 | - */ |
|
1027 | - public static function doing_it_wrong( |
|
1028 | - $function, |
|
1029 | - $message, |
|
1030 | - $version, |
|
1031 | - $applies_when = '', |
|
1032 | - $error_type = null |
|
1033 | - ) { |
|
1034 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1035 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1036 | - } |
|
1037 | - } |
|
1038 | - |
|
1039 | - |
|
1040 | - |
|
1041 | - /** |
|
1042 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
1043 | - * |
|
1044 | - * @return array { |
|
1045 | - * @type array $success all the success messages |
|
1046 | - * @type array $errors all the error messages |
|
1047 | - * @type array $attention all the attention messages |
|
1048 | - * } |
|
1049 | - */ |
|
1050 | - public static function get_raw_notices() |
|
1051 | - { |
|
1052 | - return self::$_espresso_notices; |
|
1053 | - } |
|
1054 | - |
|
1055 | - |
|
1056 | - |
|
1057 | - /** |
|
1058 | - * @deprecated 4.9.27 |
|
1059 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1060 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1061 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1062 | - * @return void |
|
1063 | - * @throws InvalidDataTypeException |
|
1064 | - */ |
|
1065 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1066 | - { |
|
1067 | - new PersistentAdminNotice( |
|
1068 | - $pan_name, |
|
1069 | - $pan_message, |
|
1070 | - $force_update |
|
1071 | - ); |
|
1072 | - EE_Error::doing_it_wrong( |
|
1073 | - __METHOD__, |
|
1074 | - sprintf( |
|
1075 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1076 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1077 | - ), |
|
1078 | - '4.9.27' |
|
1079 | - ); |
|
1080 | - } |
|
1081 | - |
|
1082 | - |
|
1083 | - |
|
1084 | - /** |
|
1085 | - * @deprecated 4.9.27 |
|
1086 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1087 | - * @param bool $purge |
|
1088 | - * @param bool $return |
|
1089 | - * @throws DomainException |
|
1090 | - * @throws InvalidInterfaceException |
|
1091 | - * @throws InvalidDataTypeException |
|
1092 | - * @throws ServiceNotFoundException |
|
1093 | - * @throws InvalidArgumentException |
|
1094 | - */ |
|
1095 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1096 | - { |
|
1097 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1098 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1099 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1100 | - ); |
|
1101 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1102 | - EE_Error::doing_it_wrong( |
|
1103 | - __METHOD__, |
|
1104 | - sprintf( |
|
1105 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1106 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1107 | - ), |
|
1108 | - '4.9.27' |
|
1109 | - ); |
|
1110 | - } |
|
1111 | - |
|
1112 | - |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * @deprecated 4.9.27 |
|
1116 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1117 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1118 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
1119 | - */ |
|
1120 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1121 | - { |
|
1122 | - EE_Error::doing_it_wrong( |
|
1123 | - __METHOD__, |
|
1124 | - sprintf( |
|
1125 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1126 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1127 | - ), |
|
1128 | - '4.9.27' |
|
1129 | - ); |
|
1130 | - } |
|
1131 | - |
|
1132 | - |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * @deprecated 4.9.27 |
|
1136 | - * @param string $return_url |
|
1137 | - */ |
|
1138 | - public static function get_persistent_admin_notices($return_url = '') |
|
1139 | - { |
|
1140 | - EE_Error::doing_it_wrong( |
|
1141 | - __METHOD__, |
|
1142 | - sprintf( |
|
1143 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1144 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1145 | - ), |
|
1146 | - '4.9.27' |
|
1147 | - ); |
|
1148 | - } |
|
920 | + } |
|
921 | + return ''; |
|
922 | + } |
|
923 | + |
|
924 | + |
|
925 | + |
|
926 | + /** |
|
927 | + * @return void |
|
928 | + */ |
|
929 | + public static function enqueue_error_scripts() |
|
930 | + { |
|
931 | + self::_print_scripts(); |
|
932 | + } |
|
933 | + |
|
934 | + |
|
935 | + |
|
936 | + /** |
|
937 | + * create error code from filepath, function name, |
|
938 | + * and line number where exception or error was thrown |
|
939 | + * |
|
940 | + * @param string $file |
|
941 | + * @param string $func |
|
942 | + * @param string $line |
|
943 | + * @return string |
|
944 | + */ |
|
945 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
946 | + { |
|
947 | + $file = explode('.', basename($file)); |
|
948 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
949 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
950 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
951 | + return $error_code; |
|
952 | + } |
|
953 | + |
|
954 | + |
|
955 | + |
|
956 | + /** |
|
957 | + * write exception details to log file |
|
958 | + * |
|
959 | + * @param int $time |
|
960 | + * @param array $ex |
|
961 | + * @param bool $clear |
|
962 | + * @return void |
|
963 | + */ |
|
964 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
965 | + { |
|
966 | + if (empty($ex)) { |
|
967 | + return; |
|
968 | + } |
|
969 | + if (! $time) { |
|
970 | + $time = time(); |
|
971 | + } |
|
972 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
973 | + . PHP_EOL; |
|
974 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
975 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
976 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
977 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
978 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
979 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
980 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
981 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
982 | + . PHP_EOL; |
|
983 | + try { |
|
984 | + EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR |
|
985 | + . 'logs' |
|
986 | + . DS |
|
987 | + . self::$_exception_log_file); |
|
988 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs'); |
|
989 | + if (! $clear) { |
|
990 | + //get existing log file and append new log info |
|
991 | + $exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR |
|
992 | + . 'logs' |
|
993 | + . DS |
|
994 | + . self::$_exception_log_file) . $exception_log; |
|
995 | + } |
|
996 | + EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, |
|
997 | + $exception_log); |
|
998 | + } catch (EE_Error $e) { |
|
999 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
1000 | + 'event_espresso'), $e->getMessage())); |
|
1001 | + } |
|
1002 | + } |
|
1003 | + |
|
1004 | + |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1008 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1009 | + * but the code execution is done in a manner that could lead to unexpected results |
|
1010 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
1011 | + * A good test for knowing whether to use this method is: |
|
1012 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1013 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1014 | + * 2. If this is loaded before something else, it won't break anything, |
|
1015 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1016 | + * |
|
1017 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1018 | + * @param string $function The function that was called |
|
1019 | + * @param string $message A message explaining what has been done incorrectly |
|
1020 | + * @param string $version The version of Event Espresso where the error was added |
|
1021 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1022 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
1023 | + * but not have any notices appear until a later version. This allows developers |
|
1024 | + * extra time to update their code before notices appear. |
|
1025 | + * @param int $error_type |
|
1026 | + */ |
|
1027 | + public static function doing_it_wrong( |
|
1028 | + $function, |
|
1029 | + $message, |
|
1030 | + $version, |
|
1031 | + $applies_when = '', |
|
1032 | + $error_type = null |
|
1033 | + ) { |
|
1034 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1035 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1036 | + } |
|
1037 | + } |
|
1038 | + |
|
1039 | + |
|
1040 | + |
|
1041 | + /** |
|
1042 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
1043 | + * |
|
1044 | + * @return array { |
|
1045 | + * @type array $success all the success messages |
|
1046 | + * @type array $errors all the error messages |
|
1047 | + * @type array $attention all the attention messages |
|
1048 | + * } |
|
1049 | + */ |
|
1050 | + public static function get_raw_notices() |
|
1051 | + { |
|
1052 | + return self::$_espresso_notices; |
|
1053 | + } |
|
1054 | + |
|
1055 | + |
|
1056 | + |
|
1057 | + /** |
|
1058 | + * @deprecated 4.9.27 |
|
1059 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1060 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1061 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1062 | + * @return void |
|
1063 | + * @throws InvalidDataTypeException |
|
1064 | + */ |
|
1065 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1066 | + { |
|
1067 | + new PersistentAdminNotice( |
|
1068 | + $pan_name, |
|
1069 | + $pan_message, |
|
1070 | + $force_update |
|
1071 | + ); |
|
1072 | + EE_Error::doing_it_wrong( |
|
1073 | + __METHOD__, |
|
1074 | + sprintf( |
|
1075 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1076 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1077 | + ), |
|
1078 | + '4.9.27' |
|
1079 | + ); |
|
1080 | + } |
|
1081 | + |
|
1082 | + |
|
1083 | + |
|
1084 | + /** |
|
1085 | + * @deprecated 4.9.27 |
|
1086 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1087 | + * @param bool $purge |
|
1088 | + * @param bool $return |
|
1089 | + * @throws DomainException |
|
1090 | + * @throws InvalidInterfaceException |
|
1091 | + * @throws InvalidDataTypeException |
|
1092 | + * @throws ServiceNotFoundException |
|
1093 | + * @throws InvalidArgumentException |
|
1094 | + */ |
|
1095 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1096 | + { |
|
1097 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1098 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1099 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1100 | + ); |
|
1101 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1102 | + EE_Error::doing_it_wrong( |
|
1103 | + __METHOD__, |
|
1104 | + sprintf( |
|
1105 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1106 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1107 | + ), |
|
1108 | + '4.9.27' |
|
1109 | + ); |
|
1110 | + } |
|
1111 | + |
|
1112 | + |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * @deprecated 4.9.27 |
|
1116 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1117 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1118 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
1119 | + */ |
|
1120 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1121 | + { |
|
1122 | + EE_Error::doing_it_wrong( |
|
1123 | + __METHOD__, |
|
1124 | + sprintf( |
|
1125 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1126 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1127 | + ), |
|
1128 | + '4.9.27' |
|
1129 | + ); |
|
1130 | + } |
|
1131 | + |
|
1132 | + |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * @deprecated 4.9.27 |
|
1136 | + * @param string $return_url |
|
1137 | + */ |
|
1138 | + public static function get_persistent_admin_notices($return_url = '') |
|
1139 | + { |
|
1140 | + EE_Error::doing_it_wrong( |
|
1141 | + __METHOD__, |
|
1142 | + sprintf( |
|
1143 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1144 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1145 | + ), |
|
1146 | + '4.9.27' |
|
1147 | + ); |
|
1148 | + } |
|
1149 | 1149 | |
1150 | 1150 | |
1151 | 1151 | |
@@ -1160,27 +1160,27 @@ discard block |
||
1160 | 1160 | */ |
1161 | 1161 | function espresso_error_enqueue_scripts() |
1162 | 1162 | { |
1163 | - // js for error handling |
|
1164 | - wp_register_script( |
|
1165 | - 'espresso_core', |
|
1166 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1167 | - array('jquery'), |
|
1168 | - EVENT_ESPRESSO_VERSION, |
|
1169 | - false |
|
1170 | - ); |
|
1171 | - wp_register_script( |
|
1172 | - 'ee_error_js', |
|
1173 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1174 | - array('espresso_core'), |
|
1175 | - EVENT_ESPRESSO_VERSION, |
|
1176 | - false |
|
1177 | - ); |
|
1163 | + // js for error handling |
|
1164 | + wp_register_script( |
|
1165 | + 'espresso_core', |
|
1166 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1167 | + array('jquery'), |
|
1168 | + EVENT_ESPRESSO_VERSION, |
|
1169 | + false |
|
1170 | + ); |
|
1171 | + wp_register_script( |
|
1172 | + 'ee_error_js', |
|
1173 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1174 | + array('espresso_core'), |
|
1175 | + EVENT_ESPRESSO_VERSION, |
|
1176 | + false |
|
1177 | + ); |
|
1178 | 1178 | } |
1179 | 1179 | |
1180 | 1180 | if (is_admin()) { |
1181 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1181 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1182 | 1182 | } else { |
1183 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1183 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 |