@@ -14,106 +14,106 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Register_Widget implements EEI_Plugin_API |
16 | 16 | { |
17 | - /** |
|
18 | - * Holds values for registered widgets |
|
19 | - * |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected static $_settings = []; |
|
17 | + /** |
|
18 | + * Holds values for registered widgets |
|
19 | + * |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected static $_settings = []; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Method for registering new EED_Widgets |
|
27 | - * |
|
28 | - * @param string $addon_name a unique identifier for this set of widgets |
|
29 | - * @param array $setup_args an array of arguments provided for registering widgets |
|
30 | - * @type array widget_paths an array of full server paths to folders containing any EED_Widgets, or to the |
|
31 | - * EED_Widget files themselves |
|
32 | - * @return bool |
|
33 | - * @throws EE_Error |
|
34 | - * @since 4.3.0 |
|
35 | - */ |
|
36 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
37 | - { |
|
25 | + /** |
|
26 | + * Method for registering new EED_Widgets |
|
27 | + * |
|
28 | + * @param string $addon_name a unique identifier for this set of widgets |
|
29 | + * @param array $setup_args an array of arguments provided for registering widgets |
|
30 | + * @type array widget_paths an array of full server paths to folders containing any EED_Widgets, or to the |
|
31 | + * EED_Widget files themselves |
|
32 | + * @return bool |
|
33 | + * @throws EE_Error |
|
34 | + * @since 4.3.0 |
|
35 | + */ |
|
36 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
37 | + { |
|
38 | 38 | |
39 | - // required fields MUST be present, so let's make sure they are. |
|
40 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['widget_paths'])) { |
|
41 | - throw new EE_Error( |
|
42 | - esc_html__( |
|
43 | - 'In order to register Widgets with EE_Register_Widget::register(), you must include a "widget_id" (a unique identifier for this set of widgets), and an array containing the following keys: "widget_paths" (an array of full server paths to folders that contain widgets, or to the widget files themselves)', |
|
44 | - 'event_espresso' |
|
45 | - ) |
|
46 | - ); |
|
47 | - } |
|
39 | + // required fields MUST be present, so let's make sure they are. |
|
40 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['widget_paths'])) { |
|
41 | + throw new EE_Error( |
|
42 | + esc_html__( |
|
43 | + 'In order to register Widgets with EE_Register_Widget::register(), you must include a "widget_id" (a unique identifier for this set of widgets), and an array containing the following keys: "widget_paths" (an array of full server paths to folders that contain widgets, or to the widget files themselves)', |
|
44 | + 'event_espresso' |
|
45 | + ) |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | - // make sure we don't register twice |
|
50 | - if (isset(self::$_settings[ $addon_name ])) { |
|
51 | - return true; |
|
52 | - } |
|
49 | + // make sure we don't register twice |
|
50 | + if (isset(self::$_settings[ $addon_name ])) { |
|
51 | + return true; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - // make sure this was called in the right place! |
|
56 | - if ( |
|
57 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
58 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
59 | - ) { |
|
60 | - EE_Error::doing_it_wrong( |
|
61 | - __METHOD__, |
|
62 | - esc_html__( |
|
63 | - 'An attempt to register widgets has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register widgets.', |
|
64 | - 'event_espresso' |
|
65 | - ), |
|
66 | - '4.3.0' |
|
67 | - ); |
|
68 | - } |
|
69 | - // setup $_settings array from incoming values. |
|
70 | - self::$_settings[ $addon_name ] = [ |
|
71 | - // array of full server paths to any EED_Widgets used by the widget |
|
72 | - 'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [], |
|
73 | - ]; |
|
74 | - // add to list of widgets to be registered |
|
75 | - add_filter( |
|
76 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
77 | - ['EE_Register_Widget', 'add_widgets'] |
|
78 | - ); |
|
79 | - return true; |
|
80 | - } |
|
55 | + // make sure this was called in the right place! |
|
56 | + if ( |
|
57 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
58 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
59 | + ) { |
|
60 | + EE_Error::doing_it_wrong( |
|
61 | + __METHOD__, |
|
62 | + esc_html__( |
|
63 | + 'An attempt to register widgets has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register widgets.', |
|
64 | + 'event_espresso' |
|
65 | + ), |
|
66 | + '4.3.0' |
|
67 | + ); |
|
68 | + } |
|
69 | + // setup $_settings array from incoming values. |
|
70 | + self::$_settings[ $addon_name ] = [ |
|
71 | + // array of full server paths to any EED_Widgets used by the widget |
|
72 | + 'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [], |
|
73 | + ]; |
|
74 | + // add to list of widgets to be registered |
|
75 | + add_filter( |
|
76 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
77 | + ['EE_Register_Widget', 'add_widgets'] |
|
78 | + ); |
|
79 | + return true; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Filters the list of widgets to add ours. |
|
85 | - * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
86 | - * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/widgets/espresso_monkey'...) |
|
87 | - * |
|
88 | - * @param array $widgets_to_register array of paths to all widgets that require registering |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - public static function add_widgets(array $widgets_to_register = []): array |
|
92 | - { |
|
93 | - $widget_paths = []; |
|
94 | - foreach (self::$_settings as $settings) { |
|
95 | - $widget_paths[] = $settings['widget_paths']; |
|
96 | - } |
|
97 | - return array_merge($widgets_to_register, ...$widget_paths); |
|
98 | - } |
|
83 | + /** |
|
84 | + * Filters the list of widgets to add ours. |
|
85 | + * and they're just full filepaths to FOLDERS containing a shortcode class file. Eg. |
|
86 | + * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/widgets/espresso_monkey'...) |
|
87 | + * |
|
88 | + * @param array $widgets_to_register array of paths to all widgets that require registering |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + public static function add_widgets(array $widgets_to_register = []): array |
|
92 | + { |
|
93 | + $widget_paths = []; |
|
94 | + foreach (self::$_settings as $settings) { |
|
95 | + $widget_paths[] = $settings['widget_paths']; |
|
96 | + } |
|
97 | + return array_merge($widgets_to_register, ...$widget_paths); |
|
98 | + } |
|
99 | 99 | |
100 | 100 | |
101 | - /** |
|
102 | - * This deregisters a widget that was previously registered with a specific $addon_name. |
|
103 | - * |
|
104 | - * @param string $addon_name the name for the widget that was previously registered |
|
105 | - * @return void |
|
106 | - * @since 4.3.0 |
|
107 | - * |
|
108 | - */ |
|
109 | - public static function deregister(string $addon_name = '') |
|
110 | - { |
|
111 | - unset(self::$_settings[ $addon_name ]); |
|
112 | - } |
|
101 | + /** |
|
102 | + * This deregisters a widget that was previously registered with a specific $addon_name. |
|
103 | + * |
|
104 | + * @param string $addon_name the name for the widget that was previously registered |
|
105 | + * @return void |
|
106 | + * @since 4.3.0 |
|
107 | + * |
|
108 | + */ |
|
109 | + public static function deregister(string $addon_name = '') |
|
110 | + { |
|
111 | + unset(self::$_settings[ $addon_name ]); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | - public static function reset(): void |
|
116 | - { |
|
117 | - self::$_settings = []; |
|
118 | - } |
|
115 | + public static function reset(): void |
|
116 | + { |
|
117 | + self::$_settings = []; |
|
118 | + } |
|
119 | 119 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | // make sure we don't register twice |
50 | - if (isset(self::$_settings[ $addon_name ])) { |
|
50 | + if (isset(self::$_settings[$addon_name])) { |
|
51 | 51 | return true; |
52 | 52 | } |
53 | 53 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | ); |
68 | 68 | } |
69 | 69 | // setup $_settings array from incoming values. |
70 | - self::$_settings[ $addon_name ] = [ |
|
70 | + self::$_settings[$addon_name] = [ |
|
71 | 71 | // array of full server paths to any EED_Widgets used by the widget |
72 | 72 | 'widget_paths' => isset($setup_args['widget_paths']) ? (array) $setup_args['widget_paths'] : [], |
73 | 73 | ]; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public static function deregister(string $addon_name = '') |
110 | 110 | { |
111 | - unset(self::$_settings[ $addon_name ]); |
|
111 | + unset(self::$_settings[$addon_name]); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 |
@@ -12,57 +12,57 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Register_Privacy_Policy implements EEI_Plugin_API |
14 | 14 | { |
15 | - /** |
|
16 | - * FQCN for all privacy policy generators |
|
17 | - * |
|
18 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | - */ |
|
20 | - protected static $privacy_policies = []; |
|
15 | + /** |
|
16 | + * FQCN for all privacy policy generators |
|
17 | + * |
|
18 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | + */ |
|
20 | + protected static $privacy_policies = []; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param string $addon_name |
|
25 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | - * OR fully qualified class names of privacy policies |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | - { |
|
31 | - self::$privacy_policies[ $addon_name ] = $setup_args; |
|
32 | - // add to list of modules to be registered |
|
33 | - add_filter( |
|
34 | - 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
|
35 | - ['EE_Register_Privacy_Policy', 'addPrivacyPolicies'] |
|
36 | - ); |
|
37 | - return true; |
|
38 | - } |
|
23 | + /** |
|
24 | + * @param string $addon_name |
|
25 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | + * OR fully qualified class names of privacy policies |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | + { |
|
31 | + self::$privacy_policies[ $addon_name ] = $setup_args; |
|
32 | + // add to list of modules to be registered |
|
33 | + add_filter( |
|
34 | + 'FHEE__EventEspresso_core_services_privacy_policy_PrivacyPolicyManager__privacy_policies', |
|
35 | + ['EE_Register_Privacy_Policy', 'addPrivacyPolicies'] |
|
36 | + ); |
|
37 | + return true; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param string $addon_name |
|
43 | - */ |
|
44 | - public static function deregister(string $addon_name = '') |
|
45 | - { |
|
46 | - unset(self::$privacy_policies[ $addon_name ]); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @param string $addon_name |
|
43 | + */ |
|
44 | + public static function deregister(string $addon_name = '') |
|
45 | + { |
|
46 | + unset(self::$privacy_policies[ $addon_name ]); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Adds our privacy policy generators registered by add-ons |
|
52 | - * |
|
53 | - * @param string[] $privacy_policies |
|
54 | - * @return string[] |
|
55 | - */ |
|
56 | - public static function addPrivacyPolicies(array $privacy_policies): array |
|
57 | - { |
|
58 | - return array_merge($privacy_policies, ...self::$privacy_policies); |
|
59 | - } |
|
50 | + /** |
|
51 | + * Adds our privacy policy generators registered by add-ons |
|
52 | + * |
|
53 | + * @param string[] $privacy_policies |
|
54 | + * @return string[] |
|
55 | + */ |
|
56 | + public static function addPrivacyPolicies(array $privacy_policies): array |
|
57 | + { |
|
58 | + return array_merge($privacy_policies, ...self::$privacy_policies); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - public static function reset(): void |
|
63 | - { |
|
64 | - self::$privacy_policies = []; |
|
65 | - } |
|
62 | + public static function reset(): void |
|
63 | + { |
|
64 | + self::$privacy_policies = []; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | // End of file EE_Register_Privacy_Policy.lib.php |
68 | 68 | // Location: ${NAMESPACE}/EE_Register_Privacy_Policy.lib.php |
@@ -11,124 +11,124 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Register_Config implements EEI_Plugin_API |
13 | 13 | { |
14 | - /** |
|
15 | - * Holds registered EE_Config items |
|
16 | - * |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected static $_ee_config_registry = []; |
|
14 | + /** |
|
15 | + * Holds registered EE_Config items |
|
16 | + * |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected static $_ee_config_registry = []; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * Handles registering the new config with the EE_Config::instance()->addons property |
|
24 | - * |
|
25 | - * @param string $addon_name The name of the Config class being registered. |
|
26 | - * Note this class must extend EE_Config Base and must have |
|
27 | - * already been registered with an autoloader. |
|
28 | - * @param array $setup_args { |
|
29 | - * |
|
30 | - * @type string $config_name Optional. by default the new config will be registered to |
|
31 | - * EE_Config::instance()->addons->{config_class}, |
|
32 | - * but supplying a "config_name" will set the property name |
|
33 | - * that this variable is accessible by. |
|
34 | - * ie: EE_Config::instance()->addons->{config_name} |
|
35 | - * } |
|
36 | - * @return bool |
|
37 | - * @throws EE_Error |
|
38 | - * |
|
39 | - * @since 4.3.0 |
|
40 | - */ |
|
41 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
42 | - { |
|
22 | + /** |
|
23 | + * Handles registering the new config with the EE_Config::instance()->addons property |
|
24 | + * |
|
25 | + * @param string $addon_name The name of the Config class being registered. |
|
26 | + * Note this class must extend EE_Config Base and must have |
|
27 | + * already been registered with an autoloader. |
|
28 | + * @param array $setup_args { |
|
29 | + * |
|
30 | + * @type string $config_name Optional. by default the new config will be registered to |
|
31 | + * EE_Config::instance()->addons->{config_class}, |
|
32 | + * but supplying a "config_name" will set the property name |
|
33 | + * that this variable is accessible by. |
|
34 | + * ie: EE_Config::instance()->addons->{config_name} |
|
35 | + * } |
|
36 | + * @return bool |
|
37 | + * @throws EE_Error |
|
38 | + * |
|
39 | + * @since 4.3.0 |
|
40 | + */ |
|
41 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
42 | + { |
|
43 | 43 | |
44 | - $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
45 | - ? $setup_args['config_name'] : $addon_name; |
|
46 | - $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
47 | - ? $setup_args['config_section'] : 'addons'; |
|
44 | + $setup_args['config_name'] = isset($setup_args['config_name']) && ! empty($setup_args['config_name']) |
|
45 | + ? $setup_args['config_name'] : $addon_name; |
|
46 | + $setup_args['config_section'] = isset($setup_args['config_section']) && ! empty($setup_args['config_section']) |
|
47 | + ? $setup_args['config_section'] : 'addons'; |
|
48 | 48 | |
49 | - // required fields MUST be present, so let's make sure they are. |
|
50 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
51 | - throw new EE_Error( |
|
52 | - esc_html__( |
|
53 | - 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
54 | - 'event_espresso' |
|
55 | - ) |
|
56 | - ); |
|
57 | - } |
|
49 | + // required fields MUST be present, so let's make sure they are. |
|
50 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['config_name'])) { |
|
51 | + throw new EE_Error( |
|
52 | + esc_html__( |
|
53 | + 'In order to register a Config Class with EE_Register_Config::register(), you must include a "config_class" (the actual class name for this config class). As well, you can supply an array containing the following keys: "config_section" the main section of the config object the settings will be saved under (by default the new config will be registered under EE_Config::instance()->modules or EE_Config::instance()->addons depending on what type of class is calling this), "config_name" (by default the new config will be registered to EE_Config::instance()->{config_section}->{config_class}, but supplying a "config_name" will set the property name that this variable is accessible by. ie: EE_Config::instance()->{config_section}->{config_name})', |
|
54 | + 'event_espresso' |
|
55 | + ) |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | - // make sure we don't register twice |
|
60 | - if (isset(self::$_ee_config_registry[ $addon_name ])) { |
|
61 | - return true; |
|
62 | - } |
|
59 | + // make sure we don't register twice |
|
60 | + if (isset(self::$_ee_config_registry[ $addon_name ])) { |
|
61 | + return true; |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - // first find out if this happened too late. |
|
66 | - if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
67 | - EE_Error::doing_it_wrong( |
|
68 | - __METHOD__, |
|
69 | - sprintf( |
|
70 | - esc_html__( |
|
71 | - 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
72 | - 'event_espresso' |
|
73 | - ), |
|
74 | - $setup_args['config_name'] |
|
75 | - ), |
|
76 | - '4.3' |
|
77 | - ); |
|
78 | - } |
|
79 | - // add incoming stuff to our registry property |
|
80 | - self::$_ee_config_registry[ $addon_name ] = [ |
|
81 | - 'section' => $setup_args['config_section'], |
|
82 | - 'name' => $setup_args['config_name'], |
|
83 | - ]; |
|
65 | + // first find out if this happened too late. |
|
66 | + if (did_action('AHEE__EE_System__load_core_configuration__begin')) { |
|
67 | + EE_Error::doing_it_wrong( |
|
68 | + __METHOD__, |
|
69 | + sprintf( |
|
70 | + esc_html__( |
|
71 | + 'An attempt to register "%s" as an EE_Config object has failed because it was not registered at the correct hookpoint. Please register before the "AHEE__EE_System__load_core_configuration__begin" hook has fired', |
|
72 | + 'event_espresso' |
|
73 | + ), |
|
74 | + $setup_args['config_name'] |
|
75 | + ), |
|
76 | + '4.3' |
|
77 | + ); |
|
78 | + } |
|
79 | + // add incoming stuff to our registry property |
|
80 | + self::$_ee_config_registry[ $addon_name ] = [ |
|
81 | + 'section' => $setup_args['config_section'], |
|
82 | + 'name' => $setup_args['config_name'], |
|
83 | + ]; |
|
84 | 84 | |
85 | - add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
86 | - add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
87 | - return true; |
|
88 | - } |
|
85 | + add_action('AHEE__EE_Config___load_core_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
86 | + add_action('AHEE__EE_Config__update_espresso_config__end', ['EE_Register_Config', 'set_config'], 15, 1); |
|
87 | + return true; |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | - /** |
|
92 | - * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
93 | - * basically just calls EE_Config->get_config() |
|
94 | - * which will take care of loading or creating our config object for us |
|
95 | - * |
|
96 | - * @param EE_Config $EE_Config |
|
97 | - * @return void |
|
98 | - * @throws EE_Error |
|
99 | - * @since 4.3.0 |
|
100 | - */ |
|
101 | - public static function set_config(EE_Config $EE_Config) |
|
102 | - { |
|
103 | - foreach (self::$_ee_config_registry as $addon_name => $settings) { |
|
104 | - // first some validation of our incoming class_name. |
|
105 | - // We'll throw an error early if its' not registered correctly |
|
106 | - if (! class_exists($addon_name)) { |
|
107 | - throw new EE_Error( |
|
108 | - sprintf( |
|
109 | - esc_html__( |
|
110 | - 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
111 | - 'event_espresso' |
|
112 | - ), |
|
113 | - $addon_name |
|
114 | - ) |
|
115 | - ); |
|
116 | - } |
|
117 | - $EE_Config->get_config($settings['section'], $settings['name'], $addon_name); |
|
118 | - } |
|
119 | - } |
|
91 | + /** |
|
92 | + * Callback for the AHEE__EE_Config___load_core_config__end hook. |
|
93 | + * basically just calls EE_Config->get_config() |
|
94 | + * which will take care of loading or creating our config object for us |
|
95 | + * |
|
96 | + * @param EE_Config $EE_Config |
|
97 | + * @return void |
|
98 | + * @throws EE_Error |
|
99 | + * @since 4.3.0 |
|
100 | + */ |
|
101 | + public static function set_config(EE_Config $EE_Config) |
|
102 | + { |
|
103 | + foreach (self::$_ee_config_registry as $addon_name => $settings) { |
|
104 | + // first some validation of our incoming class_name. |
|
105 | + // We'll throw an error early if its' not registered correctly |
|
106 | + if (! class_exists($addon_name)) { |
|
107 | + throw new EE_Error( |
|
108 | + sprintf( |
|
109 | + esc_html__( |
|
110 | + 'The "%s" config class can not be registered with EE_Config because it does not exist. Verify that an autoloader has been set for this class', |
|
111 | + 'event_espresso' |
|
112 | + ), |
|
113 | + $addon_name |
|
114 | + ) |
|
115 | + ); |
|
116 | + } |
|
117 | + $EE_Config->get_config($settings['section'], $settings['name'], $addon_name); |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - /** |
|
123 | - * @param string $addon_name |
|
124 | - */ |
|
125 | - public static function deregister(string $addon_name = '') |
|
126 | - { |
|
127 | - unset(self::$_ee_config_registry[ $addon_name ]); |
|
128 | - } |
|
122 | + /** |
|
123 | + * @param string $addon_name |
|
124 | + */ |
|
125 | + public static function deregister(string $addon_name = '') |
|
126 | + { |
|
127 | + unset(self::$_ee_config_registry[ $addon_name ]); |
|
128 | + } |
|
129 | 129 | |
130 | - public static function reset(): void |
|
131 | - { |
|
132 | - self::$_ee_config_registry = []; |
|
133 | - } |
|
130 | + public static function reset(): void |
|
131 | + { |
|
132 | + self::$_ee_config_registry = []; |
|
133 | + } |
|
134 | 134 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | // make sure we don't register twice |
60 | - if (isset(self::$_ee_config_registry[ $addon_name ])) { |
|
60 | + if (isset(self::$_ee_config_registry[$addon_name])) { |
|
61 | 61 | return true; |
62 | 62 | } |
63 | 63 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | ); |
78 | 78 | } |
79 | 79 | // add incoming stuff to our registry property |
80 | - self::$_ee_config_registry[ $addon_name ] = [ |
|
80 | + self::$_ee_config_registry[$addon_name] = [ |
|
81 | 81 | 'section' => $setup_args['config_section'], |
82 | 82 | 'name' => $setup_args['config_name'], |
83 | 83 | ]; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | foreach (self::$_ee_config_registry as $addon_name => $settings) { |
104 | 104 | // first some validation of our incoming class_name. |
105 | 105 | // We'll throw an error early if its' not registered correctly |
106 | - if (! class_exists($addon_name)) { |
|
106 | + if ( ! class_exists($addon_name)) { |
|
107 | 107 | throw new EE_Error( |
108 | 108 | sprintf( |
109 | 109 | esc_html__( |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public static function deregister(string $addon_name = '') |
126 | 126 | { |
127 | - unset(self::$_ee_config_registry[ $addon_name ]); |
|
127 | + unset(self::$_ee_config_registry[$addon_name]); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | public static function reset(): void |
@@ -10,208 +10,208 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Register_Messages_Template_Pack implements EEI_Plugin_API |
12 | 12 | { |
13 | - /** |
|
14 | - * Holds values for registered template pack |
|
15 | - * |
|
16 | - * @since 4.5.0 |
|
17 | - * |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected static $_registry = []; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * Used to register a new template pack with the messages system. |
|
25 | - * |
|
26 | - * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to |
|
27 | - * change entire layouts for a set of message templates. This method is used to register the new template pack and |
|
28 | - * automatically have it loaded in the appropriate places. |
|
29 | - * |
|
30 | - * This registry also verifies that there isn't already a template pack registered with the same name and if there |
|
31 | - * is then it will add an EE_Error notice. |
|
32 | - * |
|
33 | - * Note that this only handles registering the your Template Pack class with the message template pack system. |
|
34 | - * However, there is also a naming schema you must follow for templates you are providing with your template pack. |
|
35 | - * |
|
36 | - * @param string $addon_name The internal reference used to refer to this template pack. Note, this is first come, |
|
37 | - * first serve. If there is already a template pack registered with this name then the |
|
38 | - * registry will assign a unique reference for it so it can still be activated (but this |
|
39 | - * makes it harder to deregister as it will be unique per load - so its best to try to |
|
40 | - * make this a unique string!) |
|
41 | - * @param array $setup_args array { |
|
42 | - * An array of required values for registering the template pack. |
|
43 | - * @type string $path The path for the new template pack class. |
|
44 | - * @type string $classname The name of the new Template Pack Class. |
|
45 | - * } |
|
46 | - * @return bool |
|
47 | - * @throws EE_Error |
|
48 | - * |
|
49 | - * @see core/libraries/messages/defaults/default/* for all the example templates the default template pack |
|
50 | - * supports. |
|
51 | - * |
|
52 | - * |
|
53 | - * @since 4.5.0 |
|
54 | - * @see EE_Messages_Template_Pack_Default for an example class |
|
55 | - */ |
|
56 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
57 | - { |
|
58 | - |
|
59 | - // check for required params |
|
60 | - if (empty($addon_name) || empty($setup_args['path']) || empty($setup_args['classname'])) { |
|
61 | - throw new EE_Error( |
|
62 | - esc_html__( |
|
63 | - 'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ', |
|
64 | - 'event_espresso' |
|
65 | - ) |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - // make sure we don't register twice |
|
70 | - if (isset(self::$_registry[ $addon_name ])) { |
|
71 | - return true; |
|
72 | - } |
|
73 | - |
|
74 | - // check that incoming $addon_name doesn't already exist. If it does then we'll create a unique reference for this template pack. |
|
75 | - if (isset(self::$_registry[ $addon_name ])) { |
|
76 | - $addon_name = uniqid() . '_' . $addon_name; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - // make sure this was called in the right place! |
|
81 | - if ( |
|
82 | - ! did_action('EE_Brewing_Regular___messages_caf') |
|
83 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
84 | - ) { |
|
85 | - EE_Error::doing_it_wrong( |
|
86 | - __METHOD__, |
|
87 | - sprintf( |
|
88 | - esc_html__( |
|
89 | - 'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - $addon_name |
|
93 | - ), |
|
94 | - '4.5.0' |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - if (self::_verify_class_not_exist($setup_args['classname'])) { |
|
99 | - self::$_registry[ $addon_name ] = [ |
|
100 | - 'path' => (string) $setup_args['path'], |
|
101 | - 'classname' => (string) $setup_args['classname'], |
|
102 | - ]; |
|
103 | - } |
|
104 | - |
|
105 | - // hook into the system |
|
106 | - add_filter( |
|
107 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
108 | - ['EE_Register_Messages_Template_Pack', 'set_template_pack_path'], |
|
109 | - 10 |
|
110 | - ); |
|
111 | - add_filter( |
|
112 | - 'FHEE__EED_Messages__get_template_packs__template_packs', |
|
113 | - ['EE_Register_Messages_Template_Pack', 'set_template_pack'], |
|
114 | - 10 |
|
115 | - ); |
|
116 | - return true; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. This adds this template packs path |
|
122 | - * to the messages autoloader paths. |
|
123 | - * |
|
124 | - * @param array $paths Array of paths already registered with the messages autoloader |
|
125 | - * |
|
126 | - * @return array |
|
127 | - * @since 4.5.0 |
|
128 | - * |
|
129 | - */ |
|
130 | - public static function set_template_pack_path(array $paths): array |
|
131 | - { |
|
132 | - foreach (self::$_registry as $args) { |
|
133 | - $paths[] = $args['path']; |
|
134 | - } |
|
135 | - return $paths; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated, |
|
141 | - * registered template pack to the template packs array when requested by client code. |
|
142 | - * |
|
143 | - * @param EE_Messages_Template_Pack[] $template_packs |
|
144 | - * @return EE_Messages_Template_Pack[] |
|
145 | - * @since 4.5.0 |
|
146 | - * |
|
147 | - */ |
|
148 | - public static function set_template_pack(array $template_packs): array |
|
149 | - { |
|
150 | - foreach (self::$_registry as $args) { |
|
151 | - // verify class_exists |
|
152 | - if (! class_exists($args['classname'])) { |
|
153 | - require_once($args['path'] . '/' . $args['classname'] . '.class.php'); |
|
154 | - } |
|
155 | - |
|
156 | - // check again! |
|
157 | - if (class_exists($args['classname'])) { |
|
158 | - $template_pack = new $args['classname'](); |
|
159 | - $template_packs[ $template_pack->dbref ] = $template_pack; |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - return $template_packs; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * This verifies that the classes for each registered template pack are unique names. |
|
169 | - * |
|
170 | - * @param string $classname The classname being checked |
|
171 | - * |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - private static function _verify_class_not_exist(string $classname): bool |
|
175 | - { |
|
176 | - // loop through the existing registry and see if the classname is already present. |
|
177 | - foreach (self::$_registry as $args) { |
|
178 | - if ($args['classname'] == $classname) { |
|
179 | - EE_Error::add_error( |
|
180 | - sprintf( |
|
181 | - esc_html__( |
|
182 | - 'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname. Contact the author of this template pack to let them know of the conflict. To stop seeing this message you will need to deactivate this template pack.', |
|
183 | - 'event_espresso' |
|
184 | - ), |
|
185 | - $classname |
|
186 | - ), |
|
187 | - __FILE__, |
|
188 | - __LINE__, |
|
189 | - __FUNCTION__ |
|
190 | - ); |
|
191 | - return false; |
|
192 | - } |
|
193 | - } |
|
194 | - return true; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * This deregisters a variation set that was previously registered with the given slug. |
|
200 | - * |
|
201 | - * @param string $addon_name The name for the variation set that was previously registered. |
|
202 | - * |
|
203 | - * @return void |
|
204 | - * @since 4.5.0 |
|
205 | - * |
|
206 | - */ |
|
207 | - public static function deregister(string $addon_name = '') |
|
208 | - { |
|
209 | - unset(self::$_registry[ $addon_name ]); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - public static function reset(): void |
|
214 | - { |
|
215 | - self::$_registry = []; |
|
216 | - } |
|
13 | + /** |
|
14 | + * Holds values for registered template pack |
|
15 | + * |
|
16 | + * @since 4.5.0 |
|
17 | + * |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected static $_registry = []; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * Used to register a new template pack with the messages system. |
|
25 | + * |
|
26 | + * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to |
|
27 | + * change entire layouts for a set of message templates. This method is used to register the new template pack and |
|
28 | + * automatically have it loaded in the appropriate places. |
|
29 | + * |
|
30 | + * This registry also verifies that there isn't already a template pack registered with the same name and if there |
|
31 | + * is then it will add an EE_Error notice. |
|
32 | + * |
|
33 | + * Note that this only handles registering the your Template Pack class with the message template pack system. |
|
34 | + * However, there is also a naming schema you must follow for templates you are providing with your template pack. |
|
35 | + * |
|
36 | + * @param string $addon_name The internal reference used to refer to this template pack. Note, this is first come, |
|
37 | + * first serve. If there is already a template pack registered with this name then the |
|
38 | + * registry will assign a unique reference for it so it can still be activated (but this |
|
39 | + * makes it harder to deregister as it will be unique per load - so its best to try to |
|
40 | + * make this a unique string!) |
|
41 | + * @param array $setup_args array { |
|
42 | + * An array of required values for registering the template pack. |
|
43 | + * @type string $path The path for the new template pack class. |
|
44 | + * @type string $classname The name of the new Template Pack Class. |
|
45 | + * } |
|
46 | + * @return bool |
|
47 | + * @throws EE_Error |
|
48 | + * |
|
49 | + * @see core/libraries/messages/defaults/default/* for all the example templates the default template pack |
|
50 | + * supports. |
|
51 | + * |
|
52 | + * |
|
53 | + * @since 4.5.0 |
|
54 | + * @see EE_Messages_Template_Pack_Default for an example class |
|
55 | + */ |
|
56 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
57 | + { |
|
58 | + |
|
59 | + // check for required params |
|
60 | + if (empty($addon_name) || empty($setup_args['path']) || empty($setup_args['classname'])) { |
|
61 | + throw new EE_Error( |
|
62 | + esc_html__( |
|
63 | + 'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ', |
|
64 | + 'event_espresso' |
|
65 | + ) |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + // make sure we don't register twice |
|
70 | + if (isset(self::$_registry[ $addon_name ])) { |
|
71 | + return true; |
|
72 | + } |
|
73 | + |
|
74 | + // check that incoming $addon_name doesn't already exist. If it does then we'll create a unique reference for this template pack. |
|
75 | + if (isset(self::$_registry[ $addon_name ])) { |
|
76 | + $addon_name = uniqid() . '_' . $addon_name; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + // make sure this was called in the right place! |
|
81 | + if ( |
|
82 | + ! did_action('EE_Brewing_Regular___messages_caf') |
|
83 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
84 | + ) { |
|
85 | + EE_Error::doing_it_wrong( |
|
86 | + __METHOD__, |
|
87 | + sprintf( |
|
88 | + esc_html__( |
|
89 | + 'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System. It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + $addon_name |
|
93 | + ), |
|
94 | + '4.5.0' |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + if (self::_verify_class_not_exist($setup_args['classname'])) { |
|
99 | + self::$_registry[ $addon_name ] = [ |
|
100 | + 'path' => (string) $setup_args['path'], |
|
101 | + 'classname' => (string) $setup_args['classname'], |
|
102 | + ]; |
|
103 | + } |
|
104 | + |
|
105 | + // hook into the system |
|
106 | + add_filter( |
|
107 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
108 | + ['EE_Register_Messages_Template_Pack', 'set_template_pack_path'], |
|
109 | + 10 |
|
110 | + ); |
|
111 | + add_filter( |
|
112 | + 'FHEE__EED_Messages__get_template_packs__template_packs', |
|
113 | + ['EE_Register_Messages_Template_Pack', 'set_template_pack'], |
|
114 | + 10 |
|
115 | + ); |
|
116 | + return true; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. This adds this template packs path |
|
122 | + * to the messages autoloader paths. |
|
123 | + * |
|
124 | + * @param array $paths Array of paths already registered with the messages autoloader |
|
125 | + * |
|
126 | + * @return array |
|
127 | + * @since 4.5.0 |
|
128 | + * |
|
129 | + */ |
|
130 | + public static function set_template_pack_path(array $paths): array |
|
131 | + { |
|
132 | + foreach (self::$_registry as $args) { |
|
133 | + $paths[] = $args['path']; |
|
134 | + } |
|
135 | + return $paths; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated, |
|
141 | + * registered template pack to the template packs array when requested by client code. |
|
142 | + * |
|
143 | + * @param EE_Messages_Template_Pack[] $template_packs |
|
144 | + * @return EE_Messages_Template_Pack[] |
|
145 | + * @since 4.5.0 |
|
146 | + * |
|
147 | + */ |
|
148 | + public static function set_template_pack(array $template_packs): array |
|
149 | + { |
|
150 | + foreach (self::$_registry as $args) { |
|
151 | + // verify class_exists |
|
152 | + if (! class_exists($args['classname'])) { |
|
153 | + require_once($args['path'] . '/' . $args['classname'] . '.class.php'); |
|
154 | + } |
|
155 | + |
|
156 | + // check again! |
|
157 | + if (class_exists($args['classname'])) { |
|
158 | + $template_pack = new $args['classname'](); |
|
159 | + $template_packs[ $template_pack->dbref ] = $template_pack; |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + return $template_packs; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * This verifies that the classes for each registered template pack are unique names. |
|
169 | + * |
|
170 | + * @param string $classname The classname being checked |
|
171 | + * |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + private static function _verify_class_not_exist(string $classname): bool |
|
175 | + { |
|
176 | + // loop through the existing registry and see if the classname is already present. |
|
177 | + foreach (self::$_registry as $args) { |
|
178 | + if ($args['classname'] == $classname) { |
|
179 | + EE_Error::add_error( |
|
180 | + sprintf( |
|
181 | + esc_html__( |
|
182 | + 'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname. Contact the author of this template pack to let them know of the conflict. To stop seeing this message you will need to deactivate this template pack.', |
|
183 | + 'event_espresso' |
|
184 | + ), |
|
185 | + $classname |
|
186 | + ), |
|
187 | + __FILE__, |
|
188 | + __LINE__, |
|
189 | + __FUNCTION__ |
|
190 | + ); |
|
191 | + return false; |
|
192 | + } |
|
193 | + } |
|
194 | + return true; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * This deregisters a variation set that was previously registered with the given slug. |
|
200 | + * |
|
201 | + * @param string $addon_name The name for the variation set that was previously registered. |
|
202 | + * |
|
203 | + * @return void |
|
204 | + * @since 4.5.0 |
|
205 | + * |
|
206 | + */ |
|
207 | + public static function deregister(string $addon_name = '') |
|
208 | + { |
|
209 | + unset(self::$_registry[ $addon_name ]); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + public static function reset(): void |
|
214 | + { |
|
215 | + self::$_registry = []; |
|
216 | + } |
|
217 | 217 | } |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | // make sure we don't register twice |
70 | - if (isset(self::$_registry[ $addon_name ])) { |
|
70 | + if (isset(self::$_registry[$addon_name])) { |
|
71 | 71 | return true; |
72 | 72 | } |
73 | 73 | |
74 | 74 | // check that incoming $addon_name doesn't already exist. If it does then we'll create a unique reference for this template pack. |
75 | - if (isset(self::$_registry[ $addon_name ])) { |
|
76 | - $addon_name = uniqid() . '_' . $addon_name; |
|
75 | + if (isset(self::$_registry[$addon_name])) { |
|
76 | + $addon_name = uniqid().'_'.$addon_name; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | if (self::_verify_class_not_exist($setup_args['classname'])) { |
99 | - self::$_registry[ $addon_name ] = [ |
|
99 | + self::$_registry[$addon_name] = [ |
|
100 | 100 | 'path' => (string) $setup_args['path'], |
101 | 101 | 'classname' => (string) $setup_args['classname'], |
102 | 102 | ]; |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | { |
150 | 150 | foreach (self::$_registry as $args) { |
151 | 151 | // verify class_exists |
152 | - if (! class_exists($args['classname'])) { |
|
153 | - require_once($args['path'] . '/' . $args['classname'] . '.class.php'); |
|
152 | + if ( ! class_exists($args['classname'])) { |
|
153 | + require_once($args['path'].'/'.$args['classname'].'.class.php'); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | // check again! |
157 | 157 | if (class_exists($args['classname'])) { |
158 | 158 | $template_pack = new $args['classname'](); |
159 | - $template_packs[ $template_pack->dbref ] = $template_pack; |
|
159 | + $template_packs[$template_pack->dbref] = $template_pack; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public static function deregister(string $addon_name = '') |
208 | 208 | { |
209 | - unset(self::$_registry[ $addon_name ]); |
|
209 | + unset(self::$_registry[$addon_name]); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 |
@@ -10,180 +10,180 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Register_Messages_Shortcode_Library implements EEI_Plugin_API |
12 | 12 | { |
13 | - /** |
|
14 | - * holds values for registered messages shortcode libraries |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected static $_ee_messages_shortcode_registry = []; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * Helper method for registering a new shortcodes library class for the messages system. |
|
23 | - * |
|
24 | - * Note this is not used for adding shortcodes to existing libraries. It's for registering anything |
|
25 | - * related to registering a new EE_{shortcode_library_name}_Shortcodes.lib.php class. |
|
26 | - * |
|
27 | - * @param string $addon_name What is the name of this shortcode library (e.g. 'question_list'); |
|
28 | - * @param array $setup_args An array of arguments provided for registering the new messages shortcode library. |
|
29 | - * { |
|
30 | - * |
|
31 | - * @type array $autoloadpaths An array of paths to add to the messages autoloader |
|
32 | - * for the new shortcode library class file. |
|
33 | - * @type string $msgr_validator_callback Callback for a method that will register the library with the |
|
34 | - * messenger _validator_config. Optional. |
|
35 | - * @type string $msgr_template_fields_callback Callback for changing adding the _template_fields property for |
|
36 | - * messenger. For example, the shortcode library may add a new |
|
37 | - * field to the message templates. Optional. |
|
38 | - * @type string $valid_shortcodes_callback Callback for message types _valid_shortcodes array setup. |
|
39 | - * Optional. |
|
40 | - * @type array $list_type_shortcodes If there are any specific shortcodes with this message |
|
41 | - * shortcode library that should be considered "list type" |
|
42 | - * then include them in an array. |
|
43 | - * List Type shortcodes are shortcodes that have a corresponding |
|
44 | - * field that indicates how they are parsed. Optional. |
|
45 | - * } |
|
46 | - * @return bool |
|
47 | - * @throws EE_Error |
|
48 | - * @throws EE_Error |
|
49 | - * @since 4.3.0 |
|
50 | - * |
|
51 | - */ |
|
52 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
53 | - { |
|
54 | - |
|
55 | - // required fields MUST be present, so let's make sure they are. |
|
56 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['autoloadpaths'])) { |
|
57 | - throw new EE_Error( |
|
58 | - esc_html__( |
|
59 | - 'In order to register a messages shortcode library with EE_Register_Messages_Shortcode_Library::register, you must include a "name" (a unique identifier for this set of message shortcodes), and an array containing the following keys: : "autoload_paths"', |
|
60 | - 'event_espresso' |
|
61 | - ) |
|
62 | - ); |
|
63 | - } |
|
64 | - |
|
65 | - // make sure we don't register twice |
|
66 | - if (isset(self::$_ee_messages_shortcode_registry[ $addon_name ])) { |
|
67 | - return true; |
|
68 | - } |
|
69 | - |
|
70 | - // make sure this was called in the right place! |
|
71 | - if ( |
|
72 | - ! did_action('EE_Brewing_Regular___messages_caf') |
|
73 | - || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
74 | - ) { |
|
75 | - EE_Error::doing_it_wrong( |
|
76 | - __METHOD__, |
|
77 | - sprintf( |
|
78 | - esc_html__( |
|
79 | - 'Should be only called on the "EE_Brewing_Regular___messages_caf" hook (Trying to register a library named %s).', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - $addon_name |
|
83 | - ), |
|
84 | - '4.3.0' |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - self::$_ee_messages_shortcode_registry[ $addon_name ] = [ |
|
89 | - 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
|
90 | - 'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes']) |
|
91 | - ? (array) $setup_args['list_type_shortcodes'] : [], |
|
92 | - ]; |
|
93 | - |
|
94 | - // add filters |
|
95 | - add_filter( |
|
96 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
97 | - ['EE_Register_Messages_Shortcode_Library', 'register_msgs_autoload_paths'], |
|
98 | - 10 |
|
99 | - ); |
|
100 | - |
|
101 | - // add below filters if the required callback is provided. |
|
102 | - if (! empty($setup_args['msgr_validator_callback'])) { |
|
103 | - add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2); |
|
104 | - } |
|
105 | - |
|
106 | - if (! empty($setup_args['msgr_template_fields_callback'])) { |
|
107 | - add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2); |
|
108 | - } |
|
109 | - |
|
110 | - if (! empty($setup_args['valid_shortcodes_callback'])) { |
|
111 | - add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2); |
|
112 | - } |
|
113 | - |
|
114 | - if (! empty($setup_args['list_type_shortcodes'])) { |
|
115 | - add_filter( |
|
116 | - 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
117 | - ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'], |
|
118 | - 10 |
|
119 | - ); |
|
120 | - } |
|
121 | - return true; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * This deregisters any messages shortcode library previously registered with the given name. |
|
127 | - * |
|
128 | - * @param string $addon_name name used to register the shortcode library. |
|
129 | - * @return void |
|
130 | - * @since 4.3.0 |
|
131 | - */ |
|
132 | - public static function deregister(string $addon_name = '') |
|
133 | - { |
|
134 | - unset(self::$_ee_messages_shortcode_registry[ $addon_name ]); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
140 | - * |
|
141 | - * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
142 | - * @return array |
|
143 | - * @since 4.3.0 |
|
144 | - * |
|
145 | - */ |
|
146 | - public static function register_msgs_autoload_paths(array $paths): array |
|
147 | - { |
|
148 | - $autoload_paths = []; |
|
149 | - if (! empty(self::$_ee_messages_shortcode_registry)) { |
|
150 | - foreach (self::$_ee_messages_shortcode_registry as $st_reg) { |
|
151 | - if (empty($st_reg['autoloadpaths'])) { |
|
152 | - continue; |
|
153 | - } |
|
154 | - $autoload_paths[] = $st_reg['autoloadpaths']; |
|
155 | - } |
|
156 | - } |
|
157 | - return array_merge($paths, ...$autoload_paths); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * This is the callback for the FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes |
|
163 | - * filter which is used to add additional list type shortcodes. |
|
164 | - * |
|
165 | - * @param array $original_shortcodes |
|
166 | - * @return array Modifications to original shortcodes. |
|
167 | - * @since 4.3.0 |
|
168 | - * |
|
169 | - */ |
|
170 | - public static function register_list_type_shortcodes(array $original_shortcodes): array |
|
171 | - { |
|
172 | - if (empty(self::$_ee_messages_shortcode_registry)) { |
|
173 | - return $original_shortcodes; |
|
174 | - } |
|
175 | - $shortcodes = []; |
|
176 | - foreach (self::$_ee_messages_shortcode_registry as $sc_reg) { |
|
177 | - if (! empty($sc_reg['list_type_shortcodes'])) { |
|
178 | - $shortcodes[] = $sc_reg['list_type_shortcodes']; |
|
179 | - } |
|
180 | - } |
|
181 | - return array_merge($original_shortcodes, ...$shortcodes); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - public static function reset(): void |
|
186 | - { |
|
187 | - self::$_ee_messages_shortcode_registry = []; |
|
188 | - } |
|
13 | + /** |
|
14 | + * holds values for registered messages shortcode libraries |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected static $_ee_messages_shortcode_registry = []; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * Helper method for registering a new shortcodes library class for the messages system. |
|
23 | + * |
|
24 | + * Note this is not used for adding shortcodes to existing libraries. It's for registering anything |
|
25 | + * related to registering a new EE_{shortcode_library_name}_Shortcodes.lib.php class. |
|
26 | + * |
|
27 | + * @param string $addon_name What is the name of this shortcode library (e.g. 'question_list'); |
|
28 | + * @param array $setup_args An array of arguments provided for registering the new messages shortcode library. |
|
29 | + * { |
|
30 | + * |
|
31 | + * @type array $autoloadpaths An array of paths to add to the messages autoloader |
|
32 | + * for the new shortcode library class file. |
|
33 | + * @type string $msgr_validator_callback Callback for a method that will register the library with the |
|
34 | + * messenger _validator_config. Optional. |
|
35 | + * @type string $msgr_template_fields_callback Callback for changing adding the _template_fields property for |
|
36 | + * messenger. For example, the shortcode library may add a new |
|
37 | + * field to the message templates. Optional. |
|
38 | + * @type string $valid_shortcodes_callback Callback for message types _valid_shortcodes array setup. |
|
39 | + * Optional. |
|
40 | + * @type array $list_type_shortcodes If there are any specific shortcodes with this message |
|
41 | + * shortcode library that should be considered "list type" |
|
42 | + * then include them in an array. |
|
43 | + * List Type shortcodes are shortcodes that have a corresponding |
|
44 | + * field that indicates how they are parsed. Optional. |
|
45 | + * } |
|
46 | + * @return bool |
|
47 | + * @throws EE_Error |
|
48 | + * @throws EE_Error |
|
49 | + * @since 4.3.0 |
|
50 | + * |
|
51 | + */ |
|
52 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
53 | + { |
|
54 | + |
|
55 | + // required fields MUST be present, so let's make sure they are. |
|
56 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['autoloadpaths'])) { |
|
57 | + throw new EE_Error( |
|
58 | + esc_html__( |
|
59 | + 'In order to register a messages shortcode library with EE_Register_Messages_Shortcode_Library::register, you must include a "name" (a unique identifier for this set of message shortcodes), and an array containing the following keys: : "autoload_paths"', |
|
60 | + 'event_espresso' |
|
61 | + ) |
|
62 | + ); |
|
63 | + } |
|
64 | + |
|
65 | + // make sure we don't register twice |
|
66 | + if (isset(self::$_ee_messages_shortcode_registry[ $addon_name ])) { |
|
67 | + return true; |
|
68 | + } |
|
69 | + |
|
70 | + // make sure this was called in the right place! |
|
71 | + if ( |
|
72 | + ! did_action('EE_Brewing_Regular___messages_caf') |
|
73 | + || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations') |
|
74 | + ) { |
|
75 | + EE_Error::doing_it_wrong( |
|
76 | + __METHOD__, |
|
77 | + sprintf( |
|
78 | + esc_html__( |
|
79 | + 'Should be only called on the "EE_Brewing_Regular___messages_caf" hook (Trying to register a library named %s).', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + $addon_name |
|
83 | + ), |
|
84 | + '4.3.0' |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + self::$_ee_messages_shortcode_registry[ $addon_name ] = [ |
|
89 | + 'autoloadpaths' => (array) $setup_args['autoloadpaths'], |
|
90 | + 'list_type_shortcodes' => ! empty($setup_args['list_type_shortcodes']) |
|
91 | + ? (array) $setup_args['list_type_shortcodes'] : [], |
|
92 | + ]; |
|
93 | + |
|
94 | + // add filters |
|
95 | + add_filter( |
|
96 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
97 | + ['EE_Register_Messages_Shortcode_Library', 'register_msgs_autoload_paths'], |
|
98 | + 10 |
|
99 | + ); |
|
100 | + |
|
101 | + // add below filters if the required callback is provided. |
|
102 | + if (! empty($setup_args['msgr_validator_callback'])) { |
|
103 | + add_filter('FHEE__EE_messenger__get_validator_config', $setup_args['msgr_validator_callback'], 10, 2); |
|
104 | + } |
|
105 | + |
|
106 | + if (! empty($setup_args['msgr_template_fields_callback'])) { |
|
107 | + add_filter('FHEE__EE_messenger__get_template_fields', $setup_args['msgr_template_fields_callback'], 10, 2); |
|
108 | + } |
|
109 | + |
|
110 | + if (! empty($setup_args['valid_shortcodes_callback'])) { |
|
111 | + add_filter('FHEE__EE_Messages_Base__get_valid_shortcodes', $setup_args['valid_shortcodes_callback'], 10, 2); |
|
112 | + } |
|
113 | + |
|
114 | + if (! empty($setup_args['list_type_shortcodes'])) { |
|
115 | + add_filter( |
|
116 | + 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', |
|
117 | + ['EE_Register_Messages_Shortcode_Library', 'register_list_type_shortcodes'], |
|
118 | + 10 |
|
119 | + ); |
|
120 | + } |
|
121 | + return true; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * This deregisters any messages shortcode library previously registered with the given name. |
|
127 | + * |
|
128 | + * @param string $addon_name name used to register the shortcode library. |
|
129 | + * @return void |
|
130 | + * @since 4.3.0 |
|
131 | + */ |
|
132 | + public static function deregister(string $addon_name = '') |
|
133 | + { |
|
134 | + unset(self::$_ee_messages_shortcode_registry[ $addon_name ]); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter. |
|
140 | + * |
|
141 | + * @param array $paths array of paths to be checked by EE_messages autoloader. |
|
142 | + * @return array |
|
143 | + * @since 4.3.0 |
|
144 | + * |
|
145 | + */ |
|
146 | + public static function register_msgs_autoload_paths(array $paths): array |
|
147 | + { |
|
148 | + $autoload_paths = []; |
|
149 | + if (! empty(self::$_ee_messages_shortcode_registry)) { |
|
150 | + foreach (self::$_ee_messages_shortcode_registry as $st_reg) { |
|
151 | + if (empty($st_reg['autoloadpaths'])) { |
|
152 | + continue; |
|
153 | + } |
|
154 | + $autoload_paths[] = $st_reg['autoloadpaths']; |
|
155 | + } |
|
156 | + } |
|
157 | + return array_merge($paths, ...$autoload_paths); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * This is the callback for the FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes |
|
163 | + * filter which is used to add additional list type shortcodes. |
|
164 | + * |
|
165 | + * @param array $original_shortcodes |
|
166 | + * @return array Modifications to original shortcodes. |
|
167 | + * @since 4.3.0 |
|
168 | + * |
|
169 | + */ |
|
170 | + public static function register_list_type_shortcodes(array $original_shortcodes): array |
|
171 | + { |
|
172 | + if (empty(self::$_ee_messages_shortcode_registry)) { |
|
173 | + return $original_shortcodes; |
|
174 | + } |
|
175 | + $shortcodes = []; |
|
176 | + foreach (self::$_ee_messages_shortcode_registry as $sc_reg) { |
|
177 | + if (! empty($sc_reg['list_type_shortcodes'])) { |
|
178 | + $shortcodes[] = $sc_reg['list_type_shortcodes']; |
|
179 | + } |
|
180 | + } |
|
181 | + return array_merge($original_shortcodes, ...$shortcodes); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + public static function reset(): void |
|
186 | + { |
|
187 | + self::$_ee_messages_shortcode_registry = []; |
|
188 | + } |
|
189 | 189 | } |
@@ -17,186 +17,186 @@ |
||
17 | 17 | */ |
18 | 18 | class EE_Primary_Registration_Details_Shortcodes extends EE_Shortcodes |
19 | 19 | { |
20 | - protected function _init_props() |
|
21 | - { |
|
22 | - $this->label = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso'); |
|
23 | - $this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso'); |
|
24 | - $this->_shortcodes = array( |
|
25 | - '[PRIMARY_REGISTRANT_FNAME]' => esc_html__( |
|
26 | - 'Parses to the first name of the primary registration for the transaction.', |
|
27 | - 'event_espresso' |
|
28 | - ), |
|
29 | - '[PRIMARY_REGISTRANT_LNAME]' => esc_html__( |
|
30 | - 'Parses to the last name of the primary registration for the transaction.', |
|
31 | - 'event_espresso' |
|
32 | - ), |
|
33 | - '[PRIMARY_REGISTRANT_EMAIL]' => esc_html__( |
|
34 | - 'Parses to the email address of the primary registration for the transaction.', |
|
35 | - 'event_espresso' |
|
36 | - ), |
|
37 | - '[PRIMARY_REGISTRANT_REGISTRATION_ID]' => esc_html__( |
|
38 | - 'Parses to the registration ID of the primary registrant for the transaction.', |
|
39 | - 'event_espresso' |
|
40 | - ), |
|
41 | - '[PRIMARY_REGISTRANT_REGISTRATION_CODE]' => esc_html__( |
|
42 | - 'Parses to the registration code of the primary registrant for the transaction.', |
|
43 | - 'event_espresso' |
|
44 | - ), |
|
45 | - '[PRIMARY_REGISTRANT_PHONE_NUMBER]' => esc_html__( |
|
46 | - 'The Phone Number for the primary registrant for the transaction.', |
|
47 | - 'event_espresso' |
|
48 | - ), |
|
49 | - '[PRIMARY_REGISTRANT_ADDRESS]' => esc_html__( |
|
50 | - 'The Address for the primary registrant for the transaction.', |
|
51 | - 'event_espresso' |
|
52 | - ), |
|
53 | - '[PRIMARY_REGISTRANT_ADDRESS2]' => esc_html__( |
|
54 | - 'Whatever was in the address 2 field for the primary registrant for the transaction.', |
|
55 | - 'event_espresso' |
|
56 | - ), |
|
57 | - '[PRIMARY_REGISTRANT_CITY]' => esc_html__( |
|
58 | - 'The city for the primary registrant for the transaction.', |
|
59 | - 'event_espresso' |
|
60 | - ), |
|
61 | - '[PRIMARY_REGISTRANT_ZIP_PC]' => esc_html__( |
|
62 | - 'The ZIP (or Postal) Code for the primary registrant for the transaction.', |
|
63 | - 'event_espresso' |
|
64 | - ), |
|
65 | - '[PRIMARY_REGISTRANT_ADDRESS_STATE]' => esc_html__( |
|
66 | - 'The state/province for the primary registrant for the transaction.', |
|
67 | - 'event_espresso' |
|
68 | - ), |
|
69 | - '[PRIMARY_REGISTRANT_COUNTRY]' => esc_html__( |
|
70 | - 'The country for the primary registrant for the transaction.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - '[PRIMARY_REGISTRANT_REGISTRATION_DATE]' => esc_html__( |
|
74 | - 'The date the registration occured for the primary registration.', |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
78 | - 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - '[PRIMARY_REGISTRANT_ANSWER_*]' => esc_html__( |
|
82 | - 'This is a special dynamic shortcode. After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - protected function _parser($shortcode) |
|
90 | - { |
|
91 | - // make sure we end up with a copy of the EE_Messages_Addressee object |
|
92 | - $primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
93 | - $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && is_array( |
|
94 | - $this->_data |
|
95 | - ) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data'] |
|
96 | - : $primary_registration; |
|
97 | - $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
98 | - ? $this->_extra_data['data'] : $primary_registration; |
|
99 | - |
|
100 | - if (! $primary_registration instanceof EE_Messages_Addressee) { |
|
101 | - return ''; |
|
102 | - } |
|
103 | - |
|
104 | - $attendee = $primary_registration->primary_att_obj; |
|
105 | - $primary_reg = $primary_registration->primary_reg_obj; |
|
106 | - |
|
107 | - if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) { |
|
108 | - return ''; |
|
109 | - } |
|
110 | - |
|
111 | - switch ($shortcode) { |
|
112 | - case '[PRIMARY_REGISTRANT_FNAME]': |
|
113 | - return $attendee->fname(); |
|
114 | - |
|
115 | - case '[PRIMARY_REGISTRANT_LNAME]': |
|
116 | - return $attendee->lname(); |
|
117 | - |
|
118 | - case '[PRIMARY_REGISTRANT_EMAIL]': |
|
119 | - return $attendee->email(); |
|
120 | - |
|
121 | - case '[PRIMARY_REGISTRANT_REGISTRATION_ID]': |
|
122 | - return $primary_reg->ID(); |
|
123 | - |
|
124 | - case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]': |
|
125 | - return $primary_reg->reg_code(); |
|
126 | - |
|
127 | - case '[PRIMARY_REGISTRANT_PHONE_NUMBER]': |
|
128 | - return $attendee->phone(); |
|
129 | - |
|
130 | - case '[PRIMARY_REGISTRANT_ADDRESS]': |
|
131 | - return $attendee->address(); |
|
132 | - |
|
133 | - case '[PRIMARY_REGISTRANT_ADDRESS2]': |
|
134 | - return $attendee->address2(); |
|
135 | - |
|
136 | - case '[PRIMARY_REGISTRANT_CITY]': |
|
137 | - return $attendee->city(); |
|
138 | - |
|
139 | - case '[PRIMARY_REGISTRANT_ZIP_PC]': |
|
140 | - return $attendee->zip(); |
|
141 | - |
|
142 | - case '[PRIMARY_REGISTRANT_ADDRESS_STATE]': |
|
143 | - $state_obj = $attendee->state_obj(); |
|
144 | - return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
145 | - |
|
146 | - case '[PRIMARY_REGISTRANT_COUNTRY]': |
|
147 | - $country_obj = $attendee->country_obj(); |
|
148 | - return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
149 | - |
|
150 | - case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]': |
|
151 | - if (! $primary_registration->primary_reg_obj instanceof EE_Registration) { |
|
152 | - return ''; |
|
153 | - } |
|
154 | - return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format')); |
|
155 | - |
|
156 | - case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]': |
|
157 | - return $primary_reg->edit_attendee_information_url(); |
|
158 | - } |
|
159 | - |
|
160 | - if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) { |
|
161 | - $shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode); |
|
162 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
163 | - |
|
164 | - |
|
165 | - // now let's figure out what question has this text |
|
166 | - if (empty($primary_registration->questions)) { |
|
167 | - return ''; |
|
168 | - } |
|
169 | - |
|
170 | - foreach ($primary_registration->questions as $ansid => $question) { |
|
171 | - if ( |
|
172 | - $question instanceof EE_Question |
|
173 | - && trim($question->get('QST_display_text')) === trim($shortcode) |
|
174 | - && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]) |
|
175 | - ) { |
|
176 | - $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]; |
|
177 | - |
|
178 | - // what we show for the answer depends on the question type! |
|
179 | - switch ($question->get('QST_type')) { |
|
180 | - case EEM_Question::QST_type_state: |
|
181 | - $state = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value')); |
|
182 | - $answer = $state instanceof EE_State ? $state->name() : ''; |
|
183 | - break; |
|
184 | - |
|
185 | - case EEM_Question::QST_type_country: |
|
186 | - $country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value')); |
|
187 | - $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
188 | - break; |
|
189 | - |
|
190 | - default: |
|
191 | - $answer = $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop'); |
|
192 | - break; |
|
193 | - } |
|
194 | - |
|
195 | - return $answer; |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
20 | + protected function _init_props() |
|
21 | + { |
|
22 | + $this->label = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso'); |
|
23 | + $this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso'); |
|
24 | + $this->_shortcodes = array( |
|
25 | + '[PRIMARY_REGISTRANT_FNAME]' => esc_html__( |
|
26 | + 'Parses to the first name of the primary registration for the transaction.', |
|
27 | + 'event_espresso' |
|
28 | + ), |
|
29 | + '[PRIMARY_REGISTRANT_LNAME]' => esc_html__( |
|
30 | + 'Parses to the last name of the primary registration for the transaction.', |
|
31 | + 'event_espresso' |
|
32 | + ), |
|
33 | + '[PRIMARY_REGISTRANT_EMAIL]' => esc_html__( |
|
34 | + 'Parses to the email address of the primary registration for the transaction.', |
|
35 | + 'event_espresso' |
|
36 | + ), |
|
37 | + '[PRIMARY_REGISTRANT_REGISTRATION_ID]' => esc_html__( |
|
38 | + 'Parses to the registration ID of the primary registrant for the transaction.', |
|
39 | + 'event_espresso' |
|
40 | + ), |
|
41 | + '[PRIMARY_REGISTRANT_REGISTRATION_CODE]' => esc_html__( |
|
42 | + 'Parses to the registration code of the primary registrant for the transaction.', |
|
43 | + 'event_espresso' |
|
44 | + ), |
|
45 | + '[PRIMARY_REGISTRANT_PHONE_NUMBER]' => esc_html__( |
|
46 | + 'The Phone Number for the primary registrant for the transaction.', |
|
47 | + 'event_espresso' |
|
48 | + ), |
|
49 | + '[PRIMARY_REGISTRANT_ADDRESS]' => esc_html__( |
|
50 | + 'The Address for the primary registrant for the transaction.', |
|
51 | + 'event_espresso' |
|
52 | + ), |
|
53 | + '[PRIMARY_REGISTRANT_ADDRESS2]' => esc_html__( |
|
54 | + 'Whatever was in the address 2 field for the primary registrant for the transaction.', |
|
55 | + 'event_espresso' |
|
56 | + ), |
|
57 | + '[PRIMARY_REGISTRANT_CITY]' => esc_html__( |
|
58 | + 'The city for the primary registrant for the transaction.', |
|
59 | + 'event_espresso' |
|
60 | + ), |
|
61 | + '[PRIMARY_REGISTRANT_ZIP_PC]' => esc_html__( |
|
62 | + 'The ZIP (or Postal) Code for the primary registrant for the transaction.', |
|
63 | + 'event_espresso' |
|
64 | + ), |
|
65 | + '[PRIMARY_REGISTRANT_ADDRESS_STATE]' => esc_html__( |
|
66 | + 'The state/province for the primary registrant for the transaction.', |
|
67 | + 'event_espresso' |
|
68 | + ), |
|
69 | + '[PRIMARY_REGISTRANT_COUNTRY]' => esc_html__( |
|
70 | + 'The country for the primary registrant for the transaction.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + '[PRIMARY_REGISTRANT_REGISTRATION_DATE]' => esc_html__( |
|
74 | + 'The date the registration occured for the primary registration.', |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__( |
|
78 | + 'Generates a link for the given registration to edit this registration details on the frontend.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + '[PRIMARY_REGISTRANT_ANSWER_*]' => esc_html__( |
|
82 | + 'This is a special dynamic shortcode. After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + protected function _parser($shortcode) |
|
90 | + { |
|
91 | + // make sure we end up with a copy of the EE_Messages_Addressee object |
|
92 | + $primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
93 | + $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && is_array( |
|
94 | + $this->_data |
|
95 | + ) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data'] |
|
96 | + : $primary_registration; |
|
97 | + $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
98 | + ? $this->_extra_data['data'] : $primary_registration; |
|
99 | + |
|
100 | + if (! $primary_registration instanceof EE_Messages_Addressee) { |
|
101 | + return ''; |
|
102 | + } |
|
103 | + |
|
104 | + $attendee = $primary_registration->primary_att_obj; |
|
105 | + $primary_reg = $primary_registration->primary_reg_obj; |
|
106 | + |
|
107 | + if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) { |
|
108 | + return ''; |
|
109 | + } |
|
110 | + |
|
111 | + switch ($shortcode) { |
|
112 | + case '[PRIMARY_REGISTRANT_FNAME]': |
|
113 | + return $attendee->fname(); |
|
114 | + |
|
115 | + case '[PRIMARY_REGISTRANT_LNAME]': |
|
116 | + return $attendee->lname(); |
|
117 | + |
|
118 | + case '[PRIMARY_REGISTRANT_EMAIL]': |
|
119 | + return $attendee->email(); |
|
120 | + |
|
121 | + case '[PRIMARY_REGISTRANT_REGISTRATION_ID]': |
|
122 | + return $primary_reg->ID(); |
|
123 | + |
|
124 | + case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]': |
|
125 | + return $primary_reg->reg_code(); |
|
126 | + |
|
127 | + case '[PRIMARY_REGISTRANT_PHONE_NUMBER]': |
|
128 | + return $attendee->phone(); |
|
129 | + |
|
130 | + case '[PRIMARY_REGISTRANT_ADDRESS]': |
|
131 | + return $attendee->address(); |
|
132 | + |
|
133 | + case '[PRIMARY_REGISTRANT_ADDRESS2]': |
|
134 | + return $attendee->address2(); |
|
135 | + |
|
136 | + case '[PRIMARY_REGISTRANT_CITY]': |
|
137 | + return $attendee->city(); |
|
138 | + |
|
139 | + case '[PRIMARY_REGISTRANT_ZIP_PC]': |
|
140 | + return $attendee->zip(); |
|
141 | + |
|
142 | + case '[PRIMARY_REGISTRANT_ADDRESS_STATE]': |
|
143 | + $state_obj = $attendee->state_obj(); |
|
144 | + return $state_obj instanceof EE_State ? $state_obj->name() : ''; |
|
145 | + |
|
146 | + case '[PRIMARY_REGISTRANT_COUNTRY]': |
|
147 | + $country_obj = $attendee->country_obj(); |
|
148 | + return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
|
149 | + |
|
150 | + case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]': |
|
151 | + if (! $primary_registration->primary_reg_obj instanceof EE_Registration) { |
|
152 | + return ''; |
|
153 | + } |
|
154 | + return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format')); |
|
155 | + |
|
156 | + case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]': |
|
157 | + return $primary_reg->edit_attendee_information_url(); |
|
158 | + } |
|
159 | + |
|
160 | + if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) { |
|
161 | + $shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode); |
|
162 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
163 | + |
|
164 | + |
|
165 | + // now let's figure out what question has this text |
|
166 | + if (empty($primary_registration->questions)) { |
|
167 | + return ''; |
|
168 | + } |
|
169 | + |
|
170 | + foreach ($primary_registration->questions as $ansid => $question) { |
|
171 | + if ( |
|
172 | + $question instanceof EE_Question |
|
173 | + && trim($question->get('QST_display_text')) === trim($shortcode) |
|
174 | + && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]) |
|
175 | + ) { |
|
176 | + $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]; |
|
177 | + |
|
178 | + // what we show for the answer depends on the question type! |
|
179 | + switch ($question->get('QST_type')) { |
|
180 | + case EEM_Question::QST_type_state: |
|
181 | + $state = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value')); |
|
182 | + $answer = $state instanceof EE_State ? $state->name() : ''; |
|
183 | + break; |
|
184 | + |
|
185 | + case EEM_Question::QST_type_country: |
|
186 | + $country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value')); |
|
187 | + $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
188 | + break; |
|
189 | + |
|
190 | + default: |
|
191 | + $answer = $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop'); |
|
192 | + break; |
|
193 | + } |
|
194 | + |
|
195 | + return $answer; |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | 199 | |
200 | - return ''; |
|
201 | - } |
|
200 | + return ''; |
|
201 | + } |
|
202 | 202 | } |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
98 | 98 | ? $this->_extra_data['data'] : $primary_registration; |
99 | 99 | |
100 | - if (! $primary_registration instanceof EE_Messages_Addressee) { |
|
100 | + if ( ! $primary_registration instanceof EE_Messages_Addressee) { |
|
101 | 101 | return ''; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $attendee = $primary_registration->primary_att_obj; |
105 | 105 | $primary_reg = $primary_registration->primary_reg_obj; |
106 | 106 | |
107 | - if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) { |
|
107 | + if ( ! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) { |
|
108 | 108 | return ''; |
109 | 109 | } |
110 | 110 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | return $country_obj instanceof EE_Country ? $country_obj->name() : ''; |
149 | 149 | |
150 | 150 | case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]': |
151 | - if (! $primary_registration->primary_reg_obj instanceof EE_Registration) { |
|
151 | + if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration) { |
|
152 | 152 | return ''; |
153 | 153 | } |
154 | 154 | return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format')); |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | if ( |
172 | 172 | $question instanceof EE_Question |
173 | 173 | && trim($question->get('QST_display_text')) === trim($shortcode) |
174 | - && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]) |
|
174 | + && isset($primary_registration->registrations[$primary_reg->ID()]['ans_objs'][$ansid]) |
|
175 | 175 | ) { |
176 | - $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ]; |
|
176 | + $primary_reg_ansid = $primary_registration->registrations[$primary_reg->ID()]['ans_objs'][$ansid]; |
|
177 | 177 | |
178 | 178 | // what we show for the answer depends on the question type! |
179 | 179 | switch ($question->get('QST_type')) { |
@@ -16,786 +16,786 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Transaction_Shortcodes extends EE_Shortcodes |
18 | 18 | { |
19 | - /** |
|
20 | - * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc |
|
21 | - */ |
|
22 | - protected $_invoice_pm; |
|
23 | - |
|
24 | - |
|
25 | - protected function _init_props() |
|
26 | - { |
|
27 | - $this->label = esc_html__('Transaction Shortcodes', 'event_espresso'); |
|
28 | - $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso'); |
|
29 | - $this->_shortcodes = array( |
|
30 | - '[TXN_ID]' => esc_html__('The transaction id for the purchase.', 'event_espresso'), |
|
31 | - '[PAYMENT_URL]' => esc_html__( |
|
32 | - 'This is a link to make a payment for the event', |
|
33 | - 'event_espresso' |
|
34 | - ), |
|
35 | - '[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__( |
|
36 | - 'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', |
|
37 | - 'event_espresso' |
|
38 | - ) |
|
39 | - . '<ul>' |
|
40 | - . '<li>' |
|
41 | - . sprintf( |
|
42 | - esc_html__( |
|
43 | - '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '<strong>', |
|
47 | - '</strong>' |
|
48 | - ) |
|
49 | - . '</li>' |
|
50 | - . '<li>' |
|
51 | - . sprintf( |
|
52 | - esc_html__( |
|
53 | - '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', |
|
54 | - 'event_espresso' |
|
55 | - ), |
|
56 | - '<strong>', |
|
57 | - '</strong>' |
|
58 | - ) |
|
59 | - . '</li>' |
|
60 | - . '<li>' |
|
61 | - . sprintf( |
|
62 | - esc_html__( |
|
63 | - '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', |
|
64 | - 'event_espresso' |
|
65 | - ), |
|
66 | - '<strong>', |
|
67 | - '</strong>' |
|
68 | - ) |
|
69 | - . '</li>' |
|
70 | - . '</ul>', |
|
71 | - '[PAYMENT_DUE_DATE_*]' => esc_html__( |
|
72 | - 'This is a special dynamic shortcode that allows one to output a payment due date. It will only result in a date shown if there is money owing. Three parameters are available on this shortcode:', |
|
73 | - 'event_espresso' |
|
74 | - ) |
|
75 | - . '<ul>' |
|
76 | - . '<li>' |
|
77 | - . sprintf( |
|
78 | - esc_html__( |
|
79 | - '%sformat:%s This is used to indicate what format the date is in. Default is whatever is set as date formats for your website.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - '<strong>', |
|
83 | - '</strong>' |
|
84 | - ) |
|
85 | - . '</li>' |
|
86 | - . '<li>' |
|
87 | - . sprintf( |
|
88 | - esc_html__( |
|
89 | - '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due. Defaults to 30.', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - '<strong>', |
|
93 | - '</strong>' |
|
94 | - ) |
|
95 | - . '</li>' |
|
96 | - . '<li>' |
|
97 | - . sprintf( |
|
98 | - esc_html__( |
|
99 | - '%sprefix_text:%s You can use this to indicate what text will prefix the date string. Defaults to "Payment in full due by:"', |
|
100 | - 'event_espresso' |
|
101 | - ), |
|
102 | - '<strong>', |
|
103 | - '</strong>' |
|
104 | - ) |
|
105 | - . '</li>', |
|
106 | - '[INVOICE_LINK]' => esc_html__( |
|
107 | - 'This is a full html link to the invoice', |
|
108 | - 'event_espresso' |
|
109 | - ), |
|
110 | - '[INVOICE_URL]' => esc_html__( |
|
111 | - 'This is just the url for the invoice', |
|
112 | - 'event_espresso' |
|
113 | - ), |
|
114 | - '[INVOICE_LOGO_URL]' => esc_html__( |
|
115 | - 'This returns the url for the logo uploaded via the invoice settings page.', |
|
116 | - 'event_espresso' |
|
117 | - ), |
|
118 | - '[INVOICE_LOGO]' => esc_html__( |
|
119 | - 'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', |
|
120 | - 'event_espresso' |
|
121 | - ), |
|
122 | - '[INVOICE_PAYEE_NAME]' => esc_html__( |
|
123 | - 'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', |
|
124 | - 'event_espresso' |
|
125 | - ), |
|
126 | - '[INVOICE_PAYEE_ADDRESS]' => esc_html__( |
|
127 | - 'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', |
|
128 | - 'event_espresso' |
|
129 | - ), |
|
130 | - '[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__( |
|
131 | - 'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', |
|
132 | - 'event_espresso' |
|
133 | - ), |
|
134 | - '[INVOICE_PAYEE_EMAIL]' => esc_html__( |
|
135 | - 'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', |
|
136 | - 'event_espresso' |
|
137 | - ), |
|
138 | - '[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf( |
|
139 | - esc_html__( |
|
140 | - 'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56. If you have no tax number in your settings, then no prefix will be output either.', |
|
141 | - 'event_espresso' |
|
142 | - ), |
|
143 | - '<code>', |
|
144 | - '</code>' |
|
145 | - ), |
|
146 | - '[TOTAL_COST]' => esc_html__('The total cost for the transaction', 'event_espresso'), |
|
147 | - '[TXN_STATUS]' => esc_html__( |
|
148 | - 'The transaction status for the transaction.', |
|
149 | - 'event_espresso' |
|
150 | - ), |
|
151 | - '[TXN_STATUS_ID]' => esc_html__( |
|
152 | - 'The ID representing the transaction status as saved in the db. This tends to be useful for including with css classes for styling certain statuses differently from others.', |
|
153 | - 'event_espresso' |
|
154 | - ), |
|
155 | - '[PAYMENT_STATUS]' => esc_html__( |
|
156 | - 'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', |
|
157 | - 'event_espresso' |
|
158 | - ), |
|
159 | - '[PAYMENT_GATEWAY]' => esc_html__( |
|
160 | - 'The payment gateway used for the transaction', |
|
161 | - 'event_espresso' |
|
162 | - ), |
|
163 | - '[AMOUNT_PAID]' => esc_html__( |
|
164 | - 'The amount paid or refunded. This will only have a value if there was a payment or refund at the time of generating the message.', |
|
165 | - 'event_espresso' |
|
166 | - ), |
|
167 | - '[LAST_AMOUNT_PAID]' => esc_html__( |
|
168 | - 'This is the last payment or refund made on the transaction related to the message being generated.', |
|
169 | - 'event_espresso' |
|
170 | - ), |
|
171 | - '[TOTAL_AMOUNT_PAID]' => esc_html__( |
|
172 | - 'This parses to the total amount paid over all payments', |
|
173 | - 'event_espresso' |
|
174 | - ), |
|
175 | - '[TOTAL_OWING]' => esc_html__( |
|
176 | - 'The total owing on a transaction with no attributes.', |
|
177 | - 'event_espresso' |
|
178 | - ), |
|
179 | - '[TXN_SUBTOTAL]' => esc_html__('The subtotal for all txn line items.', 'event_espresso'), |
|
180 | - '[TXN_TAX_SUBTOTAL]' => esc_html__('The subtotal for all tax line items.', 'event_espresso'), |
|
181 | - '[OWING_STATUS_MESSAGE_*]' => esc_html__( |
|
182 | - 'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', |
|
183 | - 'event_espresso' |
|
184 | - ) |
|
185 | - . '<p></ul>' |
|
186 | - . '<li><strong>still_owing</strong>:' |
|
187 | - . esc_html__( |
|
188 | - 'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', |
|
189 | - 'event_espresso' |
|
190 | - ) |
|
191 | - . sprintf( |
|
192 | - esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
193 | - '<a href="[PAYMENT_URL]" class="noPrint">', |
|
194 | - '</a>' |
|
195 | - ) |
|
196 | - . '</li>' |
|
197 | - . |
|
198 | - '<li><strong>none_owing</strong>:' |
|
199 | - . esc_html__( |
|
200 | - 'If the transaction is paid in full, then you can indicate how this gets displayed. Note, that it defaults to just be the total owing.', |
|
201 | - 'event_espresso' |
|
202 | - ) |
|
203 | - . '</li></ul></p>', |
|
204 | - '[TXN_TOTAL_TICKETS]' => esc_html__( |
|
205 | - 'The total number of all tickets purchased in a transaction', |
|
206 | - 'event_espresso' |
|
207 | - ), |
|
208 | - '[TKT_QTY_PURCHASED]' => sprintf( |
|
209 | - esc_html__( |
|
210 | - 'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', |
|
211 | - 'event_espresso' |
|
212 | - ), |
|
213 | - '<strong>', |
|
214 | - '</strong>' |
|
215 | - ), |
|
216 | - '[TRANSACTION_ADMIN_URL]' => esc_html__( |
|
217 | - 'The url to the admin page for this transaction', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - '[RECEIPT_URL]' => esc_html__( |
|
221 | - 'This parses to the generated url for retrieving the receipt for the transaction', |
|
222 | - 'event_espresso' |
|
223 | - ), |
|
224 | - '[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__( |
|
225 | - 'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active then will parse to an empty string.', |
|
226 | - 'event_espresso' |
|
227 | - ), |
|
228 | - '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf( |
|
229 | - esc_html__( |
|
230 | - 'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.', |
|
231 | - 'event_espresso' |
|
232 | - ), |
|
233 | - '<code>[INVOICE_RECEIPT_SWITCHER_URL]', |
|
234 | - '</code>' |
|
235 | - ), |
|
236 | - '[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__( |
|
237 | - 'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.', |
|
238 | - 'event_espresso' |
|
239 | - ), |
|
240 | - ); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * @param string $shortcode the shortcode to be parsed. |
|
246 | - * @return string parsed shortcode |
|
247 | - * @throws EE_Error |
|
248 | - * @throws InvalidArgumentException |
|
249 | - * @throws ReflectionException |
|
250 | - * @throws InvalidDataTypeException |
|
251 | - * @throws InvalidInterfaceException |
|
252 | - */ |
|
253 | - protected function _parser($shortcode) |
|
254 | - { |
|
255 | - // attempt to get the transaction. Since this is potentially used in more fields, we may have to look in the |
|
256 | - // _extra_data for the transaction. |
|
257 | - $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
258 | - $transaction = ! $transaction instanceof EE_Transaction |
|
259 | - && is_array($this->_extra_data) |
|
260 | - && isset($this->_extra_data['data']) |
|
261 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
262 | - ? $this->_extra_data['data']->txn |
|
263 | - : $transaction; |
|
264 | - // payment |
|
265 | - $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null; |
|
266 | - $payment = ! $payment instanceof EE_Payment |
|
267 | - && is_array($this->_extra_data) |
|
268 | - && isset($this->_extra_data['data']) |
|
269 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
|
270 | - : $payment; |
|
271 | - if (! $transaction instanceof EE_Transaction) { |
|
272 | - return ''; |
|
273 | - } |
|
274 | - switch ($shortcode) { |
|
275 | - case '[TXN_ID]': |
|
276 | - return $transaction->ID(); |
|
277 | - break; |
|
278 | - case '[PAYMENT_URL]': |
|
279 | - $payment_url = $transaction->payment_overview_url(); |
|
280 | - return empty($payment_url) |
|
281 | - ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso') |
|
282 | - : $payment_url; |
|
283 | - break; |
|
284 | - case '[INVOICE_LINK]': |
|
285 | - $invoice_url = $transaction->invoice_url(); |
|
286 | - $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
287 | - return sprintf( |
|
288 | - esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
|
289 | - '<a href="' . $invoice_url . '">', |
|
290 | - '</a>' |
|
291 | - ); |
|
292 | - break; |
|
293 | - case '[INVOICE_URL]': |
|
294 | - $invoice_url = $transaction->invoice_url(); |
|
295 | - return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
296 | - break; |
|
297 | - case '[INVOICE_LOGO_URL]': |
|
298 | - return $this->_get_invoice_logo(); |
|
299 | - break; |
|
300 | - case '[INVOICE_LOGO]': |
|
301 | - return $this->_get_invoice_logo(true); |
|
302 | - break; |
|
303 | - case '[INVOICE_PAYEE_NAME]': |
|
304 | - return $this->_get_invoice_payee_name(); |
|
305 | - break; |
|
306 | - case '[INVOICE_PAYEE_ADDRESS]': |
|
307 | - return $this->_get_invoice_payee_address(); |
|
308 | - break; |
|
309 | - case '[INVOICE_PAYMENT_INSTRUCTIONS]': |
|
310 | - return $this->_get_invoice_payment_instructions(); |
|
311 | - break; |
|
312 | - case '[INVOICE_PAYEE_EMAIL]': |
|
313 | - return $this->_get_invoice_payee_email(); |
|
314 | - break; |
|
315 | - case '[TOTAL_COST]': |
|
316 | - $total = $transaction->total(); |
|
317 | - return ! empty($total) ? EEH_Template::format_currency($total) : ''; |
|
318 | - break; |
|
319 | - case '[PAYMENT_STATUS]': |
|
320 | - $status = $transaction->pretty_status(); |
|
321 | - return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
322 | - break; /**/ |
|
323 | - // note the [payment_status] shortcode is kind of misleading because payment status might be different |
|
324 | - // from txn status so I'm adding this here for clarity. |
|
325 | - case '[TXN_STATUS]': |
|
326 | - $status = $transaction->pretty_status(); |
|
327 | - return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
328 | - break; |
|
329 | - case '[TXN_STATUS_ID]': |
|
330 | - return $transaction->status_ID(); |
|
331 | - break; |
|
332 | - case '[PAYMENT_GATEWAY]': |
|
333 | - return $this->_get_payment_gateway($transaction); |
|
334 | - break; |
|
335 | - case '[AMOUNT_PAID]': |
|
336 | - return $payment instanceof EE_Payment |
|
337 | - ? EEH_Template::format_currency($payment->amount()) |
|
338 | - : EEH_Template::format_currency(0); |
|
339 | - break; |
|
340 | - case '[LAST_AMOUNT_PAID]': |
|
341 | - $last_payment = $transaction->last_payment(); |
|
342 | - return $last_payment instanceof EE_Payment |
|
343 | - ? EEH_Template::format_currency($last_payment->amount()) |
|
344 | - : EEH_Template::format_currency(0); |
|
345 | - case '[TOTAL_AMOUNT_PAID]': |
|
346 | - return EEH_Template::format_currency($transaction->paid()); |
|
347 | - break; |
|
348 | - case '[TOTAL_OWING]': |
|
349 | - $total_owing = $transaction->remaining(); |
|
350 | - return EEH_Template::format_currency($total_owing); |
|
351 | - break; |
|
352 | - case '[TXN_SUBTOTAL]': |
|
353 | - return EEH_Template::format_currency($this->_get_subtotal()); |
|
354 | - break; |
|
355 | - case '[TXN_TAX_SUBTOTAL]': |
|
356 | - return EEH_Template::format_currency($this->_get_subtotal(true)); |
|
357 | - break; |
|
358 | - case '[TKT_QTY_PURCHASED]': |
|
359 | - case '[TXN_TOTAL_TICKETS]': |
|
360 | - return $this->_data->total_ticket_count; |
|
361 | - break; |
|
362 | - case '[TRANSACTION_ADMIN_URL]': |
|
363 | - require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
364 | - $query_args = array( |
|
365 | - 'page' => 'espresso_transactions', |
|
366 | - 'action' => 'view_transaction', |
|
367 | - 'TXN_ID' => $transaction->ID(), |
|
368 | - ); |
|
369 | - $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php')); |
|
370 | - return $url; |
|
371 | - break; |
|
372 | - case '[RECEIPT_URL]': |
|
373 | - // get primary_registration |
|
374 | - $reg = $this->_data->primary_reg_obj; |
|
375 | - if (! $reg instanceof EE_Registration) { |
|
376 | - return ''; |
|
377 | - } |
|
378 | - return $reg->receipt_url(); |
|
379 | - break; |
|
380 | - case '[INVOICE_RECEIPT_SWITCHER_URL]': |
|
381 | - return $this->_get_invoice_receipt_switcher(false); |
|
382 | - break; |
|
383 | - case '[INVOICE_RECEIPT_SWITCHER_BUTTON]': |
|
384 | - return $this->_get_invoice_receipt_switcher(); |
|
385 | - break; |
|
386 | - case '[LAST_PAYMENT_TRANSACTION_ID]': |
|
387 | - $id = ''; |
|
388 | - $payment = $payment instanceof EE_Payment && $payment->ID() !== 0 |
|
389 | - ? $payment |
|
390 | - : $transaction->last_payment(); |
|
391 | - if ($payment instanceof EE_Payment) { |
|
392 | - $id = $payment->txn_id_chq_nmbr(); |
|
393 | - } |
|
394 | - return $id; |
|
395 | - break; |
|
396 | - } |
|
397 | - if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) { |
|
398 | - return $this->_get_custom_total_owing($shortcode); |
|
399 | - } |
|
400 | - if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) { |
|
401 | - return $this->_get_invoice_payee_tax_number($shortcode); |
|
402 | - } |
|
403 | - if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) { |
|
404 | - return $this->_get_payment_link_if_needed($shortcode); |
|
405 | - } |
|
406 | - if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) { |
|
407 | - return $this->_get_payment_due_date($shortcode, $transaction); |
|
408 | - } |
|
409 | - return ''; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode |
|
415 | - * |
|
416 | - * @since 4.5.0 |
|
417 | - * @param string $shortcode the incoming shortcode |
|
418 | - * @return string parsed. |
|
419 | - * @throws EE_Error |
|
420 | - */ |
|
421 | - private function _get_custom_total_owing($shortcode) |
|
422 | - { |
|
423 | - $valid_shortcodes = array('transaction'); |
|
424 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
425 | - // ensure default is set. |
|
426 | - $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
427 | - $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
428 | - ? $addressee->txn->remaining() : 0; |
|
429 | - if ($total_owing > 0) { |
|
430 | - $owing_content = ! empty($attrs['still_owing']) |
|
431 | - ? $attrs['still_owing'] |
|
432 | - : sprintf( |
|
433 | - esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
434 | - '<a href="[PAYMENT_URL]" class="noPrint">', |
|
435 | - '</a>' |
|
436 | - ); |
|
437 | - $owing_content = $this->_shortcode_helper->parse_message_template( |
|
438 | - $owing_content, |
|
439 | - $addressee, |
|
440 | - $valid_shortcodes, |
|
441 | - $this->_message_type, |
|
442 | - $this->_messenger, |
|
443 | - $this->_message |
|
444 | - ); |
|
445 | - } else { |
|
446 | - $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : ''; |
|
447 | - } |
|
448 | - return $owing_content; |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * @param EE_Transaction $transaction |
|
454 | - * @return string |
|
455 | - * @throws EE_Error |
|
456 | - */ |
|
457 | - private function _get_payment_gateway($transaction) |
|
458 | - { |
|
459 | - if ($transaction instanceof EE_Transaction) { |
|
460 | - $pm = $transaction->payment_method(); |
|
461 | - } else { |
|
462 | - $pm = null; |
|
463 | - } |
|
464 | - return $pm instanceof EE_Payment_Method ? $pm->name() : ''; |
|
465 | - } |
|
466 | - |
|
467 | - |
|
468 | - /** |
|
469 | - * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page. If its |
|
470 | - * not present then the organization logo is used if its found (set on the organization settings page). |
|
471 | - * |
|
472 | - * @param bool $img_tags TRUE means to return with the img tag wrappers. False just returns the url to the image. |
|
473 | - * @return string url or html |
|
474 | - * @throws EE_Error |
|
475 | - * @throws InvalidArgumentException |
|
476 | - * @throws InvalidDataTypeException |
|
477 | - * @throws InvalidInterfaceException |
|
478 | - * @throws ReflectionException |
|
479 | - * @since 4.5.0 |
|
480 | - */ |
|
481 | - private function _get_invoice_logo(bool $img_tags = false): string |
|
482 | - { |
|
483 | - $invoice_logo_url = ''; |
|
484 | - // try to get the invoice payment method's logo for this transaction image first |
|
485 | - $pm = $this->_get_invoice_payment_method(); |
|
486 | - if ($pm instanceof EE_Payment_Method) { |
|
487 | - $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true); |
|
488 | - } |
|
489 | - if (empty($invoice_logo_url)) { |
|
490 | - $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url; |
|
491 | - } |
|
492 | - if (empty($invoice_logo_url)) { |
|
493 | - return ''; |
|
494 | - } |
|
495 | - if (! $img_tags) { |
|
496 | - return $invoice_logo_url; |
|
497 | - } |
|
498 | - $invoice_logo_url = esc_url_raw($invoice_logo_url); |
|
499 | - // image tags have been requested. |
|
500 | - $image_size = @getimagesize($invoice_logo_url); |
|
501 | - $image_width_attr = ''; |
|
502 | - // if image is wider than 300px, set the width to 300 |
|
503 | - if ($image_size !== false) { |
|
504 | - $image_width = min($image_size[0], 300); |
|
505 | - $image_width = esc_attr($image_width); |
|
506 | - $image_width_attr = " width='$image_width'"; |
|
507 | - } |
|
508 | - return '<img class="logo screen" src="' . $invoice_logo_url . '"' . $image_width_attr . ' alt="logo" />'; |
|
509 | - } |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * Used to retrieve the appropriate content for the invoice payee name shortcode |
|
514 | - * |
|
515 | - * @since 4.5.0 |
|
516 | - * @return string |
|
517 | - * @throws EE_Error |
|
518 | - * @throws InvalidArgumentException |
|
519 | - * @throws InvalidDataTypeException |
|
520 | - * @throws InvalidInterfaceException |
|
521 | - */ |
|
522 | - private function _get_invoice_payee_name() |
|
523 | - { |
|
524 | - $payee_name = null; |
|
525 | - $pm = $this->_get_invoice_payment_method(); |
|
526 | - if ($pm instanceof EE_Payment_Method) { |
|
527 | - $payee_name = $pm->get_extra_meta('pdf_payee_name', true); |
|
528 | - } |
|
529 | - $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name; |
|
530 | - return $payee_name; |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * gets the default invoice payment method, but has a filter so it can be overridden |
|
536 | - * |
|
537 | - * @return EE_Payment_Method|null |
|
538 | - * @throws EE_Error |
|
539 | - * @throws InvalidArgumentException |
|
540 | - * @throws InvalidDataTypeException |
|
541 | - * @throws InvalidInterfaceException |
|
542 | - */ |
|
543 | - private function _get_invoice_payment_method() |
|
544 | - { |
|
545 | - if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
546 | - $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
547 | - $transaction = ! $transaction instanceof EE_Transaction |
|
548 | - && is_array($this->_extra_data) |
|
549 | - && isset($this->_extra_data['data']) |
|
550 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
551 | - ? $this->_extra_data['data']->txn : $transaction; |
|
552 | - // get the invoice payment method, and remember it for the next call too |
|
553 | - $this->_invoice_pm = apply_filters( |
|
554 | - 'FHEE__EE_Transaction_Shortcodes__get_payment_method__default', |
|
555 | - EEM_Payment_Method::instance()->get_one_of_type('Invoice'), |
|
556 | - $transaction |
|
557 | - ); |
|
558 | - } |
|
559 | - return $this->_invoice_pm; |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Used to retrieve the appropriate content for the invoice payee email shortcode |
|
565 | - * |
|
566 | - * @since 4.5.0 |
|
567 | - * @return string |
|
568 | - * @throws EE_Error |
|
569 | - * @throws InvalidArgumentException |
|
570 | - * @throws InvalidDataTypeException |
|
571 | - * @throws InvalidInterfaceException |
|
572 | - */ |
|
573 | - private function _get_invoice_payee_email() |
|
574 | - { |
|
575 | - $payee_email = null; |
|
576 | - $pm = $this->_get_invoice_payment_method(); |
|
577 | - if ($pm instanceof EE_Payment_Method) { |
|
578 | - $payee_email = $pm->get_extra_meta('pdf_payee_email', true); |
|
579 | - } |
|
580 | - $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
581 | - : $payee_email; |
|
582 | - return $payee_email; |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Used to retrieve the appropriate content for the invoice payee tax number shortcode |
|
588 | - * |
|
589 | - * @since 4.5.0 |
|
590 | - * @param string $shortcode |
|
591 | - * @return string |
|
592 | - * @throws EE_Error |
|
593 | - * @throws InvalidArgumentException |
|
594 | - * @throws InvalidDataTypeException |
|
595 | - * @throws InvalidInterfaceException |
|
596 | - */ |
|
597 | - private function _get_invoice_payee_tax_number($shortcode) |
|
598 | - { |
|
599 | - $payee_tax_number = null; |
|
600 | - $pm = $this->_get_invoice_payment_method(); |
|
601 | - if ($pm instanceof EE_Payment_Method) { |
|
602 | - $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true); |
|
603 | - } |
|
604 | - $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat |
|
605 | - : $payee_tax_number; |
|
606 | - if (empty($payee_tax_number)) { |
|
607 | - return ''; |
|
608 | - } |
|
609 | - // any attributes? |
|
610 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
611 | - // prefix? |
|
612 | - $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
613 | - return $prefix . $payee_tax_number; |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - /** |
|
618 | - * Used to retrieve the appropriate content for the invoice payee address shortcode. |
|
619 | - * |
|
620 | - * @since 4.5.0 |
|
621 | - * @return string |
|
622 | - * @throws EE_Error |
|
623 | - * @throws InvalidArgumentException |
|
624 | - * @throws ReflectionException |
|
625 | - * @throws InvalidDataTypeException |
|
626 | - * @throws InvalidInterfaceException |
|
627 | - */ |
|
628 | - private function _get_invoice_payee_address() |
|
629 | - { |
|
630 | - $payee_address = null; |
|
631 | - $pm = $this->_get_invoice_payment_method(); |
|
632 | - if ($pm instanceof EE_Payment_Method) { |
|
633 | - $payee_address = $pm->get_extra_meta('pdf_payee_address', true); |
|
634 | - } |
|
635 | - if (empty($payee_address)) { |
|
636 | - $organization = EE_Registry::instance()->CFG->organization; |
|
637 | - $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
638 | - $payee_address .= ! empty($organization->address_2) |
|
639 | - ? $organization->get_pretty('address_2') . '<br>' |
|
640 | - : ''; |
|
641 | - $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
642 | - // state |
|
643 | - $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
|
644 | - $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
|
645 | - // Country |
|
646 | - $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
647 | - $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
|
648 | - } |
|
649 | - return $payee_address; |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * Used to retrieve the appropriate content for the invoice payment instructions shortcode. |
|
655 | - * |
|
656 | - * @since 4.5.0 |
|
657 | - * @return string |
|
658 | - * @throws EE_Error |
|
659 | - * @throws InvalidArgumentException |
|
660 | - * @throws InvalidDataTypeException |
|
661 | - * @throws InvalidInterfaceException |
|
662 | - */ |
|
663 | - private function _get_invoice_payment_instructions() |
|
664 | - { |
|
665 | - $instructions = null; |
|
666 | - $pm = $this->_get_invoice_payment_method(); |
|
667 | - return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : ''; |
|
668 | - } |
|
669 | - |
|
670 | - |
|
671 | - /** |
|
672 | - * get invoice/receipt switch button or url. |
|
673 | - * |
|
674 | - * @param bool $button true (default) returns the html for a button, false just returns the url. |
|
675 | - * @return string |
|
676 | - * @throws EE_Error |
|
677 | - */ |
|
678 | - protected function _get_invoice_receipt_switcher($button = true) |
|
679 | - { |
|
680 | - $reg = $this->_data->primary_reg_obj; |
|
681 | - $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
|
682 | - if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
683 | - return ''; |
|
684 | - } |
|
685 | - $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
|
686 | - $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type |
|
687 | - ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
|
688 | - $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
|
689 | - $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
|
690 | - if (! $button) { |
|
691 | - return $switch_to_url; |
|
692 | - } |
|
693 | - if (! empty($switch_to_url)) { |
|
694 | - return ' |
|
19 | + /** |
|
20 | + * @var EE_Payment_Method $_invoice_pm the invoice payment method for use in invoices etc |
|
21 | + */ |
|
22 | + protected $_invoice_pm; |
|
23 | + |
|
24 | + |
|
25 | + protected function _init_props() |
|
26 | + { |
|
27 | + $this->label = esc_html__('Transaction Shortcodes', 'event_espresso'); |
|
28 | + $this->description = esc_html__('All shortcodes specific to transaction related data', 'event_espresso'); |
|
29 | + $this->_shortcodes = array( |
|
30 | + '[TXN_ID]' => esc_html__('The transaction id for the purchase.', 'event_espresso'), |
|
31 | + '[PAYMENT_URL]' => esc_html__( |
|
32 | + 'This is a link to make a payment for the event', |
|
33 | + 'event_espresso' |
|
34 | + ), |
|
35 | + '[PAYMENT_LINK_IF_NEEDED_*]' => esc_html__( |
|
36 | + 'This is a special dynamic shortcode that allows one to insert a payment link conditional on there being amount owing on the transaction. Three params are available on this shortcode:', |
|
37 | + 'event_espresso' |
|
38 | + ) |
|
39 | + . '<ul>' |
|
40 | + . '<li>' |
|
41 | + . sprintf( |
|
42 | + esc_html__( |
|
43 | + '%sclass:%s This can be used to indicate css class is given to the containing css element (default is "callout").', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '<strong>', |
|
47 | + '</strong>' |
|
48 | + ) |
|
49 | + . '</li>' |
|
50 | + . '<li>' |
|
51 | + . sprintf( |
|
52 | + esc_html__( |
|
53 | + '%scustom_text:%s This should be a sprintf format text string (with %%s for where the hyperlink tags go) that is used for the generated link text (The default is "You can %%smake a payment here »%%s.)', |
|
54 | + 'event_espresso' |
|
55 | + ), |
|
56 | + '<strong>', |
|
57 | + '</strong>' |
|
58 | + ) |
|
59 | + . '</li>' |
|
60 | + . '<li>' |
|
61 | + . sprintf( |
|
62 | + esc_html__( |
|
63 | + '%scontainer_tag:%s Use this to indicate what container tag you want surrounding the payment link (default is "p").', |
|
64 | + 'event_espresso' |
|
65 | + ), |
|
66 | + '<strong>', |
|
67 | + '</strong>' |
|
68 | + ) |
|
69 | + . '</li>' |
|
70 | + . '</ul>', |
|
71 | + '[PAYMENT_DUE_DATE_*]' => esc_html__( |
|
72 | + 'This is a special dynamic shortcode that allows one to output a payment due date. It will only result in a date shown if there is money owing. Three parameters are available on this shortcode:', |
|
73 | + 'event_espresso' |
|
74 | + ) |
|
75 | + . '<ul>' |
|
76 | + . '<li>' |
|
77 | + . sprintf( |
|
78 | + esc_html__( |
|
79 | + '%sformat:%s This is used to indicate what format the date is in. Default is whatever is set as date formats for your website.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + '<strong>', |
|
83 | + '</strong>' |
|
84 | + ) |
|
85 | + . '</li>' |
|
86 | + . '<li>' |
|
87 | + . sprintf( |
|
88 | + esc_html__( |
|
89 | + '%sdays_until_due:%s This is the number of days form the transaction creation date that the payment is due. Defaults to 30.', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + '<strong>', |
|
93 | + '</strong>' |
|
94 | + ) |
|
95 | + . '</li>' |
|
96 | + . '<li>' |
|
97 | + . sprintf( |
|
98 | + esc_html__( |
|
99 | + '%sprefix_text:%s You can use this to indicate what text will prefix the date string. Defaults to "Payment in full due by:"', |
|
100 | + 'event_espresso' |
|
101 | + ), |
|
102 | + '<strong>', |
|
103 | + '</strong>' |
|
104 | + ) |
|
105 | + . '</li>', |
|
106 | + '[INVOICE_LINK]' => esc_html__( |
|
107 | + 'This is a full html link to the invoice', |
|
108 | + 'event_espresso' |
|
109 | + ), |
|
110 | + '[INVOICE_URL]' => esc_html__( |
|
111 | + 'This is just the url for the invoice', |
|
112 | + 'event_espresso' |
|
113 | + ), |
|
114 | + '[INVOICE_LOGO_URL]' => esc_html__( |
|
115 | + 'This returns the url for the logo uploaded via the invoice settings page.', |
|
116 | + 'event_espresso' |
|
117 | + ), |
|
118 | + '[INVOICE_LOGO]' => esc_html__( |
|
119 | + 'This returns the logo uploaded via the invoice settings page wrapped in img_tags and with a "logo screen" classes. The image size is also set in the img tags automatically to match the uploaded logo.', |
|
120 | + 'event_espresso' |
|
121 | + ), |
|
122 | + '[INVOICE_PAYEE_NAME]' => esc_html__( |
|
123 | + 'This will parse to either: the value of the "Company Name" field in the invoice payment method settings; if that is blank, then the value of the Company Name in the "Your Organization Settings", if that is blank then an empty string.', |
|
124 | + 'event_espresso' |
|
125 | + ), |
|
126 | + '[INVOICE_PAYEE_ADDRESS]' => esc_html__( |
|
127 | + 'This will parse to either: the value of the "Company Address" field in the invoice payment method settings; if that is blank, then the value of the Company Address in the "Your Organization Settings", if that is blank then an empty string.', |
|
128 | + 'event_espresso' |
|
129 | + ), |
|
130 | + '[INVOICE_PAYMENT_INSTRUCTIONS]' => esc_html__( |
|
131 | + 'This will parse to the value of the "Payment Instructions" field found on the Invoice payment methods settings page', |
|
132 | + 'event_espresso' |
|
133 | + ), |
|
134 | + '[INVOICE_PAYEE_EMAIL]' => esc_html__( |
|
135 | + 'This will parse to either: the value of the "Company Email" field in the invoice payment method settings; if that is blank, then the value of the Company Email in the "Your Organization Settings", if that is blank then an empty string.', |
|
136 | + 'event_espresso' |
|
137 | + ), |
|
138 | + '[INVOICE_PAYEE_TAX_NUMBER_*]' => sprintf( |
|
139 | + esc_html__( |
|
140 | + 'This will parse to either: the value of the "Company Tax Number" field in the invoice payment method settings; if that is blank, then the value of the Company Tax Number in the "Your Organization Settings", if that is blank then an empty string. Note this is also a special dynamic shortcode. You can use the "prefix" parameter to indicate what text you want to use as a prefix before this tax number. It defaults to "VAT/Tax Number:". To change this prefix you do the following format for this shortcode: %1$s[INVOICE_PAYEE_TAX_NUMBER_* prefix="GST:"]%2$s and that will output: GST: 12345t56. If you have no tax number in your settings, then no prefix will be output either.', |
|
141 | + 'event_espresso' |
|
142 | + ), |
|
143 | + '<code>', |
|
144 | + '</code>' |
|
145 | + ), |
|
146 | + '[TOTAL_COST]' => esc_html__('The total cost for the transaction', 'event_espresso'), |
|
147 | + '[TXN_STATUS]' => esc_html__( |
|
148 | + 'The transaction status for the transaction.', |
|
149 | + 'event_espresso' |
|
150 | + ), |
|
151 | + '[TXN_STATUS_ID]' => esc_html__( |
|
152 | + 'The ID representing the transaction status as saved in the db. This tends to be useful for including with css classes for styling certain statuses differently from others.', |
|
153 | + 'event_espresso' |
|
154 | + ), |
|
155 | + '[PAYMENT_STATUS]' => esc_html__( |
|
156 | + 'The transaction status for the transaction. This parses to the same value as the [TXN_STATUS] shortcode and still remains here for legacy support.', |
|
157 | + 'event_espresso' |
|
158 | + ), |
|
159 | + '[PAYMENT_GATEWAY]' => esc_html__( |
|
160 | + 'The payment gateway used for the transaction', |
|
161 | + 'event_espresso' |
|
162 | + ), |
|
163 | + '[AMOUNT_PAID]' => esc_html__( |
|
164 | + 'The amount paid or refunded. This will only have a value if there was a payment or refund at the time of generating the message.', |
|
165 | + 'event_espresso' |
|
166 | + ), |
|
167 | + '[LAST_AMOUNT_PAID]' => esc_html__( |
|
168 | + 'This is the last payment or refund made on the transaction related to the message being generated.', |
|
169 | + 'event_espresso' |
|
170 | + ), |
|
171 | + '[TOTAL_AMOUNT_PAID]' => esc_html__( |
|
172 | + 'This parses to the total amount paid over all payments', |
|
173 | + 'event_espresso' |
|
174 | + ), |
|
175 | + '[TOTAL_OWING]' => esc_html__( |
|
176 | + 'The total owing on a transaction with no attributes.', |
|
177 | + 'event_espresso' |
|
178 | + ), |
|
179 | + '[TXN_SUBTOTAL]' => esc_html__('The subtotal for all txn line items.', 'event_espresso'), |
|
180 | + '[TXN_TAX_SUBTOTAL]' => esc_html__('The subtotal for all tax line items.', 'event_espresso'), |
|
181 | + '[OWING_STATUS_MESSAGE_*]' => esc_html__( |
|
182 | + 'A dynamic shortcode for adjusting how total owing gets shown. The acceptable attributes on the shortcode are:', |
|
183 | + 'event_espresso' |
|
184 | + ) |
|
185 | + . '<p></ul>' |
|
186 | + . '<li><strong>still_owing</strong>:' |
|
187 | + . esc_html__( |
|
188 | + 'If the transaction is not paid in full, then whatever is set for this attribute is shown (otherwise its just the amount owing). The default is:', |
|
189 | + 'event_espresso' |
|
190 | + ) |
|
191 | + . sprintf( |
|
192 | + esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
193 | + '<a href="[PAYMENT_URL]" class="noPrint">', |
|
194 | + '</a>' |
|
195 | + ) |
|
196 | + . '</li>' |
|
197 | + . |
|
198 | + '<li><strong>none_owing</strong>:' |
|
199 | + . esc_html__( |
|
200 | + 'If the transaction is paid in full, then you can indicate how this gets displayed. Note, that it defaults to just be the total owing.', |
|
201 | + 'event_espresso' |
|
202 | + ) |
|
203 | + . '</li></ul></p>', |
|
204 | + '[TXN_TOTAL_TICKETS]' => esc_html__( |
|
205 | + 'The total number of all tickets purchased in a transaction', |
|
206 | + 'event_espresso' |
|
207 | + ), |
|
208 | + '[TKT_QTY_PURCHASED]' => sprintf( |
|
209 | + esc_html__( |
|
210 | + 'The total number of all tickets purchased in a transaction. %1$sNOTE: This shortcode is good to use in the "[TICKET_LIST]" field but has been deprecated from all other contexts in favor of the more explicit [TXN_TOTAL_TICKETS] shortcode.%2$s', |
|
211 | + 'event_espresso' |
|
212 | + ), |
|
213 | + '<strong>', |
|
214 | + '</strong>' |
|
215 | + ), |
|
216 | + '[TRANSACTION_ADMIN_URL]' => esc_html__( |
|
217 | + 'The url to the admin page for this transaction', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + '[RECEIPT_URL]' => esc_html__( |
|
221 | + 'This parses to the generated url for retrieving the receipt for the transaction', |
|
222 | + 'event_espresso' |
|
223 | + ), |
|
224 | + '[INVOICE_RECEIPT_SWITCHER_URL]' => esc_html__( |
|
225 | + 'This parses to the url that will switch to the receipt if an invoice is displayed, and switch to the invoice if receipt is displayed. If a message type OTHER than invoice or receipt is displayed then this will just return the url for the invoice. If the related message type is not active then will parse to an empty string.', |
|
226 | + 'event_espresso' |
|
227 | + ), |
|
228 | + '[INVOICE_RECEIPT_SWITCHER_BUTTON]' => sprintf( |
|
229 | + esc_html__( |
|
230 | + 'The same as %1$s%2$s except this returns the html for a button linked to the invoice or receipt.', |
|
231 | + 'event_espresso' |
|
232 | + ), |
|
233 | + '<code>[INVOICE_RECEIPT_SWITCHER_URL]', |
|
234 | + '</code>' |
|
235 | + ), |
|
236 | + '[LAST_PAYMENT_TRANSACTION_ID]' => esc_html__( |
|
237 | + 'This will output the value of the payment transaction id for the last payment made on the transaction. Note, if a specific payment was included for message generation, that will be used when parsing the shortcode.', |
|
238 | + 'event_espresso' |
|
239 | + ), |
|
240 | + ); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * @param string $shortcode the shortcode to be parsed. |
|
246 | + * @return string parsed shortcode |
|
247 | + * @throws EE_Error |
|
248 | + * @throws InvalidArgumentException |
|
249 | + * @throws ReflectionException |
|
250 | + * @throws InvalidDataTypeException |
|
251 | + * @throws InvalidInterfaceException |
|
252 | + */ |
|
253 | + protected function _parser($shortcode) |
|
254 | + { |
|
255 | + // attempt to get the transaction. Since this is potentially used in more fields, we may have to look in the |
|
256 | + // _extra_data for the transaction. |
|
257 | + $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
258 | + $transaction = ! $transaction instanceof EE_Transaction |
|
259 | + && is_array($this->_extra_data) |
|
260 | + && isset($this->_extra_data['data']) |
|
261 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
262 | + ? $this->_extra_data['data']->txn |
|
263 | + : $transaction; |
|
264 | + // payment |
|
265 | + $payment = $this->_data->payment instanceof EE_Payment ? $this->_data->payment : null; |
|
266 | + $payment = ! $payment instanceof EE_Payment |
|
267 | + && is_array($this->_extra_data) |
|
268 | + && isset($this->_extra_data['data']) |
|
269 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data']->payment |
|
270 | + : $payment; |
|
271 | + if (! $transaction instanceof EE_Transaction) { |
|
272 | + return ''; |
|
273 | + } |
|
274 | + switch ($shortcode) { |
|
275 | + case '[TXN_ID]': |
|
276 | + return $transaction->ID(); |
|
277 | + break; |
|
278 | + case '[PAYMENT_URL]': |
|
279 | + $payment_url = $transaction->payment_overview_url(); |
|
280 | + return empty($payment_url) |
|
281 | + ? esc_html__('http://dummypaymenturlforpreview.com', 'event_espresso') |
|
282 | + : $payment_url; |
|
283 | + break; |
|
284 | + case '[INVOICE_LINK]': |
|
285 | + $invoice_url = $transaction->invoice_url(); |
|
286 | + $invoice_url = empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
287 | + return sprintf( |
|
288 | + esc_html__('%sClick here for Invoice%s', 'event_espresso'), |
|
289 | + '<a href="' . $invoice_url . '">', |
|
290 | + '</a>' |
|
291 | + ); |
|
292 | + break; |
|
293 | + case '[INVOICE_URL]': |
|
294 | + $invoice_url = $transaction->invoice_url(); |
|
295 | + return empty($invoice_url) ? 'http://dummyinvoicelinksforpreview.com' : $invoice_url; |
|
296 | + break; |
|
297 | + case '[INVOICE_LOGO_URL]': |
|
298 | + return $this->_get_invoice_logo(); |
|
299 | + break; |
|
300 | + case '[INVOICE_LOGO]': |
|
301 | + return $this->_get_invoice_logo(true); |
|
302 | + break; |
|
303 | + case '[INVOICE_PAYEE_NAME]': |
|
304 | + return $this->_get_invoice_payee_name(); |
|
305 | + break; |
|
306 | + case '[INVOICE_PAYEE_ADDRESS]': |
|
307 | + return $this->_get_invoice_payee_address(); |
|
308 | + break; |
|
309 | + case '[INVOICE_PAYMENT_INSTRUCTIONS]': |
|
310 | + return $this->_get_invoice_payment_instructions(); |
|
311 | + break; |
|
312 | + case '[INVOICE_PAYEE_EMAIL]': |
|
313 | + return $this->_get_invoice_payee_email(); |
|
314 | + break; |
|
315 | + case '[TOTAL_COST]': |
|
316 | + $total = $transaction->total(); |
|
317 | + return ! empty($total) ? EEH_Template::format_currency($total) : ''; |
|
318 | + break; |
|
319 | + case '[PAYMENT_STATUS]': |
|
320 | + $status = $transaction->pretty_status(); |
|
321 | + return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
322 | + break; /**/ |
|
323 | + // note the [payment_status] shortcode is kind of misleading because payment status might be different |
|
324 | + // from txn status so I'm adding this here for clarity. |
|
325 | + case '[TXN_STATUS]': |
|
326 | + $status = $transaction->pretty_status(); |
|
327 | + return ! empty($status) ? $status : esc_html__('Unknown', 'event_espresso'); |
|
328 | + break; |
|
329 | + case '[TXN_STATUS_ID]': |
|
330 | + return $transaction->status_ID(); |
|
331 | + break; |
|
332 | + case '[PAYMENT_GATEWAY]': |
|
333 | + return $this->_get_payment_gateway($transaction); |
|
334 | + break; |
|
335 | + case '[AMOUNT_PAID]': |
|
336 | + return $payment instanceof EE_Payment |
|
337 | + ? EEH_Template::format_currency($payment->amount()) |
|
338 | + : EEH_Template::format_currency(0); |
|
339 | + break; |
|
340 | + case '[LAST_AMOUNT_PAID]': |
|
341 | + $last_payment = $transaction->last_payment(); |
|
342 | + return $last_payment instanceof EE_Payment |
|
343 | + ? EEH_Template::format_currency($last_payment->amount()) |
|
344 | + : EEH_Template::format_currency(0); |
|
345 | + case '[TOTAL_AMOUNT_PAID]': |
|
346 | + return EEH_Template::format_currency($transaction->paid()); |
|
347 | + break; |
|
348 | + case '[TOTAL_OWING]': |
|
349 | + $total_owing = $transaction->remaining(); |
|
350 | + return EEH_Template::format_currency($total_owing); |
|
351 | + break; |
|
352 | + case '[TXN_SUBTOTAL]': |
|
353 | + return EEH_Template::format_currency($this->_get_subtotal()); |
|
354 | + break; |
|
355 | + case '[TXN_TAX_SUBTOTAL]': |
|
356 | + return EEH_Template::format_currency($this->_get_subtotal(true)); |
|
357 | + break; |
|
358 | + case '[TKT_QTY_PURCHASED]': |
|
359 | + case '[TXN_TOTAL_TICKETS]': |
|
360 | + return $this->_data->total_ticket_count; |
|
361 | + break; |
|
362 | + case '[TRANSACTION_ADMIN_URL]': |
|
363 | + require_once EE_CORE . 'admin/EE_Admin_Page.core.php'; |
|
364 | + $query_args = array( |
|
365 | + 'page' => 'espresso_transactions', |
|
366 | + 'action' => 'view_transaction', |
|
367 | + 'TXN_ID' => $transaction->ID(), |
|
368 | + ); |
|
369 | + $url = EE_Admin_Page::add_query_args_and_nonce($query_args, admin_url('admin.php')); |
|
370 | + return $url; |
|
371 | + break; |
|
372 | + case '[RECEIPT_URL]': |
|
373 | + // get primary_registration |
|
374 | + $reg = $this->_data->primary_reg_obj; |
|
375 | + if (! $reg instanceof EE_Registration) { |
|
376 | + return ''; |
|
377 | + } |
|
378 | + return $reg->receipt_url(); |
|
379 | + break; |
|
380 | + case '[INVOICE_RECEIPT_SWITCHER_URL]': |
|
381 | + return $this->_get_invoice_receipt_switcher(false); |
|
382 | + break; |
|
383 | + case '[INVOICE_RECEIPT_SWITCHER_BUTTON]': |
|
384 | + return $this->_get_invoice_receipt_switcher(); |
|
385 | + break; |
|
386 | + case '[LAST_PAYMENT_TRANSACTION_ID]': |
|
387 | + $id = ''; |
|
388 | + $payment = $payment instanceof EE_Payment && $payment->ID() !== 0 |
|
389 | + ? $payment |
|
390 | + : $transaction->last_payment(); |
|
391 | + if ($payment instanceof EE_Payment) { |
|
392 | + $id = $payment->txn_id_chq_nmbr(); |
|
393 | + } |
|
394 | + return $id; |
|
395 | + break; |
|
396 | + } |
|
397 | + if (strpos($shortcode, '[OWING_STATUS_MESSAGE_*') !== false) { |
|
398 | + return $this->_get_custom_total_owing($shortcode); |
|
399 | + } |
|
400 | + if (strpos($shortcode, '[INVOICE_PAYEE_TAX_NUMBER_*') !== false) { |
|
401 | + return $this->_get_invoice_payee_tax_number($shortcode); |
|
402 | + } |
|
403 | + if (strpos($shortcode, '[PAYMENT_LINK_IF_NEEDED_*') !== false) { |
|
404 | + return $this->_get_payment_link_if_needed($shortcode); |
|
405 | + } |
|
406 | + if (strpos($shortcode, '[PAYMENT_DUE_DATE_*') !== false) { |
|
407 | + return $this->_get_payment_due_date($shortcode, $transaction); |
|
408 | + } |
|
409 | + return ''; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * parser for the [OWING_STATUS_MESSAGE_*] attribute type shortcode |
|
415 | + * |
|
416 | + * @since 4.5.0 |
|
417 | + * @param string $shortcode the incoming shortcode |
|
418 | + * @return string parsed. |
|
419 | + * @throws EE_Error |
|
420 | + */ |
|
421 | + private function _get_custom_total_owing($shortcode) |
|
422 | + { |
|
423 | + $valid_shortcodes = array('transaction'); |
|
424 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
425 | + // ensure default is set. |
|
426 | + $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
427 | + $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
428 | + ? $addressee->txn->remaining() : 0; |
|
429 | + if ($total_owing > 0) { |
|
430 | + $owing_content = ! empty($attrs['still_owing']) |
|
431 | + ? $attrs['still_owing'] |
|
432 | + : sprintf( |
|
433 | + esc_html__('%sPlease make a payment.%s', 'event_espresso'), |
|
434 | + '<a href="[PAYMENT_URL]" class="noPrint">', |
|
435 | + '</a>' |
|
436 | + ); |
|
437 | + $owing_content = $this->_shortcode_helper->parse_message_template( |
|
438 | + $owing_content, |
|
439 | + $addressee, |
|
440 | + $valid_shortcodes, |
|
441 | + $this->_message_type, |
|
442 | + $this->_messenger, |
|
443 | + $this->_message |
|
444 | + ); |
|
445 | + } else { |
|
446 | + $owing_content = ! empty($attrs['none_owing']) ? $attrs['none_owing'] : ''; |
|
447 | + } |
|
448 | + return $owing_content; |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * @param EE_Transaction $transaction |
|
454 | + * @return string |
|
455 | + * @throws EE_Error |
|
456 | + */ |
|
457 | + private function _get_payment_gateway($transaction) |
|
458 | + { |
|
459 | + if ($transaction instanceof EE_Transaction) { |
|
460 | + $pm = $transaction->payment_method(); |
|
461 | + } else { |
|
462 | + $pm = null; |
|
463 | + } |
|
464 | + return $pm instanceof EE_Payment_Method ? $pm->name() : ''; |
|
465 | + } |
|
466 | + |
|
467 | + |
|
468 | + /** |
|
469 | + * This retrieves a logo to be used for the invoice from whatever is set on the invoice logo settings page. If its |
|
470 | + * not present then the organization logo is used if its found (set on the organization settings page). |
|
471 | + * |
|
472 | + * @param bool $img_tags TRUE means to return with the img tag wrappers. False just returns the url to the image. |
|
473 | + * @return string url or html |
|
474 | + * @throws EE_Error |
|
475 | + * @throws InvalidArgumentException |
|
476 | + * @throws InvalidDataTypeException |
|
477 | + * @throws InvalidInterfaceException |
|
478 | + * @throws ReflectionException |
|
479 | + * @since 4.5.0 |
|
480 | + */ |
|
481 | + private function _get_invoice_logo(bool $img_tags = false): string |
|
482 | + { |
|
483 | + $invoice_logo_url = ''; |
|
484 | + // try to get the invoice payment method's logo for this transaction image first |
|
485 | + $pm = $this->_get_invoice_payment_method(); |
|
486 | + if ($pm instanceof EE_Payment_Method) { |
|
487 | + $invoice_logo_url = $pm->get_extra_meta('pdf_logo_image', true); |
|
488 | + } |
|
489 | + if (empty($invoice_logo_url)) { |
|
490 | + $invoice_logo_url = EE_Registry::instance()->CFG->organization->logo_url; |
|
491 | + } |
|
492 | + if (empty($invoice_logo_url)) { |
|
493 | + return ''; |
|
494 | + } |
|
495 | + if (! $img_tags) { |
|
496 | + return $invoice_logo_url; |
|
497 | + } |
|
498 | + $invoice_logo_url = esc_url_raw($invoice_logo_url); |
|
499 | + // image tags have been requested. |
|
500 | + $image_size = @getimagesize($invoice_logo_url); |
|
501 | + $image_width_attr = ''; |
|
502 | + // if image is wider than 300px, set the width to 300 |
|
503 | + if ($image_size !== false) { |
|
504 | + $image_width = min($image_size[0], 300); |
|
505 | + $image_width = esc_attr($image_width); |
|
506 | + $image_width_attr = " width='$image_width'"; |
|
507 | + } |
|
508 | + return '<img class="logo screen" src="' . $invoice_logo_url . '"' . $image_width_attr . ' alt="logo" />'; |
|
509 | + } |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * Used to retrieve the appropriate content for the invoice payee name shortcode |
|
514 | + * |
|
515 | + * @since 4.5.0 |
|
516 | + * @return string |
|
517 | + * @throws EE_Error |
|
518 | + * @throws InvalidArgumentException |
|
519 | + * @throws InvalidDataTypeException |
|
520 | + * @throws InvalidInterfaceException |
|
521 | + */ |
|
522 | + private function _get_invoice_payee_name() |
|
523 | + { |
|
524 | + $payee_name = null; |
|
525 | + $pm = $this->_get_invoice_payment_method(); |
|
526 | + if ($pm instanceof EE_Payment_Method) { |
|
527 | + $payee_name = $pm->get_extra_meta('pdf_payee_name', true); |
|
528 | + } |
|
529 | + $payee_name = empty($payee_name) ? EE_Registry::instance()->CFG->organization->get_pretty('name') : $payee_name; |
|
530 | + return $payee_name; |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * gets the default invoice payment method, but has a filter so it can be overridden |
|
536 | + * |
|
537 | + * @return EE_Payment_Method|null |
|
538 | + * @throws EE_Error |
|
539 | + * @throws InvalidArgumentException |
|
540 | + * @throws InvalidDataTypeException |
|
541 | + * @throws InvalidInterfaceException |
|
542 | + */ |
|
543 | + private function _get_invoice_payment_method() |
|
544 | + { |
|
545 | + if (! $this->_invoice_pm instanceof EE_Payment_Method) { |
|
546 | + $transaction = $this->_data->txn instanceof EE_Transaction ? $this->_data->txn : null; |
|
547 | + $transaction = ! $transaction instanceof EE_Transaction |
|
548 | + && is_array($this->_extra_data) |
|
549 | + && isset($this->_extra_data['data']) |
|
550 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
551 | + ? $this->_extra_data['data']->txn : $transaction; |
|
552 | + // get the invoice payment method, and remember it for the next call too |
|
553 | + $this->_invoice_pm = apply_filters( |
|
554 | + 'FHEE__EE_Transaction_Shortcodes__get_payment_method__default', |
|
555 | + EEM_Payment_Method::instance()->get_one_of_type('Invoice'), |
|
556 | + $transaction |
|
557 | + ); |
|
558 | + } |
|
559 | + return $this->_invoice_pm; |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Used to retrieve the appropriate content for the invoice payee email shortcode |
|
565 | + * |
|
566 | + * @since 4.5.0 |
|
567 | + * @return string |
|
568 | + * @throws EE_Error |
|
569 | + * @throws InvalidArgumentException |
|
570 | + * @throws InvalidDataTypeException |
|
571 | + * @throws InvalidInterfaceException |
|
572 | + */ |
|
573 | + private function _get_invoice_payee_email() |
|
574 | + { |
|
575 | + $payee_email = null; |
|
576 | + $pm = $this->_get_invoice_payment_method(); |
|
577 | + if ($pm instanceof EE_Payment_Method) { |
|
578 | + $payee_email = $pm->get_extra_meta('pdf_payee_email', true); |
|
579 | + } |
|
580 | + $payee_email = empty($payee_email) ? EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
581 | + : $payee_email; |
|
582 | + return $payee_email; |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Used to retrieve the appropriate content for the invoice payee tax number shortcode |
|
588 | + * |
|
589 | + * @since 4.5.0 |
|
590 | + * @param string $shortcode |
|
591 | + * @return string |
|
592 | + * @throws EE_Error |
|
593 | + * @throws InvalidArgumentException |
|
594 | + * @throws InvalidDataTypeException |
|
595 | + * @throws InvalidInterfaceException |
|
596 | + */ |
|
597 | + private function _get_invoice_payee_tax_number($shortcode) |
|
598 | + { |
|
599 | + $payee_tax_number = null; |
|
600 | + $pm = $this->_get_invoice_payment_method(); |
|
601 | + if ($pm instanceof EE_Payment_Method) { |
|
602 | + $payee_tax_number = $pm->get_extra_meta('pdf_payee_tax_number', true); |
|
603 | + } |
|
604 | + $payee_tax_number = empty($payee_tax_number) ? EE_Registry::instance()->CFG->organization->vat |
|
605 | + : $payee_tax_number; |
|
606 | + if (empty($payee_tax_number)) { |
|
607 | + return ''; |
|
608 | + } |
|
609 | + // any attributes? |
|
610 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
611 | + // prefix? |
|
612 | + $prefix = isset($attrs['prefix']) ? $attrs['prefix'] : esc_html__('VAT/Tax Number: ', 'event_espresso'); |
|
613 | + return $prefix . $payee_tax_number; |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + /** |
|
618 | + * Used to retrieve the appropriate content for the invoice payee address shortcode. |
|
619 | + * |
|
620 | + * @since 4.5.0 |
|
621 | + * @return string |
|
622 | + * @throws EE_Error |
|
623 | + * @throws InvalidArgumentException |
|
624 | + * @throws ReflectionException |
|
625 | + * @throws InvalidDataTypeException |
|
626 | + * @throws InvalidInterfaceException |
|
627 | + */ |
|
628 | + private function _get_invoice_payee_address() |
|
629 | + { |
|
630 | + $payee_address = null; |
|
631 | + $pm = $this->_get_invoice_payment_method(); |
|
632 | + if ($pm instanceof EE_Payment_Method) { |
|
633 | + $payee_address = $pm->get_extra_meta('pdf_payee_address', true); |
|
634 | + } |
|
635 | + if (empty($payee_address)) { |
|
636 | + $organization = EE_Registry::instance()->CFG->organization; |
|
637 | + $payee_address = $organization->get_pretty('address_1') . '<br>'; |
|
638 | + $payee_address .= ! empty($organization->address_2) |
|
639 | + ? $organization->get_pretty('address_2') . '<br>' |
|
640 | + : ''; |
|
641 | + $payee_address .= $organization->get_pretty('city') . '<br>'; |
|
642 | + // state |
|
643 | + $state = EE_Registry::instance()->load_model('State')->get_one_by_ID($organization->STA_ID); |
|
644 | + $payee_address .= $state instanceof EE_State ? $state->name() : ''; |
|
645 | + // Country |
|
646 | + $payee_address .= ! empty($organization->CNT_ISO) ? ', ' . $organization->CNT_ISO . '<br>' : ''; |
|
647 | + $payee_address .= ! empty($organization->zip) ? $organization->zip : ''; |
|
648 | + } |
|
649 | + return $payee_address; |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * Used to retrieve the appropriate content for the invoice payment instructions shortcode. |
|
655 | + * |
|
656 | + * @since 4.5.0 |
|
657 | + * @return string |
|
658 | + * @throws EE_Error |
|
659 | + * @throws InvalidArgumentException |
|
660 | + * @throws InvalidDataTypeException |
|
661 | + * @throws InvalidInterfaceException |
|
662 | + */ |
|
663 | + private function _get_invoice_payment_instructions() |
|
664 | + { |
|
665 | + $instructions = null; |
|
666 | + $pm = $this->_get_invoice_payment_method(); |
|
667 | + return ($pm instanceof EE_Payment_Method) ? $pm->get_extra_meta('pdf_instructions', true) : ''; |
|
668 | + } |
|
669 | + |
|
670 | + |
|
671 | + /** |
|
672 | + * get invoice/receipt switch button or url. |
|
673 | + * |
|
674 | + * @param bool $button true (default) returns the html for a button, false just returns the url. |
|
675 | + * @return string |
|
676 | + * @throws EE_Error |
|
677 | + */ |
|
678 | + protected function _get_invoice_receipt_switcher($button = true) |
|
679 | + { |
|
680 | + $reg = $this->_data->primary_reg_obj; |
|
681 | + $message_type = isset($this->_extra_data['message_type']) ? $this->_extra_data['message_type'] : ''; |
|
682 | + if (! $reg instanceof EE_Registration || empty($message_type)) { |
|
683 | + return ''; |
|
684 | + } |
|
685 | + $switch_to_invoice = ! $message_type instanceof EE_Invoice_message_type ? true : false; |
|
686 | + $switch_to_label = $switch_to_invoice && ! $message_type instanceof EE_Receipt_message_type |
|
687 | + ? esc_html__('View Invoice', 'event_espresso') : esc_html__('Switch to Invoice', 'event_espresso'); |
|
688 | + $switch_to_label = ! $switch_to_invoice ? esc_html__('Switch to Receipt', 'event_espresso') : $switch_to_label; |
|
689 | + $switch_to_url = $switch_to_invoice ? $reg->invoice_url() : $reg->receipt_url(); |
|
690 | + if (! $button) { |
|
691 | + return $switch_to_url; |
|
692 | + } |
|
693 | + if (! empty($switch_to_url)) { |
|
694 | + return ' |
|
695 | 695 | <form method="post" action="' . $switch_to_url . '" > |
696 | 696 | <input class="print_button" type="submit" value="' . $switch_to_label . '" /> |
697 | 697 | </form> |
698 | 698 | '; |
699 | - } |
|
700 | - return ''; |
|
701 | - } |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * This returns a subtotal. |
|
706 | - * |
|
707 | - * @param bool $tax if true then return the subtotal for tax otherwise return subtotal. |
|
708 | - * @return int |
|
709 | - * @throws EE_Error |
|
710 | - */ |
|
711 | - private function _get_subtotal($tax = false) |
|
712 | - { |
|
713 | - $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
|
714 | - if (! $grand_total instanceof EE_Line_Item) { |
|
715 | - return 0; |
|
716 | - } |
|
717 | - return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - /** |
|
722 | - * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode |
|
723 | - * |
|
724 | - * @since 4.7.0 |
|
725 | - * @param string $shortcode the incoming shortcode |
|
726 | - * @return string parsed. |
|
727 | - * @throws EE_Error |
|
728 | - */ |
|
729 | - private function _get_payment_link_if_needed($shortcode) |
|
730 | - { |
|
731 | - $valid_shortcodes = array('transaction'); |
|
732 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
733 | - // ensure default is set. |
|
734 | - $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
735 | - $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
736 | - ? $addressee->txn->remaining() : 0; |
|
737 | - if ($total_owing > 0) { |
|
738 | - $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
|
739 | - $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
|
740 | - $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
|
741 | - $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
742 | - $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
743 | - $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
|
744 | - $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
745 | - $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
746 | - // we need to re run this string through the parser to catch any shortcodes that are in it. |
|
747 | - $owing_content = $this->_shortcode_helper->parse_message_template( |
|
748 | - $content, |
|
749 | - $addressee, |
|
750 | - $valid_shortcodes, |
|
751 | - $this->_message_type, |
|
752 | - $this->_messenger, |
|
753 | - $this->_message |
|
754 | - ); |
|
755 | - } else { |
|
756 | - return ''; |
|
757 | - } |
|
758 | - return $owing_content; |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode |
|
764 | - * |
|
765 | - * @since 4.8.28.rc.011 |
|
766 | - * @param string $shortcode The shortcode being parsed. |
|
767 | - * @param EE_Transaction $transaction |
|
768 | - * @return string |
|
769 | - * @throws EE_Error |
|
770 | - */ |
|
771 | - protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) |
|
772 | - { |
|
773 | - // if transaction is paid in full then we can just return an empty string |
|
774 | - if ($transaction->remaining() === 0) { |
|
775 | - return ''; |
|
776 | - } |
|
777 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
778 | - $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
|
779 | - $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30; |
|
780 | - $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
|
781 | - : esc_html__('Payment in full due by: ', 'event_espresso'); |
|
782 | - $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
|
783 | - // setup date due: |
|
784 | - try { |
|
785 | - if ($transaction_created instanceof DateTime) { |
|
786 | - $date_due = $transaction_created->add( |
|
787 | - new DateInterval('P' . $days_until_due . 'D') |
|
788 | - )->format($format); |
|
789 | - } else { |
|
790 | - throw new Exception(); |
|
791 | - } |
|
792 | - } catch (Exception $e) { |
|
793 | - // format was likely invalid. |
|
794 | - $date_due = esc_html__( |
|
795 | - 'Unable to calculate date due, likely the format string is invalid.', |
|
796 | - 'event_espresso' |
|
797 | - ); |
|
798 | - } |
|
799 | - return $prefix_text . $date_due; |
|
800 | - } |
|
699 | + } |
|
700 | + return ''; |
|
701 | + } |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * This returns a subtotal. |
|
706 | + * |
|
707 | + * @param bool $tax if true then return the subtotal for tax otherwise return subtotal. |
|
708 | + * @return int |
|
709 | + * @throws EE_Error |
|
710 | + */ |
|
711 | + private function _get_subtotal($tax = false) |
|
712 | + { |
|
713 | + $grand_total = isset($this->_data->grand_total_line_item) ? $this->_data->grand_total_line_item : null; |
|
714 | + if (! $grand_total instanceof EE_Line_Item) { |
|
715 | + return 0; |
|
716 | + } |
|
717 | + return $tax ? $grand_total->get_total_tax() : $grand_total->get_items_total(); |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + /** |
|
722 | + * parser for the [PAYMENT_LINK_IF_NEEDED_*] attribute type shortcode |
|
723 | + * |
|
724 | + * @since 4.7.0 |
|
725 | + * @param string $shortcode the incoming shortcode |
|
726 | + * @return string parsed. |
|
727 | + * @throws EE_Error |
|
728 | + */ |
|
729 | + private function _get_payment_link_if_needed($shortcode) |
|
730 | + { |
|
731 | + $valid_shortcodes = array('transaction'); |
|
732 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
733 | + // ensure default is set. |
|
734 | + $addressee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
735 | + $total_owing = $addressee instanceof EE_Messages_Addressee && $addressee->txn instanceof EE_Transaction |
|
736 | + ? $addressee->txn->remaining() : 0; |
|
737 | + if ($total_owing > 0) { |
|
738 | + $class = isset($attrs['class']) ? $attrs['class'] : 'callout'; |
|
739 | + $custom_text = isset($attrs['custom_text']) ? $attrs['custom_text'] : 'You can %smake a payment here »%s.'; |
|
740 | + $container_tag = isset($attrs['container_tag']) ? $attrs['container_tag'] : 'p'; |
|
741 | + $opening_tag = ! empty($container_tag) ? '<' . $container_tag : ''; |
|
742 | + $opening_tag .= ! empty($opening_tag) && ! empty($class) ? ' class="' . $class . '"' : $opening_tag; |
|
743 | + $opening_tag .= ! empty($opening_tag) ? '>' : $opening_tag; |
|
744 | + $closing_tag = ! empty($container_tag) ? '</' . $container_tag . '>' : ''; |
|
745 | + $content = $opening_tag . sprintf($custom_text, '<a href="[PAYMENT_URL]">', '</a>') . $closing_tag; |
|
746 | + // we need to re run this string through the parser to catch any shortcodes that are in it. |
|
747 | + $owing_content = $this->_shortcode_helper->parse_message_template( |
|
748 | + $content, |
|
749 | + $addressee, |
|
750 | + $valid_shortcodes, |
|
751 | + $this->_message_type, |
|
752 | + $this->_messenger, |
|
753 | + $this->_message |
|
754 | + ); |
|
755 | + } else { |
|
756 | + return ''; |
|
757 | + } |
|
758 | + return $owing_content; |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode |
|
764 | + * |
|
765 | + * @since 4.8.28.rc.011 |
|
766 | + * @param string $shortcode The shortcode being parsed. |
|
767 | + * @param EE_Transaction $transaction |
|
768 | + * @return string |
|
769 | + * @throws EE_Error |
|
770 | + */ |
|
771 | + protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) |
|
772 | + { |
|
773 | + // if transaction is paid in full then we can just return an empty string |
|
774 | + if ($transaction->remaining() === 0) { |
|
775 | + return ''; |
|
776 | + } |
|
777 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
778 | + $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); |
|
779 | + $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30; |
|
780 | + $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] |
|
781 | + : esc_html__('Payment in full due by: ', 'event_espresso'); |
|
782 | + $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); |
|
783 | + // setup date due: |
|
784 | + try { |
|
785 | + if ($transaction_created instanceof DateTime) { |
|
786 | + $date_due = $transaction_created->add( |
|
787 | + new DateInterval('P' . $days_until_due . 'D') |
|
788 | + )->format($format); |
|
789 | + } else { |
|
790 | + throw new Exception(); |
|
791 | + } |
|
792 | + } catch (Exception $e) { |
|
793 | + // format was likely invalid. |
|
794 | + $date_due = esc_html__( |
|
795 | + 'Unable to calculate date due, likely the format string is invalid.', |
|
796 | + 'event_espresso' |
|
797 | + ); |
|
798 | + } |
|
799 | + return $prefix_text . $date_due; |
|
800 | + } |
|
801 | 801 | } |
@@ -15,77 +15,77 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Datetime_Shortcodes extends EE_Shortcodes |
17 | 17 | { |
18 | - /** |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - protected function _init_props() |
|
22 | - { |
|
23 | - $this->label = esc_html__('Datetime Shortcodes', 'event_espresso'); |
|
24 | - $this->description = esc_html__('All shortcodes specific to datetime related data', 'event_espresso'); |
|
25 | - $this->_shortcodes = array( |
|
26 | - '[DATETIME_START]' => esc_html__('The start date and time.', 'event_espresso'), |
|
27 | - '[DATETIME_END]' => esc_html__('The end date and time.', 'event_espresso'), |
|
28 | - '[DATETIME_TIMEZONE]' => esc_html__('The timezone for the date and time', 'event_espresso'), |
|
29 | - '[DATE_START]' => esc_html__('The datetime start date.', 'event_espresso'), |
|
30 | - '[DATE_END]' => esc_html__('The datetime end date.', 'event_espresso'), |
|
31 | - '[TIME_START]' => esc_html__('The datetime start time.', 'event_espresso'), |
|
32 | - '[TIME_END]' => esc_html__('The datetime end time.', 'event_espresso'), |
|
33 | - '[ICAL_LINK_*]' => esc_html__( |
|
34 | - 'The datetime iCal link. The optional "link_text" attribute can be used to set custom text within the link (Default is "Add to iCal Calendar").', |
|
35 | - 'event_espresso' |
|
36 | - ), |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @param string $shortcode |
|
43 | - * @return string |
|
44 | - * @throws EE_Error |
|
45 | - * @throws ReflectionException |
|
46 | - */ |
|
47 | - protected function _parser($shortcode) |
|
48 | - { |
|
49 | - |
|
50 | - if (! $this->_data instanceof EE_Datetime) { |
|
51 | - return ''; // get out cause we can only parse with the datetime object. |
|
52 | - } |
|
53 | - |
|
54 | - switch ($shortcode) { |
|
55 | - case '[DATETIME_START]': |
|
56 | - return $this->_data->get_i18n_datetime('DTT_EVT_start'); |
|
57 | - |
|
58 | - case '[DATETIME_END]': |
|
59 | - return $this->_data->get_i18n_datetime('DTT_EVT_end'); |
|
60 | - |
|
61 | - case '[DATETIME_TIMEZONE]': |
|
62 | - return $this->_data->get_timezone(); |
|
63 | - |
|
64 | - case '[DATE_START]': |
|
65 | - return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('date_format')); |
|
66 | - |
|
67 | - case '[DATE_END]': |
|
68 | - return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('date_format')); |
|
69 | - |
|
70 | - case '[TIME_START]': |
|
71 | - return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('time_format')); |
|
72 | - |
|
73 | - case '[TIME_END]': |
|
74 | - return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('time_format')); |
|
75 | - |
|
76 | - } |
|
77 | - |
|
78 | - if (strpos($shortcode, '[ICAL_LINK_*') !== false) { |
|
79 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
80 | - |
|
81 | - $link_text = empty($attrs['link_text']) ? esc_html__('Add to iCal Calendar', 'event_espresso') |
|
82 | - : $attrs['link_text']; |
|
83 | - |
|
84 | - $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url()); |
|
85 | - |
|
86 | - return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>'; |
|
87 | - } |
|
88 | - |
|
89 | - return ''; |
|
90 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + protected function _init_props() |
|
22 | + { |
|
23 | + $this->label = esc_html__('Datetime Shortcodes', 'event_espresso'); |
|
24 | + $this->description = esc_html__('All shortcodes specific to datetime related data', 'event_espresso'); |
|
25 | + $this->_shortcodes = array( |
|
26 | + '[DATETIME_START]' => esc_html__('The start date and time.', 'event_espresso'), |
|
27 | + '[DATETIME_END]' => esc_html__('The end date and time.', 'event_espresso'), |
|
28 | + '[DATETIME_TIMEZONE]' => esc_html__('The timezone for the date and time', 'event_espresso'), |
|
29 | + '[DATE_START]' => esc_html__('The datetime start date.', 'event_espresso'), |
|
30 | + '[DATE_END]' => esc_html__('The datetime end date.', 'event_espresso'), |
|
31 | + '[TIME_START]' => esc_html__('The datetime start time.', 'event_espresso'), |
|
32 | + '[TIME_END]' => esc_html__('The datetime end time.', 'event_espresso'), |
|
33 | + '[ICAL_LINK_*]' => esc_html__( |
|
34 | + 'The datetime iCal link. The optional "link_text" attribute can be used to set custom text within the link (Default is "Add to iCal Calendar").', |
|
35 | + 'event_espresso' |
|
36 | + ), |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @param string $shortcode |
|
43 | + * @return string |
|
44 | + * @throws EE_Error |
|
45 | + * @throws ReflectionException |
|
46 | + */ |
|
47 | + protected function _parser($shortcode) |
|
48 | + { |
|
49 | + |
|
50 | + if (! $this->_data instanceof EE_Datetime) { |
|
51 | + return ''; // get out cause we can only parse with the datetime object. |
|
52 | + } |
|
53 | + |
|
54 | + switch ($shortcode) { |
|
55 | + case '[DATETIME_START]': |
|
56 | + return $this->_data->get_i18n_datetime('DTT_EVT_start'); |
|
57 | + |
|
58 | + case '[DATETIME_END]': |
|
59 | + return $this->_data->get_i18n_datetime('DTT_EVT_end'); |
|
60 | + |
|
61 | + case '[DATETIME_TIMEZONE]': |
|
62 | + return $this->_data->get_timezone(); |
|
63 | + |
|
64 | + case '[DATE_START]': |
|
65 | + return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('date_format')); |
|
66 | + |
|
67 | + case '[DATE_END]': |
|
68 | + return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('date_format')); |
|
69 | + |
|
70 | + case '[TIME_START]': |
|
71 | + return $this->_data->get_i18n_datetime('DTT_EVT_start', get_option('time_format')); |
|
72 | + |
|
73 | + case '[TIME_END]': |
|
74 | + return $this->_data->get_i18n_datetime('DTT_EVT_end', get_option('time_format')); |
|
75 | + |
|
76 | + } |
|
77 | + |
|
78 | + if (strpos($shortcode, '[ICAL_LINK_*') !== false) { |
|
79 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
80 | + |
|
81 | + $link_text = empty($attrs['link_text']) ? esc_html__('Add to iCal Calendar', 'event_espresso') |
|
82 | + : $attrs['link_text']; |
|
83 | + |
|
84 | + $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $this->_data->ID()), site_url()); |
|
85 | + |
|
86 | + return '<a class="ee-ical" href="' . $URL . '">' . $link_text . '</a>'; |
|
87 | + } |
|
88 | + |
|
89 | + return ''; |
|
90 | + } |
|
91 | 91 | } |
@@ -23,477 +23,477 @@ |
||
23 | 23 | |
24 | 24 | class DatetimeOffsetFix extends JobHandler |
25 | 25 | { |
26 | - /** |
|
27 | - * Key for the option used to track which models have been processed when doing the batches. |
|
28 | - */ |
|
29 | - const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix'; |
|
30 | - |
|
31 | - |
|
32 | - const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed'; |
|
33 | - |
|
34 | - /** |
|
35 | - * Key for the option used to track what the current offset is that will be applied when this tool is executed. |
|
36 | - */ |
|
37 | - const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply'; |
|
38 | - |
|
39 | - |
|
40 | - const OPTION_KEY_OFFSET_RANGE_START_DATE = 'ee_datetime_offset_start_date_range'; |
|
41 | - |
|
42 | - |
|
43 | - const OPTION_KEY_OFFSET_RANGE_END_DATE = 'ee_datetime_offset_end_date_range'; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * String labelling the datetime offset fix type for change-log entries. |
|
48 | - */ |
|
49 | - const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix'; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * String labelling a datetime offset fix error for change-log entries. |
|
54 | - */ |
|
55 | - const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error'; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EEM_Base[] |
|
59 | - */ |
|
60 | - protected $models_with_datetime_fields = array(); |
|
61 | - |
|
62 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
63 | - |
|
64 | - /** |
|
65 | - * Performs any necessary setup for starting the job. This is also a good |
|
66 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
67 | - * when continue_job will be called |
|
68 | - * |
|
69 | - * @param JobParameters $job_parameters |
|
70 | - * @return JobStepResponse |
|
71 | - * @throws EE_Error |
|
72 | - * @throws InvalidArgumentException |
|
73 | - * @throws InvalidDataTypeException |
|
74 | - * @throws InvalidInterfaceException |
|
75 | - */ |
|
76 | - public function create_job(JobParameters $job_parameters): JobStepResponse |
|
77 | - { |
|
78 | - $models_with_datetime_fields = $this->getModelsWithDatetimeFields(); |
|
79 | - // we'll be doing each model as a batch. |
|
80 | - $job_parameters->set_job_size(count($models_with_datetime_fields)); |
|
81 | - return new JobStepResponse( |
|
82 | - $job_parameters, |
|
83 | - esc_html__('Starting Datetime Offset Fix', 'event_espresso') |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Performs another step of the job |
|
89 | - * |
|
90 | - * @param JobParameters $job_parameters |
|
91 | - * @param int $batch_size |
|
92 | - * @return JobStepResponse |
|
93 | - * @throws EE_Error |
|
94 | - * @throws InvalidArgumentException |
|
95 | - * @throws InvalidDataTypeException |
|
96 | - * @throws InvalidInterfaceException |
|
97 | - */ |
|
98 | - public function continue_job(JobParameters $job_parameters, int $batch_size = 50): JobStepResponse |
|
99 | - { |
|
100 | - $models_to_process = $this->getModelsWithDatetimeFields(); |
|
101 | - // let's pop off the a model and do the query to apply the offset. |
|
102 | - $model_to_process = array_pop($models_to_process); |
|
103 | - // update our record |
|
104 | - $this->setModelsToProcess($models_to_process); |
|
105 | - $this->processModel($model_to_process); |
|
106 | - $this->updateCountOfModelsProcessed(); |
|
107 | - $job_parameters->set_units_processed($this->getCountOfModelsProcessed()); |
|
108 | - if (count($models_to_process) > 0) { |
|
109 | - $job_parameters->set_status(JobParameters::status_continue); |
|
110 | - } else { |
|
111 | - $job_parameters->set_status(JobParameters::status_complete); |
|
112 | - } |
|
113 | - return new JobStepResponse( |
|
114 | - $job_parameters, |
|
115 | - sprintf( |
|
116 | - esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'), |
|
117 | - $model_to_process |
|
118 | - ) |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Performs any clean-up logic when we know the job is completed |
|
124 | - * |
|
125 | - * @param JobParameters $job_parameters |
|
126 | - * @return JobStepResponse |
|
127 | - * @throws BatchRequestException |
|
128 | - */ |
|
129 | - public function cleanup_job(JobParameters $job_parameters): JobStepResponse |
|
130 | - { |
|
131 | - // delete important saved options. |
|
132 | - delete_option(self::MODELS_TO_PROCESS_OPTION_KEY); |
|
133 | - delete_option(self::COUNT_OF_MODELS_PROCESSED); |
|
134 | - delete_option(self::OPTION_KEY_OFFSET_RANGE_START_DATE); |
|
135 | - delete_option(self::OPTION_KEY_OFFSET_RANGE_END_DATE); |
|
136 | - return new JobStepResponse($job_parameters, esc_html__( |
|
137 | - 'Offset has been applied to all affected fields.', |
|
138 | - 'event_espresso' |
|
139 | - )); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * Contains the logic for processing a model and applying the datetime offset to affected fields on that model. |
|
145 | - * |
|
146 | - * @param string $model_class_name |
|
147 | - * @throws EE_Error |
|
148 | - */ |
|
149 | - protected function processModel($model_class_name) |
|
150 | - { |
|
151 | - global $wpdb; |
|
152 | - /** @var EEM_Base $model */ |
|
153 | - $model = $model_class_name::instance(); |
|
154 | - $original_offset = self::getOffset(); |
|
155 | - $start_date_range = self::getStartDateRange(); |
|
156 | - $end_date_range = self::getEndDateRange(); |
|
157 | - $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB'; |
|
158 | - $offset = abs($original_offset) * 60; |
|
159 | - $date_ranges = array(); |
|
160 | - // since some affected models might have two tables, we have to get our tables and set up a query for each table. |
|
161 | - foreach ($model->get_tables() as $table) { |
|
162 | - $query = 'UPDATE ' . $table->get_table_name(); |
|
163 | - $fields_affected = array(); |
|
164 | - $inner_query = array(); |
|
165 | - foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
|
166 | - if ($model_field instanceof EE_Datetime_Field) { |
|
167 | - $inner_query[ $model_field->get_table_column() ] = $model_field->get_table_column() . ' = ' |
|
168 | - . $sql_date_function . '(' |
|
169 | - . $model_field->get_table_column() |
|
170 | - . ", INTERVAL {$offset} MINUTE)"; |
|
171 | - $fields_affected[] = $model_field; |
|
172 | - } |
|
173 | - } |
|
174 | - if (! $fields_affected) { |
|
175 | - continue; |
|
176 | - } |
|
177 | - // do we do one query per column/field or one query for all fields on the model? It all depends on whether |
|
178 | - // there is a date range applied or not. |
|
179 | - if ($start_date_range instanceof DbSafeDateTime || $end_date_range instanceof DbSafeDateTime) { |
|
180 | - $result = $this->doQueryForEachField($query, $inner_query, $start_date_range, $end_date_range); |
|
181 | - } else { |
|
182 | - $result = $this->doQueryForAllFields($query, $inner_query); |
|
183 | - } |
|
184 | - |
|
185 | - // record appropriate logs for the query |
|
186 | - switch (true) { |
|
187 | - case $result === false: |
|
188 | - // record error. |
|
189 | - $error_message = $wpdb->last_error; |
|
190 | - // handle the edge cases where last_error might be empty. |
|
191 | - if (! $error_message) { |
|
192 | - $error_message = esc_html__('Unknown mysql error occurred.', 'event_espresso'); |
|
193 | - } |
|
194 | - $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
|
195 | - break; |
|
196 | - case is_array($result) && ! empty($result): |
|
197 | - foreach ($result as $field_name => $error_message) { |
|
198 | - $this->recordChangeLog($model, $original_offset, $table, array($field_name), $error_message); |
|
199 | - } |
|
200 | - break; |
|
201 | - default: |
|
202 | - $this->recordChangeLog($model, $original_offset, $table, $fields_affected); |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Does the query on each $inner_query individually. |
|
210 | - * |
|
211 | - * @param string $query |
|
212 | - * @param array $inner_query |
|
213 | - * @param DbSafeDateTime|null $start_date_range |
|
214 | - * @param DbSafeDateTime|null $end_date_range |
|
215 | - * @return array An array of any errors encountered and the fields they were for. |
|
216 | - */ |
|
217 | - private function doQueryForEachField($query, array $inner_query, $start_date_range, $end_date_range) |
|
218 | - { |
|
219 | - global $wpdb; |
|
220 | - $errors = array(); |
|
221 | - foreach ($inner_query as $field_name => $field_query) { |
|
222 | - $query_to_run = $query; |
|
223 | - $where_conditions = array(); |
|
224 | - $query_to_run .= ' SET ' . $field_query; |
|
225 | - if ($start_date_range instanceof DbSafeDateTime) { |
|
226 | - $start_date = $start_date_range->format(EE_Datetime_Field::mysql_timestamp_format); |
|
227 | - $where_conditions[] = "{$field_name} > '{$start_date}'"; |
|
228 | - } |
|
229 | - if ($end_date_range instanceof DbSafeDateTime) { |
|
230 | - $end_date = $end_date_range->format(EE_Datetime_Field::mysql_timestamp_format); |
|
231 | - $where_conditions[] = "{$field_name} < '{$end_date}'"; |
|
232 | - } |
|
233 | - if ($where_conditions) { |
|
234 | - $query_to_run .= ' WHERE ' . implode(' AND ', $where_conditions); |
|
235 | - } |
|
236 | - $result = $wpdb->query($query_to_run); |
|
237 | - if ($result === false) { |
|
238 | - // record error. |
|
239 | - $error_message = $wpdb->last_error; |
|
240 | - // handle the edgecases where last_error might be empty. |
|
241 | - if (! $error_message) { |
|
242 | - $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
|
243 | - } |
|
244 | - $errors[ $field_name ] = $error_message; |
|
245 | - } |
|
246 | - } |
|
247 | - return $errors; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Performs the query for all fields within the inner_query |
|
253 | - * |
|
254 | - * @param string $query |
|
255 | - * @param array $inner_query |
|
256 | - * @return false|int |
|
257 | - */ |
|
258 | - private function doQueryForAllFields($query, array $inner_query) |
|
259 | - { |
|
260 | - global $wpdb; |
|
261 | - $query .= ' SET ' . implode(',', $inner_query); |
|
262 | - return $wpdb->query($query); |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * Records a changelog entry using the given information. |
|
268 | - * |
|
269 | - * @param EEM_Base $model |
|
270 | - * @param float $offset |
|
271 | - * @param EE_Table_Base $table |
|
272 | - * @param EE_Model_Field_Base[] $model_fields_affected |
|
273 | - * @param string $error_message If present then there was an error so let's record that instead. |
|
274 | - * @throws EE_Error |
|
275 | - */ |
|
276 | - private function recordChangeLog( |
|
277 | - EEM_Base $model, |
|
278 | - $offset, |
|
279 | - EE_Table_Base $table, |
|
280 | - $model_fields_affected, |
|
281 | - $error_message = '' |
|
282 | - ) { |
|
283 | - // setup $fields list. |
|
284 | - $fields = array(); |
|
285 | - /** @var EE_Datetime_Field $model_field */ |
|
286 | - foreach ($model_fields_affected as $model_field) { |
|
287 | - if (! $model_field instanceof EE_Datetime_Field) { |
|
288 | - continue; |
|
289 | - } |
|
290 | - $fields[] = $model_field->get_name(); |
|
291 | - } |
|
292 | - // setup the message for the changelog entry. |
|
293 | - $message = $error_message |
|
294 | - ? sprintf( |
|
295 | - esc_html__( |
|
296 | - 'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s', |
|
297 | - 'event_espresso' |
|
298 | - ), |
|
299 | - $table->get_table_name(), |
|
300 | - $model->get_this_model_name(), |
|
301 | - $offset, |
|
302 | - implode(',', $fields), |
|
303 | - $error_message |
|
304 | - ) |
|
305 | - : sprintf( |
|
306 | - esc_html__( |
|
307 | - 'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s', |
|
308 | - 'event_espresso' |
|
309 | - ), |
|
310 | - $table->get_table_name(), |
|
311 | - $model->get_this_model_name(), |
|
312 | - $offset, |
|
313 | - implode(',', $fields) |
|
314 | - ); |
|
315 | - // write to the log |
|
316 | - $changelog = EE_Change_Log::new_instance(array( |
|
317 | - 'LOG_type' => $error_message |
|
318 | - ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE |
|
319 | - : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE, |
|
320 | - 'LOG_message' => $message, |
|
321 | - )); |
|
322 | - $changelog->save(); |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * Returns an array of models that have datetime fields. |
|
328 | - * This array is added to a short lived transient cache to keep having to build this list to a minimum. |
|
329 | - * |
|
330 | - * @return array an array of model class names. |
|
331 | - * @throws EE_Error |
|
332 | - * @throws InvalidDataTypeException |
|
333 | - * @throws InvalidInterfaceException |
|
334 | - * @throws InvalidArgumentException |
|
335 | - */ |
|
336 | - private function getModelsWithDatetimeFields() |
|
337 | - { |
|
338 | - $this->getModelsToProcess(); |
|
339 | - if (! empty($this->models_with_datetime_fields)) { |
|
340 | - return $this->models_with_datetime_fields; |
|
341 | - } |
|
342 | - |
|
343 | - $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models; |
|
344 | - foreach ($all_non_abstract_models as $non_abstract_model) { |
|
345 | - // get model instance |
|
346 | - /** @var EEM_Base $non_abstract_model */ |
|
347 | - $non_abstract_model = $non_abstract_model::instance(); |
|
348 | - if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) { |
|
349 | - $this->models_with_datetime_fields[] = get_class($non_abstract_model); |
|
350 | - } |
|
351 | - } |
|
352 | - $this->setModelsToProcess($this->models_with_datetime_fields); |
|
353 | - return $this->models_with_datetime_fields; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * This simply records the models that have been processed with our tracking option. |
|
359 | - * |
|
360 | - * @param array $models_to_set array of model class names. |
|
361 | - */ |
|
362 | - private function setModelsToProcess($models_to_set) |
|
363 | - { |
|
364 | - update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Used to keep track of how many models have been processed for the batch |
|
370 | - * |
|
371 | - * @param $count |
|
372 | - */ |
|
373 | - private function updateCountOfModelsProcessed($count = 1) |
|
374 | - { |
|
375 | - $count = $this->getCountOfModelsProcessed() + (int) $count; |
|
376 | - update_option(self::COUNT_OF_MODELS_PROCESSED, $count); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * Retrieve the tracked number of models processed between requests. |
|
382 | - * |
|
383 | - * @return int |
|
384 | - */ |
|
385 | - private function getCountOfModelsProcessed() |
|
386 | - { |
|
387 | - return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0); |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Returns the models that are left to process. |
|
393 | - * |
|
394 | - * @return array an array of model class names. |
|
395 | - */ |
|
396 | - private function getModelsToProcess() |
|
397 | - { |
|
398 | - if (empty($this->models_with_datetime_fields)) { |
|
399 | - $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array()); |
|
400 | - } |
|
401 | - return $this->models_with_datetime_fields; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
407 | - * |
|
408 | - * @param float $offset |
|
409 | - */ |
|
410 | - public static function updateOffset($offset) |
|
411 | - { |
|
412 | - update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset); |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
418 | - * |
|
419 | - * @return float |
|
420 | - */ |
|
421 | - public static function getOffset() |
|
422 | - { |
|
423 | - return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0); |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * Used to set the saved offset range start date. |
|
429 | - * |
|
430 | - * @param DbSafeDateTime|null $start_date |
|
431 | - */ |
|
432 | - public static function updateStartDateRange(DbSafeDateTime $start_date = null) |
|
433 | - { |
|
434 | - $date_to_save = $start_date instanceof DbSafeDateTime |
|
435 | - ? $start_date->format('U') |
|
436 | - : ''; |
|
437 | - update_option(self::OPTION_KEY_OFFSET_RANGE_START_DATE, $date_to_save); |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * Used to get the saved offset range start date. |
|
443 | - * |
|
444 | - * @return DbSafeDateTime|null |
|
445 | - */ |
|
446 | - public static function getStartDateRange(): ?DbSafeDateTime |
|
447 | - { |
|
448 | - $start_date = get_option(self::OPTION_KEY_OFFSET_RANGE_START_DATE, null); |
|
449 | - if (! $start_date) { |
|
450 | - return null; |
|
451 | - } |
|
452 | - try { |
|
453 | - $datetime = DateTime::createFromFormat('U', $start_date, new DateTimeZone('UTC')); |
|
454 | - $start_date = $datetime instanceof DateTime |
|
455 | - ? DbSafeDateTime::createFromDateTime($datetime) |
|
456 | - : null; |
|
457 | - } catch (Exception $e) { |
|
458 | - $start_date = null; |
|
459 | - } |
|
460 | - return $start_date; |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * Used to set the saved offset range end date. |
|
466 | - * |
|
467 | - * @param DbSafeDateTime|null $end_date |
|
468 | - */ |
|
469 | - public static function updateEndDateRange(DbSafeDateTime $end_date = null) |
|
470 | - { |
|
471 | - $date_to_save = $end_date instanceof DbSafeDateTime |
|
472 | - ? $end_date->format('U') |
|
473 | - : ''; |
|
474 | - update_option(self::OPTION_KEY_OFFSET_RANGE_END_DATE, $date_to_save); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * Used to get the saved offset range end date. |
|
480 | - * |
|
481 | - * @return DbSafeDateTime|null |
|
482 | - */ |
|
483 | - public static function getEndDateRange(): ?DbSafeDateTime |
|
484 | - { |
|
485 | - $end_date = get_option(self::OPTION_KEY_OFFSET_RANGE_END_DATE, null); |
|
486 | - if (! $end_date) { |
|
487 | - return null; |
|
488 | - } |
|
489 | - try { |
|
490 | - $datetime = DateTime::createFromFormat('U', $end_date, new DateTimeZone('UTC')); |
|
491 | - $end_date = $datetime instanceof Datetime |
|
492 | - ? DbSafeDateTime::createFromDateTime($datetime) |
|
493 | - : null; |
|
494 | - } catch (Exception $e) { |
|
495 | - $end_date = null; |
|
496 | - } |
|
497 | - return $end_date; |
|
498 | - } |
|
26 | + /** |
|
27 | + * Key for the option used to track which models have been processed when doing the batches. |
|
28 | + */ |
|
29 | + const MODELS_TO_PROCESS_OPTION_KEY = 'ee_models_processed_for_datetime_offset_fix'; |
|
30 | + |
|
31 | + |
|
32 | + const COUNT_OF_MODELS_PROCESSED = 'ee_count_of_ee_models_processed_for_datetime_offset_fixed'; |
|
33 | + |
|
34 | + /** |
|
35 | + * Key for the option used to track what the current offset is that will be applied when this tool is executed. |
|
36 | + */ |
|
37 | + const OFFSET_TO_APPLY_OPTION_KEY = 'ee_datetime_offset_fix_offset_to_apply'; |
|
38 | + |
|
39 | + |
|
40 | + const OPTION_KEY_OFFSET_RANGE_START_DATE = 'ee_datetime_offset_start_date_range'; |
|
41 | + |
|
42 | + |
|
43 | + const OPTION_KEY_OFFSET_RANGE_END_DATE = 'ee_datetime_offset_end_date_range'; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * String labelling the datetime offset fix type for change-log entries. |
|
48 | + */ |
|
49 | + const DATETIME_OFFSET_FIX_CHANGELOG_TYPE = 'datetime_offset_fix'; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * String labelling a datetime offset fix error for change-log entries. |
|
54 | + */ |
|
55 | + const DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE = 'datetime_offset_fix_error'; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EEM_Base[] |
|
59 | + */ |
|
60 | + protected $models_with_datetime_fields = array(); |
|
61 | + |
|
62 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
63 | + |
|
64 | + /** |
|
65 | + * Performs any necessary setup for starting the job. This is also a good |
|
66 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
67 | + * when continue_job will be called |
|
68 | + * |
|
69 | + * @param JobParameters $job_parameters |
|
70 | + * @return JobStepResponse |
|
71 | + * @throws EE_Error |
|
72 | + * @throws InvalidArgumentException |
|
73 | + * @throws InvalidDataTypeException |
|
74 | + * @throws InvalidInterfaceException |
|
75 | + */ |
|
76 | + public function create_job(JobParameters $job_parameters): JobStepResponse |
|
77 | + { |
|
78 | + $models_with_datetime_fields = $this->getModelsWithDatetimeFields(); |
|
79 | + // we'll be doing each model as a batch. |
|
80 | + $job_parameters->set_job_size(count($models_with_datetime_fields)); |
|
81 | + return new JobStepResponse( |
|
82 | + $job_parameters, |
|
83 | + esc_html__('Starting Datetime Offset Fix', 'event_espresso') |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Performs another step of the job |
|
89 | + * |
|
90 | + * @param JobParameters $job_parameters |
|
91 | + * @param int $batch_size |
|
92 | + * @return JobStepResponse |
|
93 | + * @throws EE_Error |
|
94 | + * @throws InvalidArgumentException |
|
95 | + * @throws InvalidDataTypeException |
|
96 | + * @throws InvalidInterfaceException |
|
97 | + */ |
|
98 | + public function continue_job(JobParameters $job_parameters, int $batch_size = 50): JobStepResponse |
|
99 | + { |
|
100 | + $models_to_process = $this->getModelsWithDatetimeFields(); |
|
101 | + // let's pop off the a model and do the query to apply the offset. |
|
102 | + $model_to_process = array_pop($models_to_process); |
|
103 | + // update our record |
|
104 | + $this->setModelsToProcess($models_to_process); |
|
105 | + $this->processModel($model_to_process); |
|
106 | + $this->updateCountOfModelsProcessed(); |
|
107 | + $job_parameters->set_units_processed($this->getCountOfModelsProcessed()); |
|
108 | + if (count($models_to_process) > 0) { |
|
109 | + $job_parameters->set_status(JobParameters::status_continue); |
|
110 | + } else { |
|
111 | + $job_parameters->set_status(JobParameters::status_complete); |
|
112 | + } |
|
113 | + return new JobStepResponse( |
|
114 | + $job_parameters, |
|
115 | + sprintf( |
|
116 | + esc_html__('Updated the offset for all datetime fields on the %s model.', 'event_espresso'), |
|
117 | + $model_to_process |
|
118 | + ) |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Performs any clean-up logic when we know the job is completed |
|
124 | + * |
|
125 | + * @param JobParameters $job_parameters |
|
126 | + * @return JobStepResponse |
|
127 | + * @throws BatchRequestException |
|
128 | + */ |
|
129 | + public function cleanup_job(JobParameters $job_parameters): JobStepResponse |
|
130 | + { |
|
131 | + // delete important saved options. |
|
132 | + delete_option(self::MODELS_TO_PROCESS_OPTION_KEY); |
|
133 | + delete_option(self::COUNT_OF_MODELS_PROCESSED); |
|
134 | + delete_option(self::OPTION_KEY_OFFSET_RANGE_START_DATE); |
|
135 | + delete_option(self::OPTION_KEY_OFFSET_RANGE_END_DATE); |
|
136 | + return new JobStepResponse($job_parameters, esc_html__( |
|
137 | + 'Offset has been applied to all affected fields.', |
|
138 | + 'event_espresso' |
|
139 | + )); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * Contains the logic for processing a model and applying the datetime offset to affected fields on that model. |
|
145 | + * |
|
146 | + * @param string $model_class_name |
|
147 | + * @throws EE_Error |
|
148 | + */ |
|
149 | + protected function processModel($model_class_name) |
|
150 | + { |
|
151 | + global $wpdb; |
|
152 | + /** @var EEM_Base $model */ |
|
153 | + $model = $model_class_name::instance(); |
|
154 | + $original_offset = self::getOffset(); |
|
155 | + $start_date_range = self::getStartDateRange(); |
|
156 | + $end_date_range = self::getEndDateRange(); |
|
157 | + $sql_date_function = $original_offset > 0 ? 'DATE_ADD' : 'DATE_SUB'; |
|
158 | + $offset = abs($original_offset) * 60; |
|
159 | + $date_ranges = array(); |
|
160 | + // since some affected models might have two tables, we have to get our tables and set up a query for each table. |
|
161 | + foreach ($model->get_tables() as $table) { |
|
162 | + $query = 'UPDATE ' . $table->get_table_name(); |
|
163 | + $fields_affected = array(); |
|
164 | + $inner_query = array(); |
|
165 | + foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
|
166 | + if ($model_field instanceof EE_Datetime_Field) { |
|
167 | + $inner_query[ $model_field->get_table_column() ] = $model_field->get_table_column() . ' = ' |
|
168 | + . $sql_date_function . '(' |
|
169 | + . $model_field->get_table_column() |
|
170 | + . ", INTERVAL {$offset} MINUTE)"; |
|
171 | + $fields_affected[] = $model_field; |
|
172 | + } |
|
173 | + } |
|
174 | + if (! $fields_affected) { |
|
175 | + continue; |
|
176 | + } |
|
177 | + // do we do one query per column/field or one query for all fields on the model? It all depends on whether |
|
178 | + // there is a date range applied or not. |
|
179 | + if ($start_date_range instanceof DbSafeDateTime || $end_date_range instanceof DbSafeDateTime) { |
|
180 | + $result = $this->doQueryForEachField($query, $inner_query, $start_date_range, $end_date_range); |
|
181 | + } else { |
|
182 | + $result = $this->doQueryForAllFields($query, $inner_query); |
|
183 | + } |
|
184 | + |
|
185 | + // record appropriate logs for the query |
|
186 | + switch (true) { |
|
187 | + case $result === false: |
|
188 | + // record error. |
|
189 | + $error_message = $wpdb->last_error; |
|
190 | + // handle the edge cases where last_error might be empty. |
|
191 | + if (! $error_message) { |
|
192 | + $error_message = esc_html__('Unknown mysql error occurred.', 'event_espresso'); |
|
193 | + } |
|
194 | + $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
|
195 | + break; |
|
196 | + case is_array($result) && ! empty($result): |
|
197 | + foreach ($result as $field_name => $error_message) { |
|
198 | + $this->recordChangeLog($model, $original_offset, $table, array($field_name), $error_message); |
|
199 | + } |
|
200 | + break; |
|
201 | + default: |
|
202 | + $this->recordChangeLog($model, $original_offset, $table, $fields_affected); |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Does the query on each $inner_query individually. |
|
210 | + * |
|
211 | + * @param string $query |
|
212 | + * @param array $inner_query |
|
213 | + * @param DbSafeDateTime|null $start_date_range |
|
214 | + * @param DbSafeDateTime|null $end_date_range |
|
215 | + * @return array An array of any errors encountered and the fields they were for. |
|
216 | + */ |
|
217 | + private function doQueryForEachField($query, array $inner_query, $start_date_range, $end_date_range) |
|
218 | + { |
|
219 | + global $wpdb; |
|
220 | + $errors = array(); |
|
221 | + foreach ($inner_query as $field_name => $field_query) { |
|
222 | + $query_to_run = $query; |
|
223 | + $where_conditions = array(); |
|
224 | + $query_to_run .= ' SET ' . $field_query; |
|
225 | + if ($start_date_range instanceof DbSafeDateTime) { |
|
226 | + $start_date = $start_date_range->format(EE_Datetime_Field::mysql_timestamp_format); |
|
227 | + $where_conditions[] = "{$field_name} > '{$start_date}'"; |
|
228 | + } |
|
229 | + if ($end_date_range instanceof DbSafeDateTime) { |
|
230 | + $end_date = $end_date_range->format(EE_Datetime_Field::mysql_timestamp_format); |
|
231 | + $where_conditions[] = "{$field_name} < '{$end_date}'"; |
|
232 | + } |
|
233 | + if ($where_conditions) { |
|
234 | + $query_to_run .= ' WHERE ' . implode(' AND ', $where_conditions); |
|
235 | + } |
|
236 | + $result = $wpdb->query($query_to_run); |
|
237 | + if ($result === false) { |
|
238 | + // record error. |
|
239 | + $error_message = $wpdb->last_error; |
|
240 | + // handle the edgecases where last_error might be empty. |
|
241 | + if (! $error_message) { |
|
242 | + $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
|
243 | + } |
|
244 | + $errors[ $field_name ] = $error_message; |
|
245 | + } |
|
246 | + } |
|
247 | + return $errors; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Performs the query for all fields within the inner_query |
|
253 | + * |
|
254 | + * @param string $query |
|
255 | + * @param array $inner_query |
|
256 | + * @return false|int |
|
257 | + */ |
|
258 | + private function doQueryForAllFields($query, array $inner_query) |
|
259 | + { |
|
260 | + global $wpdb; |
|
261 | + $query .= ' SET ' . implode(',', $inner_query); |
|
262 | + return $wpdb->query($query); |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * Records a changelog entry using the given information. |
|
268 | + * |
|
269 | + * @param EEM_Base $model |
|
270 | + * @param float $offset |
|
271 | + * @param EE_Table_Base $table |
|
272 | + * @param EE_Model_Field_Base[] $model_fields_affected |
|
273 | + * @param string $error_message If present then there was an error so let's record that instead. |
|
274 | + * @throws EE_Error |
|
275 | + */ |
|
276 | + private function recordChangeLog( |
|
277 | + EEM_Base $model, |
|
278 | + $offset, |
|
279 | + EE_Table_Base $table, |
|
280 | + $model_fields_affected, |
|
281 | + $error_message = '' |
|
282 | + ) { |
|
283 | + // setup $fields list. |
|
284 | + $fields = array(); |
|
285 | + /** @var EE_Datetime_Field $model_field */ |
|
286 | + foreach ($model_fields_affected as $model_field) { |
|
287 | + if (! $model_field instanceof EE_Datetime_Field) { |
|
288 | + continue; |
|
289 | + } |
|
290 | + $fields[] = $model_field->get_name(); |
|
291 | + } |
|
292 | + // setup the message for the changelog entry. |
|
293 | + $message = $error_message |
|
294 | + ? sprintf( |
|
295 | + esc_html__( |
|
296 | + 'The %1$s table for the %2$s model did not have the offset of %3$f applied to its fields (%4$s), because of the following error:%5$s', |
|
297 | + 'event_espresso' |
|
298 | + ), |
|
299 | + $table->get_table_name(), |
|
300 | + $model->get_this_model_name(), |
|
301 | + $offset, |
|
302 | + implode(',', $fields), |
|
303 | + $error_message |
|
304 | + ) |
|
305 | + : sprintf( |
|
306 | + esc_html__( |
|
307 | + 'The %1$s table for the %2$s model has had the offset of %3$f applied to its following fields: %4$s', |
|
308 | + 'event_espresso' |
|
309 | + ), |
|
310 | + $table->get_table_name(), |
|
311 | + $model->get_this_model_name(), |
|
312 | + $offset, |
|
313 | + implode(',', $fields) |
|
314 | + ); |
|
315 | + // write to the log |
|
316 | + $changelog = EE_Change_Log::new_instance(array( |
|
317 | + 'LOG_type' => $error_message |
|
318 | + ? self::DATETIME_OFFSET_FIX_CHANGELOG_ERROR_TYPE |
|
319 | + : self::DATETIME_OFFSET_FIX_CHANGELOG_TYPE, |
|
320 | + 'LOG_message' => $message, |
|
321 | + )); |
|
322 | + $changelog->save(); |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * Returns an array of models that have datetime fields. |
|
328 | + * This array is added to a short lived transient cache to keep having to build this list to a minimum. |
|
329 | + * |
|
330 | + * @return array an array of model class names. |
|
331 | + * @throws EE_Error |
|
332 | + * @throws InvalidDataTypeException |
|
333 | + * @throws InvalidInterfaceException |
|
334 | + * @throws InvalidArgumentException |
|
335 | + */ |
|
336 | + private function getModelsWithDatetimeFields() |
|
337 | + { |
|
338 | + $this->getModelsToProcess(); |
|
339 | + if (! empty($this->models_with_datetime_fields)) { |
|
340 | + return $this->models_with_datetime_fields; |
|
341 | + } |
|
342 | + |
|
343 | + $all_non_abstract_models = EE_Registry::instance()->non_abstract_db_models; |
|
344 | + foreach ($all_non_abstract_models as $non_abstract_model) { |
|
345 | + // get model instance |
|
346 | + /** @var EEM_Base $non_abstract_model */ |
|
347 | + $non_abstract_model = $non_abstract_model::instance(); |
|
348 | + if ($non_abstract_model->get_a_field_of_type('EE_Datetime_Field') instanceof EE_Datetime_Field) { |
|
349 | + $this->models_with_datetime_fields[] = get_class($non_abstract_model); |
|
350 | + } |
|
351 | + } |
|
352 | + $this->setModelsToProcess($this->models_with_datetime_fields); |
|
353 | + return $this->models_with_datetime_fields; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * This simply records the models that have been processed with our tracking option. |
|
359 | + * |
|
360 | + * @param array $models_to_set array of model class names. |
|
361 | + */ |
|
362 | + private function setModelsToProcess($models_to_set) |
|
363 | + { |
|
364 | + update_option(self::MODELS_TO_PROCESS_OPTION_KEY, $models_to_set); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Used to keep track of how many models have been processed for the batch |
|
370 | + * |
|
371 | + * @param $count |
|
372 | + */ |
|
373 | + private function updateCountOfModelsProcessed($count = 1) |
|
374 | + { |
|
375 | + $count = $this->getCountOfModelsProcessed() + (int) $count; |
|
376 | + update_option(self::COUNT_OF_MODELS_PROCESSED, $count); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * Retrieve the tracked number of models processed between requests. |
|
382 | + * |
|
383 | + * @return int |
|
384 | + */ |
|
385 | + private function getCountOfModelsProcessed() |
|
386 | + { |
|
387 | + return (int) get_option(self::COUNT_OF_MODELS_PROCESSED, 0); |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Returns the models that are left to process. |
|
393 | + * |
|
394 | + * @return array an array of model class names. |
|
395 | + */ |
|
396 | + private function getModelsToProcess() |
|
397 | + { |
|
398 | + if (empty($this->models_with_datetime_fields)) { |
|
399 | + $this->models_with_datetime_fields = get_option(self::MODELS_TO_PROCESS_OPTION_KEY, array()); |
|
400 | + } |
|
401 | + return $this->models_with_datetime_fields; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * Used to record the offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
407 | + * |
|
408 | + * @param float $offset |
|
409 | + */ |
|
410 | + public static function updateOffset($offset) |
|
411 | + { |
|
412 | + update_option(self::OFFSET_TO_APPLY_OPTION_KEY, $offset); |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * Used to retrieve the saved offset that will be applied to dates and times for EE_Datetime_Field columns. |
|
418 | + * |
|
419 | + * @return float |
|
420 | + */ |
|
421 | + public static function getOffset() |
|
422 | + { |
|
423 | + return (float) get_option(self::OFFSET_TO_APPLY_OPTION_KEY, 0); |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * Used to set the saved offset range start date. |
|
429 | + * |
|
430 | + * @param DbSafeDateTime|null $start_date |
|
431 | + */ |
|
432 | + public static function updateStartDateRange(DbSafeDateTime $start_date = null) |
|
433 | + { |
|
434 | + $date_to_save = $start_date instanceof DbSafeDateTime |
|
435 | + ? $start_date->format('U') |
|
436 | + : ''; |
|
437 | + update_option(self::OPTION_KEY_OFFSET_RANGE_START_DATE, $date_to_save); |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * Used to get the saved offset range start date. |
|
443 | + * |
|
444 | + * @return DbSafeDateTime|null |
|
445 | + */ |
|
446 | + public static function getStartDateRange(): ?DbSafeDateTime |
|
447 | + { |
|
448 | + $start_date = get_option(self::OPTION_KEY_OFFSET_RANGE_START_DATE, null); |
|
449 | + if (! $start_date) { |
|
450 | + return null; |
|
451 | + } |
|
452 | + try { |
|
453 | + $datetime = DateTime::createFromFormat('U', $start_date, new DateTimeZone('UTC')); |
|
454 | + $start_date = $datetime instanceof DateTime |
|
455 | + ? DbSafeDateTime::createFromDateTime($datetime) |
|
456 | + : null; |
|
457 | + } catch (Exception $e) { |
|
458 | + $start_date = null; |
|
459 | + } |
|
460 | + return $start_date; |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * Used to set the saved offset range end date. |
|
466 | + * |
|
467 | + * @param DbSafeDateTime|null $end_date |
|
468 | + */ |
|
469 | + public static function updateEndDateRange(DbSafeDateTime $end_date = null) |
|
470 | + { |
|
471 | + $date_to_save = $end_date instanceof DbSafeDateTime |
|
472 | + ? $end_date->format('U') |
|
473 | + : ''; |
|
474 | + update_option(self::OPTION_KEY_OFFSET_RANGE_END_DATE, $date_to_save); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * Used to get the saved offset range end date. |
|
480 | + * |
|
481 | + * @return DbSafeDateTime|null |
|
482 | + */ |
|
483 | + public static function getEndDateRange(): ?DbSafeDateTime |
|
484 | + { |
|
485 | + $end_date = get_option(self::OPTION_KEY_OFFSET_RANGE_END_DATE, null); |
|
486 | + if (! $end_date) { |
|
487 | + return null; |
|
488 | + } |
|
489 | + try { |
|
490 | + $datetime = DateTime::createFromFormat('U', $end_date, new DateTimeZone('UTC')); |
|
491 | + $end_date = $datetime instanceof Datetime |
|
492 | + ? DbSafeDateTime::createFromDateTime($datetime) |
|
493 | + : null; |
|
494 | + } catch (Exception $e) { |
|
495 | + $end_date = null; |
|
496 | + } |
|
497 | + return $end_date; |
|
498 | + } |
|
499 | 499 | } |
@@ -159,19 +159,19 @@ discard block |
||
159 | 159 | $date_ranges = array(); |
160 | 160 | // since some affected models might have two tables, we have to get our tables and set up a query for each table. |
161 | 161 | foreach ($model->get_tables() as $table) { |
162 | - $query = 'UPDATE ' . $table->get_table_name(); |
|
162 | + $query = 'UPDATE '.$table->get_table_name(); |
|
163 | 163 | $fields_affected = array(); |
164 | 164 | $inner_query = array(); |
165 | 165 | foreach ($model->_get_fields_for_table($table->get_table_alias()) as $model_field) { |
166 | 166 | if ($model_field instanceof EE_Datetime_Field) { |
167 | - $inner_query[ $model_field->get_table_column() ] = $model_field->get_table_column() . ' = ' |
|
168 | - . $sql_date_function . '(' |
|
167 | + $inner_query[$model_field->get_table_column()] = $model_field->get_table_column().' = ' |
|
168 | + . $sql_date_function.'(' |
|
169 | 169 | . $model_field->get_table_column() |
170 | 170 | . ", INTERVAL {$offset} MINUTE)"; |
171 | 171 | $fields_affected[] = $model_field; |
172 | 172 | } |
173 | 173 | } |
174 | - if (! $fields_affected) { |
|
174 | + if ( ! $fields_affected) { |
|
175 | 175 | continue; |
176 | 176 | } |
177 | 177 | // do we do one query per column/field or one query for all fields on the model? It all depends on whether |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | // record error. |
189 | 189 | $error_message = $wpdb->last_error; |
190 | 190 | // handle the edge cases where last_error might be empty. |
191 | - if (! $error_message) { |
|
191 | + if ( ! $error_message) { |
|
192 | 192 | $error_message = esc_html__('Unknown mysql error occurred.', 'event_espresso'); |
193 | 193 | } |
194 | 194 | $this->recordChangeLog($model, $original_offset, $table, $fields_affected, $error_message); |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | foreach ($inner_query as $field_name => $field_query) { |
222 | 222 | $query_to_run = $query; |
223 | 223 | $where_conditions = array(); |
224 | - $query_to_run .= ' SET ' . $field_query; |
|
224 | + $query_to_run .= ' SET '.$field_query; |
|
225 | 225 | if ($start_date_range instanceof DbSafeDateTime) { |
226 | 226 | $start_date = $start_date_range->format(EE_Datetime_Field::mysql_timestamp_format); |
227 | 227 | $where_conditions[] = "{$field_name} > '{$start_date}'"; |
@@ -231,17 +231,17 @@ discard block |
||
231 | 231 | $where_conditions[] = "{$field_name} < '{$end_date}'"; |
232 | 232 | } |
233 | 233 | if ($where_conditions) { |
234 | - $query_to_run .= ' WHERE ' . implode(' AND ', $where_conditions); |
|
234 | + $query_to_run .= ' WHERE '.implode(' AND ', $where_conditions); |
|
235 | 235 | } |
236 | 236 | $result = $wpdb->query($query_to_run); |
237 | 237 | if ($result === false) { |
238 | 238 | // record error. |
239 | 239 | $error_message = $wpdb->last_error; |
240 | 240 | // handle the edgecases where last_error might be empty. |
241 | - if (! $error_message) { |
|
241 | + if ( ! $error_message) { |
|
242 | 242 | $error_message = esc_html__('Unknown mysql error occured.', 'event_espresso'); |
243 | 243 | } |
244 | - $errors[ $field_name ] = $error_message; |
|
244 | + $errors[$field_name] = $error_message; |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | return $errors; |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | private function doQueryForAllFields($query, array $inner_query) |
259 | 259 | { |
260 | 260 | global $wpdb; |
261 | - $query .= ' SET ' . implode(',', $inner_query); |
|
261 | + $query .= ' SET '.implode(',', $inner_query); |
|
262 | 262 | return $wpdb->query($query); |
263 | 263 | } |
264 | 264 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | $fields = array(); |
285 | 285 | /** @var EE_Datetime_Field $model_field */ |
286 | 286 | foreach ($model_fields_affected as $model_field) { |
287 | - if (! $model_field instanceof EE_Datetime_Field) { |
|
287 | + if ( ! $model_field instanceof EE_Datetime_Field) { |
|
288 | 288 | continue; |
289 | 289 | } |
290 | 290 | $fields[] = $model_field->get_name(); |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | private function getModelsWithDatetimeFields() |
337 | 337 | { |
338 | 338 | $this->getModelsToProcess(); |
339 | - if (! empty($this->models_with_datetime_fields)) { |
|
339 | + if ( ! empty($this->models_with_datetime_fields)) { |
|
340 | 340 | return $this->models_with_datetime_fields; |
341 | 341 | } |
342 | 342 | |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | public static function getStartDateRange(): ?DbSafeDateTime |
447 | 447 | { |
448 | 448 | $start_date = get_option(self::OPTION_KEY_OFFSET_RANGE_START_DATE, null); |
449 | - if (! $start_date) { |
|
449 | + if ( ! $start_date) { |
|
450 | 450 | return null; |
451 | 451 | } |
452 | 452 | try { |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | public static function getEndDateRange(): ?DbSafeDateTime |
484 | 484 | { |
485 | 485 | $end_date = get_option(self::OPTION_KEY_OFFSET_RANGE_END_DATE, null); |
486 | - if (! $end_date) { |
|
486 | + if ( ! $end_date) { |
|
487 | 487 | return null; |
488 | 488 | } |
489 | 489 | try { |