@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @since 4.5.0 |
| 8 | 8 | */ |
| 9 | 9 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 10 | - exit('No direct script access allowed'); |
|
| 10 | + exit('No direct script access allowed'); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -21,174 +21,174 @@ discard block |
||
| 21 | 21 | class EE_Register_Capabilities implements EEI_Plugin_API |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Holds the settings for a specific registration. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected static $_registry = array(); |
|
| 24 | + /** |
|
| 25 | + * Holds the settings for a specific registration. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected static $_registry = array(); |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Used to register capability items with EE core. |
|
| 34 | - * |
|
| 35 | - * @since 4.5.0 |
|
| 36 | - * @param string $cap_reference usually will be a class name |
|
| 37 | - * that references capability |
|
| 38 | - * related items setup for |
|
| 39 | - * something. |
|
| 40 | - * @param array $setup_args { |
|
| 41 | - * An array of items related to |
|
| 42 | - * registering capabilities. |
|
| 43 | - * @type array $capabilities An array mapping capability |
|
| 44 | - * strings to core WP Role. Something like: array( |
|
| 45 | - * 'administrator' => array( |
|
| 46 | - * 'read_cap', 'edit_cap', |
|
| 47 | - * 'delete_cap'), |
|
| 48 | - * 'author' => |
|
| 49 | - * array( 'read_cap' ) |
|
| 50 | - * ). |
|
| 51 | - * @type array $capability_maps EE_Meta_Capability_Map[] |
|
| 52 | - * @see EE_Capabilities.php for php docs on these objects. |
|
| 53 | - * Should be indexed by the |
|
| 54 | - * classname for the capability |
|
| 55 | - * map and values representing |
|
| 56 | - * the arguments for the map. |
|
| 57 | - * } |
|
| 58 | - * @throws EE_Error |
|
| 59 | - * @return void |
|
| 60 | - */ |
|
| 61 | - public static function register($cap_reference = null, $setup_args = array()) |
|
| 62 | - { |
|
| 63 | - //required fields MUST be present, so let's make sure they are. |
|
| 64 | - if ($cap_reference === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
| 65 | - throw new EE_Error( |
|
| 66 | - __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
| 67 | - 'event_espresso') |
|
| 68 | - ); |
|
| 69 | - } |
|
| 70 | - //make sure we don't register twice |
|
| 71 | - if (isset(self::$_registry[$cap_reference])) { |
|
| 72 | - return; |
|
| 73 | - } |
|
| 74 | - //make sure this is not registered too late or too early. |
|
| 75 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
| 76 | - EE_Error::doing_it_wrong(__METHOD__, |
|
| 77 | - sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
| 78 | - 'event_espresso'), $cap_reference), '4.5.0'); |
|
| 79 | - } |
|
| 80 | - //some preliminary sanitization and setting to the $_registry property |
|
| 81 | - self::$_registry[ $cap_reference ] = array( |
|
| 82 | - 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
| 83 | - ? $setup_args['capabilities'] |
|
| 84 | - : array(), |
|
| 85 | - 'cap_maps' => isset($setup_args['capability_maps']) |
|
| 86 | - ? $setup_args['capability_maps'] |
|
| 87 | - : array(), |
|
| 88 | - ); |
|
| 89 | - //set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
| 90 | - add_filter( |
|
| 91 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 92 | - array('EE_Register_Capabilities', 'register_capabilities') |
|
| 93 | - ); |
|
| 94 | - //add filter for cap maps |
|
| 95 | - add_filter( |
|
| 96 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 97 | - array('EE_Register_Capabilities', 'register_cap_maps') |
|
| 98 | - ); |
|
| 99 | - } |
|
| 32 | + /** |
|
| 33 | + * Used to register capability items with EE core. |
|
| 34 | + * |
|
| 35 | + * @since 4.5.0 |
|
| 36 | + * @param string $cap_reference usually will be a class name |
|
| 37 | + * that references capability |
|
| 38 | + * related items setup for |
|
| 39 | + * something. |
|
| 40 | + * @param array $setup_args { |
|
| 41 | + * An array of items related to |
|
| 42 | + * registering capabilities. |
|
| 43 | + * @type array $capabilities An array mapping capability |
|
| 44 | + * strings to core WP Role. Something like: array( |
|
| 45 | + * 'administrator' => array( |
|
| 46 | + * 'read_cap', 'edit_cap', |
|
| 47 | + * 'delete_cap'), |
|
| 48 | + * 'author' => |
|
| 49 | + * array( 'read_cap' ) |
|
| 50 | + * ). |
|
| 51 | + * @type array $capability_maps EE_Meta_Capability_Map[] |
|
| 52 | + * @see EE_Capabilities.php for php docs on these objects. |
|
| 53 | + * Should be indexed by the |
|
| 54 | + * classname for the capability |
|
| 55 | + * map and values representing |
|
| 56 | + * the arguments for the map. |
|
| 57 | + * } |
|
| 58 | + * @throws EE_Error |
|
| 59 | + * @return void |
|
| 60 | + */ |
|
| 61 | + public static function register($cap_reference = null, $setup_args = array()) |
|
| 62 | + { |
|
| 63 | + //required fields MUST be present, so let's make sure they are. |
|
| 64 | + if ($cap_reference === null || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
| 65 | + throw new EE_Error( |
|
| 66 | + __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', |
|
| 67 | + 'event_espresso') |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | + //make sure we don't register twice |
|
| 71 | + if (isset(self::$_registry[$cap_reference])) { |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | + //make sure this is not registered too late or too early. |
|
| 75 | + if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
| 76 | + EE_Error::doing_it_wrong(__METHOD__, |
|
| 77 | + sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
|
| 78 | + 'event_espresso'), $cap_reference), '4.5.0'); |
|
| 79 | + } |
|
| 80 | + //some preliminary sanitization and setting to the $_registry property |
|
| 81 | + self::$_registry[ $cap_reference ] = array( |
|
| 82 | + 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
|
| 83 | + ? $setup_args['capabilities'] |
|
| 84 | + : array(), |
|
| 85 | + 'cap_maps' => isset($setup_args['capability_maps']) |
|
| 86 | + ? $setup_args['capability_maps'] |
|
| 87 | + : array(), |
|
| 88 | + ); |
|
| 89 | + //set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
|
| 90 | + add_filter( |
|
| 91 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 92 | + array('EE_Register_Capabilities', 'register_capabilities') |
|
| 93 | + ); |
|
| 94 | + //add filter for cap maps |
|
| 95 | + add_filter( |
|
| 96 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 97 | + array('EE_Register_Capabilities', 'register_cap_maps') |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
| 104 | - * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
| 105 | - * registration ensures that new capabilities are added to existing roles. |
|
| 106 | - * |
|
| 107 | - * @param array $incoming_caps The original caps map. |
|
| 108 | - * @return array merged in new caps. |
|
| 109 | - */ |
|
| 110 | - public static function register_capabilities($incoming_caps) |
|
| 111 | - { |
|
| 112 | - foreach (self::$_registry as $cap_reference => $caps_and_cap_map) { |
|
| 113 | - $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
| 114 | - } |
|
| 115 | - return $incoming_caps; |
|
| 116 | - } |
|
| 102 | + /** |
|
| 103 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter. |
|
| 104 | + * Takes care of registering additional capabilities to the caps map. Note, that this also on the initial |
|
| 105 | + * registration ensures that new capabilities are added to existing roles. |
|
| 106 | + * |
|
| 107 | + * @param array $incoming_caps The original caps map. |
|
| 108 | + * @return array merged in new caps. |
|
| 109 | + */ |
|
| 110 | + public static function register_capabilities($incoming_caps) |
|
| 111 | + { |
|
| 112 | + foreach (self::$_registry as $cap_reference => $caps_and_cap_map) { |
|
| 113 | + $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
| 114 | + } |
|
| 115 | + return $incoming_caps; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
| 121 | - * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
| 122 | - * |
|
| 123 | - * @since 4.5.0 |
|
| 124 | - * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
| 125 | - * @return EE_Meta_Capability_Map[] |
|
| 126 | - * @throws EE_Error |
|
| 127 | - */ |
|
| 128 | - public static function register_cap_maps($cap_maps) |
|
| 129 | - { |
|
| 130 | - //loop through and instantiate cap maps. |
|
| 131 | - foreach (self::$_registry as $cap_reference => $setup) { |
|
| 132 | - if (! isset($setup['cap_maps'])) { |
|
| 133 | - continue; |
|
| 134 | - } |
|
| 135 | - foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
| 119 | + /** |
|
| 120 | + * Callback for the 'FHEE__EE_Capabilities___set_meta_caps__meta_caps' filter which registers an array of |
|
| 121 | + * capability maps for the WP meta_caps filter called in EE_Capabilities. |
|
| 122 | + * |
|
| 123 | + * @since 4.5.0 |
|
| 124 | + * @param EE_Meta_Capability_Map[] $cap_maps The existing cap maps array. |
|
| 125 | + * @return EE_Meta_Capability_Map[] |
|
| 126 | + * @throws EE_Error |
|
| 127 | + */ |
|
| 128 | + public static function register_cap_maps($cap_maps) |
|
| 129 | + { |
|
| 130 | + //loop through and instantiate cap maps. |
|
| 131 | + foreach (self::$_registry as $cap_reference => $setup) { |
|
| 132 | + if (! isset($setup['cap_maps'])) { |
|
| 133 | + continue; |
|
| 134 | + } |
|
| 135 | + foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * account for cases where capability maps may be indexed |
|
| 139 | - * numerically to allow for the same map class to be utilized |
|
| 140 | - * In those cases, maps will be setup in an array like: |
|
| 141 | - * array( |
|
| 142 | - * 0 => array( 'EE_Meta_Capability' => array( |
|
| 143 | - * 'ee_edit_cap', array( 'Object_Name', |
|
| 144 | - * 'ee_edit_published_cap', |
|
| 145 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
| 146 | - * ) ) |
|
| 147 | - * 1 => ... |
|
| 148 | - * ) |
|
| 149 | - * instead of: |
|
| 150 | - * array( |
|
| 151 | - * 'EE_Meta_Capability' => array( |
|
| 152 | - * 'ee_edit_cap', array( 'Object_Name', |
|
| 153 | - * 'ee_edit_published_cap', |
|
| 154 | - * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
| 155 | - * ), |
|
| 156 | - * ... |
|
| 157 | - * ) |
|
| 158 | - */ |
|
| 159 | - if (is_numeric($cap_class)) { |
|
| 160 | - $cap_class = key($args); |
|
| 161 | - $args = $args[$cap_class]; |
|
| 162 | - } |
|
| 137 | + /** |
|
| 138 | + * account for cases where capability maps may be indexed |
|
| 139 | + * numerically to allow for the same map class to be utilized |
|
| 140 | + * In those cases, maps will be setup in an array like: |
|
| 141 | + * array( |
|
| 142 | + * 0 => array( 'EE_Meta_Capability' => array( |
|
| 143 | + * 'ee_edit_cap', array( 'Object_Name', |
|
| 144 | + * 'ee_edit_published_cap', |
|
| 145 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
| 146 | + * ) ) |
|
| 147 | + * 1 => ... |
|
| 148 | + * ) |
|
| 149 | + * instead of: |
|
| 150 | + * array( |
|
| 151 | + * 'EE_Meta_Capability' => array( |
|
| 152 | + * 'ee_edit_cap', array( 'Object_Name', |
|
| 153 | + * 'ee_edit_published_cap', |
|
| 154 | + * 'ee_edit_others_cap', 'ee_edit_private_cap' ) |
|
| 155 | + * ), |
|
| 156 | + * ... |
|
| 157 | + * ) |
|
| 158 | + */ |
|
| 159 | + if (is_numeric($cap_class)) { |
|
| 160 | + $cap_class = key($args); |
|
| 161 | + $args = $args[$cap_class]; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - if (! class_exists($cap_class)) { |
|
| 165 | - throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
| 166 | - 'event_espresso'), $cap_reference)); |
|
| 167 | - } |
|
| 164 | + if (! class_exists($cap_class)) { |
|
| 165 | + throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
|
| 166 | + 'event_espresso'), $cap_reference)); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - if (count($args) !== 2) { |
|
| 170 | - throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
| 171 | - 'event_espresso'), $cap_reference)); |
|
| 172 | - } |
|
| 173 | - $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - return $cap_maps; |
|
| 177 | - } |
|
| 169 | + if (count($args) !== 2) { |
|
| 170 | + throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', |
|
| 171 | + 'event_espresso'), $cap_reference)); |
|
| 172 | + } |
|
| 173 | + $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + return $cap_maps; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * @param string $cap_reference |
|
| 183 | - * @throws EE_Error |
|
| 184 | - */ |
|
| 185 | - public static function deregister($cap_reference = '') |
|
| 186 | - { |
|
| 187 | - if (! empty(self::$_registry[$cap_reference])) { |
|
| 188 | - if (! empty(self::$_registry[ $cap_reference ]['caps'])) { |
|
| 189 | - EE_Capabilities::instance()->removeCaps(self::$_registry[ $cap_reference ]['caps']); |
|
| 190 | - } |
|
| 191 | - unset(self::$_registry[$cap_reference]); |
|
| 192 | - } |
|
| 193 | - } |
|
| 181 | + /** |
|
| 182 | + * @param string $cap_reference |
|
| 183 | + * @throws EE_Error |
|
| 184 | + */ |
|
| 185 | + public static function deregister($cap_reference = '') |
|
| 186 | + { |
|
| 187 | + if (! empty(self::$_registry[$cap_reference])) { |
|
| 188 | + if (! empty(self::$_registry[ $cap_reference ]['caps'])) { |
|
| 189 | + EE_Capabilities::instance()->removeCaps(self::$_registry[ $cap_reference ]['caps']); |
|
| 190 | + } |
|
| 191 | + unset(self::$_registry[$cap_reference]); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | 194 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @subpackage plugin api, capabilities |
| 7 | 7 | * @since 4.5.0 |
| 8 | 8 | */ |
| 9 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | 10 | exit('No direct script access allowed'); |
| 11 | 11 | } |
| 12 | 12 | |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | //make sure this is not registered too late or too early. |
| 75 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
| 75 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
| 76 | 76 | EE_Error::doing_it_wrong(__METHOD__, |
| 77 | 77 | sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', |
| 78 | 78 | 'event_espresso'), $cap_reference), '4.5.0'); |
| 79 | 79 | } |
| 80 | 80 | //some preliminary sanitization and setting to the $_registry property |
| 81 | - self::$_registry[ $cap_reference ] = array( |
|
| 81 | + self::$_registry[$cap_reference] = array( |
|
| 82 | 82 | 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) |
| 83 | 83 | ? $setup_args['capabilities'] |
| 84 | 84 | : array(), |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | { |
| 130 | 130 | //loop through and instantiate cap maps. |
| 131 | 131 | foreach (self::$_registry as $cap_reference => $setup) { |
| 132 | - if (! isset($setup['cap_maps'])) { |
|
| 132 | + if ( ! isset($setup['cap_maps'])) { |
|
| 133 | 133 | continue; |
| 134 | 134 | } |
| 135 | 135 | foreach ($setup['cap_maps'] as $cap_class => $args) { |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | $args = $args[$cap_class]; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if (! class_exists($cap_class)) { |
|
| 164 | + if ( ! class_exists($cap_class)) { |
|
| 165 | 165 | throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', |
| 166 | 166 | 'event_espresso'), $cap_reference)); |
| 167 | 167 | } |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public static function deregister($cap_reference = '') |
| 186 | 186 | { |
| 187 | - if (! empty(self::$_registry[$cap_reference])) { |
|
| 188 | - if (! empty(self::$_registry[ $cap_reference ]['caps'])) { |
|
| 189 | - EE_Capabilities::instance()->removeCaps(self::$_registry[ $cap_reference ]['caps']); |
|
| 187 | + if ( ! empty(self::$_registry[$cap_reference])) { |
|
| 188 | + if ( ! empty(self::$_registry[$cap_reference]['caps'])) { |
|
| 189 | + EE_Capabilities::instance()->removeCaps(self::$_registry[$cap_reference]['caps']); |
|
| 190 | 190 | } |
| 191 | 191 | unset(self::$_registry[$cap_reference]); |
| 192 | 192 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -19,1050 +19,1050 @@ discard block |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * possibly truncated version of the EE core version string |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected static $_core_version = ''; |
|
| 22 | + /** |
|
| 23 | + * possibly truncated version of the EE core version string |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected static $_core_version = ''; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Holds values for registered addons |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected static $_settings = array(); |
|
| 29 | + /** |
|
| 30 | + * Holds values for registered addons |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected static $_settings = array(); |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 38 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 39 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 40 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 41 | - * EE core with knowledge of ALL the addons out there. |
|
| 42 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 43 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 44 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 45 | - * minimum plugin version. |
|
| 46 | - * @access protected |
|
| 47 | - */ |
|
| 48 | - protected static $_incompatible_addons = array( |
|
| 49 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 50 | - 'Promotions' => '1.0.0.rc.084', |
|
| 51 | - ); |
|
| 36 | + /** |
|
| 37 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 38 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 39 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 40 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 41 | + * EE core with knowledge of ALL the addons out there. |
|
| 42 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 43 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 44 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 45 | + * minimum plugin version. |
|
| 46 | + * @access protected |
|
| 47 | + */ |
|
| 48 | + protected static $_incompatible_addons = array( |
|
| 49 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 50 | + 'Promotions' => '1.0.0.rc.084', |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 56 | - * not just '4.3.0'. |
|
| 57 | - * So if the addon developer doesn't provide that full version string, |
|
| 58 | - * fill in the blanks for them |
|
| 59 | - * |
|
| 60 | - * @param string $min_core_version |
|
| 61 | - * @return string always like '4.3.0.rc.000' |
|
| 62 | - */ |
|
| 63 | - protected static function _effective_version($min_core_version) |
|
| 64 | - { |
|
| 65 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 66 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 67 | - $version_parts = explode('.', $min_core_version); |
|
| 68 | - //check they specified the micro version (after 2nd period) |
|
| 69 | - if (! isset($version_parts[2])) { |
|
| 70 | - $version_parts[2] = '0'; |
|
| 71 | - } |
|
| 72 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 73 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 74 | - if (! isset($version_parts[3])) { |
|
| 75 | - $version_parts[3] = 'dev'; |
|
| 76 | - } |
|
| 77 | - if (! isset($version_parts[4])) { |
|
| 78 | - $version_parts[4] = '000'; |
|
| 79 | - } |
|
| 80 | - return implode('.', $version_parts); |
|
| 81 | - } |
|
| 54 | + /** |
|
| 55 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 56 | + * not just '4.3.0'. |
|
| 57 | + * So if the addon developer doesn't provide that full version string, |
|
| 58 | + * fill in the blanks for them |
|
| 59 | + * |
|
| 60 | + * @param string $min_core_version |
|
| 61 | + * @return string always like '4.3.0.rc.000' |
|
| 62 | + */ |
|
| 63 | + protected static function _effective_version($min_core_version) |
|
| 64 | + { |
|
| 65 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 66 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 67 | + $version_parts = explode('.', $min_core_version); |
|
| 68 | + //check they specified the micro version (after 2nd period) |
|
| 69 | + if (! isset($version_parts[2])) { |
|
| 70 | + $version_parts[2] = '0'; |
|
| 71 | + } |
|
| 72 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 73 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 74 | + if (! isset($version_parts[3])) { |
|
| 75 | + $version_parts[3] = 'dev'; |
|
| 76 | + } |
|
| 77 | + if (! isset($version_parts[4])) { |
|
| 78 | + $version_parts[4] = '000'; |
|
| 79 | + } |
|
| 80 | + return implode('.', $version_parts); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 86 | - * |
|
| 87 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 88 | - * @param string $actual_core_version the actual core version, optional |
|
| 89 | - * @return boolean |
|
| 90 | - */ |
|
| 91 | - public static function _meets_min_core_version_requirement( |
|
| 92 | - $min_core_version, |
|
| 93 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 94 | - ) { |
|
| 95 | - return version_compare( |
|
| 96 | - self::_effective_version($actual_core_version), |
|
| 97 | - self::_effective_version($min_core_version), |
|
| 98 | - '>=' |
|
| 99 | - ); |
|
| 100 | - } |
|
| 84 | + /** |
|
| 85 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 86 | + * |
|
| 87 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 88 | + * @param string $actual_core_version the actual core version, optional |
|
| 89 | + * @return boolean |
|
| 90 | + */ |
|
| 91 | + public static function _meets_min_core_version_requirement( |
|
| 92 | + $min_core_version, |
|
| 93 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 94 | + ) { |
|
| 95 | + return version_compare( |
|
| 96 | + self::_effective_version($actual_core_version), |
|
| 97 | + self::_effective_version($min_core_version), |
|
| 98 | + '>=' |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Method for registering new EE_Addons. |
|
| 105 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 106 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 107 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 108 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 109 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 110 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 111 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 112 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 113 | - * |
|
| 114 | - * @since 4.3.0 |
|
| 115 | - * @param string $addon_name the EE_Addon's name. Required. |
|
| 116 | - * @param array $setup_args { An |
|
| 117 | - * array of arguments provided for registering |
|
| 118 | - * the message type. |
|
| 119 | - * @type string $class_name the addon's main file name. |
|
| 120 | - * If left blank, generated from the addon |
|
| 121 | - * name, changes something like "calendar" to |
|
| 122 | - * "EE_Calendar" |
|
| 123 | - * @type string $min_core_version the minimum version of EE Core that the |
|
| 124 | - * addon will work with. eg "4.8.1.rc.084" |
|
| 125 | - * @type string $version the "software" version for the addon. eg |
|
| 126 | - * "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress |
|
| 127 | - * @type string $main_file_path the full server path to the main file |
|
| 128 | - * loaded |
|
| 129 | - * directly by WP |
|
| 130 | - * @type string $admin_path full server path to the folder where the |
|
| 131 | - * addon\'s admin files reside |
|
| 132 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
| 133 | - * first invoked, can be used for hooking into any admin page |
|
| 134 | - * @type string $config_section the section name for this addon's |
|
| 135 | - * configuration settings section (defaults to "addons") |
|
| 136 | - * @type string $config_class the class name for this addon's |
|
| 137 | - * configuration settings object |
|
| 138 | - * @type string $config_name the class name for this addon's |
|
| 139 | - * configuration settings object |
|
| 140 | - * @type string $autoloader_paths an array of class names and the full server |
|
| 141 | - * paths to those files. Required. |
|
| 142 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
| 143 | - * folders containing classes that might be invoked by the addon |
|
| 144 | - * @type string $dms_paths an array of full server paths to folders |
|
| 145 | - * that contain data migration scripts. Required. |
|
| 146 | - * @type string $module_paths an array of full server paths to any |
|
| 147 | - * EED_Modules used by the addon |
|
| 148 | - * @type string $shortcode_paths an array of full server paths to folders |
|
| 149 | - * that contain EES_Shortcodes |
|
| 150 | - * @type string $widget_paths an array of full server paths to folders |
|
| 151 | - * that contain WP_Widgets |
|
| 152 | - * @type string $pue_options |
|
| 153 | - * @type array $capabilities an array indexed by role name |
|
| 154 | - * (i.e administrator,author ) and the values |
|
| 155 | - * are an array of caps to add to the role. |
|
| 156 | - * 'administrator' => array( |
|
| 157 | - * 'read_addon', 'edit_addon', etc. |
|
| 158 | - * ). |
|
| 159 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 160 | - * for any addons that need to register any special meta mapped capabilities. Should be indexed where the |
|
| 161 | - * key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class. |
|
| 162 | - * @type array $model_paths array of folders containing DB models |
|
| 163 | - * @see EE_Register_Model |
|
| 164 | - * @type array $class_paths array of folders containing DB classes |
|
| 165 | - * @see EE_Register_Model |
|
| 166 | - * @type array $model_extension_paths array of folders containing DB model |
|
| 167 | - * extensions |
|
| 168 | - * @see EE_Register_Model_Extension |
|
| 169 | - * @type array $class_extension_paths array of folders containing DB class |
|
| 170 | - * extensions |
|
| 171 | - * @see EE_Register_Model_Extension |
|
| 172 | - * @type array message_types { |
|
| 173 | - * An array of message types with the key as |
|
| 174 | - * the message type name and the values as |
|
| 175 | - * below: |
|
| 176 | - * @type string $mtfilename The filename of the message type being |
|
| 177 | - * registered. This will be the main EE_{Messagetype_Name}_message_type class. |
|
| 178 | - * (eg. |
|
| 179 | - * EE_Declined_Registration_message_type.class.php) |
|
| 180 | - * Required. |
|
| 181 | - * @type array $autoloadpaths An array of paths to add to the messages |
|
| 182 | - * autoloader for the new message type. |
|
| 183 | - * Required. |
|
| 184 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 185 | - * type should activate with. Each value in |
|
| 186 | - * the |
|
| 187 | - * array |
|
| 188 | - * should match the name property of a |
|
| 189 | - * EE_messenger. Optional. |
|
| 190 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 191 | - * type should validate with. Each value in |
|
| 192 | - * the |
|
| 193 | - * array |
|
| 194 | - * should match the name property of an |
|
| 195 | - * EE_messenger. |
|
| 196 | - * Optional. |
|
| 197 | - * } |
|
| 198 | - * @type array $custom_post_types |
|
| 199 | - * @type array $custom_taxonomies |
|
| 200 | - * @type array $payment_method_paths each element is the folder containing the |
|
| 201 | - * EE_PMT_Base child class |
|
| 202 | - * (eg, |
|
| 203 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 204 | - * which contains the files |
|
| 205 | - * EE_PMT_Payomatic.pm.php) |
|
| 206 | - * @type array $default_terms |
|
| 207 | - * @type array $namespace { |
|
| 208 | - * An array with two items for registering the |
|
| 209 | - * addon's namespace. (If, for some reason, |
|
| 210 | - * you |
|
| 211 | - * require additional namespaces, use |
|
| 212 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 213 | - * directly) |
|
| 214 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 215 | - * @type string $FQNS the namespace prefix |
|
| 216 | - * @type string $DIR a base directory for class files in the |
|
| 217 | - * namespace. |
|
| 218 | - * } |
|
| 219 | - * } |
|
| 220 | - * @throws EE_Error |
|
| 221 | - * @return void |
|
| 222 | - */ |
|
| 223 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 224 | - { |
|
| 225 | - // required fields MUST be present, so let's make sure they are. |
|
| 226 | - \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 227 | - // get class name for addon |
|
| 228 | - $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 229 | - //setup $_settings array from incoming values. |
|
| 230 | - $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 231 | - // setup PUE |
|
| 232 | - \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 233 | - // does this addon work with this version of core or WordPress ? |
|
| 234 | - if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 235 | - return; |
|
| 236 | - } |
|
| 237 | - // register namespaces |
|
| 238 | - \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 239 | - // check if this is an activation request |
|
| 240 | - if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 241 | - // dont bother setting up the rest of the addon atm |
|
| 242 | - return; |
|
| 243 | - } |
|
| 244 | - // we need cars |
|
| 245 | - \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 246 | - // register new models and extensions |
|
| 247 | - \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 248 | - // setup DMS |
|
| 249 | - \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 250 | - // if config_class is present let's register config. |
|
| 251 | - \EE_Register_Addon::_register_config($addon_name); |
|
| 252 | - // register admin pages |
|
| 253 | - \EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 254 | - // add to list of modules to be registered |
|
| 255 | - \EE_Register_Addon::_register_modules($addon_name); |
|
| 256 | - // add to list of shortcodes to be registered |
|
| 257 | - \EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 258 | - // add to list of widgets to be registered |
|
| 259 | - \EE_Register_Addon::_register_widgets($addon_name); |
|
| 260 | - // register capability related stuff. |
|
| 261 | - \EE_Register_Addon::_register_capabilities($addon_name); |
|
| 262 | - // any message type to register? |
|
| 263 | - \EE_Register_Addon::_register_message_types($addon_name); |
|
| 264 | - // any custom post type/ custom capabilities or default terms to register |
|
| 265 | - \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 266 | - // and any payment methods |
|
| 267 | - \EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 268 | - // load and instantiate main addon class |
|
| 269 | - $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 270 | - $addon->after_registration(); |
|
| 271 | - } |
|
| 103 | + /** |
|
| 104 | + * Method for registering new EE_Addons. |
|
| 105 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 106 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 107 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 108 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 109 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 110 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 111 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 112 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 113 | + * |
|
| 114 | + * @since 4.3.0 |
|
| 115 | + * @param string $addon_name the EE_Addon's name. Required. |
|
| 116 | + * @param array $setup_args { An |
|
| 117 | + * array of arguments provided for registering |
|
| 118 | + * the message type. |
|
| 119 | + * @type string $class_name the addon's main file name. |
|
| 120 | + * If left blank, generated from the addon |
|
| 121 | + * name, changes something like "calendar" to |
|
| 122 | + * "EE_Calendar" |
|
| 123 | + * @type string $min_core_version the minimum version of EE Core that the |
|
| 124 | + * addon will work with. eg "4.8.1.rc.084" |
|
| 125 | + * @type string $version the "software" version for the addon. eg |
|
| 126 | + * "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress |
|
| 127 | + * @type string $main_file_path the full server path to the main file |
|
| 128 | + * loaded |
|
| 129 | + * directly by WP |
|
| 130 | + * @type string $admin_path full server path to the folder where the |
|
| 131 | + * addon\'s admin files reside |
|
| 132 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
| 133 | + * first invoked, can be used for hooking into any admin page |
|
| 134 | + * @type string $config_section the section name for this addon's |
|
| 135 | + * configuration settings section (defaults to "addons") |
|
| 136 | + * @type string $config_class the class name for this addon's |
|
| 137 | + * configuration settings object |
|
| 138 | + * @type string $config_name the class name for this addon's |
|
| 139 | + * configuration settings object |
|
| 140 | + * @type string $autoloader_paths an array of class names and the full server |
|
| 141 | + * paths to those files. Required. |
|
| 142 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
| 143 | + * folders containing classes that might be invoked by the addon |
|
| 144 | + * @type string $dms_paths an array of full server paths to folders |
|
| 145 | + * that contain data migration scripts. Required. |
|
| 146 | + * @type string $module_paths an array of full server paths to any |
|
| 147 | + * EED_Modules used by the addon |
|
| 148 | + * @type string $shortcode_paths an array of full server paths to folders |
|
| 149 | + * that contain EES_Shortcodes |
|
| 150 | + * @type string $widget_paths an array of full server paths to folders |
|
| 151 | + * that contain WP_Widgets |
|
| 152 | + * @type string $pue_options |
|
| 153 | + * @type array $capabilities an array indexed by role name |
|
| 154 | + * (i.e administrator,author ) and the values |
|
| 155 | + * are an array of caps to add to the role. |
|
| 156 | + * 'administrator' => array( |
|
| 157 | + * 'read_addon', 'edit_addon', etc. |
|
| 158 | + * ). |
|
| 159 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 160 | + * for any addons that need to register any special meta mapped capabilities. Should be indexed where the |
|
| 161 | + * key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class. |
|
| 162 | + * @type array $model_paths array of folders containing DB models |
|
| 163 | + * @see EE_Register_Model |
|
| 164 | + * @type array $class_paths array of folders containing DB classes |
|
| 165 | + * @see EE_Register_Model |
|
| 166 | + * @type array $model_extension_paths array of folders containing DB model |
|
| 167 | + * extensions |
|
| 168 | + * @see EE_Register_Model_Extension |
|
| 169 | + * @type array $class_extension_paths array of folders containing DB class |
|
| 170 | + * extensions |
|
| 171 | + * @see EE_Register_Model_Extension |
|
| 172 | + * @type array message_types { |
|
| 173 | + * An array of message types with the key as |
|
| 174 | + * the message type name and the values as |
|
| 175 | + * below: |
|
| 176 | + * @type string $mtfilename The filename of the message type being |
|
| 177 | + * registered. This will be the main EE_{Messagetype_Name}_message_type class. |
|
| 178 | + * (eg. |
|
| 179 | + * EE_Declined_Registration_message_type.class.php) |
|
| 180 | + * Required. |
|
| 181 | + * @type array $autoloadpaths An array of paths to add to the messages |
|
| 182 | + * autoloader for the new message type. |
|
| 183 | + * Required. |
|
| 184 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 185 | + * type should activate with. Each value in |
|
| 186 | + * the |
|
| 187 | + * array |
|
| 188 | + * should match the name property of a |
|
| 189 | + * EE_messenger. Optional. |
|
| 190 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 191 | + * type should validate with. Each value in |
|
| 192 | + * the |
|
| 193 | + * array |
|
| 194 | + * should match the name property of an |
|
| 195 | + * EE_messenger. |
|
| 196 | + * Optional. |
|
| 197 | + * } |
|
| 198 | + * @type array $custom_post_types |
|
| 199 | + * @type array $custom_taxonomies |
|
| 200 | + * @type array $payment_method_paths each element is the folder containing the |
|
| 201 | + * EE_PMT_Base child class |
|
| 202 | + * (eg, |
|
| 203 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 204 | + * which contains the files |
|
| 205 | + * EE_PMT_Payomatic.pm.php) |
|
| 206 | + * @type array $default_terms |
|
| 207 | + * @type array $namespace { |
|
| 208 | + * An array with two items for registering the |
|
| 209 | + * addon's namespace. (If, for some reason, |
|
| 210 | + * you |
|
| 211 | + * require additional namespaces, use |
|
| 212 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 213 | + * directly) |
|
| 214 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 215 | + * @type string $FQNS the namespace prefix |
|
| 216 | + * @type string $DIR a base directory for class files in the |
|
| 217 | + * namespace. |
|
| 218 | + * } |
|
| 219 | + * } |
|
| 220 | + * @throws EE_Error |
|
| 221 | + * @return void |
|
| 222 | + */ |
|
| 223 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 224 | + { |
|
| 225 | + // required fields MUST be present, so let's make sure they are. |
|
| 226 | + \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 227 | + // get class name for addon |
|
| 228 | + $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 229 | + //setup $_settings array from incoming values. |
|
| 230 | + $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 231 | + // setup PUE |
|
| 232 | + \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 233 | + // does this addon work with this version of core or WordPress ? |
|
| 234 | + if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 235 | + return; |
|
| 236 | + } |
|
| 237 | + // register namespaces |
|
| 238 | + \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 239 | + // check if this is an activation request |
|
| 240 | + if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 241 | + // dont bother setting up the rest of the addon atm |
|
| 242 | + return; |
|
| 243 | + } |
|
| 244 | + // we need cars |
|
| 245 | + \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 246 | + // register new models and extensions |
|
| 247 | + \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 248 | + // setup DMS |
|
| 249 | + \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 250 | + // if config_class is present let's register config. |
|
| 251 | + \EE_Register_Addon::_register_config($addon_name); |
|
| 252 | + // register admin pages |
|
| 253 | + \EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 254 | + // add to list of modules to be registered |
|
| 255 | + \EE_Register_Addon::_register_modules($addon_name); |
|
| 256 | + // add to list of shortcodes to be registered |
|
| 257 | + \EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 258 | + // add to list of widgets to be registered |
|
| 259 | + \EE_Register_Addon::_register_widgets($addon_name); |
|
| 260 | + // register capability related stuff. |
|
| 261 | + \EE_Register_Addon::_register_capabilities($addon_name); |
|
| 262 | + // any message type to register? |
|
| 263 | + \EE_Register_Addon::_register_message_types($addon_name); |
|
| 264 | + // any custom post type/ custom capabilities or default terms to register |
|
| 265 | + \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 266 | + // and any payment methods |
|
| 267 | + \EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 268 | + // load and instantiate main addon class |
|
| 269 | + $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 270 | + $addon->after_registration(); |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * @param string $addon_name |
|
| 276 | - * @param array $setup_args |
|
| 277 | - * @return void |
|
| 278 | - * @throws \EE_Error |
|
| 279 | - */ |
|
| 280 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 281 | - { |
|
| 282 | - // required fields MUST be present, so let's make sure they are. |
|
| 283 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 284 | - throw new EE_Error( |
|
| 285 | - __( |
|
| 286 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 287 | - 'event_espresso' |
|
| 288 | - ) |
|
| 289 | - ); |
|
| 290 | - } |
|
| 291 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 292 | - throw new EE_Error( |
|
| 293 | - sprintf( |
|
| 294 | - __( |
|
| 295 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 296 | - 'event_espresso' |
|
| 297 | - ), |
|
| 298 | - implode(',', array_keys($setup_args)) |
|
| 299 | - ) |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - // check that addon has not already been registered with that name |
|
| 303 | - if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 304 | - throw new EE_Error( |
|
| 305 | - sprintf( |
|
| 306 | - __( |
|
| 307 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 308 | - 'event_espresso' |
|
| 309 | - ), |
|
| 310 | - $addon_name |
|
| 311 | - ) |
|
| 312 | - ); |
|
| 313 | - } |
|
| 314 | - } |
|
| 274 | + /** |
|
| 275 | + * @param string $addon_name |
|
| 276 | + * @param array $setup_args |
|
| 277 | + * @return void |
|
| 278 | + * @throws \EE_Error |
|
| 279 | + */ |
|
| 280 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 281 | + { |
|
| 282 | + // required fields MUST be present, so let's make sure they are. |
|
| 283 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 284 | + throw new EE_Error( |
|
| 285 | + __( |
|
| 286 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 287 | + 'event_espresso' |
|
| 288 | + ) |
|
| 289 | + ); |
|
| 290 | + } |
|
| 291 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 292 | + throw new EE_Error( |
|
| 293 | + sprintf( |
|
| 294 | + __( |
|
| 295 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 296 | + 'event_espresso' |
|
| 297 | + ), |
|
| 298 | + implode(',', array_keys($setup_args)) |
|
| 299 | + ) |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + // check that addon has not already been registered with that name |
|
| 303 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 304 | + throw new EE_Error( |
|
| 305 | + sprintf( |
|
| 306 | + __( |
|
| 307 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 308 | + 'event_espresso' |
|
| 309 | + ), |
|
| 310 | + $addon_name |
|
| 311 | + ) |
|
| 312 | + ); |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | |
| 317 | - /** |
|
| 318 | - * @param string $addon_name |
|
| 319 | - * @param array $setup_args |
|
| 320 | - * @return string |
|
| 321 | - */ |
|
| 322 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 323 | - { |
|
| 324 | - if (empty($setup_args['class_name'])) { |
|
| 325 | - // generate one by first separating name with spaces |
|
| 326 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 327 | - //capitalize, then replace spaces with underscores |
|
| 328 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 329 | - } else { |
|
| 330 | - $class_name = $setup_args['class_name']; |
|
| 331 | - } |
|
| 332 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
| 333 | - } |
|
| 317 | + /** |
|
| 318 | + * @param string $addon_name |
|
| 319 | + * @param array $setup_args |
|
| 320 | + * @return string |
|
| 321 | + */ |
|
| 322 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 323 | + { |
|
| 324 | + if (empty($setup_args['class_name'])) { |
|
| 325 | + // generate one by first separating name with spaces |
|
| 326 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 327 | + //capitalize, then replace spaces with underscores |
|
| 328 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 329 | + } else { |
|
| 330 | + $class_name = $setup_args['class_name']; |
|
| 331 | + } |
|
| 332 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * @param string $class_name |
|
| 338 | - * @param array $setup_args |
|
| 339 | - * @return array |
|
| 340 | - */ |
|
| 341 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 342 | - { |
|
| 343 | - //setup $_settings array from incoming values. |
|
| 344 | - $addon_settings = array( |
|
| 345 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 346 | - 'class_name' => $class_name, |
|
| 347 | - // the addon slug for use in URLs, etc |
|
| 348 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 349 | - ? (string)$setup_args['plugin_slug'] |
|
| 350 | - : '', |
|
| 351 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 352 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 353 | - ? (string)$setup_args['plugin_action_slug'] |
|
| 354 | - : '', |
|
| 355 | - // the "software" version for the addon |
|
| 356 | - 'version' => isset($setup_args['version']) |
|
| 357 | - ? (string)$setup_args['version'] |
|
| 358 | - : '', |
|
| 359 | - // the minimum version of EE Core that the addon will work with |
|
| 360 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 361 | - ? (string)$setup_args['min_core_version'] |
|
| 362 | - : '', |
|
| 363 | - // the minimum version of WordPress that the addon will work with |
|
| 364 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 365 | - ? (string)$setup_args['min_wp_version'] |
|
| 366 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 367 | - // full server path to main file (file loaded directly by WP) |
|
| 368 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 369 | - ? (string)$setup_args['main_file_path'] |
|
| 370 | - : '', |
|
| 371 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 372 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 373 | - ? (string)$setup_args['admin_path'] : '', |
|
| 374 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 375 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 376 | - ? (string)$setup_args['admin_callback'] |
|
| 377 | - : '', |
|
| 378 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 379 | - 'config_section' => isset($setup_args['config_section']) |
|
| 380 | - ? (string)$setup_args['config_section'] |
|
| 381 | - : 'addons', |
|
| 382 | - // the class name for this addon's configuration settings object |
|
| 383 | - 'config_class' => isset($setup_args['config_class']) |
|
| 384 | - ? (string)$setup_args['config_class'] : '', |
|
| 385 | - //the name given to the config for this addons' configuration settings object (optional) |
|
| 386 | - 'config_name' => isset($setup_args['config_name']) |
|
| 387 | - ? (string)$setup_args['config_name'] : '', |
|
| 388 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 389 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 390 | - ? (array)$setup_args['autoloader_paths'] |
|
| 391 | - : array(), |
|
| 392 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 393 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 394 | - ? (array)$setup_args['autoloader_folders'] |
|
| 395 | - : array(), |
|
| 396 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 397 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 398 | - ? (array)$setup_args['dms_paths'] |
|
| 399 | - : array(), |
|
| 400 | - // array of full server paths to any EED_Modules used by the addon |
|
| 401 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 402 | - ? (array)$setup_args['module_paths'] |
|
| 403 | - : array(), |
|
| 404 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 405 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 406 | - ? (array)$setup_args['shortcode_paths'] |
|
| 407 | - : array(), |
|
| 408 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 409 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 410 | - ? (array)$setup_args['widget_paths'] |
|
| 411 | - : array(), |
|
| 412 | - // array of PUE options used by the addon |
|
| 413 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 414 | - ? (array)$setup_args['pue_options'] |
|
| 415 | - : array(), |
|
| 416 | - 'message_types' => isset($setup_args['message_types']) |
|
| 417 | - ? (array)$setup_args['message_types'] |
|
| 418 | - : array(), |
|
| 419 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 420 | - ? (array)$setup_args['capabilities'] |
|
| 421 | - : array(), |
|
| 422 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 423 | - ? (array)$setup_args['capability_maps'] |
|
| 424 | - : array(), |
|
| 425 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 426 | - ? (array)$setup_args['model_paths'] |
|
| 427 | - : array(), |
|
| 428 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 429 | - ? (array)$setup_args['class_paths'] |
|
| 430 | - : array(), |
|
| 431 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 432 | - ? (array)$setup_args['model_extension_paths'] |
|
| 433 | - : array(), |
|
| 434 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 435 | - ? (array)$setup_args['class_extension_paths'] |
|
| 436 | - : array(), |
|
| 437 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 438 | - ? (array)$setup_args['custom_post_types'] |
|
| 439 | - : array(), |
|
| 440 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 441 | - ? (array)$setup_args['custom_taxonomies'] |
|
| 442 | - : array(), |
|
| 443 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 444 | - ? (array)$setup_args['payment_method_paths'] |
|
| 445 | - : array(), |
|
| 446 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 447 | - ? (array)$setup_args['default_terms'] |
|
| 448 | - : array(), |
|
| 449 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 450 | - // that can be used for adding upgrading/marketing info |
|
| 451 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 452 | - ? $setup_args['plugins_page_row'] |
|
| 453 | - : '', |
|
| 454 | - 'namespace' => isset( |
|
| 455 | - $setup_args['namespace'], |
|
| 456 | - $setup_args['namespace']['FQNS'], |
|
| 457 | - $setup_args['namespace']['DIR'] |
|
| 458 | - ) |
|
| 459 | - ? (array)$setup_args['namespace'] |
|
| 460 | - : array(), |
|
| 461 | - ); |
|
| 462 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 463 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 464 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 465 | - && ! empty($addon_settings['admin_path']) |
|
| 466 | - ? $addon_settings['plugin_slug'] |
|
| 467 | - : $addon_settings['plugin_action_slug']; |
|
| 468 | - // full server path to main file (file loaded directly by WP) |
|
| 469 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 470 | - return $addon_settings; |
|
| 471 | - } |
|
| 336 | + /** |
|
| 337 | + * @param string $class_name |
|
| 338 | + * @param array $setup_args |
|
| 339 | + * @return array |
|
| 340 | + */ |
|
| 341 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 342 | + { |
|
| 343 | + //setup $_settings array from incoming values. |
|
| 344 | + $addon_settings = array( |
|
| 345 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 346 | + 'class_name' => $class_name, |
|
| 347 | + // the addon slug for use in URLs, etc |
|
| 348 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 349 | + ? (string)$setup_args['plugin_slug'] |
|
| 350 | + : '', |
|
| 351 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 352 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 353 | + ? (string)$setup_args['plugin_action_slug'] |
|
| 354 | + : '', |
|
| 355 | + // the "software" version for the addon |
|
| 356 | + 'version' => isset($setup_args['version']) |
|
| 357 | + ? (string)$setup_args['version'] |
|
| 358 | + : '', |
|
| 359 | + // the minimum version of EE Core that the addon will work with |
|
| 360 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 361 | + ? (string)$setup_args['min_core_version'] |
|
| 362 | + : '', |
|
| 363 | + // the minimum version of WordPress that the addon will work with |
|
| 364 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 365 | + ? (string)$setup_args['min_wp_version'] |
|
| 366 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 367 | + // full server path to main file (file loaded directly by WP) |
|
| 368 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 369 | + ? (string)$setup_args['main_file_path'] |
|
| 370 | + : '', |
|
| 371 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 372 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 373 | + ? (string)$setup_args['admin_path'] : '', |
|
| 374 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 375 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 376 | + ? (string)$setup_args['admin_callback'] |
|
| 377 | + : '', |
|
| 378 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 379 | + 'config_section' => isset($setup_args['config_section']) |
|
| 380 | + ? (string)$setup_args['config_section'] |
|
| 381 | + : 'addons', |
|
| 382 | + // the class name for this addon's configuration settings object |
|
| 383 | + 'config_class' => isset($setup_args['config_class']) |
|
| 384 | + ? (string)$setup_args['config_class'] : '', |
|
| 385 | + //the name given to the config for this addons' configuration settings object (optional) |
|
| 386 | + 'config_name' => isset($setup_args['config_name']) |
|
| 387 | + ? (string)$setup_args['config_name'] : '', |
|
| 388 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 389 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 390 | + ? (array)$setup_args['autoloader_paths'] |
|
| 391 | + : array(), |
|
| 392 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 393 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 394 | + ? (array)$setup_args['autoloader_folders'] |
|
| 395 | + : array(), |
|
| 396 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 397 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 398 | + ? (array)$setup_args['dms_paths'] |
|
| 399 | + : array(), |
|
| 400 | + // array of full server paths to any EED_Modules used by the addon |
|
| 401 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 402 | + ? (array)$setup_args['module_paths'] |
|
| 403 | + : array(), |
|
| 404 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 405 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 406 | + ? (array)$setup_args['shortcode_paths'] |
|
| 407 | + : array(), |
|
| 408 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 409 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 410 | + ? (array)$setup_args['widget_paths'] |
|
| 411 | + : array(), |
|
| 412 | + // array of PUE options used by the addon |
|
| 413 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 414 | + ? (array)$setup_args['pue_options'] |
|
| 415 | + : array(), |
|
| 416 | + 'message_types' => isset($setup_args['message_types']) |
|
| 417 | + ? (array)$setup_args['message_types'] |
|
| 418 | + : array(), |
|
| 419 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 420 | + ? (array)$setup_args['capabilities'] |
|
| 421 | + : array(), |
|
| 422 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 423 | + ? (array)$setup_args['capability_maps'] |
|
| 424 | + : array(), |
|
| 425 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 426 | + ? (array)$setup_args['model_paths'] |
|
| 427 | + : array(), |
|
| 428 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 429 | + ? (array)$setup_args['class_paths'] |
|
| 430 | + : array(), |
|
| 431 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 432 | + ? (array)$setup_args['model_extension_paths'] |
|
| 433 | + : array(), |
|
| 434 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 435 | + ? (array)$setup_args['class_extension_paths'] |
|
| 436 | + : array(), |
|
| 437 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 438 | + ? (array)$setup_args['custom_post_types'] |
|
| 439 | + : array(), |
|
| 440 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 441 | + ? (array)$setup_args['custom_taxonomies'] |
|
| 442 | + : array(), |
|
| 443 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 444 | + ? (array)$setup_args['payment_method_paths'] |
|
| 445 | + : array(), |
|
| 446 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 447 | + ? (array)$setup_args['default_terms'] |
|
| 448 | + : array(), |
|
| 449 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 450 | + // that can be used for adding upgrading/marketing info |
|
| 451 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 452 | + ? $setup_args['plugins_page_row'] |
|
| 453 | + : '', |
|
| 454 | + 'namespace' => isset( |
|
| 455 | + $setup_args['namespace'], |
|
| 456 | + $setup_args['namespace']['FQNS'], |
|
| 457 | + $setup_args['namespace']['DIR'] |
|
| 458 | + ) |
|
| 459 | + ? (array)$setup_args['namespace'] |
|
| 460 | + : array(), |
|
| 461 | + ); |
|
| 462 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 463 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 464 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 465 | + && ! empty($addon_settings['admin_path']) |
|
| 466 | + ? $addon_settings['plugin_slug'] |
|
| 467 | + : $addon_settings['plugin_action_slug']; |
|
| 468 | + // full server path to main file (file loaded directly by WP) |
|
| 469 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 470 | + return $addon_settings; |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | 473 | |
| 474 | - /** |
|
| 475 | - * @param string $addon_name |
|
| 476 | - * @param array $addon_settings |
|
| 477 | - * @return boolean |
|
| 478 | - */ |
|
| 479 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 480 | - { |
|
| 481 | - global $wp_version; |
|
| 482 | - $incompatibility_message = ''; |
|
| 483 | - //check whether this addon version is compatible with EE core |
|
| 484 | - if ( |
|
| 485 | - isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 486 | - && ! self::_meets_min_core_version_requirement( |
|
| 487 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 488 | - $addon_settings['version'] |
|
| 489 | - ) |
|
| 490 | - ) { |
|
| 491 | - $incompatibility_message = sprintf( |
|
| 492 | - __( |
|
| 493 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 494 | - ), |
|
| 495 | - $addon_name, |
|
| 496 | - '<br />', |
|
| 497 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 498 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 499 | - '</span><br />' |
|
| 500 | - ); |
|
| 501 | - } else if ( |
|
| 502 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 503 | - ) { |
|
| 504 | - $incompatibility_message = sprintf( |
|
| 505 | - __( |
|
| 506 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 507 | - 'event_espresso' |
|
| 508 | - ), |
|
| 509 | - $addon_name, |
|
| 510 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 511 | - self::_effective_version(espresso_version()), |
|
| 512 | - '<br />', |
|
| 513 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 514 | - '</span><br />' |
|
| 515 | - ); |
|
| 516 | - } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 517 | - $incompatibility_message = sprintf( |
|
| 518 | - __( |
|
| 519 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 520 | - 'event_espresso' |
|
| 521 | - ), |
|
| 522 | - $addon_name, |
|
| 523 | - $addon_settings['min_wp_version'], |
|
| 524 | - '<br />', |
|
| 525 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 526 | - '</span><br />' |
|
| 527 | - ); |
|
| 528 | - } |
|
| 529 | - if (! empty($incompatibility_message)) { |
|
| 530 | - // remove 'activate' from the REQUEST |
|
| 531 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 532 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 533 | - if (current_user_can('activate_plugins')) { |
|
| 534 | - // show an error message indicating the plugin didn't activate properly |
|
| 535 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 536 | - } |
|
| 537 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 538 | - return false; |
|
| 539 | - } |
|
| 540 | - // addon IS compatible |
|
| 541 | - return true; |
|
| 542 | - } |
|
| 474 | + /** |
|
| 475 | + * @param string $addon_name |
|
| 476 | + * @param array $addon_settings |
|
| 477 | + * @return boolean |
|
| 478 | + */ |
|
| 479 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 480 | + { |
|
| 481 | + global $wp_version; |
|
| 482 | + $incompatibility_message = ''; |
|
| 483 | + //check whether this addon version is compatible with EE core |
|
| 484 | + if ( |
|
| 485 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 486 | + && ! self::_meets_min_core_version_requirement( |
|
| 487 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 488 | + $addon_settings['version'] |
|
| 489 | + ) |
|
| 490 | + ) { |
|
| 491 | + $incompatibility_message = sprintf( |
|
| 492 | + __( |
|
| 493 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 494 | + ), |
|
| 495 | + $addon_name, |
|
| 496 | + '<br />', |
|
| 497 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 498 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 499 | + '</span><br />' |
|
| 500 | + ); |
|
| 501 | + } else if ( |
|
| 502 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 503 | + ) { |
|
| 504 | + $incompatibility_message = sprintf( |
|
| 505 | + __( |
|
| 506 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 507 | + 'event_espresso' |
|
| 508 | + ), |
|
| 509 | + $addon_name, |
|
| 510 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 511 | + self::_effective_version(espresso_version()), |
|
| 512 | + '<br />', |
|
| 513 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 514 | + '</span><br />' |
|
| 515 | + ); |
|
| 516 | + } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 517 | + $incompatibility_message = sprintf( |
|
| 518 | + __( |
|
| 519 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 520 | + 'event_espresso' |
|
| 521 | + ), |
|
| 522 | + $addon_name, |
|
| 523 | + $addon_settings['min_wp_version'], |
|
| 524 | + '<br />', |
|
| 525 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 526 | + '</span><br />' |
|
| 527 | + ); |
|
| 528 | + } |
|
| 529 | + if (! empty($incompatibility_message)) { |
|
| 530 | + // remove 'activate' from the REQUEST |
|
| 531 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 532 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 533 | + if (current_user_can('activate_plugins')) { |
|
| 534 | + // show an error message indicating the plugin didn't activate properly |
|
| 535 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 536 | + } |
|
| 537 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 538 | + return false; |
|
| 539 | + } |
|
| 540 | + // addon IS compatible |
|
| 541 | + return true; |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | 544 | |
| 545 | - /** |
|
| 546 | - * if plugin update engine is being used for auto-updates, |
|
| 547 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 548 | - * (not needed if PUE is not being used) |
|
| 549 | - * |
|
| 550 | - * @param string $addon_name |
|
| 551 | - * @param string $class_name |
|
| 552 | - * @param array $setup_args |
|
| 553 | - * @return void |
|
| 554 | - */ |
|
| 555 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 556 | - { |
|
| 557 | - if (! empty($setup_args['pue_options'])) { |
|
| 558 | - self::$_settings[$addon_name]['pue_options'] = array( |
|
| 559 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 560 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 561 | - : 'espresso_' . strtolower($class_name), |
|
| 562 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 563 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 564 | - : plugin_basename($setup_args['main_file_path']), |
|
| 565 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 566 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 567 | - : '24', |
|
| 568 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 569 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 570 | - : false, |
|
| 571 | - ); |
|
| 572 | - add_action( |
|
| 573 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 574 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 575 | - ); |
|
| 576 | - } |
|
| 577 | - } |
|
| 545 | + /** |
|
| 546 | + * if plugin update engine is being used for auto-updates, |
|
| 547 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 548 | + * (not needed if PUE is not being used) |
|
| 549 | + * |
|
| 550 | + * @param string $addon_name |
|
| 551 | + * @param string $class_name |
|
| 552 | + * @param array $setup_args |
|
| 553 | + * @return void |
|
| 554 | + */ |
|
| 555 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 556 | + { |
|
| 557 | + if (! empty($setup_args['pue_options'])) { |
|
| 558 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 559 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 560 | + ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 561 | + : 'espresso_' . strtolower($class_name), |
|
| 562 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 563 | + ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 564 | + : plugin_basename($setup_args['main_file_path']), |
|
| 565 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 566 | + ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 567 | + : '24', |
|
| 568 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 569 | + ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 570 | + : false, |
|
| 571 | + ); |
|
| 572 | + add_action( |
|
| 573 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 574 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 575 | + ); |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | 578 | |
| 579 | 579 | |
| 580 | - /** |
|
| 581 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 582 | - * |
|
| 583 | - * @param array $addon_settings |
|
| 584 | - * @return void |
|
| 585 | - */ |
|
| 586 | - private static function _setup_namespaces(array $addon_settings) |
|
| 587 | - { |
|
| 588 | - // |
|
| 589 | - if ( |
|
| 590 | - isset( |
|
| 591 | - $addon_settings['namespace'], |
|
| 592 | - $addon_settings['namespace']['FQNS'], |
|
| 593 | - $addon_settings['namespace']['DIR'] |
|
| 594 | - ) |
|
| 595 | - ) { |
|
| 596 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 597 | - $addon_settings['namespace']['FQNS'], |
|
| 598 | - $addon_settings['namespace']['DIR'] |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - } |
|
| 580 | + /** |
|
| 581 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 582 | + * |
|
| 583 | + * @param array $addon_settings |
|
| 584 | + * @return void |
|
| 585 | + */ |
|
| 586 | + private static function _setup_namespaces(array $addon_settings) |
|
| 587 | + { |
|
| 588 | + // |
|
| 589 | + if ( |
|
| 590 | + isset( |
|
| 591 | + $addon_settings['namespace'], |
|
| 592 | + $addon_settings['namespace']['FQNS'], |
|
| 593 | + $addon_settings['namespace']['DIR'] |
|
| 594 | + ) |
|
| 595 | + ) { |
|
| 596 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 597 | + $addon_settings['namespace']['FQNS'], |
|
| 598 | + $addon_settings['namespace']['DIR'] |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | 602 | |
| 603 | 603 | |
| 604 | - /** |
|
| 605 | - * @param string $addon_name |
|
| 606 | - * @param array $addon_settings |
|
| 607 | - * @return bool |
|
| 608 | - */ |
|
| 609 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
| 610 | - { |
|
| 611 | - // this is an activation request |
|
| 612 | - if (did_action('activate_plugin')) { |
|
| 613 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 614 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 615 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 616 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 617 | - if (! isset(self::$_settings[$addon_name]) |
|
| 618 | - || (isset(self::$_settings[$addon_name]) |
|
| 619 | - && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 620 | - ) |
|
| 621 | - ) { |
|
| 622 | - self::$_settings[$addon_name] = $addon_settings; |
|
| 623 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 624 | - $addon->set_activation_indicator_option(); |
|
| 625 | - // dont bother setting up the rest of the addon. |
|
| 626 | - // we know it was just activated and the request will end soon |
|
| 627 | - } |
|
| 628 | - return true; |
|
| 629 | - } |
|
| 630 | - // make sure this was called in the right place! |
|
| 631 | - if ( |
|
| 632 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 633 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 634 | - ) { |
|
| 635 | - EE_Error::doing_it_wrong( |
|
| 636 | - __METHOD__, |
|
| 637 | - sprintf( |
|
| 638 | - __( |
|
| 639 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 640 | - 'event_espresso' |
|
| 641 | - ), |
|
| 642 | - $addon_name |
|
| 643 | - ), |
|
| 644 | - '4.3.0' |
|
| 645 | - ); |
|
| 646 | - } |
|
| 647 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 648 | - if (isset(self::$_settings[$addon_name])) { |
|
| 649 | - self::$_settings[$addon_name] += $addon_settings; |
|
| 650 | - } else { |
|
| 651 | - self::$_settings[$addon_name] = $addon_settings; |
|
| 652 | - } |
|
| 653 | - return false; |
|
| 654 | - } |
|
| 604 | + /** |
|
| 605 | + * @param string $addon_name |
|
| 606 | + * @param array $addon_settings |
|
| 607 | + * @return bool |
|
| 608 | + */ |
|
| 609 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
| 610 | + { |
|
| 611 | + // this is an activation request |
|
| 612 | + if (did_action('activate_plugin')) { |
|
| 613 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 614 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 615 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 616 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 617 | + if (! isset(self::$_settings[$addon_name]) |
|
| 618 | + || (isset(self::$_settings[$addon_name]) |
|
| 619 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 620 | + ) |
|
| 621 | + ) { |
|
| 622 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 623 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 624 | + $addon->set_activation_indicator_option(); |
|
| 625 | + // dont bother setting up the rest of the addon. |
|
| 626 | + // we know it was just activated and the request will end soon |
|
| 627 | + } |
|
| 628 | + return true; |
|
| 629 | + } |
|
| 630 | + // make sure this was called in the right place! |
|
| 631 | + if ( |
|
| 632 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 633 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 634 | + ) { |
|
| 635 | + EE_Error::doing_it_wrong( |
|
| 636 | + __METHOD__, |
|
| 637 | + sprintf( |
|
| 638 | + __( |
|
| 639 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 640 | + 'event_espresso' |
|
| 641 | + ), |
|
| 642 | + $addon_name |
|
| 643 | + ), |
|
| 644 | + '4.3.0' |
|
| 645 | + ); |
|
| 646 | + } |
|
| 647 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 648 | + if (isset(self::$_settings[$addon_name])) { |
|
| 649 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 650 | + } else { |
|
| 651 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 652 | + } |
|
| 653 | + return false; |
|
| 654 | + } |
|
| 655 | 655 | |
| 656 | 656 | |
| 657 | - /** |
|
| 658 | - * @param string $addon_name |
|
| 659 | - * @return void |
|
| 660 | - * @throws \EE_Error |
|
| 661 | - */ |
|
| 662 | - private static function _setup_autoloaders($addon_name) |
|
| 663 | - { |
|
| 664 | - if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 665 | - // setup autoloader for single file |
|
| 666 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 667 | - } |
|
| 668 | - // setup autoloaders for folders |
|
| 669 | - if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 670 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 671 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - } |
|
| 657 | + /** |
|
| 658 | + * @param string $addon_name |
|
| 659 | + * @return void |
|
| 660 | + * @throws \EE_Error |
|
| 661 | + */ |
|
| 662 | + private static function _setup_autoloaders($addon_name) |
|
| 663 | + { |
|
| 664 | + if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 665 | + // setup autoloader for single file |
|
| 666 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 667 | + } |
|
| 668 | + // setup autoloaders for folders |
|
| 669 | + if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 670 | + foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 671 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + } |
|
| 675 | 675 | |
| 676 | 676 | |
| 677 | - /** |
|
| 678 | - * register new models and extensions |
|
| 679 | - * |
|
| 680 | - * @param string $addon_name |
|
| 681 | - * @return void |
|
| 682 | - * @throws \EE_Error |
|
| 683 | - */ |
|
| 684 | - private static function _register_models_and_extensions($addon_name) |
|
| 685 | - { |
|
| 686 | - // register new models |
|
| 687 | - if ( |
|
| 688 | - ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 689 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 690 | - ) { |
|
| 691 | - EE_Register_Model::register( |
|
| 692 | - $addon_name, |
|
| 693 | - array( |
|
| 694 | - 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 695 | - 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 696 | - ) |
|
| 697 | - ); |
|
| 698 | - } |
|
| 699 | - // register model extensions |
|
| 700 | - if ( |
|
| 701 | - ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 702 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 703 | - ) { |
|
| 704 | - EE_Register_Model_Extensions::register( |
|
| 705 | - $addon_name, |
|
| 706 | - array( |
|
| 707 | - 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 708 | - 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 709 | - ) |
|
| 710 | - ); |
|
| 711 | - } |
|
| 712 | - } |
|
| 677 | + /** |
|
| 678 | + * register new models and extensions |
|
| 679 | + * |
|
| 680 | + * @param string $addon_name |
|
| 681 | + * @return void |
|
| 682 | + * @throws \EE_Error |
|
| 683 | + */ |
|
| 684 | + private static function _register_models_and_extensions($addon_name) |
|
| 685 | + { |
|
| 686 | + // register new models |
|
| 687 | + if ( |
|
| 688 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 689 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 690 | + ) { |
|
| 691 | + EE_Register_Model::register( |
|
| 692 | + $addon_name, |
|
| 693 | + array( |
|
| 694 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 695 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 696 | + ) |
|
| 697 | + ); |
|
| 698 | + } |
|
| 699 | + // register model extensions |
|
| 700 | + if ( |
|
| 701 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 702 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 703 | + ) { |
|
| 704 | + EE_Register_Model_Extensions::register( |
|
| 705 | + $addon_name, |
|
| 706 | + array( |
|
| 707 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 708 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 709 | + ) |
|
| 710 | + ); |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | 713 | |
| 714 | 714 | |
| 715 | - /** |
|
| 716 | - * @param string $addon_name |
|
| 717 | - * @return void |
|
| 718 | - * @throws \EE_Error |
|
| 719 | - */ |
|
| 720 | - private static function _register_data_migration_scripts($addon_name) |
|
| 721 | - { |
|
| 722 | - // setup DMS |
|
| 723 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 724 | - EE_Register_Data_Migration_Scripts::register( |
|
| 725 | - $addon_name, |
|
| 726 | - array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 727 | - ); |
|
| 728 | - } |
|
| 729 | - } |
|
| 715 | + /** |
|
| 716 | + * @param string $addon_name |
|
| 717 | + * @return void |
|
| 718 | + * @throws \EE_Error |
|
| 719 | + */ |
|
| 720 | + private static function _register_data_migration_scripts($addon_name) |
|
| 721 | + { |
|
| 722 | + // setup DMS |
|
| 723 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 724 | + EE_Register_Data_Migration_Scripts::register( |
|
| 725 | + $addon_name, |
|
| 726 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 727 | + ); |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | 730 | |
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * @param string $addon_name |
|
| 734 | - * @return void |
|
| 735 | - * @throws \EE_Error |
|
| 736 | - */ |
|
| 737 | - private static function _register_config($addon_name) |
|
| 738 | - { |
|
| 739 | - // if config_class is present let's register config. |
|
| 740 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 741 | - EE_Register_Config::register( |
|
| 742 | - self::$_settings[$addon_name]['config_class'], |
|
| 743 | - array( |
|
| 744 | - 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 745 | - 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 746 | - ) |
|
| 747 | - ); |
|
| 748 | - } |
|
| 749 | - } |
|
| 732 | + /** |
|
| 733 | + * @param string $addon_name |
|
| 734 | + * @return void |
|
| 735 | + * @throws \EE_Error |
|
| 736 | + */ |
|
| 737 | + private static function _register_config($addon_name) |
|
| 738 | + { |
|
| 739 | + // if config_class is present let's register config. |
|
| 740 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 741 | + EE_Register_Config::register( |
|
| 742 | + self::$_settings[$addon_name]['config_class'], |
|
| 743 | + array( |
|
| 744 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 745 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 746 | + ) |
|
| 747 | + ); |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | 751 | |
| 752 | - /** |
|
| 753 | - * @param string $addon_name |
|
| 754 | - * @return void |
|
| 755 | - * @throws \EE_Error |
|
| 756 | - */ |
|
| 757 | - private static function _register_admin_pages($addon_name) |
|
| 758 | - { |
|
| 759 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 760 | - EE_Register_Admin_Page::register( |
|
| 761 | - $addon_name, |
|
| 762 | - array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 763 | - ); |
|
| 764 | - } |
|
| 765 | - } |
|
| 752 | + /** |
|
| 753 | + * @param string $addon_name |
|
| 754 | + * @return void |
|
| 755 | + * @throws \EE_Error |
|
| 756 | + */ |
|
| 757 | + private static function _register_admin_pages($addon_name) |
|
| 758 | + { |
|
| 759 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 760 | + EE_Register_Admin_Page::register( |
|
| 761 | + $addon_name, |
|
| 762 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 763 | + ); |
|
| 764 | + } |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | 767 | |
| 768 | - /** |
|
| 769 | - * @param string $addon_name |
|
| 770 | - * @return void |
|
| 771 | - * @throws \EE_Error |
|
| 772 | - */ |
|
| 773 | - private static function _register_modules($addon_name) |
|
| 774 | - { |
|
| 775 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 776 | - EE_Register_Module::register( |
|
| 777 | - $addon_name, |
|
| 778 | - array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 779 | - ); |
|
| 780 | - } |
|
| 781 | - } |
|
| 768 | + /** |
|
| 769 | + * @param string $addon_name |
|
| 770 | + * @return void |
|
| 771 | + * @throws \EE_Error |
|
| 772 | + */ |
|
| 773 | + private static function _register_modules($addon_name) |
|
| 774 | + { |
|
| 775 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 776 | + EE_Register_Module::register( |
|
| 777 | + $addon_name, |
|
| 778 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 779 | + ); |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | 782 | |
| 783 | 783 | |
| 784 | - /** |
|
| 785 | - * @param string $addon_name |
|
| 786 | - * @return void |
|
| 787 | - * @throws \EE_Error |
|
| 788 | - */ |
|
| 789 | - private static function _register_shortcodes($addon_name) |
|
| 790 | - { |
|
| 791 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 792 | - EE_Register_Shortcode::register( |
|
| 793 | - $addon_name, |
|
| 794 | - array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
| 795 | - ); |
|
| 796 | - } |
|
| 797 | - } |
|
| 784 | + /** |
|
| 785 | + * @param string $addon_name |
|
| 786 | + * @return void |
|
| 787 | + * @throws \EE_Error |
|
| 788 | + */ |
|
| 789 | + private static function _register_shortcodes($addon_name) |
|
| 790 | + { |
|
| 791 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 792 | + EE_Register_Shortcode::register( |
|
| 793 | + $addon_name, |
|
| 794 | + array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
| 795 | + ); |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | 799 | |
| 800 | - /** |
|
| 801 | - * @param string $addon_name |
|
| 802 | - * @return void |
|
| 803 | - * @throws \EE_Error |
|
| 804 | - */ |
|
| 805 | - private static function _register_widgets($addon_name) |
|
| 806 | - { |
|
| 807 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 808 | - EE_Register_Widget::register( |
|
| 809 | - $addon_name, |
|
| 810 | - array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 811 | - ); |
|
| 812 | - } |
|
| 813 | - } |
|
| 800 | + /** |
|
| 801 | + * @param string $addon_name |
|
| 802 | + * @return void |
|
| 803 | + * @throws \EE_Error |
|
| 804 | + */ |
|
| 805 | + private static function _register_widgets($addon_name) |
|
| 806 | + { |
|
| 807 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 808 | + EE_Register_Widget::register( |
|
| 809 | + $addon_name, |
|
| 810 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 811 | + ); |
|
| 812 | + } |
|
| 813 | + } |
|
| 814 | 814 | |
| 815 | 815 | |
| 816 | - /** |
|
| 817 | - * @param string $addon_name |
|
| 818 | - * @return void |
|
| 819 | - * @throws \EE_Error |
|
| 820 | - */ |
|
| 821 | - private static function _register_capabilities($addon_name) |
|
| 822 | - { |
|
| 823 | - if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 824 | - EE_Register_Capabilities::register( |
|
| 825 | - $addon_name, |
|
| 826 | - array( |
|
| 827 | - 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 828 | - 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 829 | - ) |
|
| 830 | - ); |
|
| 831 | - } |
|
| 832 | - } |
|
| 816 | + /** |
|
| 817 | + * @param string $addon_name |
|
| 818 | + * @return void |
|
| 819 | + * @throws \EE_Error |
|
| 820 | + */ |
|
| 821 | + private static function _register_capabilities($addon_name) |
|
| 822 | + { |
|
| 823 | + if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 824 | + EE_Register_Capabilities::register( |
|
| 825 | + $addon_name, |
|
| 826 | + array( |
|
| 827 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 828 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 829 | + ) |
|
| 830 | + ); |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | 833 | |
| 834 | 834 | |
| 835 | - /** |
|
| 836 | - * @param string $addon_name |
|
| 837 | - * @return void |
|
| 838 | - * @throws \EE_Error |
|
| 839 | - */ |
|
| 840 | - private static function _register_message_types($addon_name) |
|
| 841 | - { |
|
| 842 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 843 | - add_action( |
|
| 844 | - 'EE_Brewing_Regular___messages_caf', |
|
| 845 | - array('EE_Register_Addon', 'register_message_types') |
|
| 846 | - ); |
|
| 847 | - } |
|
| 848 | - } |
|
| 835 | + /** |
|
| 836 | + * @param string $addon_name |
|
| 837 | + * @return void |
|
| 838 | + * @throws \EE_Error |
|
| 839 | + */ |
|
| 840 | + private static function _register_message_types($addon_name) |
|
| 841 | + { |
|
| 842 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 843 | + add_action( |
|
| 844 | + 'EE_Brewing_Regular___messages_caf', |
|
| 845 | + array('EE_Register_Addon', 'register_message_types') |
|
| 846 | + ); |
|
| 847 | + } |
|
| 848 | + } |
|
| 849 | 849 | |
| 850 | 850 | |
| 851 | - /** |
|
| 852 | - * @param string $addon_name |
|
| 853 | - * @return void |
|
| 854 | - * @throws \EE_Error |
|
| 855 | - */ |
|
| 856 | - private static function _register_custom_post_types($addon_name) |
|
| 857 | - { |
|
| 858 | - if ( |
|
| 859 | - ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 860 | - || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 861 | - ) { |
|
| 862 | - EE_Register_CPT::register( |
|
| 863 | - $addon_name, |
|
| 864 | - array( |
|
| 865 | - 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 866 | - 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 867 | - 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 868 | - ) |
|
| 869 | - ); |
|
| 870 | - } |
|
| 871 | - } |
|
| 851 | + /** |
|
| 852 | + * @param string $addon_name |
|
| 853 | + * @return void |
|
| 854 | + * @throws \EE_Error |
|
| 855 | + */ |
|
| 856 | + private static function _register_custom_post_types($addon_name) |
|
| 857 | + { |
|
| 858 | + if ( |
|
| 859 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 860 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 861 | + ) { |
|
| 862 | + EE_Register_CPT::register( |
|
| 863 | + $addon_name, |
|
| 864 | + array( |
|
| 865 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 866 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 867 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 868 | + ) |
|
| 869 | + ); |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | 872 | |
| 873 | 873 | |
| 874 | - /** |
|
| 875 | - * @param string $addon_name |
|
| 876 | - * @return void |
|
| 877 | - * @throws \EE_Error |
|
| 878 | - */ |
|
| 879 | - private static function _register_payment_methods($addon_name) |
|
| 880 | - { |
|
| 881 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 882 | - EE_Register_Payment_Method::register( |
|
| 883 | - $addon_name, |
|
| 884 | - array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 885 | - ); |
|
| 886 | - } |
|
| 887 | - } |
|
| 874 | + /** |
|
| 875 | + * @param string $addon_name |
|
| 876 | + * @return void |
|
| 877 | + * @throws \EE_Error |
|
| 878 | + */ |
|
| 879 | + private static function _register_payment_methods($addon_name) |
|
| 880 | + { |
|
| 881 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 882 | + EE_Register_Payment_Method::register( |
|
| 883 | + $addon_name, |
|
| 884 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 885 | + ); |
|
| 886 | + } |
|
| 887 | + } |
|
| 888 | 888 | |
| 889 | 889 | |
| 890 | - /** |
|
| 891 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 892 | - * |
|
| 893 | - * @param string $addon_name |
|
| 894 | - * @return EE_Addon |
|
| 895 | - */ |
|
| 896 | - private static function _load_and_init_addon_class($addon_name) |
|
| 897 | - { |
|
| 898 | - $addon = EE_Registry::instance()->load_addon( |
|
| 899 | - dirname(self::$_settings[$addon_name]['main_file_path']), |
|
| 900 | - self::$_settings[$addon_name]['class_name'] |
|
| 901 | - ); |
|
| 902 | - $addon->set_name($addon_name); |
|
| 903 | - $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 904 | - $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 905 | - $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 906 | - $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 907 | - $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 908 | - $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 909 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 910 | - $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 911 | - $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 912 | - $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 913 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 914 | - //the plugin mainfile's path upon construction. |
|
| 915 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 916 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 917 | - if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 918 | - add_action( |
|
| 919 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 920 | - array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 921 | - ); |
|
| 922 | - } |
|
| 923 | - return $addon; |
|
| 924 | - } |
|
| 890 | + /** |
|
| 891 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 892 | + * |
|
| 893 | + * @param string $addon_name |
|
| 894 | + * @return EE_Addon |
|
| 895 | + */ |
|
| 896 | + private static function _load_and_init_addon_class($addon_name) |
|
| 897 | + { |
|
| 898 | + $addon = EE_Registry::instance()->load_addon( |
|
| 899 | + dirname(self::$_settings[$addon_name]['main_file_path']), |
|
| 900 | + self::$_settings[$addon_name]['class_name'] |
|
| 901 | + ); |
|
| 902 | + $addon->set_name($addon_name); |
|
| 903 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 904 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 905 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 906 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 907 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 908 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 909 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 910 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 911 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 912 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 913 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 914 | + //the plugin mainfile's path upon construction. |
|
| 915 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 916 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 917 | + if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 918 | + add_action( |
|
| 919 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 920 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 921 | + ); |
|
| 922 | + } |
|
| 923 | + return $addon; |
|
| 924 | + } |
|
| 925 | 925 | |
| 926 | 926 | |
| 927 | - /** |
|
| 928 | - * load_pue_update - Update notifications |
|
| 929 | - * |
|
| 930 | - * @return void |
|
| 931 | - */ |
|
| 932 | - public static function load_pue_update() |
|
| 933 | - { |
|
| 934 | - // load PUE client |
|
| 935 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 936 | - // cycle thru settings |
|
| 937 | - foreach (self::$_settings as $settings) { |
|
| 938 | - if (! empty($settings['pue_options'])) { |
|
| 939 | - // initiate the class and start the plugin update engine! |
|
| 940 | - new PluginUpdateEngineChecker( |
|
| 941 | - // host file URL |
|
| 942 | - 'https://eventespresso.com', |
|
| 943 | - // plugin slug(s) |
|
| 944 | - array( |
|
| 945 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 946 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 947 | - ), |
|
| 948 | - // options |
|
| 949 | - array( |
|
| 950 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 951 | - 'lang_domain' => 'event_espresso', |
|
| 952 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 953 | - 'option_key' => 'site_license_key', |
|
| 954 | - 'options_page_slug' => 'event_espresso', |
|
| 955 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 956 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 957 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 958 | - ) |
|
| 959 | - ); |
|
| 960 | - } |
|
| 961 | - } |
|
| 962 | - } |
|
| 927 | + /** |
|
| 928 | + * load_pue_update - Update notifications |
|
| 929 | + * |
|
| 930 | + * @return void |
|
| 931 | + */ |
|
| 932 | + public static function load_pue_update() |
|
| 933 | + { |
|
| 934 | + // load PUE client |
|
| 935 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 936 | + // cycle thru settings |
|
| 937 | + foreach (self::$_settings as $settings) { |
|
| 938 | + if (! empty($settings['pue_options'])) { |
|
| 939 | + // initiate the class and start the plugin update engine! |
|
| 940 | + new PluginUpdateEngineChecker( |
|
| 941 | + // host file URL |
|
| 942 | + 'https://eventespresso.com', |
|
| 943 | + // plugin slug(s) |
|
| 944 | + array( |
|
| 945 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 946 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 947 | + ), |
|
| 948 | + // options |
|
| 949 | + array( |
|
| 950 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 951 | + 'lang_domain' => 'event_espresso', |
|
| 952 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 953 | + 'option_key' => 'site_license_key', |
|
| 954 | + 'options_page_slug' => 'event_espresso', |
|
| 955 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 956 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 957 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 958 | + ) |
|
| 959 | + ); |
|
| 960 | + } |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | 963 | |
| 964 | 964 | |
| 965 | - /** |
|
| 966 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 967 | - * |
|
| 968 | - * @since 4.4.0 |
|
| 969 | - * @return void |
|
| 970 | - * @throws \EE_Error |
|
| 971 | - */ |
|
| 972 | - public static function register_message_types() |
|
| 973 | - { |
|
| 974 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 975 | - if (! empty($settings['message_types'])) { |
|
| 976 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 977 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - } |
|
| 981 | - } |
|
| 965 | + /** |
|
| 966 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 967 | + * |
|
| 968 | + * @since 4.4.0 |
|
| 969 | + * @return void |
|
| 970 | + * @throws \EE_Error |
|
| 971 | + */ |
|
| 972 | + public static function register_message_types() |
|
| 973 | + { |
|
| 974 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 975 | + if (! empty($settings['message_types'])) { |
|
| 976 | + foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 977 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + } |
|
| 981 | + } |
|
| 982 | 982 | |
| 983 | 983 | |
| 984 | - /** |
|
| 985 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 986 | - * |
|
| 987 | - * @since 4.3.0 |
|
| 988 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 989 | - * @throws EE_Error |
|
| 990 | - * @return void |
|
| 991 | - */ |
|
| 992 | - public static function deregister($addon_name = null) |
|
| 993 | - { |
|
| 994 | - if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
|
| 995 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 996 | - $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 997 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 998 | - // setup DMS |
|
| 999 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1000 | - } |
|
| 1001 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1002 | - // register admin page |
|
| 1003 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 1004 | - } |
|
| 1005 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1006 | - // add to list of modules to be registered |
|
| 1007 | - EE_Register_Module::deregister($addon_name); |
|
| 1008 | - } |
|
| 1009 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 1010 | - // add to list of shortcodes to be registered |
|
| 1011 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 1012 | - } |
|
| 1013 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1014 | - // if config_class present let's register config. |
|
| 1015 | - EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1016 | - } |
|
| 1017 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1018 | - // add to list of widgets to be registered |
|
| 1019 | - EE_Register_Widget::deregister($addon_name); |
|
| 1020 | - } |
|
| 1021 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1022 | - || |
|
| 1023 | - ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1024 | - ) { |
|
| 1025 | - // add to list of shortcodes to be registered |
|
| 1026 | - EE_Register_Model::deregister($addon_name); |
|
| 1027 | - } |
|
| 1028 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1029 | - || |
|
| 1030 | - ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1031 | - ) { |
|
| 1032 | - // add to list of shortcodes to be registered |
|
| 1033 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1034 | - } |
|
| 1035 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1036 | - foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1037 | - EE_Register_Message_Type::deregister($message_type); |
|
| 1038 | - } |
|
| 1039 | - } |
|
| 1040 | - //deregister capabilities for addon |
|
| 1041 | - if ( |
|
| 1042 | - ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1043 | - || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1044 | - ) { |
|
| 1045 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 1046 | - } |
|
| 1047 | - //deregister custom_post_types for addon |
|
| 1048 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1049 | - EE_Register_CPT::deregister($addon_name); |
|
| 1050 | - } |
|
| 1051 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1052 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1053 | - } |
|
| 1054 | - remove_action( |
|
| 1055 | - 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1056 | - array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
| 1057 | - ); |
|
| 1058 | - remove_action( |
|
| 1059 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1060 | - array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
| 1061 | - ); |
|
| 1062 | - unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
| 1063 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 984 | + /** |
|
| 985 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 986 | + * |
|
| 987 | + * @since 4.3.0 |
|
| 988 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 989 | + * @throws EE_Error |
|
| 990 | + * @return void |
|
| 991 | + */ |
|
| 992 | + public static function deregister($addon_name = null) |
|
| 993 | + { |
|
| 994 | + if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
|
| 995 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 996 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 997 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 998 | + // setup DMS |
|
| 999 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1000 | + } |
|
| 1001 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1002 | + // register admin page |
|
| 1003 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 1004 | + } |
|
| 1005 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1006 | + // add to list of modules to be registered |
|
| 1007 | + EE_Register_Module::deregister($addon_name); |
|
| 1008 | + } |
|
| 1009 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 1010 | + // add to list of shortcodes to be registered |
|
| 1011 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 1012 | + } |
|
| 1013 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1014 | + // if config_class present let's register config. |
|
| 1015 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1016 | + } |
|
| 1017 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1018 | + // add to list of widgets to be registered |
|
| 1019 | + EE_Register_Widget::deregister($addon_name); |
|
| 1020 | + } |
|
| 1021 | + if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1022 | + || |
|
| 1023 | + ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1024 | + ) { |
|
| 1025 | + // add to list of shortcodes to be registered |
|
| 1026 | + EE_Register_Model::deregister($addon_name); |
|
| 1027 | + } |
|
| 1028 | + if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1029 | + || |
|
| 1030 | + ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1031 | + ) { |
|
| 1032 | + // add to list of shortcodes to be registered |
|
| 1033 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1034 | + } |
|
| 1035 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1036 | + foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1037 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 1040 | + //deregister capabilities for addon |
|
| 1041 | + if ( |
|
| 1042 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1043 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1044 | + ) { |
|
| 1045 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1046 | + } |
|
| 1047 | + //deregister custom_post_types for addon |
|
| 1048 | + if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1049 | + EE_Register_CPT::deregister($addon_name); |
|
| 1050 | + } |
|
| 1051 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1052 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1053 | + } |
|
| 1054 | + remove_action( |
|
| 1055 | + 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1056 | + array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
| 1057 | + ); |
|
| 1058 | + remove_action( |
|
| 1059 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1060 | + array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
| 1061 | + ); |
|
| 1062 | + unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
| 1063 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | 1066 | |
| 1067 | 1067 | |
| 1068 | 1068 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 67 | 67 | $version_parts = explode('.', $min_core_version); |
| 68 | 68 | //check they specified the micro version (after 2nd period) |
| 69 | - if (! isset($version_parts[2])) { |
|
| 69 | + if ( ! isset($version_parts[2])) { |
|
| 70 | 70 | $version_parts[2] = '0'; |
| 71 | 71 | } |
| 72 | 72 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 73 | 73 | //soon we can assume that's 'rc', but this current version is 'alpha' |
| 74 | - if (! isset($version_parts[3])) { |
|
| 74 | + if ( ! isset($version_parts[3])) { |
|
| 75 | 75 | $version_parts[3] = 'dev'; |
| 76 | 76 | } |
| 77 | - if (! isset($version_parts[4])) { |
|
| 77 | + if ( ! isset($version_parts[4])) { |
|
| 78 | 78 | $version_parts[4] = '000'; |
| 79 | 79 | } |
| 80 | 80 | return implode('.', $version_parts); |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | // setup PUE |
| 232 | 232 | \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 233 | 233 | // does this addon work with this version of core or WordPress ? |
| 234 | - if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 234 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 235 | 235 | return; |
| 236 | 236 | } |
| 237 | 237 | // register namespaces |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | ) |
| 289 | 289 | ); |
| 290 | 290 | } |
| 291 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 291 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 292 | 292 | throw new EE_Error( |
| 293 | 293 | sprintf( |
| 294 | 294 | __( |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | } else { |
| 330 | 330 | $class_name = $setup_args['class_name']; |
| 331 | 331 | } |
| 332 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
| 332 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -346,105 +346,105 @@ discard block |
||
| 346 | 346 | 'class_name' => $class_name, |
| 347 | 347 | // the addon slug for use in URLs, etc |
| 348 | 348 | 'plugin_slug' => isset($setup_args['plugin_slug']) |
| 349 | - ? (string)$setup_args['plugin_slug'] |
|
| 349 | + ? (string) $setup_args['plugin_slug'] |
|
| 350 | 350 | : '', |
| 351 | 351 | // page slug to be used when generating the "Settings" link on the WP plugin page |
| 352 | 352 | 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
| 353 | - ? (string)$setup_args['plugin_action_slug'] |
|
| 353 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 354 | 354 | : '', |
| 355 | 355 | // the "software" version for the addon |
| 356 | 356 | 'version' => isset($setup_args['version']) |
| 357 | - ? (string)$setup_args['version'] |
|
| 357 | + ? (string) $setup_args['version'] |
|
| 358 | 358 | : '', |
| 359 | 359 | // the minimum version of EE Core that the addon will work with |
| 360 | 360 | 'min_core_version' => isset($setup_args['min_core_version']) |
| 361 | - ? (string)$setup_args['min_core_version'] |
|
| 361 | + ? (string) $setup_args['min_core_version'] |
|
| 362 | 362 | : '', |
| 363 | 363 | // the minimum version of WordPress that the addon will work with |
| 364 | 364 | 'min_wp_version' => isset($setup_args['min_wp_version']) |
| 365 | - ? (string)$setup_args['min_wp_version'] |
|
| 365 | + ? (string) $setup_args['min_wp_version'] |
|
| 366 | 366 | : EE_MIN_WP_VER_REQUIRED, |
| 367 | 367 | // full server path to main file (file loaded directly by WP) |
| 368 | 368 | 'main_file_path' => isset($setup_args['main_file_path']) |
| 369 | - ? (string)$setup_args['main_file_path'] |
|
| 369 | + ? (string) $setup_args['main_file_path'] |
|
| 370 | 370 | : '', |
| 371 | 371 | // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
| 372 | 372 | 'admin_path' => isset($setup_args['admin_path']) |
| 373 | - ? (string)$setup_args['admin_path'] : '', |
|
| 373 | + ? (string) $setup_args['admin_path'] : '', |
|
| 374 | 374 | // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
| 375 | 375 | 'admin_callback' => isset($setup_args['admin_callback']) |
| 376 | - ? (string)$setup_args['admin_callback'] |
|
| 376 | + ? (string) $setup_args['admin_callback'] |
|
| 377 | 377 | : '', |
| 378 | 378 | // the section name for this addon's configuration settings section (defaults to "addons") |
| 379 | 379 | 'config_section' => isset($setup_args['config_section']) |
| 380 | - ? (string)$setup_args['config_section'] |
|
| 380 | + ? (string) $setup_args['config_section'] |
|
| 381 | 381 | : 'addons', |
| 382 | 382 | // the class name for this addon's configuration settings object |
| 383 | 383 | 'config_class' => isset($setup_args['config_class']) |
| 384 | - ? (string)$setup_args['config_class'] : '', |
|
| 384 | + ? (string) $setup_args['config_class'] : '', |
|
| 385 | 385 | //the name given to the config for this addons' configuration settings object (optional) |
| 386 | 386 | 'config_name' => isset($setup_args['config_name']) |
| 387 | - ? (string)$setup_args['config_name'] : '', |
|
| 387 | + ? (string) $setup_args['config_name'] : '', |
|
| 388 | 388 | // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
| 389 | 389 | 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
| 390 | - ? (array)$setup_args['autoloader_paths'] |
|
| 390 | + ? (array) $setup_args['autoloader_paths'] |
|
| 391 | 391 | : array(), |
| 392 | 392 | // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
| 393 | 393 | 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
| 394 | - ? (array)$setup_args['autoloader_folders'] |
|
| 394 | + ? (array) $setup_args['autoloader_folders'] |
|
| 395 | 395 | : array(), |
| 396 | 396 | // array of full server paths to any EE_DMS data migration scripts used by the addon |
| 397 | 397 | 'dms_paths' => isset($setup_args['dms_paths']) |
| 398 | - ? (array)$setup_args['dms_paths'] |
|
| 398 | + ? (array) $setup_args['dms_paths'] |
|
| 399 | 399 | : array(), |
| 400 | 400 | // array of full server paths to any EED_Modules used by the addon |
| 401 | 401 | 'module_paths' => isset($setup_args['module_paths']) |
| 402 | - ? (array)$setup_args['module_paths'] |
|
| 402 | + ? (array) $setup_args['module_paths'] |
|
| 403 | 403 | : array(), |
| 404 | 404 | // array of full server paths to any EES_Shortcodes used by the addon |
| 405 | 405 | 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
| 406 | - ? (array)$setup_args['shortcode_paths'] |
|
| 406 | + ? (array) $setup_args['shortcode_paths'] |
|
| 407 | 407 | : array(), |
| 408 | 408 | // array of full server paths to any WP_Widgets used by the addon |
| 409 | 409 | 'widget_paths' => isset($setup_args['widget_paths']) |
| 410 | - ? (array)$setup_args['widget_paths'] |
|
| 410 | + ? (array) $setup_args['widget_paths'] |
|
| 411 | 411 | : array(), |
| 412 | 412 | // array of PUE options used by the addon |
| 413 | 413 | 'pue_options' => isset($setup_args['pue_options']) |
| 414 | - ? (array)$setup_args['pue_options'] |
|
| 414 | + ? (array) $setup_args['pue_options'] |
|
| 415 | 415 | : array(), |
| 416 | 416 | 'message_types' => isset($setup_args['message_types']) |
| 417 | - ? (array)$setup_args['message_types'] |
|
| 417 | + ? (array) $setup_args['message_types'] |
|
| 418 | 418 | : array(), |
| 419 | 419 | 'capabilities' => isset($setup_args['capabilities']) |
| 420 | - ? (array)$setup_args['capabilities'] |
|
| 420 | + ? (array) $setup_args['capabilities'] |
|
| 421 | 421 | : array(), |
| 422 | 422 | 'capability_maps' => isset($setup_args['capability_maps']) |
| 423 | - ? (array)$setup_args['capability_maps'] |
|
| 423 | + ? (array) $setup_args['capability_maps'] |
|
| 424 | 424 | : array(), |
| 425 | 425 | 'model_paths' => isset($setup_args['model_paths']) |
| 426 | - ? (array)$setup_args['model_paths'] |
|
| 426 | + ? (array) $setup_args['model_paths'] |
|
| 427 | 427 | : array(), |
| 428 | 428 | 'class_paths' => isset($setup_args['class_paths']) |
| 429 | - ? (array)$setup_args['class_paths'] |
|
| 429 | + ? (array) $setup_args['class_paths'] |
|
| 430 | 430 | : array(), |
| 431 | 431 | 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
| 432 | - ? (array)$setup_args['model_extension_paths'] |
|
| 432 | + ? (array) $setup_args['model_extension_paths'] |
|
| 433 | 433 | : array(), |
| 434 | 434 | 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
| 435 | - ? (array)$setup_args['class_extension_paths'] |
|
| 435 | + ? (array) $setup_args['class_extension_paths'] |
|
| 436 | 436 | : array(), |
| 437 | 437 | 'custom_post_types' => isset($setup_args['custom_post_types']) |
| 438 | - ? (array)$setup_args['custom_post_types'] |
|
| 438 | + ? (array) $setup_args['custom_post_types'] |
|
| 439 | 439 | : array(), |
| 440 | 440 | 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
| 441 | - ? (array)$setup_args['custom_taxonomies'] |
|
| 441 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 442 | 442 | : array(), |
| 443 | 443 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
| 444 | - ? (array)$setup_args['payment_method_paths'] |
|
| 444 | + ? (array) $setup_args['payment_method_paths'] |
|
| 445 | 445 | : array(), |
| 446 | 446 | 'default_terms' => isset($setup_args['default_terms']) |
| 447 | - ? (array)$setup_args['default_terms'] |
|
| 447 | + ? (array) $setup_args['default_terms'] |
|
| 448 | 448 | : array(), |
| 449 | 449 | // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
| 450 | 450 | // that can be used for adding upgrading/marketing info |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | $setup_args['namespace']['FQNS'], |
| 457 | 457 | $setup_args['namespace']['DIR'] |
| 458 | 458 | ) |
| 459 | - ? (array)$setup_args['namespace'] |
|
| 459 | + ? (array) $setup_args['namespace'] |
|
| 460 | 460 | : array(), |
| 461 | 461 | ); |
| 462 | 462 | // if plugin_action_slug is NOT set, but an admin page path IS set, |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | '</span><br />' |
| 527 | 527 | ); |
| 528 | 528 | } |
| 529 | - if (! empty($incompatibility_message)) { |
|
| 529 | + if ( ! empty($incompatibility_message)) { |
|
| 530 | 530 | // remove 'activate' from the REQUEST |
| 531 | 531 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 532 | 532 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -554,19 +554,19 @@ discard block |
||
| 554 | 554 | */ |
| 555 | 555 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
| 556 | 556 | { |
| 557 | - if (! empty($setup_args['pue_options'])) { |
|
| 557 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 558 | 558 | self::$_settings[$addon_name]['pue_options'] = array( |
| 559 | 559 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 560 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 561 | - : 'espresso_' . strtolower($class_name), |
|
| 560 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 561 | + : 'espresso_'.strtolower($class_name), |
|
| 562 | 562 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 563 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 563 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 564 | 564 | : plugin_basename($setup_args['main_file_path']), |
| 565 | 565 | 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
| 566 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 566 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 567 | 567 | : '24', |
| 568 | 568 | 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
| 569 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 569 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 570 | 570 | : false, |
| 571 | 571 | ); |
| 572 | 572 | add_action( |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | //(as the newly-activated addon wasn't around the first time addons were registered). |
| 615 | 615 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 616 | 616 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 617 | - if (! isset(self::$_settings[$addon_name]) |
|
| 617 | + if ( ! isset(self::$_settings[$addon_name]) |
|
| 618 | 618 | || (isset(self::$_settings[$addon_name]) |
| 619 | 619 | && ! isset(self::$_settings[$addon_name]['class_name']) |
| 620 | 620 | ) |
@@ -661,13 +661,13 @@ discard block |
||
| 661 | 661 | */ |
| 662 | 662 | private static function _setup_autoloaders($addon_name) |
| 663 | 663 | { |
| 664 | - if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 664 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 665 | 665 | // setup autoloader for single file |
| 666 | 666 | EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
| 667 | 667 | } |
| 668 | 668 | // setup autoloaders for folders |
| 669 | - if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 670 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 669 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 670 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 671 | 671 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 672 | 672 | } |
| 673 | 673 | } |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | private static function _register_data_migration_scripts($addon_name) |
| 721 | 721 | { |
| 722 | 722 | // setup DMS |
| 723 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 723 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 724 | 724 | EE_Register_Data_Migration_Scripts::register( |
| 725 | 725 | $addon_name, |
| 726 | 726 | array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | private static function _register_config($addon_name) |
| 738 | 738 | { |
| 739 | 739 | // if config_class is present let's register config. |
| 740 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 740 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 741 | 741 | EE_Register_Config::register( |
| 742 | 742 | self::$_settings[$addon_name]['config_class'], |
| 743 | 743 | array( |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | */ |
| 757 | 757 | private static function _register_admin_pages($addon_name) |
| 758 | 758 | { |
| 759 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 759 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 760 | 760 | EE_Register_Admin_Page::register( |
| 761 | 761 | $addon_name, |
| 762 | 762 | array('page_path' => self::$_settings[$addon_name]['admin_path']) |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | */ |
| 773 | 773 | private static function _register_modules($addon_name) |
| 774 | 774 | { |
| 775 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 775 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 776 | 776 | EE_Register_Module::register( |
| 777 | 777 | $addon_name, |
| 778 | 778 | array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | */ |
| 789 | 789 | private static function _register_shortcodes($addon_name) |
| 790 | 790 | { |
| 791 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 791 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 792 | 792 | EE_Register_Shortcode::register( |
| 793 | 793 | $addon_name, |
| 794 | 794 | array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
@@ -804,7 +804,7 @@ discard block |
||
| 804 | 804 | */ |
| 805 | 805 | private static function _register_widgets($addon_name) |
| 806 | 806 | { |
| 807 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 807 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 808 | 808 | EE_Register_Widget::register( |
| 809 | 809 | $addon_name, |
| 810 | 810 | array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | */ |
| 821 | 821 | private static function _register_capabilities($addon_name) |
| 822 | 822 | { |
| 823 | - if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 823 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 824 | 824 | EE_Register_Capabilities::register( |
| 825 | 825 | $addon_name, |
| 826 | 826 | array( |
@@ -839,7 +839,7 @@ discard block |
||
| 839 | 839 | */ |
| 840 | 840 | private static function _register_message_types($addon_name) |
| 841 | 841 | { |
| 842 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 842 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 843 | 843 | add_action( |
| 844 | 844 | 'EE_Brewing_Regular___messages_caf', |
| 845 | 845 | array('EE_Register_Addon', 'register_message_types') |
@@ -878,7 +878,7 @@ discard block |
||
| 878 | 878 | */ |
| 879 | 879 | private static function _register_payment_methods($addon_name) |
| 880 | 880 | { |
| 881 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 881 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 882 | 882 | EE_Register_Payment_Method::register( |
| 883 | 883 | $addon_name, |
| 884 | 884 | array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | //the plugin mainfile's path upon construction. |
| 915 | 915 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
| 916 | 916 | // call any additional admin_callback functions during load_admin_controller hook |
| 917 | - if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 917 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 918 | 918 | add_action( |
| 919 | 919 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 920 | 920 | array($addon, self::$_settings[$addon_name]['admin_callback']) |
@@ -932,10 +932,10 @@ discard block |
||
| 932 | 932 | public static function load_pue_update() |
| 933 | 933 | { |
| 934 | 934 | // load PUE client |
| 935 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 935 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
| 936 | 936 | // cycle thru settings |
| 937 | 937 | foreach (self::$_settings as $settings) { |
| 938 | - if (! empty($settings['pue_options'])) { |
|
| 938 | + if ( ! empty($settings['pue_options'])) { |
|
| 939 | 939 | // initiate the class and start the plugin update engine! |
| 940 | 940 | new PluginUpdateEngineChecker( |
| 941 | 941 | // host file URL |
@@ -943,7 +943,7 @@ discard block |
||
| 943 | 943 | // plugin slug(s) |
| 944 | 944 | array( |
| 945 | 945 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
| 946 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 946 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 947 | 947 | ), |
| 948 | 948 | // options |
| 949 | 949 | array( |
@@ -972,8 +972,8 @@ discard block |
||
| 972 | 972 | public static function register_message_types() |
| 973 | 973 | { |
| 974 | 974 | foreach (self::$_settings as $addon_name => $settings) { |
| 975 | - if (! empty($settings['message_types'])) { |
|
| 976 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 975 | + if ( ! empty($settings['message_types'])) { |
|
| 976 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 977 | 977 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 978 | 978 | } |
| 979 | 979 | } |
@@ -994,46 +994,46 @@ discard block |
||
| 994 | 994 | if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
| 995 | 995 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 996 | 996 | $class_name = self::$_settings[$addon_name]['class_name']; |
| 997 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 997 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 998 | 998 | // setup DMS |
| 999 | 999 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 1000 | 1000 | } |
| 1001 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1001 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1002 | 1002 | // register admin page |
| 1003 | 1003 | EE_Register_Admin_Page::deregister($addon_name); |
| 1004 | 1004 | } |
| 1005 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1005 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1006 | 1006 | // add to list of modules to be registered |
| 1007 | 1007 | EE_Register_Module::deregister($addon_name); |
| 1008 | 1008 | } |
| 1009 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 1009 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 1010 | 1010 | // add to list of shortcodes to be registered |
| 1011 | 1011 | EE_Register_Shortcode::deregister($addon_name); |
| 1012 | 1012 | } |
| 1013 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1013 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1014 | 1014 | // if config_class present let's register config. |
| 1015 | 1015 | EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
| 1016 | 1016 | } |
| 1017 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1017 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1018 | 1018 | // add to list of widgets to be registered |
| 1019 | 1019 | EE_Register_Widget::deregister($addon_name); |
| 1020 | 1020 | } |
| 1021 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1021 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1022 | 1022 | || |
| 1023 | 1023 | ! empty(self::$_settings[$addon_name]['class_paths']) |
| 1024 | 1024 | ) { |
| 1025 | 1025 | // add to list of shortcodes to be registered |
| 1026 | 1026 | EE_Register_Model::deregister($addon_name); |
| 1027 | 1027 | } |
| 1028 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1028 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1029 | 1029 | || |
| 1030 | 1030 | ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
| 1031 | 1031 | ) { |
| 1032 | 1032 | // add to list of shortcodes to be registered |
| 1033 | 1033 | EE_Register_Model_Extensions::deregister($addon_name); |
| 1034 | 1034 | } |
| 1035 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1036 | - foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1035 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1036 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1037 | 1037 | EE_Register_Message_Type::deregister($message_type); |
| 1038 | 1038 | } |
| 1039 | 1039 | } |
@@ -1045,14 +1045,14 @@ discard block |
||
| 1045 | 1045 | EE_Register_Capabilities::deregister($addon_name); |
| 1046 | 1046 | } |
| 1047 | 1047 | //deregister custom_post_types for addon |
| 1048 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1048 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1049 | 1049 | EE_Register_CPT::deregister($addon_name); |
| 1050 | 1050 | } |
| 1051 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1051 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1052 | 1052 | EE_Register_Payment_Method::deregister($addon_name); |
| 1053 | 1053 | } |
| 1054 | 1054 | remove_action( |
| 1055 | - 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1055 | + 'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1056 | 1056 | array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
| 1057 | 1057 | ); |
| 1058 | 1058 | remove_action( |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * prefix added to all payment method capabilities names |
| 22 | 22 | */ |
| 23 | - const CAPABILITIES_PREFIX= 'ee_payment_method_'; |
|
| 23 | + const CAPABILITIES_PREFIX = 'ee_payment_method_'; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var EE_Payment_Method_Manager $_instance |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | public static function instance() |
| 77 | 77 | { |
| 78 | 78 | // check if class object is instantiated, and instantiated properly |
| 79 | - if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
| 79 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
| 80 | 80 | EE_Registry::instance()->load_lib('PMT_Base'); |
| 81 | 81 | self::$_instance = new self(); |
| 82 | 82 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function maybe_register_payment_methods($force_recheck = false) |
| 111 | 111 | { |
| 112 | - if (! $this->_payment_method_types || $force_recheck) { |
|
| 112 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
| 113 | 113 | $this->_register_payment_methods(); |
| 114 | 114 | } |
| 115 | 115 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | protected function _register_payment_methods() |
| 125 | 125 | { |
| 126 | 126 | // grab list of installed modules |
| 127 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
| 127 | + $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR); |
|
| 128 | 128 | // filter list of modules to register |
| 129 | 129 | $pm_to_register = apply_filters( |
| 130 | 130 | 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
@@ -165,31 +165,31 @@ discard block |
||
| 165 | 165 | // create class name from module directory name |
| 166 | 166 | $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
| 167 | 167 | // add class prefix |
| 168 | - $module_class = 'EE_PMT_' . $module; |
|
| 168 | + $module_class = 'EE_PMT_'.$module; |
|
| 169 | 169 | // does the module exist ? |
| 170 | - if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
| 170 | + if ( ! is_readable($payment_method_path.DS.$module_class.$module_ext)) { |
|
| 171 | 171 | $msg = sprintf( |
| 172 | 172 | esc_html__( |
| 173 | 173 | 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
| 174 | 174 | 'event_espresso' |
| 175 | 175 | ), $module |
| 176 | 176 | ); |
| 177 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 177 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 178 | 178 | return false; |
| 179 | 179 | } |
| 180 | 180 | // load the module class file |
| 181 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
| 181 | + require_once($payment_method_path.DS.$module_class.$module_ext); |
|
| 182 | 182 | // verify that class exists |
| 183 | - if (! class_exists($module_class)) { |
|
| 183 | + if ( ! class_exists($module_class)) { |
|
| 184 | 184 | $msg = sprintf( |
| 185 | 185 | esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
| 186 | 186 | $module_class |
| 187 | 187 | ); |
| 188 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 188 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 189 | 189 | return false; |
| 190 | 190 | } |
| 191 | 191 | // add to array of registered modules |
| 192 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
| 192 | + $this->_payment_method_types[$module] = $payment_method_path.DS.$module_class.$module_ext; |
|
| 193 | 193 | return true; |
| 194 | 194 | } |
| 195 | 195 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | if ($force_recheck || empty($this->payment_method_objects)) { |
| 257 | 257 | $this->maybe_register_payment_methods($force_recheck); |
| 258 | 258 | foreach ($this->payment_method_type_names(true) as $classname) { |
| 259 | - if (! isset($this->payment_method_objects[$classname])) { |
|
| 259 | + if ( ! isset($this->payment_method_objects[$classname])) { |
|
| 260 | 260 | $this->payment_method_objects[$classname] = new $classname; |
| 261 | 261 | } |
| 262 | 262 | } |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | public function payment_method_class_from_type($type) |
| 290 | 290 | { |
| 291 | - return 'EE_PMT_' . $type; |
|
| 291 | + return 'EE_PMT_'.$type; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | { |
| 305 | 305 | $this->maybe_register_payment_methods(); |
| 306 | 306 | $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
| 307 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
| 307 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 308 | 308 | $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
| 309 | 309 | if (class_exists($pm_type_class)) { |
| 310 | 310 | /** @var $pm_type_obj EE_PMT_Base */ |
| 311 | 311 | $pm_type_obj = new $pm_type_class; |
| 312 | 312 | $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
| 313 | - if (! $payment_method) { |
|
| 313 | + if ( ! $payment_method) { |
|
| 314 | 314 | $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
| 315 | 315 | } |
| 316 | 316 | $payment_method->set_type($payment_method_type); |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | 'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
| 342 | 342 | 'event_espresso' |
| 343 | 343 | ), |
| 344 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
| 344 | + '<a href="'.admin_url('admin.php?page=espresso_messages').'">', |
|
| 345 | 345 | '</a>' |
| 346 | 346 | ), |
| 347 | 347 | true |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | 'PMD_type' => $pm_type_obj->system_name(), |
| 369 | 369 | 'PMD_name' => $pm_type_obj->pretty_name(), |
| 370 | 370 | 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
| 371 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
| 371 | + 'PMD_slug' => $pm_type_obj->system_name(), //automatically converted to slug |
|
| 372 | 372 | 'PMD_wp_user' => $current_user->ID, |
| 373 | 373 | 'PMD_order' => EEM_Payment_Method::instance()->count( |
| 374 | 374 | array(array('PMD_type' => array('!=', 'Admin_Only'))) |
@@ -391,14 +391,14 @@ discard block |
||
| 391 | 391 | { |
| 392 | 392 | $pm_type_obj = $payment_method->type_obj(); |
| 393 | 393 | $payment_method->set_description($pm_type_obj->default_description()); |
| 394 | - if (! $payment_method->button_url()) { |
|
| 394 | + if ( ! $payment_method->button_url()) { |
|
| 395 | 395 | $payment_method->set_button_url($pm_type_obj->default_button_url()); |
| 396 | 396 | } |
| 397 | 397 | //now add setup its default extra meta properties |
| 398 | 398 | $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
| 399 | - if (! empty($extra_metas)) { |
|
| 399 | + if ( ! empty($extra_metas)) { |
|
| 400 | 400 | //verify the payment method has an ID before adding extra meta |
| 401 | - if (! $payment_method->ID()) { |
|
| 401 | + if ( ! $payment_method->ID()) { |
|
| 402 | 402 | $payment_method->save(); |
| 403 | 403 | } |
| 404 | 404 | foreach ($extra_metas as $meta_name => $input) { |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | { |
| 507 | 507 | $caps = array(); |
| 508 | 508 | foreach ($this->payment_method_type_names() as $payment_method_name) { |
| 509 | - $caps = $this->addPaymentMethodCap($payment_method_name,$caps); |
|
| 509 | + $caps = $this->addPaymentMethodCap($payment_method_name, $caps); |
|
| 510 | 510 | } |
| 511 | 511 | return $caps; |
| 512 | 512 | } |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | ) |
| 542 | 542 | ); |
| 543 | 543 | } |
| 544 | - if(! isset($payment_method_caps[$role])) { |
|
| 544 | + if ( ! isset($payment_method_caps[$role])) { |
|
| 545 | 545 | $payment_method_caps[$role] = array(); |
| 546 | 546 | } |
| 547 | 547 | $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
@@ -19,570 +19,570 @@ |
||
| 19 | 19 | class EE_Payment_Method_Manager implements ResettableInterface |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * prefix added to all payment method capabilities names |
|
| 24 | - */ |
|
| 25 | - const CAPABILITIES_PREFIX= 'ee_payment_method_'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var EE_Payment_Method_Manager $_instance |
|
| 29 | - */ |
|
| 30 | - private static $_instance; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var boolean |
|
| 34 | - */ |
|
| 35 | - protected $payment_method_caps_initialized = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var array keys are class names without 'EE_PMT_', values are their filepaths |
|
| 39 | - */ |
|
| 40 | - protected $_payment_method_types = array(); |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var EE_PMT_Base[] |
|
| 44 | - */ |
|
| 45 | - protected $payment_method_objects = array(); |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * EE_Payment_Method_Manager constructor. |
|
| 51 | - * |
|
| 52 | - * @throws EE_Error |
|
| 53 | - * @throws DomainException |
|
| 54 | - */ |
|
| 55 | - public function __construct() |
|
| 56 | - { |
|
| 57 | - // if in admin lets ensure caps are set. |
|
| 58 | - if (is_admin()) { |
|
| 59 | - $this->_register_payment_methods(); |
|
| 60 | - // set them immediately |
|
| 61 | - $this->initializePaymentMethodCaps(); |
|
| 62 | - // plus any time they get reset |
|
| 63 | - add_filter( |
|
| 64 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 65 | - array($this, 'addPaymentMethodCapsDuringReset') |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @singleton method used to instantiate class object |
|
| 74 | - * @return EE_Payment_Method_Manager instance |
|
| 75 | - * @throws DomainException |
|
| 76 | - * @throws EE_Error |
|
| 77 | - */ |
|
| 78 | - public static function instance() |
|
| 79 | - { |
|
| 80 | - // check if class object is instantiated, and instantiated properly |
|
| 81 | - if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
| 82 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
| 83 | - self::$_instance = new self(); |
|
| 84 | - } |
|
| 85 | - return self::$_instance; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Resets the instance and returns a new one |
|
| 92 | - * |
|
| 93 | - * @return EE_Payment_Method_Manager |
|
| 94 | - * @throws DomainException |
|
| 95 | - * @throws EE_Error |
|
| 96 | - */ |
|
| 97 | - public static function reset() |
|
| 98 | - { |
|
| 99 | - self::$_instance = null; |
|
| 100 | - return self::instance(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * If necessary, re-register payment methods |
|
| 107 | - * |
|
| 108 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
| 109 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
| 110 | - * we have not yet checked during this request, then we need to check anyways) |
|
| 111 | - */ |
|
| 112 | - public function maybe_register_payment_methods($force_recheck = false) |
|
| 113 | - { |
|
| 114 | - if (! $this->_payment_method_types || $force_recheck) { |
|
| 115 | - $this->_register_payment_methods(); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * register_payment_methods |
|
| 123 | - * |
|
| 124 | - * @return array |
|
| 125 | - */ |
|
| 126 | - protected function _register_payment_methods() |
|
| 127 | - { |
|
| 128 | - // grab list of installed modules |
|
| 129 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
| 130 | - // filter list of modules to register |
|
| 131 | - $pm_to_register = apply_filters( |
|
| 132 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 133 | - $pm_to_register |
|
| 134 | - ); |
|
| 135 | - // remove any duplicates if that should happen for some reason |
|
| 136 | - $pm_to_register = array_unique($pm_to_register); |
|
| 137 | - // loop through folders |
|
| 138 | - foreach ($pm_to_register as $pm_path) { |
|
| 139 | - $this->register_payment_method($pm_path); |
|
| 140 | - } |
|
| 141 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
| 142 | - // filter list of installed modules |
|
| 143 | - //keep them organized alphabetically by the payment method type's name |
|
| 144 | - ksort($this->_payment_method_types); |
|
| 145 | - return apply_filters( |
|
| 146 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
| 147 | - $this->_payment_method_types |
|
| 148 | - ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * register_payment_method- makes core aware of this payment method |
|
| 155 | - * |
|
| 156 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
| 157 | - * @return boolean |
|
| 158 | - */ |
|
| 159 | - public function register_payment_method($payment_method_path = '') |
|
| 160 | - { |
|
| 161 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
| 162 | - $module_ext = '.pm.php'; |
|
| 163 | - // make all separators match |
|
| 164 | - $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
| 165 | - // grab and sanitize module name |
|
| 166 | - $module_dir = basename($payment_method_path); |
|
| 167 | - // create class name from module directory name |
|
| 168 | - $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
|
| 169 | - // add class prefix |
|
| 170 | - $module_class = 'EE_PMT_' . $module; |
|
| 171 | - // does the module exist ? |
|
| 172 | - if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
| 173 | - $msg = sprintf( |
|
| 174 | - esc_html__( |
|
| 175 | - 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
| 176 | - 'event_espresso' |
|
| 177 | - ), $module |
|
| 178 | - ); |
|
| 179 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 180 | - return false; |
|
| 181 | - } |
|
| 182 | - // load the module class file |
|
| 183 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
| 184 | - // verify that class exists |
|
| 185 | - if (! class_exists($module_class)) { |
|
| 186 | - $msg = sprintf( |
|
| 187 | - esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
|
| 188 | - $module_class |
|
| 189 | - ); |
|
| 190 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 191 | - return false; |
|
| 192 | - } |
|
| 193 | - // add to array of registered modules |
|
| 194 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
| 195 | - return true; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Checks if a payment method has been registered, and if so includes it |
|
| 202 | - * |
|
| 203 | - * @param string $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_') |
|
| 204 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 205 | - * @return boolean |
|
| 206 | - */ |
|
| 207 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
| 208 | - { |
|
| 209 | - if ( |
|
| 210 | - $force_recheck |
|
| 211 | - || ! is_array($this->_payment_method_types) |
|
| 212 | - || ! isset($this->_payment_method_types[$payment_method_name]) |
|
| 213 | - ) { |
|
| 214 | - $this->maybe_register_payment_methods($force_recheck); |
|
| 215 | - } |
|
| 216 | - if (isset($this->_payment_method_types[$payment_method_name])) { |
|
| 217 | - require_once($this->_payment_method_types[$payment_method_name]); |
|
| 218 | - return true; |
|
| 219 | - } |
|
| 220 | - return false; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Returns all the class names of the various payment method types |
|
| 227 | - * |
|
| 228 | - * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names' |
|
| 229 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
| 230 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 231 | - * @return array |
|
| 232 | - */ |
|
| 233 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
| 234 | - { |
|
| 235 | - $this->maybe_register_payment_methods($force_recheck); |
|
| 236 | - if ($with_prefixes) { |
|
| 237 | - $classnames = array_keys($this->_payment_method_types); |
|
| 238 | - $payment_methods = array(); |
|
| 239 | - foreach ($classnames as $classname) { |
|
| 240 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
| 241 | - } |
|
| 242 | - return $payment_methods; |
|
| 243 | - } |
|
| 244 | - return array_keys($this->_payment_method_types); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Gets an object of each payment method type, none of which are bound to a |
|
| 251 | - * payment method instance |
|
| 252 | - * |
|
| 253 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 254 | - * @return EE_PMT_Base[] |
|
| 255 | - */ |
|
| 256 | - public function payment_method_types($force_recheck = false) |
|
| 257 | - { |
|
| 258 | - if ($force_recheck || empty($this->payment_method_objects)) { |
|
| 259 | - $this->maybe_register_payment_methods($force_recheck); |
|
| 260 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
| 261 | - if (! isset($this->payment_method_objects[$classname])) { |
|
| 262 | - $this->payment_method_objects[$classname] = new $classname; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - return $this->payment_method_objects; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Changes the payment method's class name into the payment method type's name |
|
| 273 | - * (as used on the payment method's table's PMD_type field) |
|
| 274 | - * |
|
| 275 | - * @param string $classname |
|
| 276 | - * @return string |
|
| 277 | - */ |
|
| 278 | - public function payment_method_type_sans_class_prefix($classname) |
|
| 279 | - { |
|
| 280 | - return str_replace('EE_PMT_', '', $classname); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Does the opposite of payment-method_type_sans_prefix |
|
| 287 | - * |
|
| 288 | - * @param string $type |
|
| 289 | - * @return string |
|
| 290 | - */ |
|
| 291 | - public function payment_method_class_from_type($type) |
|
| 292 | - { |
|
| 293 | - return 'EE_PMT_' . $type; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Activates a payment method of the given type. |
|
| 300 | - * |
|
| 301 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
| 302 | - * @return EE_Payment_Method |
|
| 303 | - * @throws EE_Error |
|
| 304 | - */ |
|
| 305 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
| 306 | - { |
|
| 307 | - $this->maybe_register_payment_methods(); |
|
| 308 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
| 309 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
| 310 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
| 311 | - if (class_exists($pm_type_class)) { |
|
| 312 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
| 313 | - $pm_type_obj = new $pm_type_class; |
|
| 314 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
| 315 | - if (! $payment_method) { |
|
| 316 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
| 317 | - } |
|
| 318 | - $payment_method->set_type($payment_method_type); |
|
| 319 | - $this->initialize_payment_method($payment_method); |
|
| 320 | - } else { |
|
| 321 | - throw new EE_Error( |
|
| 322 | - sprintf( |
|
| 323 | - esc_html__( |
|
| 324 | - 'There is no payment method of type %1$s, so it could not be activated', |
|
| 325 | - 'event_espresso' |
|
| 326 | - ), |
|
| 327 | - $pm_type_class |
|
| 328 | - ) |
|
| 329 | - ); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - $payment_method->set_active(); |
|
| 333 | - $payment_method->save(); |
|
| 334 | - if ($payment_method->type() === 'Invoice') { |
|
| 335 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 336 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 337 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
| 338 | - $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
| 339 | - EE_Error::add_persistent_admin_notice( |
|
| 340 | - 'invoice_pm_requirements_notice', |
|
| 341 | - sprintf( |
|
| 342 | - esc_html__( |
|
| 343 | - 'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
| 344 | - 'event_espresso' |
|
| 345 | - ), |
|
| 346 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
| 347 | - '</a>' |
|
| 348 | - ), |
|
| 349 | - true |
|
| 350 | - ); |
|
| 351 | - } |
|
| 352 | - return $payment_method; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Creates a payment method of the specified type. Does not save it. |
|
| 359 | - * |
|
| 360 | - * @global WP_User $current_user |
|
| 361 | - * @param EE_PMT_Base $pm_type_obj |
|
| 362 | - * @return EE_Payment_Method |
|
| 363 | - * @throws EE_Error |
|
| 364 | - */ |
|
| 365 | - public function create_payment_method_of_type($pm_type_obj) |
|
| 366 | - { |
|
| 367 | - global $current_user; |
|
| 368 | - $payment_method = EE_Payment_Method::new_instance( |
|
| 369 | - array( |
|
| 370 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
| 371 | - 'PMD_name' => $pm_type_obj->pretty_name(), |
|
| 372 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
| 373 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
| 374 | - 'PMD_wp_user' => $current_user->ID, |
|
| 375 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
| 376 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
| 377 | - ) * 10, |
|
| 378 | - ) |
|
| 379 | - ); |
|
| 380 | - return $payment_method; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Sets the initial payment method properties (including extra meta) |
|
| 387 | - * |
|
| 388 | - * @param EE_Payment_Method $payment_method |
|
| 389 | - * @return EE_Payment_Method |
|
| 390 | - * @throws EE_Error |
|
| 391 | - */ |
|
| 392 | - public function initialize_payment_method($payment_method) |
|
| 393 | - { |
|
| 394 | - $pm_type_obj = $payment_method->type_obj(); |
|
| 395 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
| 396 | - if (! $payment_method->button_url()) { |
|
| 397 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
| 398 | - } |
|
| 399 | - //now add setup its default extra meta properties |
|
| 400 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
| 401 | - if (! empty($extra_metas)) { |
|
| 402 | - //verify the payment method has an ID before adding extra meta |
|
| 403 | - if (! $payment_method->ID()) { |
|
| 404 | - $payment_method->save(); |
|
| 405 | - } |
|
| 406 | - foreach ($extra_metas as $meta_name => $input) { |
|
| 407 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
| 408 | - } |
|
| 409 | - } |
|
| 410 | - return $payment_method; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Makes sure the payment method is related to the specified payment method |
|
| 417 | - * |
|
| 418 | - * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
| 419 | - * @param EE_Payment_Method $payment_method |
|
| 420 | - * @return EE_Payment_Method |
|
| 421 | - * @throws EE_Error |
|
| 422 | - */ |
|
| 423 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
| 424 | - { |
|
| 425 | - EE_Error::doing_it_wrong( |
|
| 426 | - 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
| 427 | - esc_html__( |
|
| 428 | - 'We no longer define what currencies are usable by payment methods. Its not used nor efficient.', |
|
| 429 | - 'event_espresso' |
|
| 430 | - ), |
|
| 431 | - '4.9.40' |
|
| 432 | - ); |
|
| 433 | - return $payment_method; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * Deactivates a payment method of the given payment method slug. |
|
| 440 | - * |
|
| 441 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
| 442 | - * @return int count of rows updated. |
|
| 443 | - * @throws EE_Error |
|
| 444 | - */ |
|
| 445 | - public function deactivate_payment_method($payment_method_slug) |
|
| 446 | - { |
|
| 447 | - EE_Log::instance()->log( |
|
| 448 | - __FILE__, |
|
| 449 | - __FUNCTION__, |
|
| 450 | - sprintf( |
|
| 451 | - esc_html__( |
|
| 452 | - 'Payment method with slug %1$s is being deactivated by site admin', |
|
| 453 | - 'event_espresso' |
|
| 454 | - ), |
|
| 455 | - $payment_method_slug |
|
| 456 | - ), |
|
| 457 | - 'payment_method_change' |
|
| 458 | - ); |
|
| 459 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
| 460 | - array('PMD_scope' => array()), |
|
| 461 | - array(array('PMD_slug' => $payment_method_slug)) |
|
| 462 | - ); |
|
| 463 | - return $count_updated; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * initializes payment method access caps via EE_Capabilities::init_role_caps() |
|
| 470 | - * upon EE_Payment_Method_Manager construction |
|
| 471 | - * |
|
| 472 | - * @throws EE_Error |
|
| 473 | - * @throws DomainException |
|
| 474 | - */ |
|
| 475 | - protected function initializePaymentMethodCaps() |
|
| 476 | - { |
|
| 477 | - // don't do this twice |
|
| 478 | - if ($this->payment_method_caps_initialized) { |
|
| 479 | - return; |
|
| 480 | - } |
|
| 481 | - EE_Capabilities::instance()->addCaps( |
|
| 482 | - $this->getPaymentMethodCaps() |
|
| 483 | - ); |
|
| 484 | - $this->payment_method_caps_initialized = true; |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * array of dynamic payment method access caps. |
|
| 491 | - * at the time of writing, october 20 2014, these are the caps added: |
|
| 492 | - * ee_payment_method_admin_only |
|
| 493 | - * ee_payment_method_aim |
|
| 494 | - * ee_payment_method_bank |
|
| 495 | - * ee_payment_method_check |
|
| 496 | - * ee_payment_method_invoice |
|
| 497 | - * ee_payment_method_mijireh |
|
| 498 | - * ee_payment_method_paypal_pro |
|
| 499 | - * ee_payment_method_paypal_standard |
|
| 500 | - * Any other payment methods added to core or via addons will also get |
|
| 501 | - * their related capability automatically added too, so long as they are |
|
| 502 | - * registered properly using EE_Register_Payment_Method::register() |
|
| 503 | - * |
|
| 504 | - * @return array |
|
| 505 | - * @throws DomainException |
|
| 506 | - */ |
|
| 507 | - protected function getPaymentMethodCaps() |
|
| 508 | - { |
|
| 509 | - $caps = array(); |
|
| 510 | - foreach ($this->payment_method_type_names() as $payment_method_name) { |
|
| 511 | - $caps = $this->addPaymentMethodCap($payment_method_name,$caps); |
|
| 512 | - } |
|
| 513 | - return $caps; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * @param string $payment_method_name |
|
| 520 | - * @param array $payment_method_caps |
|
| 521 | - * @param string $role |
|
| 522 | - * @return array |
|
| 523 | - * @throws DomainException |
|
| 524 | - */ |
|
| 525 | - public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator') |
|
| 526 | - { |
|
| 527 | - if (empty($payment_method_name)) { |
|
| 528 | - throw new DomainException( |
|
| 529 | - esc_html__( |
|
| 530 | - 'The name of a payment method must be specified to add capabilities.', |
|
| 531 | - 'event_espresso' |
|
| 532 | - ) |
|
| 533 | - ); |
|
| 534 | - } |
|
| 535 | - if (empty($role)) { |
|
| 536 | - throw new DomainException( |
|
| 537 | - sprintf( |
|
| 538 | - esc_html__( |
|
| 539 | - 'No role was supplied while trying to add capabilities for the %1$s payment method.', |
|
| 540 | - 'event_espresso' |
|
| 541 | - ), |
|
| 542 | - $payment_method_name |
|
| 543 | - ) |
|
| 544 | - ); |
|
| 545 | - } |
|
| 546 | - if(! isset($payment_method_caps[$role])) { |
|
| 547 | - $payment_method_caps[$role] = array(); |
|
| 548 | - } |
|
| 549 | - $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
| 550 | - . strtolower($payment_method_name); |
|
| 551 | - return $payment_method_caps; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter |
|
| 558 | - * to add dynamic payment method access caps when capabilities are reset |
|
| 559 | - * (or if that filter is called and PM caps are not already set) |
|
| 560 | - * |
|
| 561 | - * @param array $caps capabilities being filtered |
|
| 562 | - * @param bool $reset |
|
| 563 | - * @return array |
|
| 564 | - * @throws DomainException |
|
| 565 | - */ |
|
| 566 | - public function addPaymentMethodCapsDuringReset(array $caps, $reset = false) |
|
| 567 | - { |
|
| 568 | - if ($reset || ! $this->payment_method_caps_initialized) { |
|
| 569 | - $this->payment_method_caps_initialized = true; |
|
| 570 | - $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps()); |
|
| 571 | - } |
|
| 572 | - return $caps; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * @deprecated 4.9.42 |
|
| 579 | - * @param $caps |
|
| 580 | - * @return mixed |
|
| 581 | - */ |
|
| 582 | - public function add_payment_method_caps($caps) |
|
| 583 | - { |
|
| 584 | - return $caps; |
|
| 585 | - } |
|
| 22 | + /** |
|
| 23 | + * prefix added to all payment method capabilities names |
|
| 24 | + */ |
|
| 25 | + const CAPABILITIES_PREFIX= 'ee_payment_method_'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var EE_Payment_Method_Manager $_instance |
|
| 29 | + */ |
|
| 30 | + private static $_instance; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var boolean |
|
| 34 | + */ |
|
| 35 | + protected $payment_method_caps_initialized = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var array keys are class names without 'EE_PMT_', values are their filepaths |
|
| 39 | + */ |
|
| 40 | + protected $_payment_method_types = array(); |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var EE_PMT_Base[] |
|
| 44 | + */ |
|
| 45 | + protected $payment_method_objects = array(); |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * EE_Payment_Method_Manager constructor. |
|
| 51 | + * |
|
| 52 | + * @throws EE_Error |
|
| 53 | + * @throws DomainException |
|
| 54 | + */ |
|
| 55 | + public function __construct() |
|
| 56 | + { |
|
| 57 | + // if in admin lets ensure caps are set. |
|
| 58 | + if (is_admin()) { |
|
| 59 | + $this->_register_payment_methods(); |
|
| 60 | + // set them immediately |
|
| 61 | + $this->initializePaymentMethodCaps(); |
|
| 62 | + // plus any time they get reset |
|
| 63 | + add_filter( |
|
| 64 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 65 | + array($this, 'addPaymentMethodCapsDuringReset') |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @singleton method used to instantiate class object |
|
| 74 | + * @return EE_Payment_Method_Manager instance |
|
| 75 | + * @throws DomainException |
|
| 76 | + * @throws EE_Error |
|
| 77 | + */ |
|
| 78 | + public static function instance() |
|
| 79 | + { |
|
| 80 | + // check if class object is instantiated, and instantiated properly |
|
| 81 | + if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
| 82 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
| 83 | + self::$_instance = new self(); |
|
| 84 | + } |
|
| 85 | + return self::$_instance; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Resets the instance and returns a new one |
|
| 92 | + * |
|
| 93 | + * @return EE_Payment_Method_Manager |
|
| 94 | + * @throws DomainException |
|
| 95 | + * @throws EE_Error |
|
| 96 | + */ |
|
| 97 | + public static function reset() |
|
| 98 | + { |
|
| 99 | + self::$_instance = null; |
|
| 100 | + return self::instance(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * If necessary, re-register payment methods |
|
| 107 | + * |
|
| 108 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
| 109 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
| 110 | + * we have not yet checked during this request, then we need to check anyways) |
|
| 111 | + */ |
|
| 112 | + public function maybe_register_payment_methods($force_recheck = false) |
|
| 113 | + { |
|
| 114 | + if (! $this->_payment_method_types || $force_recheck) { |
|
| 115 | + $this->_register_payment_methods(); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * register_payment_methods |
|
| 123 | + * |
|
| 124 | + * @return array |
|
| 125 | + */ |
|
| 126 | + protected function _register_payment_methods() |
|
| 127 | + { |
|
| 128 | + // grab list of installed modules |
|
| 129 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
| 130 | + // filter list of modules to register |
|
| 131 | + $pm_to_register = apply_filters( |
|
| 132 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 133 | + $pm_to_register |
|
| 134 | + ); |
|
| 135 | + // remove any duplicates if that should happen for some reason |
|
| 136 | + $pm_to_register = array_unique($pm_to_register); |
|
| 137 | + // loop through folders |
|
| 138 | + foreach ($pm_to_register as $pm_path) { |
|
| 139 | + $this->register_payment_method($pm_path); |
|
| 140 | + } |
|
| 141 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
| 142 | + // filter list of installed modules |
|
| 143 | + //keep them organized alphabetically by the payment method type's name |
|
| 144 | + ksort($this->_payment_method_types); |
|
| 145 | + return apply_filters( |
|
| 146 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
| 147 | + $this->_payment_method_types |
|
| 148 | + ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * register_payment_method- makes core aware of this payment method |
|
| 155 | + * |
|
| 156 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
| 157 | + * @return boolean |
|
| 158 | + */ |
|
| 159 | + public function register_payment_method($payment_method_path = '') |
|
| 160 | + { |
|
| 161 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
| 162 | + $module_ext = '.pm.php'; |
|
| 163 | + // make all separators match |
|
| 164 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
| 165 | + // grab and sanitize module name |
|
| 166 | + $module_dir = basename($payment_method_path); |
|
| 167 | + // create class name from module directory name |
|
| 168 | + $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
|
| 169 | + // add class prefix |
|
| 170 | + $module_class = 'EE_PMT_' . $module; |
|
| 171 | + // does the module exist ? |
|
| 172 | + if (! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
| 173 | + $msg = sprintf( |
|
| 174 | + esc_html__( |
|
| 175 | + 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
| 176 | + 'event_espresso' |
|
| 177 | + ), $module |
|
| 178 | + ); |
|
| 179 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 180 | + return false; |
|
| 181 | + } |
|
| 182 | + // load the module class file |
|
| 183 | + require_once($payment_method_path . DS . $module_class . $module_ext); |
|
| 184 | + // verify that class exists |
|
| 185 | + if (! class_exists($module_class)) { |
|
| 186 | + $msg = sprintf( |
|
| 187 | + esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
|
| 188 | + $module_class |
|
| 189 | + ); |
|
| 190 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + // add to array of registered modules |
|
| 194 | + $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
| 195 | + return true; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Checks if a payment method has been registered, and if so includes it |
|
| 202 | + * |
|
| 203 | + * @param string $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_') |
|
| 204 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 205 | + * @return boolean |
|
| 206 | + */ |
|
| 207 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
| 208 | + { |
|
| 209 | + if ( |
|
| 210 | + $force_recheck |
|
| 211 | + || ! is_array($this->_payment_method_types) |
|
| 212 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
| 213 | + ) { |
|
| 214 | + $this->maybe_register_payment_methods($force_recheck); |
|
| 215 | + } |
|
| 216 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
| 217 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
| 218 | + return true; |
|
| 219 | + } |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Returns all the class names of the various payment method types |
|
| 227 | + * |
|
| 228 | + * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names' |
|
| 229 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
| 230 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 231 | + * @return array |
|
| 232 | + */ |
|
| 233 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
| 234 | + { |
|
| 235 | + $this->maybe_register_payment_methods($force_recheck); |
|
| 236 | + if ($with_prefixes) { |
|
| 237 | + $classnames = array_keys($this->_payment_method_types); |
|
| 238 | + $payment_methods = array(); |
|
| 239 | + foreach ($classnames as $classname) { |
|
| 240 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
| 241 | + } |
|
| 242 | + return $payment_methods; |
|
| 243 | + } |
|
| 244 | + return array_keys($this->_payment_method_types); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Gets an object of each payment method type, none of which are bound to a |
|
| 251 | + * payment method instance |
|
| 252 | + * |
|
| 253 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
| 254 | + * @return EE_PMT_Base[] |
|
| 255 | + */ |
|
| 256 | + public function payment_method_types($force_recheck = false) |
|
| 257 | + { |
|
| 258 | + if ($force_recheck || empty($this->payment_method_objects)) { |
|
| 259 | + $this->maybe_register_payment_methods($force_recheck); |
|
| 260 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
| 261 | + if (! isset($this->payment_method_objects[$classname])) { |
|
| 262 | + $this->payment_method_objects[$classname] = new $classname; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + return $this->payment_method_objects; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Changes the payment method's class name into the payment method type's name |
|
| 273 | + * (as used on the payment method's table's PMD_type field) |
|
| 274 | + * |
|
| 275 | + * @param string $classname |
|
| 276 | + * @return string |
|
| 277 | + */ |
|
| 278 | + public function payment_method_type_sans_class_prefix($classname) |
|
| 279 | + { |
|
| 280 | + return str_replace('EE_PMT_', '', $classname); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Does the opposite of payment-method_type_sans_prefix |
|
| 287 | + * |
|
| 288 | + * @param string $type |
|
| 289 | + * @return string |
|
| 290 | + */ |
|
| 291 | + public function payment_method_class_from_type($type) |
|
| 292 | + { |
|
| 293 | + return 'EE_PMT_' . $type; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Activates a payment method of the given type. |
|
| 300 | + * |
|
| 301 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
| 302 | + * @return EE_Payment_Method |
|
| 303 | + * @throws EE_Error |
|
| 304 | + */ |
|
| 305 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
| 306 | + { |
|
| 307 | + $this->maybe_register_payment_methods(); |
|
| 308 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
| 309 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
| 310 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
| 311 | + if (class_exists($pm_type_class)) { |
|
| 312 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
| 313 | + $pm_type_obj = new $pm_type_class; |
|
| 314 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
| 315 | + if (! $payment_method) { |
|
| 316 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
| 317 | + } |
|
| 318 | + $payment_method->set_type($payment_method_type); |
|
| 319 | + $this->initialize_payment_method($payment_method); |
|
| 320 | + } else { |
|
| 321 | + throw new EE_Error( |
|
| 322 | + sprintf( |
|
| 323 | + esc_html__( |
|
| 324 | + 'There is no payment method of type %1$s, so it could not be activated', |
|
| 325 | + 'event_espresso' |
|
| 326 | + ), |
|
| 327 | + $pm_type_class |
|
| 328 | + ) |
|
| 329 | + ); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + $payment_method->set_active(); |
|
| 333 | + $payment_method->save(); |
|
| 334 | + if ($payment_method->type() === 'Invoice') { |
|
| 335 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 336 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 337 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
| 338 | + $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
| 339 | + EE_Error::add_persistent_admin_notice( |
|
| 340 | + 'invoice_pm_requirements_notice', |
|
| 341 | + sprintf( |
|
| 342 | + esc_html__( |
|
| 343 | + 'The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
| 344 | + 'event_espresso' |
|
| 345 | + ), |
|
| 346 | + '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
| 347 | + '</a>' |
|
| 348 | + ), |
|
| 349 | + true |
|
| 350 | + ); |
|
| 351 | + } |
|
| 352 | + return $payment_method; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Creates a payment method of the specified type. Does not save it. |
|
| 359 | + * |
|
| 360 | + * @global WP_User $current_user |
|
| 361 | + * @param EE_PMT_Base $pm_type_obj |
|
| 362 | + * @return EE_Payment_Method |
|
| 363 | + * @throws EE_Error |
|
| 364 | + */ |
|
| 365 | + public function create_payment_method_of_type($pm_type_obj) |
|
| 366 | + { |
|
| 367 | + global $current_user; |
|
| 368 | + $payment_method = EE_Payment_Method::new_instance( |
|
| 369 | + array( |
|
| 370 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
| 371 | + 'PMD_name' => $pm_type_obj->pretty_name(), |
|
| 372 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
| 373 | + 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
| 374 | + 'PMD_wp_user' => $current_user->ID, |
|
| 375 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
| 376 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
| 377 | + ) * 10, |
|
| 378 | + ) |
|
| 379 | + ); |
|
| 380 | + return $payment_method; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Sets the initial payment method properties (including extra meta) |
|
| 387 | + * |
|
| 388 | + * @param EE_Payment_Method $payment_method |
|
| 389 | + * @return EE_Payment_Method |
|
| 390 | + * @throws EE_Error |
|
| 391 | + */ |
|
| 392 | + public function initialize_payment_method($payment_method) |
|
| 393 | + { |
|
| 394 | + $pm_type_obj = $payment_method->type_obj(); |
|
| 395 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
| 396 | + if (! $payment_method->button_url()) { |
|
| 397 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
| 398 | + } |
|
| 399 | + //now add setup its default extra meta properties |
|
| 400 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
| 401 | + if (! empty($extra_metas)) { |
|
| 402 | + //verify the payment method has an ID before adding extra meta |
|
| 403 | + if (! $payment_method->ID()) { |
|
| 404 | + $payment_method->save(); |
|
| 405 | + } |
|
| 406 | + foreach ($extra_metas as $meta_name => $input) { |
|
| 407 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | + return $payment_method; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Makes sure the payment method is related to the specified payment method |
|
| 417 | + * |
|
| 418 | + * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
| 419 | + * @param EE_Payment_Method $payment_method |
|
| 420 | + * @return EE_Payment_Method |
|
| 421 | + * @throws EE_Error |
|
| 422 | + */ |
|
| 423 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
| 424 | + { |
|
| 425 | + EE_Error::doing_it_wrong( |
|
| 426 | + 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
| 427 | + esc_html__( |
|
| 428 | + 'We no longer define what currencies are usable by payment methods. Its not used nor efficient.', |
|
| 429 | + 'event_espresso' |
|
| 430 | + ), |
|
| 431 | + '4.9.40' |
|
| 432 | + ); |
|
| 433 | + return $payment_method; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * Deactivates a payment method of the given payment method slug. |
|
| 440 | + * |
|
| 441 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
| 442 | + * @return int count of rows updated. |
|
| 443 | + * @throws EE_Error |
|
| 444 | + */ |
|
| 445 | + public function deactivate_payment_method($payment_method_slug) |
|
| 446 | + { |
|
| 447 | + EE_Log::instance()->log( |
|
| 448 | + __FILE__, |
|
| 449 | + __FUNCTION__, |
|
| 450 | + sprintf( |
|
| 451 | + esc_html__( |
|
| 452 | + 'Payment method with slug %1$s is being deactivated by site admin', |
|
| 453 | + 'event_espresso' |
|
| 454 | + ), |
|
| 455 | + $payment_method_slug |
|
| 456 | + ), |
|
| 457 | + 'payment_method_change' |
|
| 458 | + ); |
|
| 459 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
| 460 | + array('PMD_scope' => array()), |
|
| 461 | + array(array('PMD_slug' => $payment_method_slug)) |
|
| 462 | + ); |
|
| 463 | + return $count_updated; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * initializes payment method access caps via EE_Capabilities::init_role_caps() |
|
| 470 | + * upon EE_Payment_Method_Manager construction |
|
| 471 | + * |
|
| 472 | + * @throws EE_Error |
|
| 473 | + * @throws DomainException |
|
| 474 | + */ |
|
| 475 | + protected function initializePaymentMethodCaps() |
|
| 476 | + { |
|
| 477 | + // don't do this twice |
|
| 478 | + if ($this->payment_method_caps_initialized) { |
|
| 479 | + return; |
|
| 480 | + } |
|
| 481 | + EE_Capabilities::instance()->addCaps( |
|
| 482 | + $this->getPaymentMethodCaps() |
|
| 483 | + ); |
|
| 484 | + $this->payment_method_caps_initialized = true; |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * array of dynamic payment method access caps. |
|
| 491 | + * at the time of writing, october 20 2014, these are the caps added: |
|
| 492 | + * ee_payment_method_admin_only |
|
| 493 | + * ee_payment_method_aim |
|
| 494 | + * ee_payment_method_bank |
|
| 495 | + * ee_payment_method_check |
|
| 496 | + * ee_payment_method_invoice |
|
| 497 | + * ee_payment_method_mijireh |
|
| 498 | + * ee_payment_method_paypal_pro |
|
| 499 | + * ee_payment_method_paypal_standard |
|
| 500 | + * Any other payment methods added to core or via addons will also get |
|
| 501 | + * their related capability automatically added too, so long as they are |
|
| 502 | + * registered properly using EE_Register_Payment_Method::register() |
|
| 503 | + * |
|
| 504 | + * @return array |
|
| 505 | + * @throws DomainException |
|
| 506 | + */ |
|
| 507 | + protected function getPaymentMethodCaps() |
|
| 508 | + { |
|
| 509 | + $caps = array(); |
|
| 510 | + foreach ($this->payment_method_type_names() as $payment_method_name) { |
|
| 511 | + $caps = $this->addPaymentMethodCap($payment_method_name,$caps); |
|
| 512 | + } |
|
| 513 | + return $caps; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * @param string $payment_method_name |
|
| 520 | + * @param array $payment_method_caps |
|
| 521 | + * @param string $role |
|
| 522 | + * @return array |
|
| 523 | + * @throws DomainException |
|
| 524 | + */ |
|
| 525 | + public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator') |
|
| 526 | + { |
|
| 527 | + if (empty($payment_method_name)) { |
|
| 528 | + throw new DomainException( |
|
| 529 | + esc_html__( |
|
| 530 | + 'The name of a payment method must be specified to add capabilities.', |
|
| 531 | + 'event_espresso' |
|
| 532 | + ) |
|
| 533 | + ); |
|
| 534 | + } |
|
| 535 | + if (empty($role)) { |
|
| 536 | + throw new DomainException( |
|
| 537 | + sprintf( |
|
| 538 | + esc_html__( |
|
| 539 | + 'No role was supplied while trying to add capabilities for the %1$s payment method.', |
|
| 540 | + 'event_espresso' |
|
| 541 | + ), |
|
| 542 | + $payment_method_name |
|
| 543 | + ) |
|
| 544 | + ); |
|
| 545 | + } |
|
| 546 | + if(! isset($payment_method_caps[$role])) { |
|
| 547 | + $payment_method_caps[$role] = array(); |
|
| 548 | + } |
|
| 549 | + $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
| 550 | + . strtolower($payment_method_name); |
|
| 551 | + return $payment_method_caps; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter |
|
| 558 | + * to add dynamic payment method access caps when capabilities are reset |
|
| 559 | + * (or if that filter is called and PM caps are not already set) |
|
| 560 | + * |
|
| 561 | + * @param array $caps capabilities being filtered |
|
| 562 | + * @param bool $reset |
|
| 563 | + * @return array |
|
| 564 | + * @throws DomainException |
|
| 565 | + */ |
|
| 566 | + public function addPaymentMethodCapsDuringReset(array $caps, $reset = false) |
|
| 567 | + { |
|
| 568 | + if ($reset || ! $this->payment_method_caps_initialized) { |
|
| 569 | + $this->payment_method_caps_initialized = true; |
|
| 570 | + $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps()); |
|
| 571 | + } |
|
| 572 | + return $caps; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * @deprecated 4.9.42 |
|
| 579 | + * @param $caps |
|
| 580 | + * @return mixed |
|
| 581 | + */ |
|
| 582 | + public function add_payment_method_caps($caps) |
|
| 583 | + { |
|
| 584 | + return $caps; |
|
| 585 | + } |
|
| 586 | 586 | |
| 587 | 587 | |
| 588 | 588 | |
@@ -18,149 +18,149 @@ |
||
| 18 | 18 | class EE_Register_Payment_Method implements EEI_Plugin_API |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Holds values for registered payment methods |
|
| 23 | - * |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - protected static $_settings = array(); |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Method for registering new EE_PMT_Base children |
|
| 32 | - * |
|
| 33 | - * @since 4.5.0 |
|
| 34 | - * @param string $payment_method_id a unique identifier for this set of modules Required. |
|
| 35 | - * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
| 36 | - * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
| 37 | - * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
| 38 | - * the files EE_PMT_Payomatic.pm.php) |
|
| 39 | - * } |
|
| 40 | - * @throws EE_Error |
|
| 41 | - * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
| 42 | - * children, or to the EED_Module files themselves |
|
| 43 | - * @return void |
|
| 44 | - * @throws DomainException |
|
| 45 | - */ |
|
| 46 | - public static function register($payment_method_id = null, $setup_args = array()) |
|
| 47 | - { |
|
| 48 | - //required fields MUST be present, so let's make sure they are. |
|
| 49 | - if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
| 50 | - throw new EE_Error( |
|
| 51 | - esc_html__( |
|
| 52 | - 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
| 53 | - 'event_espresso' |
|
| 54 | - ) |
|
| 55 | - ); |
|
| 56 | - } |
|
| 57 | - //make sure we don't register twice |
|
| 58 | - if (isset(self::$_settings[$payment_method_id])) { |
|
| 59 | - return; |
|
| 60 | - } |
|
| 61 | - //make sure this was called in the right place! |
|
| 62 | - if ( |
|
| 63 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 64 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
| 65 | - ) { |
|
| 66 | - EE_Error::doing_it_wrong( |
|
| 67 | - __METHOD__, |
|
| 68 | - esc_html__( |
|
| 69 | - 'An attempt to register modules 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 modules.', |
|
| 70 | - 'event_espresso' |
|
| 71 | - ), |
|
| 72 | - '4.3.0' |
|
| 73 | - ); |
|
| 74 | - } |
|
| 75 | - //setup $_settings array from incoming values. |
|
| 76 | - self::$_settings[$payment_method_id] = array( |
|
| 77 | - // array of full server paths to any EE_PMT_Base children used |
|
| 78 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 79 | - ? (array)$setup_args['payment_method_paths'] |
|
| 80 | - : array(), |
|
| 81 | - ); |
|
| 82 | - // add to list of modules to be registered |
|
| 83 | - add_filter( |
|
| 84 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 85 | - array('EE_Register_Payment_Method', 'add_payment_methods') |
|
| 86 | - ); |
|
| 87 | - // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
| 88 | - // then we need to add our caps for this payment method manually |
|
| 89 | - if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
| 90 | - // register payment methods directly |
|
| 91 | - foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) { |
|
| 92 | - EE_Payment_Method_Manager::instance()->register_payment_method($payment_method_path); |
|
| 93 | - } |
|
| 94 | - EE_Capabilities::instance()->addCaps( |
|
| 95 | - self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id]) |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Filters the list of payment methods to add ours. |
|
| 104 | - * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
| 105 | - * |
|
| 106 | - * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
| 107 | - * @return array |
|
| 108 | - */ |
|
| 109 | - public static function add_payment_methods($payment_method_folders) |
|
| 110 | - { |
|
| 111 | - foreach (self::$_settings as $settings) { |
|
| 112 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
| 113 | - $payment_method_folders[] = $payment_method_path; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - return $payment_method_folders; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * This deregisters a module that was previously registered with a specific $module_id. |
|
| 123 | - * |
|
| 124 | - * @since 4.3.0 |
|
| 125 | - * |
|
| 126 | - * @param string $module_id the name for the module that was previously registered |
|
| 127 | - * @return void |
|
| 128 | - * @throws DomainException |
|
| 129 | - * @throws EE_Error |
|
| 130 | - */ |
|
| 131 | - public static function deregister($module_id = null) |
|
| 132 | - { |
|
| 133 | - if (isset(self::$_settings[$module_id])) { |
|
| 134 | - EE_Capabilities::instance()->removeCaps( |
|
| 135 | - self::getPaymentMethodCapabilities(self::$_settings[$module_id]) |
|
| 136 | - ); |
|
| 137 | - unset(self::$_settings[$module_id]); |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * returns an array of the caps that get added when a Payment Method is registered |
|
| 145 | - * |
|
| 146 | - * @param array $settings |
|
| 147 | - * @return array |
|
| 148 | - * @throws DomainException |
|
| 149 | - * @throws EE_Error |
|
| 150 | - */ |
|
| 151 | - private static function getPaymentMethodCapabilities(array $settings) |
|
| 152 | - { |
|
| 153 | - $payment_method_caps = array('administrator' => array()); |
|
| 154 | - if (isset($settings['payment_method_paths'])) { |
|
| 155 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
| 156 | - $payment_method_caps = EE_Payment_Method_Manager::instance()->addPaymentMethodCap( |
|
| 157 | - strtolower(basename($payment_method_path)), |
|
| 158 | - $payment_method_caps |
|
| 159 | - ); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - return $payment_method_caps; |
|
| 163 | - } |
|
| 21 | + /** |
|
| 22 | + * Holds values for registered payment methods |
|
| 23 | + * |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + protected static $_settings = array(); |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Method for registering new EE_PMT_Base children |
|
| 32 | + * |
|
| 33 | + * @since 4.5.0 |
|
| 34 | + * @param string $payment_method_id a unique identifier for this set of modules Required. |
|
| 35 | + * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
| 36 | + * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
| 37 | + * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
| 38 | + * the files EE_PMT_Payomatic.pm.php) |
|
| 39 | + * } |
|
| 40 | + * @throws EE_Error |
|
| 41 | + * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
| 42 | + * children, or to the EED_Module files themselves |
|
| 43 | + * @return void |
|
| 44 | + * @throws DomainException |
|
| 45 | + */ |
|
| 46 | + public static function register($payment_method_id = null, $setup_args = array()) |
|
| 47 | + { |
|
| 48 | + //required fields MUST be present, so let's make sure they are. |
|
| 49 | + if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
| 50 | + throw new EE_Error( |
|
| 51 | + esc_html__( |
|
| 52 | + 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
| 53 | + 'event_espresso' |
|
| 54 | + ) |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | + //make sure we don't register twice |
|
| 58 | + if (isset(self::$_settings[$payment_method_id])) { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | + //make sure this was called in the right place! |
|
| 62 | + if ( |
|
| 63 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 64 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
| 65 | + ) { |
|
| 66 | + EE_Error::doing_it_wrong( |
|
| 67 | + __METHOD__, |
|
| 68 | + esc_html__( |
|
| 69 | + 'An attempt to register modules 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 modules.', |
|
| 70 | + 'event_espresso' |
|
| 71 | + ), |
|
| 72 | + '4.3.0' |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | + //setup $_settings array from incoming values. |
|
| 76 | + self::$_settings[$payment_method_id] = array( |
|
| 77 | + // array of full server paths to any EE_PMT_Base children used |
|
| 78 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 79 | + ? (array)$setup_args['payment_method_paths'] |
|
| 80 | + : array(), |
|
| 81 | + ); |
|
| 82 | + // add to list of modules to be registered |
|
| 83 | + add_filter( |
|
| 84 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
| 85 | + array('EE_Register_Payment_Method', 'add_payment_methods') |
|
| 86 | + ); |
|
| 87 | + // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
| 88 | + // then we need to add our caps for this payment method manually |
|
| 89 | + if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
| 90 | + // register payment methods directly |
|
| 91 | + foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) { |
|
| 92 | + EE_Payment_Method_Manager::instance()->register_payment_method($payment_method_path); |
|
| 93 | + } |
|
| 94 | + EE_Capabilities::instance()->addCaps( |
|
| 95 | + self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id]) |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Filters the list of payment methods to add ours. |
|
| 104 | + * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
| 105 | + * |
|
| 106 | + * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
| 107 | + * @return array |
|
| 108 | + */ |
|
| 109 | + public static function add_payment_methods($payment_method_folders) |
|
| 110 | + { |
|
| 111 | + foreach (self::$_settings as $settings) { |
|
| 112 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
| 113 | + $payment_method_folders[] = $payment_method_path; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + return $payment_method_folders; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * This deregisters a module that was previously registered with a specific $module_id. |
|
| 123 | + * |
|
| 124 | + * @since 4.3.0 |
|
| 125 | + * |
|
| 126 | + * @param string $module_id the name for the module that was previously registered |
|
| 127 | + * @return void |
|
| 128 | + * @throws DomainException |
|
| 129 | + * @throws EE_Error |
|
| 130 | + */ |
|
| 131 | + public static function deregister($module_id = null) |
|
| 132 | + { |
|
| 133 | + if (isset(self::$_settings[$module_id])) { |
|
| 134 | + EE_Capabilities::instance()->removeCaps( |
|
| 135 | + self::getPaymentMethodCapabilities(self::$_settings[$module_id]) |
|
| 136 | + ); |
|
| 137 | + unset(self::$_settings[$module_id]); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * returns an array of the caps that get added when a Payment Method is registered |
|
| 145 | + * |
|
| 146 | + * @param array $settings |
|
| 147 | + * @return array |
|
| 148 | + * @throws DomainException |
|
| 149 | + * @throws EE_Error |
|
| 150 | + */ |
|
| 151 | + private static function getPaymentMethodCapabilities(array $settings) |
|
| 152 | + { |
|
| 153 | + $payment_method_caps = array('administrator' => array()); |
|
| 154 | + if (isset($settings['payment_method_paths'])) { |
|
| 155 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
| 156 | + $payment_method_caps = EE_Payment_Method_Manager::instance()->addPaymentMethodCap( |
|
| 157 | + strtolower(basename($payment_method_path)), |
|
| 158 | + $payment_method_caps |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + return $payment_method_caps; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | 165 | } |
| 166 | 166 | // End of file EE_Register_Payment_Method.lib.php |
@@ -1047,7 +1047,7 @@ discard block |
||
| 1047 | 1047 | ); |
| 1048 | 1048 | do_action( |
| 1049 | 1049 | 'AHEE__EE_Capabilities__init_role_caps__complete', |
| 1050 | - $capabilities_map |
|
| 1050 | + $capabilities_map |
|
| 1051 | 1051 | ); |
| 1052 | 1052 | } |
| 1053 | 1053 | ); |
@@ -1067,9 +1067,9 @@ discard block |
||
| 1067 | 1067 | 'filter' |
| 1068 | 1068 | ); |
| 1069 | 1069 | return apply_filters( |
| 1070 | - 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
| 1071 | - $existing_attendee, $registration, $attendee_data |
|
| 1072 | - ); |
|
| 1070 | + 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
| 1071 | + $existing_attendee, $registration, $attendee_data |
|
| 1072 | + ); |
|
| 1073 | 1073 | }, |
| 1074 | 1074 | 10,3 |
| 1075 | 1075 | ); |
@@ -1082,88 +1082,88 @@ discard block |
||
| 1082 | 1082 | class EE_Event_List_Query extends WP_Query |
| 1083 | 1083 | { |
| 1084 | 1084 | |
| 1085 | - private $title; |
|
| 1086 | - |
|
| 1087 | - private $css_class; |
|
| 1088 | - |
|
| 1089 | - private $category_slug; |
|
| 1090 | - |
|
| 1091 | - /** |
|
| 1092 | - * EE_Event_List_Query constructor. |
|
| 1093 | - * |
|
| 1094 | - * @param array $args |
|
| 1095 | - */ |
|
| 1096 | - public function __construct($args = array()) |
|
| 1097 | - { |
|
| 1098 | - \EE_Error::doing_it_wrong( |
|
| 1099 | - __METHOD__, |
|
| 1100 | - __( |
|
| 1101 | - 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
| 1102 | - 'event_espresso' |
|
| 1103 | - ), |
|
| 1104 | - '4.9.27', |
|
| 1105 | - '5.0.0' |
|
| 1106 | - ); |
|
| 1107 | - $this->title = isset($args['title']) ? $args['title'] : ''; |
|
| 1108 | - $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
| 1109 | - $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
| 1110 | - $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
| 1111 | - // the current "page" we are viewing |
|
| 1112 | - $paged = max(1, get_query_var('paged')); |
|
| 1113 | - // Force these args |
|
| 1114 | - $args = array_merge( |
|
| 1115 | - $args, array( |
|
| 1116 | - 'post_type' => 'espresso_events', |
|
| 1117 | - 'posts_per_page' => $limit, |
|
| 1118 | - 'update_post_term_cache' => false, |
|
| 1119 | - 'update_post_meta_cache' => false, |
|
| 1120 | - 'paged' => $paged, |
|
| 1121 | - 'offset' => ($paged - 1) * $limit |
|
| 1122 | - ) |
|
| 1123 | - ); |
|
| 1124 | - // run the query |
|
| 1125 | - parent::__construct($args); |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - |
|
| 1130 | - /** |
|
| 1131 | - * event_list_title |
|
| 1132 | - * |
|
| 1133 | - * @param string $event_list_title |
|
| 1134 | - * @return string |
|
| 1135 | - */ |
|
| 1136 | - public function event_list_title($event_list_title = '') |
|
| 1137 | - { |
|
| 1138 | - if (! empty($this->title)) { |
|
| 1139 | - return $this->title; |
|
| 1140 | - } |
|
| 1141 | - return $event_list_title; |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - |
|
| 1145 | - |
|
| 1146 | - /** |
|
| 1147 | - * event_list_css |
|
| 1148 | - * |
|
| 1149 | - * @param string $event_list_css |
|
| 1150 | - * @return string |
|
| 1151 | - */ |
|
| 1152 | - public function event_list_css($event_list_css = '') |
|
| 1153 | - { |
|
| 1154 | - $event_list_css .= ! empty($event_list_css) |
|
| 1155 | - ? ' ' |
|
| 1156 | - : ''; |
|
| 1157 | - $event_list_css .= ! empty($this->css_class) |
|
| 1158 | - ? $this->css_class |
|
| 1159 | - : ''; |
|
| 1160 | - $event_list_css .= ! empty($event_list_css) |
|
| 1161 | - ? ' ' |
|
| 1162 | - : ''; |
|
| 1163 | - $event_list_css .= ! empty($this->category_slug) |
|
| 1164 | - ? $this->category_slug |
|
| 1165 | - : ''; |
|
| 1166 | - return $event_list_css; |
|
| 1167 | - } |
|
| 1085 | + private $title; |
|
| 1086 | + |
|
| 1087 | + private $css_class; |
|
| 1088 | + |
|
| 1089 | + private $category_slug; |
|
| 1090 | + |
|
| 1091 | + /** |
|
| 1092 | + * EE_Event_List_Query constructor. |
|
| 1093 | + * |
|
| 1094 | + * @param array $args |
|
| 1095 | + */ |
|
| 1096 | + public function __construct($args = array()) |
|
| 1097 | + { |
|
| 1098 | + \EE_Error::doing_it_wrong( |
|
| 1099 | + __METHOD__, |
|
| 1100 | + __( |
|
| 1101 | + 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
| 1102 | + 'event_espresso' |
|
| 1103 | + ), |
|
| 1104 | + '4.9.27', |
|
| 1105 | + '5.0.0' |
|
| 1106 | + ); |
|
| 1107 | + $this->title = isset($args['title']) ? $args['title'] : ''; |
|
| 1108 | + $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
| 1109 | + $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
| 1110 | + $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
| 1111 | + // the current "page" we are viewing |
|
| 1112 | + $paged = max(1, get_query_var('paged')); |
|
| 1113 | + // Force these args |
|
| 1114 | + $args = array_merge( |
|
| 1115 | + $args, array( |
|
| 1116 | + 'post_type' => 'espresso_events', |
|
| 1117 | + 'posts_per_page' => $limit, |
|
| 1118 | + 'update_post_term_cache' => false, |
|
| 1119 | + 'update_post_meta_cache' => false, |
|
| 1120 | + 'paged' => $paged, |
|
| 1121 | + 'offset' => ($paged - 1) * $limit |
|
| 1122 | + ) |
|
| 1123 | + ); |
|
| 1124 | + // run the query |
|
| 1125 | + parent::__construct($args); |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * event_list_title |
|
| 1132 | + * |
|
| 1133 | + * @param string $event_list_title |
|
| 1134 | + * @return string |
|
| 1135 | + */ |
|
| 1136 | + public function event_list_title($event_list_title = '') |
|
| 1137 | + { |
|
| 1138 | + if (! empty($this->title)) { |
|
| 1139 | + return $this->title; |
|
| 1140 | + } |
|
| 1141 | + return $event_list_title; |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + |
|
| 1145 | + |
|
| 1146 | + /** |
|
| 1147 | + * event_list_css |
|
| 1148 | + * |
|
| 1149 | + * @param string $event_list_css |
|
| 1150 | + * @return string |
|
| 1151 | + */ |
|
| 1152 | + public function event_list_css($event_list_css = '') |
|
| 1153 | + { |
|
| 1154 | + $event_list_css .= ! empty($event_list_css) |
|
| 1155 | + ? ' ' |
|
| 1156 | + : ''; |
|
| 1157 | + $event_list_css .= ! empty($this->css_class) |
|
| 1158 | + ? $this->css_class |
|
| 1159 | + : ''; |
|
| 1160 | + $event_list_css .= ! empty($event_list_css) |
|
| 1161 | + ? ' ' |
|
| 1162 | + : ''; |
|
| 1163 | + $event_list_css .= ! empty($this->category_slug) |
|
| 1164 | + ? $this->category_slug |
|
| 1165 | + : ''; |
|
| 1166 | + return $event_list_css; |
|
| 1167 | + } |
|
| 1168 | 1168 | |
| 1169 | 1169 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | /** |
| 6 | 6 | * ************************************************************************ |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | $action_or_filter = 'action' |
| 44 | 44 | ) { |
| 45 | 45 | $action_or_filter = $action_or_filter === 'action' |
| 46 | - ? esc_html__( 'action', 'event_espresso' ) |
|
| 47 | - : esc_html__( 'filter', 'event_espresso' ); |
|
| 46 | + ? esc_html__('action', 'event_espresso') |
|
| 47 | + : esc_html__('filter', 'event_espresso'); |
|
| 48 | 48 | EE_Error::doing_it_wrong( |
| 49 | 49 | $deprecated_filter, |
| 50 | 50 | sprintf( |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @param \EE_Checkout $checkout |
| 69 | 69 | * @return string |
| 70 | 70 | */ |
| 71 | -function ee_deprecated__registration_checkout__button_text( $submit_button_text, EE_Checkout $checkout ) { |
|
| 71 | +function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) { |
|
| 72 | 72 | // list of old filters |
| 73 | 73 | $deprecated_filters = array( |
| 74 | 74 | 'update_registration_details' => true, |
@@ -78,16 +78,16 @@ discard block |
||
| 78 | 78 | 'proceed_to' => true, |
| 79 | 79 | ); |
| 80 | 80 | // loop thru and call doing_it_wrong() or remove any that aren't being used |
| 81 | - foreach ( $deprecated_filters as $deprecated_filter => $on ) { |
|
| 81 | + foreach ($deprecated_filters as $deprecated_filter => $on) { |
|
| 82 | 82 | // was this filter called ? |
| 83 | - if ( has_action( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter )) { |
|
| 83 | + if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) { |
|
| 84 | 84 | // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
| 85 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter' ) && ! defined( 'DOING_AJAX' ) ) { |
|
| 85 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter') && ! defined('DOING_AJAX')) { |
|
| 86 | 86 | EE_Error::doing_it_wrong( |
| 87 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
| 87 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
| 88 | 88 | sprintf( |
| 89 | - __( 'The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso' ), |
|
| 90 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
| 89 | + __('The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso'), |
|
| 90 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
| 91 | 91 | '<br />', |
| 92 | 92 | 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
| 93 | 93 | '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
@@ -96,24 +96,24 @@ discard block |
||
| 96 | 96 | ); |
| 97 | 97 | } |
| 98 | 98 | } else { |
| 99 | - unset( $deprecated_filters[ $deprecated_filter ] ); |
|
| 99 | + unset($deprecated_filters[$deprecated_filter]); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | - if ( ! empty( $deprecated_filters )) { |
|
| 103 | - |
|
| 104 | - if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset( $deprecated_filters[ 'update_registration_details' ] )) { |
|
| 105 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text ); |
|
| 106 | - } else if ( $checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset( $deprecated_filters[ 'process_payment' ] ) ) { |
|
| 107 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text ); |
|
| 108 | - } else if ( $checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset( $deprecated_filters[ 'finalize_registration' ] ) ) { |
|
| 109 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text ); |
|
| 102 | + if ( ! empty($deprecated_filters)) { |
|
| 103 | + |
|
| 104 | + if ($checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
|
| 105 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text); |
|
| 106 | + } else if ($checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) { |
|
| 107 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text); |
|
| 108 | + } else if ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) { |
|
| 109 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text); |
|
| 110 | 110 | } |
| 111 | - if ( $checkout->next_step instanceof EE_SPCO_Reg_Step ) { |
|
| 112 | - if ( $checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset( $deprecated_filters[ 'and_proceed_to_payment' ] ) ) { |
|
| 113 | - $submit_button_text .= apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text ); |
|
| 111 | + if ($checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
| 112 | + if ($checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) { |
|
| 113 | + $submit_button_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text); |
|
| 114 | 114 | } |
| 115 | - if ( $checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset( $deprecated_filters[ 'proceed_to' ] ) ) { |
|
| 116 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text ) . $checkout->next_step->name(); |
|
| 115 | + if ($checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) { |
|
| 116 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text).$checkout->next_step->name(); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | return $submit_button_text; |
| 122 | 122 | |
| 123 | 123 | } |
| 124 | -add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2 ); |
|
| 124 | +add_filter('FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2); |
|
| 125 | 125 | |
| 126 | 126 | |
| 127 | 127 | |
@@ -132,16 +132,16 @@ discard block |
||
| 132 | 132 | * @param \EE_Checkout $checkout |
| 133 | 133 | * @param boolean $status_updates |
| 134 | 134 | */ |
| 135 | -function ee_deprecated_finalize_transaction( EE_Checkout $checkout, $status_updates ) { |
|
| 135 | +function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) { |
|
| 136 | 136 | $action_ref = NULL; |
| 137 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__new_transaction' ) ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
| 138 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__all_transaction' ) ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
| 139 | - if ( $action_ref ) { |
|
| 137 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
| 138 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
| 139 | + if ($action_ref) { |
|
| 140 | 140 | |
| 141 | 141 | EE_Error::doing_it_wrong( |
| 142 | 142 | $action_ref, |
| 143 | 143 | sprintf( |
| 144 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso' ), |
|
| 144 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso'), |
|
| 145 | 145 | '<br />', |
| 146 | 146 | '/core/business/EE_Transaction_Processor.class.php', |
| 147 | 147 | 'AHEE__EE_Transaction_Processor__finalize', |
@@ -151,39 +151,39 @@ discard block |
||
| 151 | 151 | ), |
| 152 | 152 | '4.6.0' |
| 153 | 153 | ); |
| 154 | - switch ( $action_ref ) { |
|
| 154 | + switch ($action_ref) { |
|
| 155 | 155 | case 'AHEE__EE_Transaction__finalize__new_transaction' : |
| 156 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request ); |
|
| 156 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request); |
|
| 157 | 157 | break; |
| 158 | 158 | case 'AHEE__EE_Transaction__finalize__all_transaction' : |
| 159 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array( 'new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates ), $checkout->admin_request ); |
|
| 159 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), $checkout->admin_request); |
|
| 160 | 160 | break; |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | -add_action( 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2 ); |
|
| 164 | +add_action('AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2); |
|
| 165 | 165 | /** |
| 166 | 166 | * ee_deprecated_finalize_registration |
| 167 | 167 | * |
| 168 | 168 | * @param EE_Registration $registration |
| 169 | 169 | */ |
| 170 | -function ee_deprecated_finalize_registration( EE_Registration $registration ) { |
|
| 171 | - $action_ref = has_action( 'AHEE__EE_Registration__finalize__update_and_new_reg' ) ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
| 172 | - if ( $action_ref ) { |
|
| 170 | +function ee_deprecated_finalize_registration(EE_Registration $registration) { |
|
| 171 | + $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
| 172 | + if ($action_ref) { |
|
| 173 | 173 | EE_Error::doing_it_wrong( |
| 174 | 174 | $action_ref, |
| 175 | 175 | sprintf( |
| 176 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso' ), |
|
| 176 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso'), |
|
| 177 | 177 | '<br />', |
| 178 | 178 | '/core/business/EE_Registration_Processor.class.php', |
| 179 | 179 | 'AHEE__EE_Registration_Processor__trigger_registration_status_changed_hook' |
| 180 | 180 | ), |
| 181 | 181 | '4.6.0' |
| 182 | 182 | ); |
| 183 | - do_action( 'AHEE__EE_Registration__finalize__update_and_new_reg', $registration, ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ))); |
|
| 183 | + do_action('AHEE__EE_Registration__finalize__update_and_new_reg', $registration, (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | -add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1 ); |
|
| 186 | +add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1); |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | 189 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * Called after EED_Module::set_hooks() and EED_Module::set_admin_hooks() was called. |
| 192 | 192 | * Checks if any deprecated hooks were hooked-into and provide doing_it_wrong messages appropriately. |
| 193 | 193 | */ |
| 194 | -function ee_deprecated_hooks(){ |
|
| 194 | +function ee_deprecated_hooks() { |
|
| 195 | 195 | /** |
| 196 | 196 | * @var $hooks array where keys are hook names, and their values are array{ |
| 197 | 197 | * @type string $version when deprecated |
@@ -202,25 +202,25 @@ discard block |
||
| 202 | 202 | $hooks = array( |
| 203 | 203 | 'AHEE__EE_System___do_setup_validations' => array( |
| 204 | 204 | 'version' => '4.6.0', |
| 205 | - 'alternative' => __( 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso' ), |
|
| 205 | + 'alternative' => __('Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso'), |
|
| 206 | 206 | 'still_works' => FALSE |
| 207 | 207 | ) |
| 208 | 208 | ); |
| 209 | - foreach( $hooks as $name => $deprecation_info ){ |
|
| 210 | - if( has_action( $name ) ){ |
|
| 209 | + foreach ($hooks as $name => $deprecation_info) { |
|
| 210 | + if (has_action($name)) { |
|
| 211 | 211 | EE_Error::doing_it_wrong( |
| 212 | 212 | $name, |
| 213 | 213 | sprintf( |
| 214 | - __('This filter is deprecated. %1$s%2$s','event_espresso'), |
|
| 215 | - $deprecation_info[ 'still_works' ] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __( 'It has been completely removed.', 'event_espresso' ), |
|
| 216 | - isset( $deprecation_info[ 'alternative' ] ) ? $deprecation_info[ 'alternative' ] : __( 'Please read the current EE4 documentation further or contact Support.', 'event_espresso' ) |
|
| 214 | + __('This filter is deprecated. %1$s%2$s', 'event_espresso'), |
|
| 215 | + $deprecation_info['still_works'] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __('It has been completely removed.', 'event_espresso'), |
|
| 216 | + isset($deprecation_info['alternative']) ? $deprecation_info['alternative'] : __('Please read the current EE4 documentation further or contact Support.', 'event_espresso') |
|
| 217 | 217 | ), |
| 218 | - isset( $deprecation_info[ 'version' ] ) ? $deprecation_info[ 'version' ] : __( 'recently', 'event_espresso' ) |
|
| 218 | + isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso') |
|
| 219 | 219 | ); |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | -add_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks' ); |
|
| 223 | +add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks'); |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | 226 | |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | * @return boolean |
| 232 | 232 | */ |
| 233 | 233 | function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() { |
| 234 | - $in_use = has_filter( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns' ) |
|
| 235 | - || has_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' ); |
|
| 236 | - if( $in_use ) { |
|
| 234 | + $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns') |
|
| 235 | + || has_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'); |
|
| 236 | + if ($in_use) { |
|
| 237 | 237 | $msg = __( |
| 238 | 238 | 'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.' |
| 239 | 239 | . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,' |
@@ -242,18 +242,18 @@ discard block |
||
| 242 | 242 | 'event_espresso' ) |
| 243 | 243 | ; |
| 244 | 244 | EE_Error::doing_it_wrong( |
| 245 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 245 | + __CLASS__.'::'.__FUNCTION__, |
|
| 246 | 246 | $msg, |
| 247 | 247 | '4.8.32.rc.000' |
| 248 | 248 | ); |
| 249 | 249 | //it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed |
| 250 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 251 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 250 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
| 251 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | return $in_use; |
| 255 | 255 | } |
| 256 | -add_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' ); |
|
| 256 | +add_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'); |
|
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | 259 | * @deprecated since 4.8.32.rc.000 because it has issues on https://events.codebasehq.com/projects/event-espresso/tickets/9165 |
@@ -262,34 +262,34 @@ discard block |
||
| 262 | 262 | * @param EE_Admin_Page $admin_page |
| 263 | 263 | * @return void |
| 264 | 264 | */ |
| 265 | -function ee_deprecated_update_attendee_registration_form_old( $admin_page ) { |
|
| 265 | +function ee_deprecated_update_attendee_registration_form_old($admin_page) { |
|
| 266 | 266 | //check if the old hooks are in use. If not, do the default |
| 267 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
| 268 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
| 267 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
| 268 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
| 269 | 269 | return; |
| 270 | 270 | } |
| 271 | 271 | $req_data = $admin_page->get_request_data(); |
| 272 | - $qstns = isset( $req_data['qstn'] ) ? $req_data['qstn'] : FALSE; |
|
| 273 | - $REG_ID = isset( $req_data['_REG_ID'] ) ? absint( $req_data['_REG_ID'] ) : FALSE; |
|
| 274 | - $qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns ); |
|
| 275 | - if ( ! $REG_ID || ! $qstns ) { |
|
| 276 | - EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 272 | + $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : FALSE; |
|
| 273 | + $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : FALSE; |
|
| 274 | + $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
|
| 275 | + if ( ! $REG_ID || ! $qstns) { |
|
| 276 | + EE_Error::add_error(__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 277 | 277 | } |
| 278 | 278 | $success = TRUE; |
| 279 | 279 | |
| 280 | 280 | // allow others to get in on this awesome fun :D |
| 281 | - do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns ); |
|
| 281 | + do_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns); |
|
| 282 | 282 | // loop thru questions... FINALLY!!! |
| 283 | 283 | |
| 284 | - foreach ( $qstns as $QST_ID => $qstn ) { |
|
| 284 | + foreach ($qstns as $QST_ID => $qstn) { |
|
| 285 | 285 | //if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
| 286 | - if ( !is_array($qstn) ) { |
|
| 287 | - $success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn); |
|
| 286 | + if ( ! is_array($qstn)) { |
|
| 287 | + $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
|
| 288 | 288 | continue; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
| 292 | - foreach ( $qstn as $ANS_ID => $ANS_value ) { |
|
| 292 | + foreach ($qstn as $ANS_ID => $ANS_value) { |
|
| 293 | 293 | //get answer |
| 294 | 294 | $query_params = array( |
| 295 | 295 | 0 => array( |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | ); |
| 301 | 301 | $answer = EEM_Answer::instance()->get_one($query_params); |
| 302 | 302 | //this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
| 303 | - if ( ! $answer instanceof EE_Answer ) { |
|
| 303 | + if ( ! $answer instanceof EE_Answer) { |
|
| 304 | 304 | $set_values = array( |
| 305 | 305 | 'QST_ID' => $QST_ID, |
| 306 | 306 | 'REG_ID' => $REG_ID, |
@@ -315,11 +315,11 @@ discard block |
||
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | $what = __('Registration Form', 'event_espresso'); |
| 318 | - $route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' ); |
|
| 319 | - $admin_page->redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route ); |
|
| 318 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default'); |
|
| 319 | + $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
| 320 | 320 | exit; |
| 321 | 321 | } |
| 322 | -add_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1 ); |
|
| 322 | +add_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1); |
|
| 323 | 323 | /** |
| 324 | 324 | * Render the registration admin page's custom questions area in the old fashion |
| 325 | 325 | * and firing the old hooks. When this method is removed, we can probably also |
@@ -332,31 +332,31 @@ discard block |
||
| 332 | 332 | * @return bool |
| 333 | 333 | * @throws \EE_Error |
| 334 | 334 | */ |
| 335 | -function ee_deprecated_reg_questions_meta_box_old( $do_default_action, $admin_page, $registration ) { |
|
| 335 | +function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) { |
|
| 336 | 336 | //check if the old hooks are in use. If not, do the default |
| 337 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
| 338 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
| 337 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
| 338 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
| 339 | 339 | return $do_default_action; |
| 340 | 340 | } |
| 341 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $admin_page, 'form_before_question_group' ), 10, 1 ); |
|
| 342 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $admin_page, 'form_after_question_group' ), 10, 1 ); |
|
| 343 | - add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $admin_page, 'form_form_field_label_wrap' ), 10, 1 ); |
|
| 344 | - add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $admin_page, 'form_form_field_input__wrap' ), 10, 1 ); |
|
| 341 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array($admin_page, 'form_before_question_group'), 10, 1); |
|
| 342 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array($admin_page, 'form_after_question_group'), 10, 1); |
|
| 343 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1); |
|
| 344 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1); |
|
| 345 | 345 | |
| 346 | - $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $registration, $registration->get('EVT_ID') ); |
|
| 346 | + $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options($registration, $registration->get('EVT_ID')); |
|
| 347 | 347 | |
| 348 | - EE_Registry::instance()->load_helper( 'Form_Fields' ); |
|
| 348 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
| 349 | 349 | $template_args = array( |
| 350 | - 'att_questions' => EEH_Form_Fields::generate_question_groups_html( $question_groups ), |
|
| 350 | + 'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups), |
|
| 351 | 351 | 'reg_questions_form_action' => 'edit_registration', |
| 352 | 352 | 'REG_ID' => $registration->ID() |
| 353 | 353 | ); |
| 354 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 355 | - echo EEH_Template::display_template( $template_path, $template_args, TRUE ); |
|
| 354 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 355 | + echo EEH_Template::display_template($template_path, $template_args, TRUE); |
|
| 356 | 356 | //indicate that we should not do the default admin page code |
| 357 | 357 | return false; |
| 358 | 358 | } |
| 359 | -add_action( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3 ); |
|
| 359 | +add_action('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3); |
|
| 360 | 360 | |
| 361 | 361 | |
| 362 | 362 | |
@@ -397,9 +397,9 @@ discard block |
||
| 397 | 397 | '4.9.0' |
| 398 | 398 | ); |
| 399 | 399 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
| 400 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
| 401 | - $messenger = $message_resource_manager->get_messenger( $messenger_name ); |
|
| 402 | - $message_type = $message_resource_manager->get_message_type( $message_type_name ); |
|
| 400 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 401 | + $messenger = $message_resource_manager->get_messenger($messenger_name); |
|
| 402 | + $message_type = $message_resource_manager->get_message_type($message_type_name); |
|
| 403 | 403 | return EE_Registry::instance()->load_lib( |
| 404 | 404 | 'Messages_Template_Defaults', |
| 405 | 405 | array( |
@@ -464,15 +464,15 @@ discard block |
||
| 464 | 464 | /** |
| 465 | 465 | * @param string $method |
| 466 | 466 | */ |
| 467 | - public function _class_is_deprecated( $method ) { |
|
| 467 | + public function _class_is_deprecated($method) { |
|
| 468 | 468 | EE_Error::doing_it_wrong( |
| 469 | - 'EE_messages::' . $method, |
|
| 470 | - __( 'EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.' ), |
|
| 469 | + 'EE_messages::'.$method, |
|
| 470 | + __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
|
| 471 | 471 | '4.9.0', |
| 472 | 472 | '4.10.0.p' |
| 473 | 473 | ); |
| 474 | 474 | // Please use EE_Message_Resource_Manager instead |
| 475 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
| 475 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | |
@@ -482,10 +482,10 @@ discard block |
||
| 482 | 482 | * @param string $messenger_name |
| 483 | 483 | * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive |
| 484 | 484 | */ |
| 485 | - public function ensure_messenger_is_active( $messenger_name ) { |
|
| 485 | + public function ensure_messenger_is_active($messenger_name) { |
|
| 486 | 486 | // EE_messages has been deprecated |
| 487 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 488 | - return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name ); |
|
| 487 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 488 | + return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -497,10 +497,10 @@ discard block |
||
| 497 | 497 | * @return bool true if it got activated (or was active) and false if not. |
| 498 | 498 | * @throws \EE_Error |
| 499 | 499 | */ |
| 500 | - public function ensure_message_type_is_active( $message_type, $messenger ) { |
|
| 500 | + public function ensure_message_type_is_active($message_type, $messenger) { |
|
| 501 | 501 | // EE_messages has been deprecated |
| 502 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 503 | - return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger ); |
|
| 502 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 503 | + return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | |
@@ -513,10 +513,10 @@ discard block |
||
| 513 | 513 | * they are already setup.) |
| 514 | 514 | * @return boolean an array of generated templates or false if nothing generated/activated. |
| 515 | 515 | */ |
| 516 | - public function activate_messenger( $messenger_name, $mts_to_activate = array() ) { |
|
| 516 | + public function activate_messenger($messenger_name, $mts_to_activate = array()) { |
|
| 517 | 517 | // EE_messages has been deprecated |
| 518 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 519 | - return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate ); |
|
| 518 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 519 | + return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | |
@@ -528,10 +528,10 @@ discard block |
||
| 528 | 528 | * |
| 529 | 529 | * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
| 530 | 530 | */ |
| 531 | - public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) { |
|
| 531 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) { |
|
| 532 | 532 | // EE_messages has been deprecated |
| 533 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 534 | - return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type ); |
|
| 533 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 534 | + return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | |
@@ -541,10 +541,10 @@ discard block |
||
| 541 | 541 | * @param string $messenger |
| 542 | 542 | * @return EE_messenger | null |
| 543 | 543 | */ |
| 544 | - public function get_messenger_if_active( $messenger ) { |
|
| 544 | + public function get_messenger_if_active($messenger) { |
|
| 545 | 545 | // EE_messages has been deprecated |
| 546 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 547 | - return $this->_message_resource_manager->get_active_messenger( $messenger ); |
|
| 546 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 547 | + return $this->_message_resource_manager->get_active_messenger($messenger); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -565,9 +565,9 @@ discard block |
||
| 565 | 565 | * 'message_type' => null |
| 566 | 566 | * ) |
| 567 | 567 | */ |
| 568 | - public function validate_for_use( EE_Message $message ) { |
|
| 568 | + public function validate_for_use(EE_Message $message) { |
|
| 569 | 569 | // EE_messages has been deprecated |
| 570 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 570 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 571 | 571 | return array( |
| 572 | 572 | 'messenger' => $message->messenger_object(), |
| 573 | 573 | 'message_type' => $message->message_type_object(), |
@@ -595,41 +595,41 @@ discard block |
||
| 595 | 595 | $send = true |
| 596 | 596 | ) { |
| 597 | 597 | // EE_messages has been deprecated |
| 598 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 598 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 599 | 599 | /** @type EE_Messages_Processor $processor */ |
| 600 | - $processor = EE_Registry::instance()->load_lib( 'Messages_Processor' ); |
|
| 600 | + $processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 601 | 601 | $error = false; |
| 602 | 602 | //try to intelligently determine what method we'll call based on the incoming data. |
| 603 | 603 | //if generating and sending are different then generate and send immediately. |
| 604 | - if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) { |
|
| 604 | + if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
| 605 | 605 | //in the legacy system, when generating and sending were different, that means all the |
| 606 | 606 | //vars are already in the request object. So let's just use that. |
| 607 | 607 | try { |
| 608 | 608 | /** @type EE_Message_To_Generate_From_Request $mtg */ |
| 609 | - $mtg = EE_Registry::instance()->load_lib( 'Message_To_Generate_From_Request' ); |
|
| 610 | - $processor->generate_and_send_now( $mtg ); |
|
| 611 | - } catch ( EE_Error $e ) { |
|
| 609 | + $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 610 | + $processor->generate_and_send_now($mtg); |
|
| 611 | + } catch (EE_Error $e) { |
|
| 612 | 612 | $error_msg = __( |
| 613 | 613 | 'Please note that a system message failed to send due to a technical issue.', |
| 614 | 614 | 'event_espresso' |
| 615 | 615 | ); |
| 616 | 616 | // add specific message for developers if WP_DEBUG in on |
| 617 | - $error_msg .= '||' . $e->getMessage(); |
|
| 618 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 617 | + $error_msg .= '||'.$e->getMessage(); |
|
| 618 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 619 | 619 | $error = true; |
| 620 | 620 | } |
| 621 | 621 | } else { |
| 622 | - $processor->generate_for_all_active_messengers( $type, $vars, $send ); |
|
| 622 | + $processor->generate_for_all_active_messengers($type, $vars, $send); |
|
| 623 | 623 | //let's find out if there were any errors and how many successfully were queued. |
| 624 | 624 | $count_errors = $processor->get_queue()->count_STS_in_queue( |
| 625 | - array( EEM_Message::status_failed, EEM_Message::status_debug_only ) |
|
| 625 | + array(EEM_Message::status_failed, EEM_Message::status_debug_only) |
|
| 626 | 626 | ); |
| 627 | - $count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete ); |
|
| 628 | - $count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry ); |
|
| 627 | + $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete); |
|
| 628 | + $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry); |
|
| 629 | 629 | $count_errors = $count_errors + $count_retry; |
| 630 | - if ( $count_errors > 0 ) { |
|
| 630 | + if ($count_errors > 0) { |
|
| 631 | 631 | $error = true; |
| 632 | - if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1 ) { |
|
| 632 | + if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) { |
|
| 633 | 633 | $message = sprintf( |
| 634 | 634 | __( |
| 635 | 635 | 'There were %d errors and %d messages successfully queued for generation and sending', |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | $count_errors, |
| 639 | 639 | $count_queued |
| 640 | 640 | ); |
| 641 | - } elseif ( $count_errors > 1 && $count_queued === 1 ) { |
|
| 641 | + } elseif ($count_errors > 1 && $count_queued === 1) { |
|
| 642 | 642 | $message = sprintf( |
| 643 | 643 | __( |
| 644 | 644 | 'There were %d errors and %d message successfully queued for generation.', |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | $count_errors, |
| 648 | 648 | $count_queued |
| 649 | 649 | ); |
| 650 | - } elseif ( $count_errors === 1 && $count_queued > 1 ) { |
|
| 650 | + } elseif ($count_errors === 1 && $count_queued > 1) { |
|
| 651 | 651 | $message = sprintf( |
| 652 | 652 | __( |
| 653 | 653 | 'There was %d error and %d messages successfully queued for generation.', |
@@ -665,9 +665,9 @@ discard block |
||
| 665 | 665 | $count_errors |
| 666 | 666 | ); |
| 667 | 667 | } |
| 668 | - EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 668 | + EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__); |
|
| 669 | 669 | } else { |
| 670 | - if ( $count_queued === 1 ) { |
|
| 670 | + if ($count_queued === 1) { |
|
| 671 | 671 | $message = sprintf( |
| 672 | 672 | __( |
| 673 | 673 | '%d message successfully queued for generation.', |
@@ -684,18 +684,18 @@ discard block |
||
| 684 | 684 | $count_queued |
| 685 | 685 | ); |
| 686 | 686 | } |
| 687 | - EE_Error::add_success( $message ); |
|
| 687 | + EE_Error::add_success($message); |
|
| 688 | 688 | } |
| 689 | 689 | } |
| 690 | 690 | //if no error then return the generated message(s). |
| 691 | - if ( ! $error && ! $send ) { |
|
| 692 | - $generated_queue = $processor->generate_queue( false ); |
|
| 691 | + if ( ! $error && ! $send) { |
|
| 692 | + $generated_queue = $processor->generate_queue(false); |
|
| 693 | 693 | //get message and return. |
| 694 | 694 | $generated_queue->get_message_repository()->rewind(); |
| 695 | 695 | $messages = array(); |
| 696 | - while ( $generated_queue->get_message_repository()->valid() ) { |
|
| 696 | + while ($generated_queue->get_message_repository()->valid()) { |
|
| 697 | 697 | $message = $generated_queue->get_message_repository()->current(); |
| 698 | - if ( $message instanceof EE_Message ) { |
|
| 698 | + if ($message instanceof EE_Message) { |
|
| 699 | 699 | //set properties that might be expected by add-ons (backward compat) |
| 700 | 700 | $message->content = $message->content(); |
| 701 | 701 | $message->template_pack = $message->get_template_pack(); |
@@ -720,10 +720,10 @@ discard block |
||
| 720 | 720 | * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular preview |
| 721 | 721 | * @return string The body of the message. |
| 722 | 722 | */ |
| 723 | - public function preview_message( $type, $context, $messenger, $send = false ) { |
|
| 723 | + public function preview_message($type, $context, $messenger, $send = false) { |
|
| 724 | 724 | // EE_messages has been deprecated |
| 725 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 726 | - return EED_Messages::preview_message( $type, $context, $messenger, $send ); |
|
| 725 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 726 | + return EED_Messages::preview_message($type, $context, $messenger, $send); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | |
@@ -737,14 +737,14 @@ discard block |
||
| 737 | 737 | * |
| 738 | 738 | * @return bool success or fail. |
| 739 | 739 | */ |
| 740 | - public function send_message_with_messenger_only( $messenger, $message_type, $message ) { |
|
| 740 | + public function send_message_with_messenger_only($messenger, $message_type, $message) { |
|
| 741 | 741 | // EE_messages has been deprecated |
| 742 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 742 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 743 | 743 | //setup for sending to new method. |
| 744 | 744 | /** @type EE_Messages_Queue $queue */ |
| 745 | - $queue = EE_Registry::instance()->load_lib( 'Messages_Queue' ); |
|
| 745 | + $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
|
| 746 | 746 | //make sure we have a proper message object |
| 747 | - if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) { |
|
| 747 | + if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
| 748 | 748 | $msg = EE_Message_Factory::create( |
| 749 | 749 | array( |
| 750 | 750 | 'MSG_messenger' => $messenger, |
@@ -756,15 +756,15 @@ discard block |
||
| 756 | 756 | } else { |
| 757 | 757 | $msg = $message; |
| 758 | 758 | } |
| 759 | - if ( ! $msg instanceof EE_Message ) { |
|
| 759 | + if ( ! $msg instanceof EE_Message) { |
|
| 760 | 760 | return false; |
| 761 | 761 | } |
| 762 | 762 | //make sure any content in a content property (if not empty) is set on the MSG_content. |
| 763 | - if ( ! empty( $msg->content ) ) { |
|
| 764 | - $msg->set( 'MSG_content', $msg->content ); |
|
| 763 | + if ( ! empty($msg->content)) { |
|
| 764 | + $msg->set('MSG_content', $msg->content); |
|
| 765 | 765 | } |
| 766 | - $queue->add( $msg ); |
|
| 767 | - return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue ); |
|
| 766 | + $queue->add($msg); |
|
| 767 | + return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | |
@@ -778,11 +778,11 @@ discard block |
||
| 778 | 778 | * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned. |
| 779 | 779 | * @throws \EE_Error |
| 780 | 780 | */ |
| 781 | - public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) { |
|
| 781 | + public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) { |
|
| 782 | 782 | // EE_messages has been deprecated |
| 783 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 784 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
| 785 | - return EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $is_global ); |
|
| 783 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 784 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 785 | + return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | |
@@ -793,11 +793,11 @@ discard block |
||
| 793 | 793 | * @param string $message_type_name name of EE_message_type |
| 794 | 794 | * @return array |
| 795 | 795 | */ |
| 796 | - public function get_fields( $messenger_name, $message_type_name ) { |
|
| 796 | + public function get_fields($messenger_name, $message_type_name) { |
|
| 797 | 797 | // EE_messages has been deprecated |
| 798 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 799 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
| 800 | - return EEH_MSG_Template::get_fields( $messenger_name, $message_type_name ); |
|
| 798 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 799 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 800 | + return EEH_MSG_Template::get_fields($messenger_name, $message_type_name); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | |
@@ -811,13 +811,13 @@ discard block |
||
| 811 | 811 | * @return array multidimensional array of messenger and message_type objects |
| 812 | 812 | * (messengers index, and message_type index); |
| 813 | 813 | */ |
| 814 | - public function get_installed( $type = 'all', $skip_cache = false ) { |
|
| 814 | + public function get_installed($type = 'all', $skip_cache = false) { |
|
| 815 | 815 | // EE_messages has been deprecated |
| 816 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 817 | - if ( $skip_cache ) { |
|
| 816 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 817 | + if ($skip_cache) { |
|
| 818 | 818 | $this->_message_resource_manager->reset_active_messengers_and_message_types(); |
| 819 | 819 | } |
| 820 | - switch ( $type ) { |
|
| 820 | + switch ($type) { |
|
| 821 | 821 | case 'messengers' : |
| 822 | 822 | return array( |
| 823 | 823 | 'messenger' => $this->_message_resource_manager->installed_messengers(), |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | */ |
| 847 | 847 | public function get_active_messengers() { |
| 848 | 848 | // EE_messages has been deprecated |
| 849 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 849 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 850 | 850 | return $this->_message_resource_manager->active_messengers(); |
| 851 | 851 | } |
| 852 | 852 | |
@@ -858,7 +858,7 @@ discard block |
||
| 858 | 858 | */ |
| 859 | 859 | public function get_active_message_types() { |
| 860 | 860 | // EE_messages has been deprecated |
| 861 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 861 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 862 | 862 | return $this->_message_resource_manager->list_of_active_message_types(); |
| 863 | 863 | } |
| 864 | 864 | |
@@ -870,7 +870,7 @@ discard block |
||
| 870 | 870 | */ |
| 871 | 871 | public function get_active_message_type_objects() { |
| 872 | 872 | // EE_messages has been deprecated |
| 873 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 873 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 874 | 874 | return $this->_message_resource_manager->get_active_message_type_objects(); |
| 875 | 875 | } |
| 876 | 876 | |
@@ -882,10 +882,10 @@ discard block |
||
| 882 | 882 | * @param string $messenger The messenger being checked |
| 883 | 883 | * @return EE_message_type[] (or empty array if none present) |
| 884 | 884 | */ |
| 885 | - public function get_active_message_types_per_messenger( $messenger ) { |
|
| 885 | + public function get_active_message_types_per_messenger($messenger) { |
|
| 886 | 886 | // EE_messages has been deprecated |
| 887 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 888 | - return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger ); |
|
| 887 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 888 | + return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | |
@@ -896,10 +896,10 @@ discard block |
||
| 896 | 896 | * @param string $message_type The string should correspond to a message type. |
| 897 | 897 | * @return EE_message_type|null |
| 898 | 898 | */ |
| 899 | - public function get_active_message_type( $messenger, $message_type ) { |
|
| 899 | + public function get_active_message_type($messenger, $message_type) { |
|
| 900 | 900 | // EE_messages has been deprecated |
| 901 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 902 | - return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type ); |
|
| 901 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 902 | + return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type); |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | |
@@ -910,7 +910,7 @@ discard block |
||
| 910 | 910 | */ |
| 911 | 911 | public function get_installed_message_types() { |
| 912 | 912 | // EE_messages has been deprecated |
| 913 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 913 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 914 | 914 | return $this->_message_resource_manager->installed_message_types(); |
| 915 | 915 | } |
| 916 | 916 | |
@@ -922,7 +922,7 @@ discard block |
||
| 922 | 922 | */ |
| 923 | 923 | public function get_installed_messengers() { |
| 924 | 924 | // EE_messages has been deprecated |
| 925 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 925 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 926 | 926 | return $this->_message_resource_manager->installed_messengers(); |
| 927 | 927 | } |
| 928 | 928 | |
@@ -933,10 +933,10 @@ discard block |
||
| 933 | 933 | * @param bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by message type. |
| 934 | 934 | * @return array |
| 935 | 935 | */ |
| 936 | - public function get_all_contexts( $slugs_only = true ) { |
|
| 936 | + public function get_all_contexts($slugs_only = true) { |
|
| 937 | 937 | // EE_messages has been deprecated |
| 938 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
| 939 | - return $this->_message_resource_manager->get_all_contexts( $slugs_only ); |
|
| 938 | + $this->_class_is_deprecated(__FUNCTION__); |
|
| 939 | + return $this->_message_resource_manager->get_all_contexts($slugs_only); |
|
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | |
@@ -995,7 +995,7 @@ discard block |
||
| 995 | 995 | add_filter( |
| 996 | 996 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
| 997 | 997 | function($event_list_iframe_css) { |
| 998 | - if ( ! has_filter( 'FHEE__EventsArchiveIframe__event_list_iframe__css' )) { |
|
| 998 | + if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
| 999 | 999 | return $event_list_iframe_css; |
| 1000 | 1000 | } |
| 1001 | 1001 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | add_filter( |
| 1016 | 1016 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
| 1017 | 1017 | function($event_list_iframe_js) { |
| 1018 | - if ( ! has_filter( 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js' )) { |
|
| 1018 | + if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
| 1019 | 1019 | return $event_list_iframe_js; |
| 1020 | 1020 | } |
| 1021 | 1021 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1035,7 +1035,7 @@ discard block |
||
| 1035 | 1035 | add_action( |
| 1036 | 1036 | 'AHEE__EE_Capabilities__addCaps__complete', |
| 1037 | 1037 | function($capabilities_map) { |
| 1038 | - if ( ! has_action( 'AHEE__EE_Capabilities__init_role_caps__complete' )) { |
|
| 1038 | + if ( ! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
| 1039 | 1039 | return; |
| 1040 | 1040 | } |
| 1041 | 1041 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1055,7 +1055,7 @@ discard block |
||
| 1055 | 1055 | add_filter( |
| 1056 | 1056 | 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
| 1057 | 1057 | function($existing_attendee, $registration, $attendee_data) { |
| 1058 | - if ( ! has_filter( 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee' )) { |
|
| 1058 | + if ( ! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
| 1059 | 1059 | return $existing_attendee; |
| 1060 | 1060 | } |
| 1061 | 1061 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1071,7 +1071,7 @@ discard block |
||
| 1071 | 1071 | $existing_attendee, $registration, $attendee_data |
| 1072 | 1072 | ); |
| 1073 | 1073 | }, |
| 1074 | - 10,3 |
|
| 1074 | + 10, 3 |
|
| 1075 | 1075 | ); |
| 1076 | 1076 | |
| 1077 | 1077 | /** |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | */ |
| 1136 | 1136 | public function event_list_title($event_list_title = '') |
| 1137 | 1137 | { |
| 1138 | - if (! empty($this->title)) { |
|
| 1138 | + if ( ! empty($this->title)) { |
|
| 1139 | 1139 | return $this->title; |
| 1140 | 1140 | } |
| 1141 | 1141 | return $event_list_title; |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 5 | - exit('No direct script access allowed'); |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -17,243 +17,243 @@ discard block |
||
| 17 | 17 | class EEH_Activation implements ResettableInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * constant used to indicate a cron task is no longer in use |
|
| 22 | - */ |
|
| 23 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * option name that will indicate whether or not we still |
|
| 27 | - * need to create EE's folders in the uploads directory |
|
| 28 | - * (because if EE was installed without file system access, |
|
| 29 | - * we need to request credentials before we can create them) |
|
| 30 | - */ |
|
| 31 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * WP_User->ID |
|
| 35 | - * |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - private static $_default_creator_id; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * indicates whether or not we've already verified core's default data during this request, |
|
| 42 | - * because after migrations are done, any addons activated while in maintenance mode |
|
| 43 | - * will want to setup their own default data, and they might hook into core's default data |
|
| 44 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 45 | - * This prevents doing that for EVERY single addon. |
|
| 46 | - * |
|
| 47 | - * @var boolean |
|
| 48 | - */ |
|
| 49 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 53 | - */ |
|
| 54 | - private static $table_analysis; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 58 | - */ |
|
| 59 | - private static $table_manager; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 64 | - */ |
|
| 65 | - public static function getTableAnalysis() |
|
| 66 | - { |
|
| 67 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 68 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 69 | - } |
|
| 70 | - return self::$table_analysis; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @return \EventEspresso\core\services\database\TableManager |
|
| 76 | - */ |
|
| 77 | - public static function getTableManager() |
|
| 78 | - { |
|
| 79 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 80 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 81 | - } |
|
| 82 | - return self::$table_manager; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * _ensure_table_name_has_prefix |
|
| 88 | - * |
|
| 89 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 90 | - * @access public |
|
| 91 | - * @static |
|
| 92 | - * @param $table_name |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public static function ensure_table_name_has_prefix($table_name) |
|
| 96 | - { |
|
| 97 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * system_initialization |
|
| 103 | - * ensures the EE configuration settings are loaded with at least default options set |
|
| 104 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @static |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - public static function system_initialization() |
|
| 111 | - { |
|
| 112 | - EEH_Activation::reset_and_update_config(); |
|
| 113 | - //which is fired BEFORE activation of plugin anyways |
|
| 114 | - EEH_Activation::verify_default_pages_exist(); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Sets the database schema and creates folders. This should |
|
| 120 | - * be called on plugin activation and reactivation |
|
| 121 | - * |
|
| 122 | - * @return boolean success, whether the database and folders are setup properly |
|
| 123 | - * @throws \EE_Error |
|
| 124 | - */ |
|
| 125 | - public static function initialize_db_and_folders() |
|
| 126 | - { |
|
| 127 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 128 | - $good_db = EEH_Activation::create_database_tables(); |
|
| 129 | - return $good_filesystem && $good_db; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * assuming we have an up-to-date database schema, this will populate it |
|
| 135 | - * with default and initial data. This should be called |
|
| 136 | - * upon activation of a new plugin, reactivation, and at the end |
|
| 137 | - * of running migration scripts |
|
| 138 | - * |
|
| 139 | - * @throws \EE_Error |
|
| 140 | - */ |
|
| 141 | - public static function initialize_db_content() |
|
| 142 | - { |
|
| 143 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 144 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 145 | - return; |
|
| 146 | - } |
|
| 147 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 148 | - |
|
| 149 | - EEH_Activation::initialize_system_questions(); |
|
| 150 | - EEH_Activation::insert_default_status_codes(); |
|
| 151 | - EEH_Activation::generate_default_message_templates(); |
|
| 152 | - EEH_Activation::create_no_ticket_prices_array(); |
|
| 153 | - |
|
| 154 | - EEH_Activation::validate_messages_system(); |
|
| 155 | - EEH_Activation::insert_default_payment_methods(); |
|
| 156 | - //in case we've |
|
| 157 | - EEH_Activation::remove_cron_tasks(); |
|
| 158 | - EEH_Activation::create_cron_tasks(); |
|
| 159 | - // remove all TXN locks since that is being done via extra meta now |
|
| 160 | - delete_option('ee_locked_transactions'); |
|
| 161 | - //also, check for CAF default db content |
|
| 162 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 163 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 164 | - //which users really won't care about on initial activation |
|
| 165 | - EE_Error::overwrite_success(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 171 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 172 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 173 | - * (null) |
|
| 174 | - * |
|
| 175 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 176 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 177 | - * @return array |
|
| 178 | - * @throws \EE_Error |
|
| 179 | - */ |
|
| 180 | - public static function get_cron_tasks($which_to_include) |
|
| 181 | - { |
|
| 182 | - $cron_tasks = apply_filters( |
|
| 183 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 184 | - array( |
|
| 185 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 20 | + /** |
|
| 21 | + * constant used to indicate a cron task is no longer in use |
|
| 22 | + */ |
|
| 23 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * option name that will indicate whether or not we still |
|
| 27 | + * need to create EE's folders in the uploads directory |
|
| 28 | + * (because if EE was installed without file system access, |
|
| 29 | + * we need to request credentials before we can create them) |
|
| 30 | + */ |
|
| 31 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * WP_User->ID |
|
| 35 | + * |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + private static $_default_creator_id; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * indicates whether or not we've already verified core's default data during this request, |
|
| 42 | + * because after migrations are done, any addons activated while in maintenance mode |
|
| 43 | + * will want to setup their own default data, and they might hook into core's default data |
|
| 44 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 45 | + * This prevents doing that for EVERY single addon. |
|
| 46 | + * |
|
| 47 | + * @var boolean |
|
| 48 | + */ |
|
| 49 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 53 | + */ |
|
| 54 | + private static $table_analysis; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 58 | + */ |
|
| 59 | + private static $table_manager; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 64 | + */ |
|
| 65 | + public static function getTableAnalysis() |
|
| 66 | + { |
|
| 67 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 68 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 69 | + } |
|
| 70 | + return self::$table_analysis; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @return \EventEspresso\core\services\database\TableManager |
|
| 76 | + */ |
|
| 77 | + public static function getTableManager() |
|
| 78 | + { |
|
| 79 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 80 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 81 | + } |
|
| 82 | + return self::$table_manager; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * _ensure_table_name_has_prefix |
|
| 88 | + * |
|
| 89 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 90 | + * @access public |
|
| 91 | + * @static |
|
| 92 | + * @param $table_name |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public static function ensure_table_name_has_prefix($table_name) |
|
| 96 | + { |
|
| 97 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * system_initialization |
|
| 103 | + * ensures the EE configuration settings are loaded with at least default options set |
|
| 104 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @static |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + public static function system_initialization() |
|
| 111 | + { |
|
| 112 | + EEH_Activation::reset_and_update_config(); |
|
| 113 | + //which is fired BEFORE activation of plugin anyways |
|
| 114 | + EEH_Activation::verify_default_pages_exist(); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Sets the database schema and creates folders. This should |
|
| 120 | + * be called on plugin activation and reactivation |
|
| 121 | + * |
|
| 122 | + * @return boolean success, whether the database and folders are setup properly |
|
| 123 | + * @throws \EE_Error |
|
| 124 | + */ |
|
| 125 | + public static function initialize_db_and_folders() |
|
| 126 | + { |
|
| 127 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 128 | + $good_db = EEH_Activation::create_database_tables(); |
|
| 129 | + return $good_filesystem && $good_db; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * assuming we have an up-to-date database schema, this will populate it |
|
| 135 | + * with default and initial data. This should be called |
|
| 136 | + * upon activation of a new plugin, reactivation, and at the end |
|
| 137 | + * of running migration scripts |
|
| 138 | + * |
|
| 139 | + * @throws \EE_Error |
|
| 140 | + */ |
|
| 141 | + public static function initialize_db_content() |
|
| 142 | + { |
|
| 143 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 144 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 145 | + return; |
|
| 146 | + } |
|
| 147 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 148 | + |
|
| 149 | + EEH_Activation::initialize_system_questions(); |
|
| 150 | + EEH_Activation::insert_default_status_codes(); |
|
| 151 | + EEH_Activation::generate_default_message_templates(); |
|
| 152 | + EEH_Activation::create_no_ticket_prices_array(); |
|
| 153 | + |
|
| 154 | + EEH_Activation::validate_messages_system(); |
|
| 155 | + EEH_Activation::insert_default_payment_methods(); |
|
| 156 | + //in case we've |
|
| 157 | + EEH_Activation::remove_cron_tasks(); |
|
| 158 | + EEH_Activation::create_cron_tasks(); |
|
| 159 | + // remove all TXN locks since that is being done via extra meta now |
|
| 160 | + delete_option('ee_locked_transactions'); |
|
| 161 | + //also, check for CAF default db content |
|
| 162 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 163 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 164 | + //which users really won't care about on initial activation |
|
| 165 | + EE_Error::overwrite_success(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 171 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 172 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 173 | + * (null) |
|
| 174 | + * |
|
| 175 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 176 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 177 | + * @return array |
|
| 178 | + * @throws \EE_Error |
|
| 179 | + */ |
|
| 180 | + public static function get_cron_tasks($which_to_include) |
|
| 181 | + { |
|
| 182 | + $cron_tasks = apply_filters( |
|
| 183 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 184 | + array( |
|
| 185 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 186 | 186 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
| 187 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 188 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 189 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 190 | - ) |
|
| 191 | - ); |
|
| 192 | - if ($which_to_include === 'old') { |
|
| 193 | - $cron_tasks = array_filter( |
|
| 194 | - $cron_tasks, |
|
| 195 | - function ($value) { |
|
| 196 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 197 | - } |
|
| 198 | - ); |
|
| 199 | - } elseif ($which_to_include === 'current') { |
|
| 200 | - $cron_tasks = array_filter($cron_tasks); |
|
| 201 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 202 | - throw new EE_Error( |
|
| 203 | - sprintf( |
|
| 204 | - __( |
|
| 205 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 206 | - 'event_espresso' |
|
| 207 | - ), |
|
| 208 | - $which_to_include |
|
| 209 | - ) |
|
| 210 | - ); |
|
| 211 | - } |
|
| 212 | - return $cron_tasks; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 218 | - * |
|
| 219 | - * @throws \EE_Error |
|
| 220 | - */ |
|
| 221 | - public static function create_cron_tasks() |
|
| 222 | - { |
|
| 223 | - |
|
| 224 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 225 | - if (! wp_next_scheduled($hook_name)) { |
|
| 226 | - /** |
|
| 227 | - * This allows client code to define the initial start timestamp for this schedule. |
|
| 228 | - */ |
|
| 229 | - if (is_array($frequency) |
|
| 230 | - && count($frequency) === 2 |
|
| 231 | - && isset($frequency[0], $frequency[1]) |
|
| 232 | - ) { |
|
| 233 | - $start_timestamp = $frequency[0]; |
|
| 234 | - $frequency = $frequency[1]; |
|
| 235 | - } else { |
|
| 236 | - $start_timestamp = time(); |
|
| 237 | - } |
|
| 238 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Remove the currently-existing and now-removed cron tasks. |
|
| 247 | - * |
|
| 248 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 249 | - * @throws \EE_Error |
|
| 250 | - */ |
|
| 251 | - public static function remove_cron_tasks($remove_all = true) |
|
| 252 | - { |
|
| 253 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 254 | - $crons = _get_cron_array(); |
|
| 255 | - $crons = is_array($crons) ? $crons : array(); |
|
| 256 | - /* reminder of what $crons look like: |
|
| 187 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 188 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 189 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 190 | + ) |
|
| 191 | + ); |
|
| 192 | + if ($which_to_include === 'old') { |
|
| 193 | + $cron_tasks = array_filter( |
|
| 194 | + $cron_tasks, |
|
| 195 | + function ($value) { |
|
| 196 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 197 | + } |
|
| 198 | + ); |
|
| 199 | + } elseif ($which_to_include === 'current') { |
|
| 200 | + $cron_tasks = array_filter($cron_tasks); |
|
| 201 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 202 | + throw new EE_Error( |
|
| 203 | + sprintf( |
|
| 204 | + __( |
|
| 205 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 206 | + 'event_espresso' |
|
| 207 | + ), |
|
| 208 | + $which_to_include |
|
| 209 | + ) |
|
| 210 | + ); |
|
| 211 | + } |
|
| 212 | + return $cron_tasks; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 218 | + * |
|
| 219 | + * @throws \EE_Error |
|
| 220 | + */ |
|
| 221 | + public static function create_cron_tasks() |
|
| 222 | + { |
|
| 223 | + |
|
| 224 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 225 | + if (! wp_next_scheduled($hook_name)) { |
|
| 226 | + /** |
|
| 227 | + * This allows client code to define the initial start timestamp for this schedule. |
|
| 228 | + */ |
|
| 229 | + if (is_array($frequency) |
|
| 230 | + && count($frequency) === 2 |
|
| 231 | + && isset($frequency[0], $frequency[1]) |
|
| 232 | + ) { |
|
| 233 | + $start_timestamp = $frequency[0]; |
|
| 234 | + $frequency = $frequency[1]; |
|
| 235 | + } else { |
|
| 236 | + $start_timestamp = time(); |
|
| 237 | + } |
|
| 238 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Remove the currently-existing and now-removed cron tasks. |
|
| 247 | + * |
|
| 248 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 249 | + * @throws \EE_Error |
|
| 250 | + */ |
|
| 251 | + public static function remove_cron_tasks($remove_all = true) |
|
| 252 | + { |
|
| 253 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 254 | + $crons = _get_cron_array(); |
|
| 255 | + $crons = is_array($crons) ? $crons : array(); |
|
| 256 | + /* reminder of what $crons look like: |
|
| 257 | 257 | * Top-level keys are timestamps, and their values are arrays. |
| 258 | 258 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
| 259 | 259 | * and their values are arrays. |
@@ -270,912 +270,912 @@ discard block |
||
| 270 | 270 | * ... |
| 271 | 271 | * ... |
| 272 | 272 | */ |
| 273 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 274 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 275 | - if (is_array($hooks_to_fire_at_time)) { |
|
| 276 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 277 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 278 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 279 | - ) { |
|
| 280 | - unset($crons[$timestamp][$hook_name]); |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - //also take care of any empty cron timestamps. |
|
| 284 | - if (empty($hooks_to_fire_at_time)) { |
|
| 285 | - unset($crons[$timestamp]); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - _set_cron_array($crons); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * CPT_initialization |
|
| 295 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 296 | - * |
|
| 297 | - * @access public |
|
| 298 | - * @static |
|
| 299 | - * @return void |
|
| 300 | - */ |
|
| 301 | - public static function CPT_initialization() |
|
| 302 | - { |
|
| 303 | - // register Custom Post Types |
|
| 304 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 305 | - flush_rewrite_rules(); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * reset_and_update_config |
|
| 312 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 313 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
| 314 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 315 | - * |
|
| 316 | - * @access public |
|
| 317 | - * @static |
|
| 318 | - * @return void |
|
| 319 | - */ |
|
| 320 | - public static function reset_and_update_config() |
|
| 321 | - { |
|
| 322 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 323 | - add_filter( |
|
| 324 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 325 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
| 326 | - 10, |
|
| 327 | - 3 |
|
| 328 | - ); |
|
| 329 | - //EE_Config::reset(); |
|
| 330 | - if (! EE_Config::logging_enabled()) { |
|
| 331 | - delete_option(EE_Config::LOG_NAME); |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * load_calendar_config |
|
| 338 | - * |
|
| 339 | - * @access public |
|
| 340 | - * @return void |
|
| 341 | - */ |
|
| 342 | - public static function load_calendar_config() |
|
| 343 | - { |
|
| 344 | - // grab array of all plugin folders and loop thru it |
|
| 345 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 346 | - if (empty($plugins)) { |
|
| 347 | - return; |
|
| 348 | - } |
|
| 349 | - foreach ($plugins as $plugin_path) { |
|
| 350 | - // grab plugin folder name from path |
|
| 351 | - $plugin = basename($plugin_path); |
|
| 352 | - // drill down to Espresso plugins |
|
| 353 | - // then to calendar related plugins |
|
| 354 | - if ( |
|
| 355 | - strpos($plugin, 'espresso') !== false |
|
| 356 | - || strpos($plugin, 'Espresso') !== false |
|
| 357 | - || strpos($plugin, 'ee4') !== false |
|
| 358 | - || strpos($plugin, 'EE4') !== false |
|
| 359 | - || strpos($plugin, 'calendar') !== false |
|
| 360 | - ) { |
|
| 361 | - // this is what we are looking for |
|
| 362 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 363 | - // does it exist in this folder ? |
|
| 364 | - if (is_readable($calendar_config)) { |
|
| 365 | - // YEAH! let's load it |
|
| 366 | - require_once($calendar_config); |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * _migrate_old_config_data |
|
| 376 | - * |
|
| 377 | - * @access public |
|
| 378 | - * @param array|stdClass $settings |
|
| 379 | - * @param string $config |
|
| 380 | - * @param \EE_Config $EE_Config |
|
| 381 | - * @return \stdClass |
|
| 382 | - */ |
|
| 383 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 384 | - { |
|
| 385 | - $convert_from_array = array('addons'); |
|
| 386 | - // in case old settings were saved as an array |
|
| 387 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 388 | - // convert existing settings to an object |
|
| 389 | - $config_array = $settings; |
|
| 390 | - $settings = new stdClass(); |
|
| 391 | - foreach ($config_array as $key => $value) { |
|
| 392 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 393 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 394 | - } else { |
|
| 395 | - $settings->{$key} = $value; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 399 | - } |
|
| 400 | - return $settings; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * deactivate_event_espresso |
|
| 406 | - * |
|
| 407 | - * @access public |
|
| 408 | - * @static |
|
| 409 | - * @return void |
|
| 410 | - */ |
|
| 411 | - public static function deactivate_event_espresso() |
|
| 412 | - { |
|
| 413 | - // check permissions |
|
| 414 | - if (current_user_can('activate_plugins')) { |
|
| 415 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * verify_default_pages_exist |
|
| 425 | - * |
|
| 426 | - * @access public |
|
| 427 | - * @static |
|
| 428 | - * @return void |
|
| 429 | - */ |
|
| 430 | - public static function verify_default_pages_exist() |
|
| 431 | - { |
|
| 432 | - $critical_page_problem = false; |
|
| 433 | - $critical_pages = array( |
|
| 434 | - array( |
|
| 435 | - 'id' => 'reg_page_id', |
|
| 436 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 437 | - 'post' => null, |
|
| 438 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
| 439 | - ), |
|
| 440 | - array( |
|
| 441 | - 'id' => 'txn_page_id', |
|
| 442 | - 'name' => __('Transactions', 'event_espresso'), |
|
| 443 | - 'post' => null, |
|
| 444 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 445 | - ), |
|
| 446 | - array( |
|
| 447 | - 'id' => 'thank_you_page_id', |
|
| 448 | - 'name' => __('Thank You', 'event_espresso'), |
|
| 449 | - 'post' => null, |
|
| 450 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
| 451 | - ), |
|
| 452 | - array( |
|
| 453 | - 'id' => 'cancel_page_id', |
|
| 454 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 455 | - 'post' => null, |
|
| 456 | - 'code' => 'ESPRESSO_CANCELLED', |
|
| 457 | - ), |
|
| 458 | - ); |
|
| 459 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 460 | - foreach ($critical_pages as $critical_page) { |
|
| 461 | - // is critical page ID set in config ? |
|
| 462 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 463 | - // attempt to find post by ID |
|
| 464 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 465 | - } |
|
| 466 | - // no dice? |
|
| 467 | - if ($critical_page['post'] === null) { |
|
| 468 | - // attempt to find post by title |
|
| 469 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 470 | - // still nothing? |
|
| 471 | - if ($critical_page['post'] === null) { |
|
| 472 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 473 | - // REALLY? Still nothing ??!?!? |
|
| 474 | - if ($critical_page['post'] === null) { |
|
| 475 | - $msg = __( |
|
| 476 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 477 | - 'event_espresso' |
|
| 478 | - ); |
|
| 479 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 480 | - break; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - // check that Post ID matches critical page ID in config |
|
| 485 | - if ( |
|
| 486 | - isset($critical_page['post']->ID) |
|
| 487 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 488 | - ) { |
|
| 489 | - //update Config with post ID |
|
| 490 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 491 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 492 | - $msg = __( |
|
| 493 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 494 | - 'event_espresso' |
|
| 495 | - ); |
|
| 496 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - $critical_page_problem = |
|
| 500 | - ! isset($critical_page['post']->post_status) |
|
| 501 | - || $critical_page['post']->post_status !== 'publish' |
|
| 502 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 503 | - ? true |
|
| 504 | - : $critical_page_problem; |
|
| 505 | - } |
|
| 506 | - if ($critical_page_problem) { |
|
| 507 | - $msg = sprintf( |
|
| 508 | - __( |
|
| 509 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 510 | - 'event_espresso' |
|
| 511 | - ), |
|
| 512 | - '<a href="' |
|
| 513 | - . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 514 | - . '">' |
|
| 515 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 516 | - . '</a>' |
|
| 517 | - ); |
|
| 518 | - EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 519 | - } |
|
| 520 | - if (EE_Error::has_notices()) { |
|
| 521 | - EE_Error::get_notices(false, true, true); |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * Returns the first post which uses the specified shortcode |
|
| 529 | - * |
|
| 530 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 531 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 532 | - * "[ESPRESSO_THANK_YOU" |
|
| 533 | - * (we don't search for the closing shortcode bracket because they might have added |
|
| 534 | - * parameter to the shortcode |
|
| 535 | - * @return WP_Post or NULl |
|
| 536 | - */ |
|
| 537 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 538 | - { |
|
| 539 | - global $wpdb; |
|
| 540 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 541 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 542 | - if ($post_id) { |
|
| 543 | - return get_post($post_id); |
|
| 544 | - } else { |
|
| 545 | - return null; |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * This function generates a post for critical espresso pages |
|
| 552 | - * |
|
| 553 | - * @access public |
|
| 554 | - * @static |
|
| 555 | - * @param array $critical_page |
|
| 556 | - * @return array |
|
| 557 | - */ |
|
| 558 | - public static function create_critical_page($critical_page) |
|
| 559 | - { |
|
| 560 | - |
|
| 561 | - $post_args = array( |
|
| 562 | - 'post_title' => $critical_page['name'], |
|
| 563 | - 'post_status' => 'publish', |
|
| 564 | - 'post_type' => 'page', |
|
| 565 | - 'comment_status' => 'closed', |
|
| 566 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 567 | - ); |
|
| 568 | - |
|
| 569 | - $post_id = wp_insert_post($post_args); |
|
| 570 | - if (! $post_id) { |
|
| 571 | - $msg = sprintf( |
|
| 572 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 573 | - $critical_page['name'] |
|
| 574 | - ); |
|
| 575 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 576 | - return $critical_page; |
|
| 577 | - } |
|
| 578 | - // get newly created post's details |
|
| 579 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
| 580 | - $msg = sprintf( |
|
| 581 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 582 | - $critical_page['name'] |
|
| 583 | - ); |
|
| 584 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - return $critical_page; |
|
| 588 | - |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 596 | - * The role being used to check is filterable. |
|
| 597 | - * |
|
| 598 | - * @since 4.6.0 |
|
| 599 | - * @global WPDB $wpdb |
|
| 600 | - * @return mixed null|int WP_user ID or NULL |
|
| 601 | - */ |
|
| 602 | - public static function get_default_creator_id() |
|
| 603 | - { |
|
| 604 | - global $wpdb; |
|
| 605 | - if ( ! empty(self::$_default_creator_id)) { |
|
| 606 | - return self::$_default_creator_id; |
|
| 607 | - }/**/ |
|
| 608 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 609 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 610 | - $pre_filtered_id = apply_filters( |
|
| 611 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 612 | - false, |
|
| 613 | - $role_to_check |
|
| 614 | - ); |
|
| 615 | - if ($pre_filtered_id !== false) { |
|
| 616 | - return (int)$pre_filtered_id; |
|
| 617 | - } |
|
| 618 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 619 | - $query = $wpdb->prepare( |
|
| 620 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 621 | - '%' . $role_to_check . '%' |
|
| 622 | - ); |
|
| 623 | - $user_id = $wpdb->get_var($query); |
|
| 624 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 625 | - if ($user_id && (int)$user_id) { |
|
| 626 | - self::$_default_creator_id = (int)$user_id; |
|
| 627 | - return self::$_default_creator_id; |
|
| 628 | - } else { |
|
| 629 | - return null; |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * used by EE and EE addons during plugin activation to create tables. |
|
| 637 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 638 | - * but includes extra logic regarding activations. |
|
| 639 | - * |
|
| 640 | - * @access public |
|
| 641 | - * @static |
|
| 642 | - * @param string $table_name without the $wpdb->prefix |
|
| 643 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 644 | - * table query) |
|
| 645 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 646 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 647 | - * and new once this function is done (ie, you really do want to CREATE a |
|
| 648 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 649 | - * you just want to verify the table exists and matches this definition |
|
| 650 | - * (and if it HAS data in it you want to leave it be) |
|
| 651 | - * @return void |
|
| 652 | - * @throws EE_Error if there are database errors |
|
| 653 | - */ |
|
| 654 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 655 | - { |
|
| 656 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 657 | - return; |
|
| 658 | - } |
|
| 659 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 660 | - if ( ! function_exists('dbDelta')) { |
|
| 661 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 662 | - } |
|
| 663 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 664 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 665 | - // do we need to first delete an existing version of this table ? |
|
| 666 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 667 | - // ok, delete the table... but ONLY if it's empty |
|
| 668 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 669 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 670 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 671 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 672 | - } else if ( ! $deleted_safely) { |
|
| 673 | - // so we should be more cautious rather than just dropping tables so easily |
|
| 674 | - error_log( |
|
| 675 | - sprintf( |
|
| 676 | - __( |
|
| 677 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 678 | - 'event_espresso' |
|
| 679 | - ), |
|
| 680 | - $wp_table_name, |
|
| 681 | - '<br/>', |
|
| 682 | - 'espresso_db_update' |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - $engine = str_replace('ENGINE=', '', $engine); |
|
| 688 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * add_column_if_it_doesn't_exist |
|
| 695 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 696 | - * |
|
| 697 | - * @access public |
|
| 698 | - * @static |
|
| 699 | - * @deprecated instead use TableManager::addColumn() |
|
| 700 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 701 | - * @param string $column_name |
|
| 702 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 703 | - * 'VARCHAR(10)' |
|
| 704 | - * @return bool|int |
|
| 705 | - */ |
|
| 706 | - public static function add_column_if_it_doesnt_exist( |
|
| 707 | - $table_name, |
|
| 708 | - $column_name, |
|
| 709 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
| 710 | - ) { |
|
| 711 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * get_fields_on_table |
|
| 717 | - * Gets all the fields on the database table. |
|
| 718 | - * |
|
| 719 | - * @access public |
|
| 720 | - * @deprecated instead use TableManager::getTableColumns() |
|
| 721 | - * @static |
|
| 722 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
| 723 | - * @return array of database column names |
|
| 724 | - */ |
|
| 725 | - public static function get_fields_on_table($table_name = null) |
|
| 726 | - { |
|
| 727 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - |
|
| 731 | - /** |
|
| 732 | - * db_table_is_empty |
|
| 733 | - * |
|
| 734 | - * @access public\ |
|
| 735 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 736 | - * @static |
|
| 737 | - * @param string $table_name |
|
| 738 | - * @return bool |
|
| 739 | - */ |
|
| 740 | - public static function db_table_is_empty($table_name) |
|
| 741 | - { |
|
| 742 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * delete_db_table_if_empty |
|
| 748 | - * |
|
| 749 | - * @access public |
|
| 750 | - * @static |
|
| 751 | - * @param string $table_name |
|
| 752 | - * @return bool | int |
|
| 753 | - */ |
|
| 754 | - public static function delete_db_table_if_empty($table_name) |
|
| 755 | - { |
|
| 756 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 757 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 758 | - } |
|
| 759 | - return false; |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - |
|
| 763 | - /** |
|
| 764 | - * delete_unused_db_table |
|
| 765 | - * |
|
| 766 | - * @access public |
|
| 767 | - * @static |
|
| 768 | - * @deprecated instead use TableManager::dropTable() |
|
| 769 | - * @param string $table_name |
|
| 770 | - * @return bool | int |
|
| 771 | - */ |
|
| 772 | - public static function delete_unused_db_table($table_name) |
|
| 773 | - { |
|
| 774 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * drop_index |
|
| 780 | - * |
|
| 781 | - * @access public |
|
| 782 | - * @static |
|
| 783 | - * @deprecated instead use TableManager::dropIndex() |
|
| 784 | - * @param string $table_name |
|
| 785 | - * @param string $index_name |
|
| 786 | - * @return bool | int |
|
| 787 | - */ |
|
| 788 | - public static function drop_index($table_name, $index_name) |
|
| 789 | - { |
|
| 790 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - |
|
| 795 | - /** |
|
| 796 | - * create_database_tables |
|
| 797 | - * |
|
| 798 | - * @access public |
|
| 799 | - * @static |
|
| 800 | - * @throws EE_Error |
|
| 801 | - * @return boolean success (whether database is setup properly or not) |
|
| 802 | - */ |
|
| 803 | - public static function create_database_tables() |
|
| 804 | - { |
|
| 805 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 806 | - //find the migration script that sets the database to be compatible with the code |
|
| 807 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 808 | - if ($dms_name) { |
|
| 809 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 810 | - $current_data_migration_script->set_migrating(false); |
|
| 811 | - $current_data_migration_script->schema_changes_before_migration(); |
|
| 812 | - $current_data_migration_script->schema_changes_after_migration(); |
|
| 813 | - if ($current_data_migration_script->get_errors()) { |
|
| 814 | - if (WP_DEBUG) { |
|
| 815 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 816 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 817 | - } |
|
| 818 | - } else { |
|
| 819 | - EE_Error::add_error( |
|
| 820 | - __( |
|
| 821 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 273 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 274 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 275 | + if (is_array($hooks_to_fire_at_time)) { |
|
| 276 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 277 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 278 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 279 | + ) { |
|
| 280 | + unset($crons[$timestamp][$hook_name]); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + //also take care of any empty cron timestamps. |
|
| 284 | + if (empty($hooks_to_fire_at_time)) { |
|
| 285 | + unset($crons[$timestamp]); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + _set_cron_array($crons); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * CPT_initialization |
|
| 295 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 296 | + * |
|
| 297 | + * @access public |
|
| 298 | + * @static |
|
| 299 | + * @return void |
|
| 300 | + */ |
|
| 301 | + public static function CPT_initialization() |
|
| 302 | + { |
|
| 303 | + // register Custom Post Types |
|
| 304 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 305 | + flush_rewrite_rules(); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * reset_and_update_config |
|
| 312 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 313 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
| 314 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 315 | + * |
|
| 316 | + * @access public |
|
| 317 | + * @static |
|
| 318 | + * @return void |
|
| 319 | + */ |
|
| 320 | + public static function reset_and_update_config() |
|
| 321 | + { |
|
| 322 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 323 | + add_filter( |
|
| 324 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 325 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
| 326 | + 10, |
|
| 327 | + 3 |
|
| 328 | + ); |
|
| 329 | + //EE_Config::reset(); |
|
| 330 | + if (! EE_Config::logging_enabled()) { |
|
| 331 | + delete_option(EE_Config::LOG_NAME); |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * load_calendar_config |
|
| 338 | + * |
|
| 339 | + * @access public |
|
| 340 | + * @return void |
|
| 341 | + */ |
|
| 342 | + public static function load_calendar_config() |
|
| 343 | + { |
|
| 344 | + // grab array of all plugin folders and loop thru it |
|
| 345 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 346 | + if (empty($plugins)) { |
|
| 347 | + return; |
|
| 348 | + } |
|
| 349 | + foreach ($plugins as $plugin_path) { |
|
| 350 | + // grab plugin folder name from path |
|
| 351 | + $plugin = basename($plugin_path); |
|
| 352 | + // drill down to Espresso plugins |
|
| 353 | + // then to calendar related plugins |
|
| 354 | + if ( |
|
| 355 | + strpos($plugin, 'espresso') !== false |
|
| 356 | + || strpos($plugin, 'Espresso') !== false |
|
| 357 | + || strpos($plugin, 'ee4') !== false |
|
| 358 | + || strpos($plugin, 'EE4') !== false |
|
| 359 | + || strpos($plugin, 'calendar') !== false |
|
| 360 | + ) { |
|
| 361 | + // this is what we are looking for |
|
| 362 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 363 | + // does it exist in this folder ? |
|
| 364 | + if (is_readable($calendar_config)) { |
|
| 365 | + // YEAH! let's load it |
|
| 366 | + require_once($calendar_config); |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * _migrate_old_config_data |
|
| 376 | + * |
|
| 377 | + * @access public |
|
| 378 | + * @param array|stdClass $settings |
|
| 379 | + * @param string $config |
|
| 380 | + * @param \EE_Config $EE_Config |
|
| 381 | + * @return \stdClass |
|
| 382 | + */ |
|
| 383 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 384 | + { |
|
| 385 | + $convert_from_array = array('addons'); |
|
| 386 | + // in case old settings were saved as an array |
|
| 387 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 388 | + // convert existing settings to an object |
|
| 389 | + $config_array = $settings; |
|
| 390 | + $settings = new stdClass(); |
|
| 391 | + foreach ($config_array as $key => $value) { |
|
| 392 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 393 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 394 | + } else { |
|
| 395 | + $settings->{$key} = $value; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 399 | + } |
|
| 400 | + return $settings; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * deactivate_event_espresso |
|
| 406 | + * |
|
| 407 | + * @access public |
|
| 408 | + * @static |
|
| 409 | + * @return void |
|
| 410 | + */ |
|
| 411 | + public static function deactivate_event_espresso() |
|
| 412 | + { |
|
| 413 | + // check permissions |
|
| 414 | + if (current_user_can('activate_plugins')) { |
|
| 415 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * verify_default_pages_exist |
|
| 425 | + * |
|
| 426 | + * @access public |
|
| 427 | + * @static |
|
| 428 | + * @return void |
|
| 429 | + */ |
|
| 430 | + public static function verify_default_pages_exist() |
|
| 431 | + { |
|
| 432 | + $critical_page_problem = false; |
|
| 433 | + $critical_pages = array( |
|
| 434 | + array( |
|
| 435 | + 'id' => 'reg_page_id', |
|
| 436 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 437 | + 'post' => null, |
|
| 438 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
| 439 | + ), |
|
| 440 | + array( |
|
| 441 | + 'id' => 'txn_page_id', |
|
| 442 | + 'name' => __('Transactions', 'event_espresso'), |
|
| 443 | + 'post' => null, |
|
| 444 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 445 | + ), |
|
| 446 | + array( |
|
| 447 | + 'id' => 'thank_you_page_id', |
|
| 448 | + 'name' => __('Thank You', 'event_espresso'), |
|
| 449 | + 'post' => null, |
|
| 450 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
| 451 | + ), |
|
| 452 | + array( |
|
| 453 | + 'id' => 'cancel_page_id', |
|
| 454 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 455 | + 'post' => null, |
|
| 456 | + 'code' => 'ESPRESSO_CANCELLED', |
|
| 457 | + ), |
|
| 458 | + ); |
|
| 459 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 460 | + foreach ($critical_pages as $critical_page) { |
|
| 461 | + // is critical page ID set in config ? |
|
| 462 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 463 | + // attempt to find post by ID |
|
| 464 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 465 | + } |
|
| 466 | + // no dice? |
|
| 467 | + if ($critical_page['post'] === null) { |
|
| 468 | + // attempt to find post by title |
|
| 469 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 470 | + // still nothing? |
|
| 471 | + if ($critical_page['post'] === null) { |
|
| 472 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 473 | + // REALLY? Still nothing ??!?!? |
|
| 474 | + if ($critical_page['post'] === null) { |
|
| 475 | + $msg = __( |
|
| 476 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 477 | + 'event_espresso' |
|
| 478 | + ); |
|
| 479 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 480 | + break; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + // check that Post ID matches critical page ID in config |
|
| 485 | + if ( |
|
| 486 | + isset($critical_page['post']->ID) |
|
| 487 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 488 | + ) { |
|
| 489 | + //update Config with post ID |
|
| 490 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 491 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 492 | + $msg = __( |
|
| 493 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 494 | + 'event_espresso' |
|
| 495 | + ); |
|
| 496 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + $critical_page_problem = |
|
| 500 | + ! isset($critical_page['post']->post_status) |
|
| 501 | + || $critical_page['post']->post_status !== 'publish' |
|
| 502 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 503 | + ? true |
|
| 504 | + : $critical_page_problem; |
|
| 505 | + } |
|
| 506 | + if ($critical_page_problem) { |
|
| 507 | + $msg = sprintf( |
|
| 508 | + __( |
|
| 509 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 510 | + 'event_espresso' |
|
| 511 | + ), |
|
| 512 | + '<a href="' |
|
| 513 | + . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 514 | + . '">' |
|
| 515 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 516 | + . '</a>' |
|
| 517 | + ); |
|
| 518 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 519 | + } |
|
| 520 | + if (EE_Error::has_notices()) { |
|
| 521 | + EE_Error::get_notices(false, true, true); |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * Returns the first post which uses the specified shortcode |
|
| 529 | + * |
|
| 530 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 531 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 532 | + * "[ESPRESSO_THANK_YOU" |
|
| 533 | + * (we don't search for the closing shortcode bracket because they might have added |
|
| 534 | + * parameter to the shortcode |
|
| 535 | + * @return WP_Post or NULl |
|
| 536 | + */ |
|
| 537 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 538 | + { |
|
| 539 | + global $wpdb; |
|
| 540 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 541 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 542 | + if ($post_id) { |
|
| 543 | + return get_post($post_id); |
|
| 544 | + } else { |
|
| 545 | + return null; |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * This function generates a post for critical espresso pages |
|
| 552 | + * |
|
| 553 | + * @access public |
|
| 554 | + * @static |
|
| 555 | + * @param array $critical_page |
|
| 556 | + * @return array |
|
| 557 | + */ |
|
| 558 | + public static function create_critical_page($critical_page) |
|
| 559 | + { |
|
| 560 | + |
|
| 561 | + $post_args = array( |
|
| 562 | + 'post_title' => $critical_page['name'], |
|
| 563 | + 'post_status' => 'publish', |
|
| 564 | + 'post_type' => 'page', |
|
| 565 | + 'comment_status' => 'closed', |
|
| 566 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 567 | + ); |
|
| 568 | + |
|
| 569 | + $post_id = wp_insert_post($post_args); |
|
| 570 | + if (! $post_id) { |
|
| 571 | + $msg = sprintf( |
|
| 572 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 573 | + $critical_page['name'] |
|
| 574 | + ); |
|
| 575 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 576 | + return $critical_page; |
|
| 577 | + } |
|
| 578 | + // get newly created post's details |
|
| 579 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
| 580 | + $msg = sprintf( |
|
| 581 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 582 | + $critical_page['name'] |
|
| 583 | + ); |
|
| 584 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + return $critical_page; |
|
| 588 | + |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 596 | + * The role being used to check is filterable. |
|
| 597 | + * |
|
| 598 | + * @since 4.6.0 |
|
| 599 | + * @global WPDB $wpdb |
|
| 600 | + * @return mixed null|int WP_user ID or NULL |
|
| 601 | + */ |
|
| 602 | + public static function get_default_creator_id() |
|
| 603 | + { |
|
| 604 | + global $wpdb; |
|
| 605 | + if ( ! empty(self::$_default_creator_id)) { |
|
| 606 | + return self::$_default_creator_id; |
|
| 607 | + }/**/ |
|
| 608 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 609 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 610 | + $pre_filtered_id = apply_filters( |
|
| 611 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 612 | + false, |
|
| 613 | + $role_to_check |
|
| 614 | + ); |
|
| 615 | + if ($pre_filtered_id !== false) { |
|
| 616 | + return (int)$pre_filtered_id; |
|
| 617 | + } |
|
| 618 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 619 | + $query = $wpdb->prepare( |
|
| 620 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 621 | + '%' . $role_to_check . '%' |
|
| 622 | + ); |
|
| 623 | + $user_id = $wpdb->get_var($query); |
|
| 624 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 625 | + if ($user_id && (int)$user_id) { |
|
| 626 | + self::$_default_creator_id = (int)$user_id; |
|
| 627 | + return self::$_default_creator_id; |
|
| 628 | + } else { |
|
| 629 | + return null; |
|
| 630 | + } |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * used by EE and EE addons during plugin activation to create tables. |
|
| 637 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 638 | + * but includes extra logic regarding activations. |
|
| 639 | + * |
|
| 640 | + * @access public |
|
| 641 | + * @static |
|
| 642 | + * @param string $table_name without the $wpdb->prefix |
|
| 643 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 644 | + * table query) |
|
| 645 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 646 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 647 | + * and new once this function is done (ie, you really do want to CREATE a |
|
| 648 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 649 | + * you just want to verify the table exists and matches this definition |
|
| 650 | + * (and if it HAS data in it you want to leave it be) |
|
| 651 | + * @return void |
|
| 652 | + * @throws EE_Error if there are database errors |
|
| 653 | + */ |
|
| 654 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 655 | + { |
|
| 656 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 657 | + return; |
|
| 658 | + } |
|
| 659 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 660 | + if ( ! function_exists('dbDelta')) { |
|
| 661 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 662 | + } |
|
| 663 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 664 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 665 | + // do we need to first delete an existing version of this table ? |
|
| 666 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 667 | + // ok, delete the table... but ONLY if it's empty |
|
| 668 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 669 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 670 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 671 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 672 | + } else if ( ! $deleted_safely) { |
|
| 673 | + // so we should be more cautious rather than just dropping tables so easily |
|
| 674 | + error_log( |
|
| 675 | + sprintf( |
|
| 676 | + __( |
|
| 677 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 678 | + 'event_espresso' |
|
| 679 | + ), |
|
| 680 | + $wp_table_name, |
|
| 681 | + '<br/>', |
|
| 682 | + 'espresso_db_update' |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + $engine = str_replace('ENGINE=', '', $engine); |
|
| 688 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * add_column_if_it_doesn't_exist |
|
| 695 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 696 | + * |
|
| 697 | + * @access public |
|
| 698 | + * @static |
|
| 699 | + * @deprecated instead use TableManager::addColumn() |
|
| 700 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 701 | + * @param string $column_name |
|
| 702 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 703 | + * 'VARCHAR(10)' |
|
| 704 | + * @return bool|int |
|
| 705 | + */ |
|
| 706 | + public static function add_column_if_it_doesnt_exist( |
|
| 707 | + $table_name, |
|
| 708 | + $column_name, |
|
| 709 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
| 710 | + ) { |
|
| 711 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * get_fields_on_table |
|
| 717 | + * Gets all the fields on the database table. |
|
| 718 | + * |
|
| 719 | + * @access public |
|
| 720 | + * @deprecated instead use TableManager::getTableColumns() |
|
| 721 | + * @static |
|
| 722 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
| 723 | + * @return array of database column names |
|
| 724 | + */ |
|
| 725 | + public static function get_fields_on_table($table_name = null) |
|
| 726 | + { |
|
| 727 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + |
|
| 731 | + /** |
|
| 732 | + * db_table_is_empty |
|
| 733 | + * |
|
| 734 | + * @access public\ |
|
| 735 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 736 | + * @static |
|
| 737 | + * @param string $table_name |
|
| 738 | + * @return bool |
|
| 739 | + */ |
|
| 740 | + public static function db_table_is_empty($table_name) |
|
| 741 | + { |
|
| 742 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * delete_db_table_if_empty |
|
| 748 | + * |
|
| 749 | + * @access public |
|
| 750 | + * @static |
|
| 751 | + * @param string $table_name |
|
| 752 | + * @return bool | int |
|
| 753 | + */ |
|
| 754 | + public static function delete_db_table_if_empty($table_name) |
|
| 755 | + { |
|
| 756 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 757 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 758 | + } |
|
| 759 | + return false; |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + |
|
| 763 | + /** |
|
| 764 | + * delete_unused_db_table |
|
| 765 | + * |
|
| 766 | + * @access public |
|
| 767 | + * @static |
|
| 768 | + * @deprecated instead use TableManager::dropTable() |
|
| 769 | + * @param string $table_name |
|
| 770 | + * @return bool | int |
|
| 771 | + */ |
|
| 772 | + public static function delete_unused_db_table($table_name) |
|
| 773 | + { |
|
| 774 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * drop_index |
|
| 780 | + * |
|
| 781 | + * @access public |
|
| 782 | + * @static |
|
| 783 | + * @deprecated instead use TableManager::dropIndex() |
|
| 784 | + * @param string $table_name |
|
| 785 | + * @param string $index_name |
|
| 786 | + * @return bool | int |
|
| 787 | + */ |
|
| 788 | + public static function drop_index($table_name, $index_name) |
|
| 789 | + { |
|
| 790 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + |
|
| 795 | + /** |
|
| 796 | + * create_database_tables |
|
| 797 | + * |
|
| 798 | + * @access public |
|
| 799 | + * @static |
|
| 800 | + * @throws EE_Error |
|
| 801 | + * @return boolean success (whether database is setup properly or not) |
|
| 802 | + */ |
|
| 803 | + public static function create_database_tables() |
|
| 804 | + { |
|
| 805 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 806 | + //find the migration script that sets the database to be compatible with the code |
|
| 807 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 808 | + if ($dms_name) { |
|
| 809 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 810 | + $current_data_migration_script->set_migrating(false); |
|
| 811 | + $current_data_migration_script->schema_changes_before_migration(); |
|
| 812 | + $current_data_migration_script->schema_changes_after_migration(); |
|
| 813 | + if ($current_data_migration_script->get_errors()) { |
|
| 814 | + if (WP_DEBUG) { |
|
| 815 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 816 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 817 | + } |
|
| 818 | + } else { |
|
| 819 | + EE_Error::add_error( |
|
| 820 | + __( |
|
| 821 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 822 | 822 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
| 823 | - 'event_espresso' |
|
| 824 | - ) |
|
| 825 | - ); |
|
| 826 | - } |
|
| 827 | - return false; |
|
| 828 | - } |
|
| 829 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 830 | - } else { |
|
| 831 | - EE_Error::add_error( |
|
| 832 | - __( |
|
| 833 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 823 | + 'event_espresso' |
|
| 824 | + ) |
|
| 825 | + ); |
|
| 826 | + } |
|
| 827 | + return false; |
|
| 828 | + } |
|
| 829 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 830 | + } else { |
|
| 831 | + EE_Error::add_error( |
|
| 832 | + __( |
|
| 833 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 834 | 834 | structure. So database is probably not setup properly', |
| 835 | - 'event_espresso' |
|
| 836 | - ), |
|
| 837 | - __FILE__, |
|
| 838 | - __FUNCTION__, |
|
| 839 | - __LINE__ |
|
| 840 | - ); |
|
| 841 | - return false; |
|
| 842 | - } |
|
| 843 | - return true; |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * initialize_system_questions |
|
| 850 | - * |
|
| 851 | - * @access public |
|
| 852 | - * @static |
|
| 853 | - * @return void |
|
| 854 | - */ |
|
| 855 | - public static function initialize_system_questions() |
|
| 856 | - { |
|
| 857 | - // QUESTION GROUPS |
|
| 858 | - global $wpdb; |
|
| 859 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 860 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 861 | - // what we have |
|
| 862 | - $question_groups = $wpdb->get_col($SQL); |
|
| 863 | - // check the response |
|
| 864 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 865 | - // what we should have |
|
| 866 | - $QSG_systems = array(1, 2); |
|
| 867 | - // loop thru what we should have and compare to what we have |
|
| 868 | - foreach ($QSG_systems as $QSG_system) { |
|
| 869 | - // reset values array |
|
| 870 | - $QSG_values = array(); |
|
| 871 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 872 | - if (! in_array("$QSG_system", $question_groups)) { |
|
| 873 | - // add it |
|
| 874 | - switch ($QSG_system) { |
|
| 875 | - case 1: |
|
| 876 | - $QSG_values = array( |
|
| 877 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 878 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 879 | - 'QSG_desc' => '', |
|
| 880 | - 'QSG_order' => 1, |
|
| 881 | - 'QSG_show_group_name' => 1, |
|
| 882 | - 'QSG_show_group_desc' => 1, |
|
| 883 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 884 | - 'QSG_deleted' => 0, |
|
| 885 | - ); |
|
| 886 | - break; |
|
| 887 | - case 2: |
|
| 888 | - $QSG_values = array( |
|
| 889 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 890 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 891 | - 'QSG_desc' => '', |
|
| 892 | - 'QSG_order' => 2, |
|
| 893 | - 'QSG_show_group_name' => 1, |
|
| 894 | - 'QSG_show_group_desc' => 1, |
|
| 895 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
| 896 | - 'QSG_deleted' => 0, |
|
| 897 | - ); |
|
| 898 | - break; |
|
| 899 | - } |
|
| 900 | - // make sure we have some values before inserting them |
|
| 901 | - if (! empty($QSG_values)) { |
|
| 902 | - // insert system question |
|
| 903 | - $wpdb->insert( |
|
| 904 | - $table_name, |
|
| 905 | - $QSG_values, |
|
| 906 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 907 | - ); |
|
| 908 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 909 | - } |
|
| 910 | - } |
|
| 911 | - } |
|
| 912 | - // QUESTIONS |
|
| 913 | - global $wpdb; |
|
| 914 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 915 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 916 | - // what we have |
|
| 917 | - $questions = $wpdb->get_col($SQL); |
|
| 918 | - // what we should have |
|
| 919 | - $QST_systems = array( |
|
| 920 | - 'fname', |
|
| 921 | - 'lname', |
|
| 922 | - 'email', |
|
| 923 | - 'address', |
|
| 924 | - 'address2', |
|
| 925 | - 'city', |
|
| 926 | - 'country', |
|
| 927 | - 'state', |
|
| 928 | - 'zip', |
|
| 929 | - 'phone', |
|
| 930 | - ); |
|
| 931 | - $order_for_group_1 = 1; |
|
| 932 | - $order_for_group_2 = 1; |
|
| 933 | - // loop thru what we should have and compare to what we have |
|
| 934 | - foreach ($QST_systems as $QST_system) { |
|
| 935 | - // reset values array |
|
| 936 | - $QST_values = array(); |
|
| 937 | - // if we don't have what we should have |
|
| 938 | - if (! in_array($QST_system, $questions)) { |
|
| 939 | - // add it |
|
| 940 | - switch ($QST_system) { |
|
| 941 | - case 'fname': |
|
| 942 | - $QST_values = array( |
|
| 943 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 944 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 945 | - 'QST_system' => 'fname', |
|
| 946 | - 'QST_type' => 'TEXT', |
|
| 947 | - 'QST_required' => 1, |
|
| 948 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 949 | - 'QST_order' => 1, |
|
| 950 | - 'QST_admin_only' => 0, |
|
| 951 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 952 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 953 | - 'QST_deleted' => 0, |
|
| 954 | - ); |
|
| 955 | - break; |
|
| 956 | - case 'lname': |
|
| 957 | - $QST_values = array( |
|
| 958 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 959 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 960 | - 'QST_system' => 'lname', |
|
| 961 | - 'QST_type' => 'TEXT', |
|
| 962 | - 'QST_required' => 1, |
|
| 963 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 964 | - 'QST_order' => 2, |
|
| 965 | - 'QST_admin_only' => 0, |
|
| 966 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 967 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 968 | - 'QST_deleted' => 0, |
|
| 969 | - ); |
|
| 970 | - break; |
|
| 971 | - case 'email': |
|
| 972 | - $QST_values = array( |
|
| 973 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 974 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 975 | - 'QST_system' => 'email', |
|
| 976 | - 'QST_type' => 'EMAIL', |
|
| 977 | - 'QST_required' => 1, |
|
| 978 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 979 | - 'QST_order' => 3, |
|
| 980 | - 'QST_admin_only' => 0, |
|
| 981 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 982 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 983 | - 'QST_deleted' => 0, |
|
| 984 | - ); |
|
| 985 | - break; |
|
| 986 | - case 'address': |
|
| 987 | - $QST_values = array( |
|
| 988 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 989 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 990 | - 'QST_system' => 'address', |
|
| 991 | - 'QST_type' => 'TEXT', |
|
| 992 | - 'QST_required' => 0, |
|
| 993 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 994 | - 'QST_order' => 4, |
|
| 995 | - 'QST_admin_only' => 0, |
|
| 996 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 997 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 998 | - 'QST_deleted' => 0, |
|
| 999 | - ); |
|
| 1000 | - break; |
|
| 1001 | - case 'address2': |
|
| 1002 | - $QST_values = array( |
|
| 1003 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1004 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1005 | - 'QST_system' => 'address2', |
|
| 1006 | - 'QST_type' => 'TEXT', |
|
| 1007 | - 'QST_required' => 0, |
|
| 1008 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1009 | - 'QST_order' => 5, |
|
| 1010 | - 'QST_admin_only' => 0, |
|
| 1011 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1012 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1013 | - 'QST_deleted' => 0, |
|
| 1014 | - ); |
|
| 1015 | - break; |
|
| 1016 | - case 'city': |
|
| 1017 | - $QST_values = array( |
|
| 1018 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1019 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1020 | - 'QST_system' => 'city', |
|
| 1021 | - 'QST_type' => 'TEXT', |
|
| 1022 | - 'QST_required' => 0, |
|
| 1023 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1024 | - 'QST_order' => 6, |
|
| 1025 | - 'QST_admin_only' => 0, |
|
| 1026 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1027 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1028 | - 'QST_deleted' => 0, |
|
| 1029 | - ); |
|
| 1030 | - break; |
|
| 1031 | - case 'country': |
|
| 1032 | - $QST_values = array( |
|
| 1033 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1034 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1035 | - 'QST_system' => 'country', |
|
| 1036 | - 'QST_type' => 'COUNTRY', |
|
| 1037 | - 'QST_required' => 0, |
|
| 1038 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1039 | - 'QST_order' => 7, |
|
| 1040 | - 'QST_admin_only' => 0, |
|
| 1041 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1042 | - 'QST_deleted' => 0, |
|
| 1043 | - ); |
|
| 1044 | - break; |
|
| 1045 | - case 'state': |
|
| 1046 | - $QST_values = array( |
|
| 1047 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1048 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1049 | - 'QST_system' => 'state', |
|
| 1050 | - 'QST_type' => 'STATE', |
|
| 1051 | - 'QST_required' => 0, |
|
| 1052 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1053 | - 'QST_order' => 8, |
|
| 1054 | - 'QST_admin_only' => 0, |
|
| 1055 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1056 | - 'QST_deleted' => 0, |
|
| 1057 | - ); |
|
| 1058 | - break; |
|
| 1059 | - case 'zip': |
|
| 1060 | - $QST_values = array( |
|
| 1061 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1062 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1063 | - 'QST_system' => 'zip', |
|
| 1064 | - 'QST_type' => 'TEXT', |
|
| 1065 | - 'QST_required' => 0, |
|
| 1066 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1067 | - 'QST_order' => 9, |
|
| 1068 | - 'QST_admin_only' => 0, |
|
| 1069 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1070 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1071 | - 'QST_deleted' => 0, |
|
| 1072 | - ); |
|
| 1073 | - break; |
|
| 1074 | - case 'phone': |
|
| 1075 | - $QST_values = array( |
|
| 1076 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1077 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1078 | - 'QST_system' => 'phone', |
|
| 1079 | - 'QST_type' => 'TEXT', |
|
| 1080 | - 'QST_required' => 0, |
|
| 1081 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1082 | - 'QST_order' => 10, |
|
| 1083 | - 'QST_admin_only' => 0, |
|
| 1084 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1085 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1086 | - 'QST_deleted' => 0, |
|
| 1087 | - ); |
|
| 1088 | - break; |
|
| 1089 | - } |
|
| 1090 | - if (! empty($QST_values)) { |
|
| 1091 | - // insert system question |
|
| 1092 | - $wpdb->insert( |
|
| 1093 | - $table_name, |
|
| 1094 | - $QST_values, |
|
| 1095 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1096 | - ); |
|
| 1097 | - $QST_ID = $wpdb->insert_id; |
|
| 1098 | - // QUESTION GROUP QUESTIONS |
|
| 1099 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1100 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1101 | - } else { |
|
| 1102 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1103 | - } |
|
| 1104 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1105 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1106 | - } else { |
|
| 1107 | - $id_col = EEM_Question_Group::instance() |
|
| 1108 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1109 | - if (is_array($id_col)) { |
|
| 1110 | - $QSG_ID = reset($id_col); |
|
| 1111 | - } else { |
|
| 1112 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1113 | - EE_Log::instance()->log( |
|
| 1114 | - __FILE__, |
|
| 1115 | - __FUNCTION__, |
|
| 1116 | - sprintf( |
|
| 1117 | - __( |
|
| 1118 | - 'Could not associate question %1$s to a question group because no system question |
|
| 835 | + 'event_espresso' |
|
| 836 | + ), |
|
| 837 | + __FILE__, |
|
| 838 | + __FUNCTION__, |
|
| 839 | + __LINE__ |
|
| 840 | + ); |
|
| 841 | + return false; |
|
| 842 | + } |
|
| 843 | + return true; |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * initialize_system_questions |
|
| 850 | + * |
|
| 851 | + * @access public |
|
| 852 | + * @static |
|
| 853 | + * @return void |
|
| 854 | + */ |
|
| 855 | + public static function initialize_system_questions() |
|
| 856 | + { |
|
| 857 | + // QUESTION GROUPS |
|
| 858 | + global $wpdb; |
|
| 859 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 860 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 861 | + // what we have |
|
| 862 | + $question_groups = $wpdb->get_col($SQL); |
|
| 863 | + // check the response |
|
| 864 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 865 | + // what we should have |
|
| 866 | + $QSG_systems = array(1, 2); |
|
| 867 | + // loop thru what we should have and compare to what we have |
|
| 868 | + foreach ($QSG_systems as $QSG_system) { |
|
| 869 | + // reset values array |
|
| 870 | + $QSG_values = array(); |
|
| 871 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 872 | + if (! in_array("$QSG_system", $question_groups)) { |
|
| 873 | + // add it |
|
| 874 | + switch ($QSG_system) { |
|
| 875 | + case 1: |
|
| 876 | + $QSG_values = array( |
|
| 877 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 878 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
| 879 | + 'QSG_desc' => '', |
|
| 880 | + 'QSG_order' => 1, |
|
| 881 | + 'QSG_show_group_name' => 1, |
|
| 882 | + 'QSG_show_group_desc' => 1, |
|
| 883 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 884 | + 'QSG_deleted' => 0, |
|
| 885 | + ); |
|
| 886 | + break; |
|
| 887 | + case 2: |
|
| 888 | + $QSG_values = array( |
|
| 889 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 890 | + 'QSG_identifier' => 'address-information-' . time(), |
|
| 891 | + 'QSG_desc' => '', |
|
| 892 | + 'QSG_order' => 2, |
|
| 893 | + 'QSG_show_group_name' => 1, |
|
| 894 | + 'QSG_show_group_desc' => 1, |
|
| 895 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
| 896 | + 'QSG_deleted' => 0, |
|
| 897 | + ); |
|
| 898 | + break; |
|
| 899 | + } |
|
| 900 | + // make sure we have some values before inserting them |
|
| 901 | + if (! empty($QSG_values)) { |
|
| 902 | + // insert system question |
|
| 903 | + $wpdb->insert( |
|
| 904 | + $table_name, |
|
| 905 | + $QSG_values, |
|
| 906 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 907 | + ); |
|
| 908 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | + // QUESTIONS |
|
| 913 | + global $wpdb; |
|
| 914 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 915 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 916 | + // what we have |
|
| 917 | + $questions = $wpdb->get_col($SQL); |
|
| 918 | + // what we should have |
|
| 919 | + $QST_systems = array( |
|
| 920 | + 'fname', |
|
| 921 | + 'lname', |
|
| 922 | + 'email', |
|
| 923 | + 'address', |
|
| 924 | + 'address2', |
|
| 925 | + 'city', |
|
| 926 | + 'country', |
|
| 927 | + 'state', |
|
| 928 | + 'zip', |
|
| 929 | + 'phone', |
|
| 930 | + ); |
|
| 931 | + $order_for_group_1 = 1; |
|
| 932 | + $order_for_group_2 = 1; |
|
| 933 | + // loop thru what we should have and compare to what we have |
|
| 934 | + foreach ($QST_systems as $QST_system) { |
|
| 935 | + // reset values array |
|
| 936 | + $QST_values = array(); |
|
| 937 | + // if we don't have what we should have |
|
| 938 | + if (! in_array($QST_system, $questions)) { |
|
| 939 | + // add it |
|
| 940 | + switch ($QST_system) { |
|
| 941 | + case 'fname': |
|
| 942 | + $QST_values = array( |
|
| 943 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 944 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 945 | + 'QST_system' => 'fname', |
|
| 946 | + 'QST_type' => 'TEXT', |
|
| 947 | + 'QST_required' => 1, |
|
| 948 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 949 | + 'QST_order' => 1, |
|
| 950 | + 'QST_admin_only' => 0, |
|
| 951 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 952 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 953 | + 'QST_deleted' => 0, |
|
| 954 | + ); |
|
| 955 | + break; |
|
| 956 | + case 'lname': |
|
| 957 | + $QST_values = array( |
|
| 958 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 959 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 960 | + 'QST_system' => 'lname', |
|
| 961 | + 'QST_type' => 'TEXT', |
|
| 962 | + 'QST_required' => 1, |
|
| 963 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 964 | + 'QST_order' => 2, |
|
| 965 | + 'QST_admin_only' => 0, |
|
| 966 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 967 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 968 | + 'QST_deleted' => 0, |
|
| 969 | + ); |
|
| 970 | + break; |
|
| 971 | + case 'email': |
|
| 972 | + $QST_values = array( |
|
| 973 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 974 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 975 | + 'QST_system' => 'email', |
|
| 976 | + 'QST_type' => 'EMAIL', |
|
| 977 | + 'QST_required' => 1, |
|
| 978 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 979 | + 'QST_order' => 3, |
|
| 980 | + 'QST_admin_only' => 0, |
|
| 981 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 982 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 983 | + 'QST_deleted' => 0, |
|
| 984 | + ); |
|
| 985 | + break; |
|
| 986 | + case 'address': |
|
| 987 | + $QST_values = array( |
|
| 988 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 989 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 990 | + 'QST_system' => 'address', |
|
| 991 | + 'QST_type' => 'TEXT', |
|
| 992 | + 'QST_required' => 0, |
|
| 993 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 994 | + 'QST_order' => 4, |
|
| 995 | + 'QST_admin_only' => 0, |
|
| 996 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 997 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 998 | + 'QST_deleted' => 0, |
|
| 999 | + ); |
|
| 1000 | + break; |
|
| 1001 | + case 'address2': |
|
| 1002 | + $QST_values = array( |
|
| 1003 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1004 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1005 | + 'QST_system' => 'address2', |
|
| 1006 | + 'QST_type' => 'TEXT', |
|
| 1007 | + 'QST_required' => 0, |
|
| 1008 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1009 | + 'QST_order' => 5, |
|
| 1010 | + 'QST_admin_only' => 0, |
|
| 1011 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1012 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1013 | + 'QST_deleted' => 0, |
|
| 1014 | + ); |
|
| 1015 | + break; |
|
| 1016 | + case 'city': |
|
| 1017 | + $QST_values = array( |
|
| 1018 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1019 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1020 | + 'QST_system' => 'city', |
|
| 1021 | + 'QST_type' => 'TEXT', |
|
| 1022 | + 'QST_required' => 0, |
|
| 1023 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1024 | + 'QST_order' => 6, |
|
| 1025 | + 'QST_admin_only' => 0, |
|
| 1026 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1027 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1028 | + 'QST_deleted' => 0, |
|
| 1029 | + ); |
|
| 1030 | + break; |
|
| 1031 | + case 'country': |
|
| 1032 | + $QST_values = array( |
|
| 1033 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1034 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1035 | + 'QST_system' => 'country', |
|
| 1036 | + 'QST_type' => 'COUNTRY', |
|
| 1037 | + 'QST_required' => 0, |
|
| 1038 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1039 | + 'QST_order' => 7, |
|
| 1040 | + 'QST_admin_only' => 0, |
|
| 1041 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1042 | + 'QST_deleted' => 0, |
|
| 1043 | + ); |
|
| 1044 | + break; |
|
| 1045 | + case 'state': |
|
| 1046 | + $QST_values = array( |
|
| 1047 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1048 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1049 | + 'QST_system' => 'state', |
|
| 1050 | + 'QST_type' => 'STATE', |
|
| 1051 | + 'QST_required' => 0, |
|
| 1052 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1053 | + 'QST_order' => 8, |
|
| 1054 | + 'QST_admin_only' => 0, |
|
| 1055 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1056 | + 'QST_deleted' => 0, |
|
| 1057 | + ); |
|
| 1058 | + break; |
|
| 1059 | + case 'zip': |
|
| 1060 | + $QST_values = array( |
|
| 1061 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1062 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1063 | + 'QST_system' => 'zip', |
|
| 1064 | + 'QST_type' => 'TEXT', |
|
| 1065 | + 'QST_required' => 0, |
|
| 1066 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1067 | + 'QST_order' => 9, |
|
| 1068 | + 'QST_admin_only' => 0, |
|
| 1069 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1070 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1071 | + 'QST_deleted' => 0, |
|
| 1072 | + ); |
|
| 1073 | + break; |
|
| 1074 | + case 'phone': |
|
| 1075 | + $QST_values = array( |
|
| 1076 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1077 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1078 | + 'QST_system' => 'phone', |
|
| 1079 | + 'QST_type' => 'TEXT', |
|
| 1080 | + 'QST_required' => 0, |
|
| 1081 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1082 | + 'QST_order' => 10, |
|
| 1083 | + 'QST_admin_only' => 0, |
|
| 1084 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1085 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1086 | + 'QST_deleted' => 0, |
|
| 1087 | + ); |
|
| 1088 | + break; |
|
| 1089 | + } |
|
| 1090 | + if (! empty($QST_values)) { |
|
| 1091 | + // insert system question |
|
| 1092 | + $wpdb->insert( |
|
| 1093 | + $table_name, |
|
| 1094 | + $QST_values, |
|
| 1095 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1096 | + ); |
|
| 1097 | + $QST_ID = $wpdb->insert_id; |
|
| 1098 | + // QUESTION GROUP QUESTIONS |
|
| 1099 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1100 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1101 | + } else { |
|
| 1102 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1103 | + } |
|
| 1104 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1105 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1106 | + } else { |
|
| 1107 | + $id_col = EEM_Question_Group::instance() |
|
| 1108 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1109 | + if (is_array($id_col)) { |
|
| 1110 | + $QSG_ID = reset($id_col); |
|
| 1111 | + } else { |
|
| 1112 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1113 | + EE_Log::instance()->log( |
|
| 1114 | + __FILE__, |
|
| 1115 | + __FUNCTION__, |
|
| 1116 | + sprintf( |
|
| 1117 | + __( |
|
| 1118 | + 'Could not associate question %1$s to a question group because no system question |
|
| 1119 | 1119 | group existed', |
| 1120 | - 'event_espresso' |
|
| 1121 | - ), |
|
| 1122 | - $QST_ID), |
|
| 1123 | - 'error'); |
|
| 1124 | - continue; |
|
| 1125 | - } |
|
| 1126 | - } |
|
| 1127 | - // add system questions to groups |
|
| 1128 | - $wpdb->insert( |
|
| 1129 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1130 | - array( |
|
| 1131 | - 'QSG_ID' => $QSG_ID, |
|
| 1132 | - 'QST_ID' => $QST_ID, |
|
| 1133 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1134 | - ), |
|
| 1135 | - array('%d', '%d', '%d') |
|
| 1136 | - ); |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - |
|
| 1143 | - /** |
|
| 1144 | - * Makes sure the default payment method (Invoice) is active. |
|
| 1145 | - * This used to be done automatically as part of constructing the old gateways config |
|
| 1146 | - * |
|
| 1147 | - * @throws \EE_Error |
|
| 1148 | - */ |
|
| 1149 | - public static function insert_default_payment_methods() |
|
| 1150 | - { |
|
| 1151 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1152 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1153 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1154 | - } else { |
|
| 1155 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1156 | - } |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - /** |
|
| 1160 | - * insert_default_status_codes |
|
| 1161 | - * |
|
| 1162 | - * @access public |
|
| 1163 | - * @static |
|
| 1164 | - * @return void |
|
| 1165 | - */ |
|
| 1166 | - public static function insert_default_status_codes() |
|
| 1167 | - { |
|
| 1168 | - |
|
| 1169 | - global $wpdb; |
|
| 1170 | - |
|
| 1171 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1172 | - |
|
| 1173 | - $table_name = EEM_Status::instance()->table(); |
|
| 1174 | - |
|
| 1175 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1176 | - $wpdb->query($SQL); |
|
| 1177 | - |
|
| 1178 | - $SQL = "INSERT INTO $table_name |
|
| 1120 | + 'event_espresso' |
|
| 1121 | + ), |
|
| 1122 | + $QST_ID), |
|
| 1123 | + 'error'); |
|
| 1124 | + continue; |
|
| 1125 | + } |
|
| 1126 | + } |
|
| 1127 | + // add system questions to groups |
|
| 1128 | + $wpdb->insert( |
|
| 1129 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1130 | + array( |
|
| 1131 | + 'QSG_ID' => $QSG_ID, |
|
| 1132 | + 'QST_ID' => $QST_ID, |
|
| 1133 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1134 | + ), |
|
| 1135 | + array('%d', '%d', '%d') |
|
| 1136 | + ); |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + |
|
| 1143 | + /** |
|
| 1144 | + * Makes sure the default payment method (Invoice) is active. |
|
| 1145 | + * This used to be done automatically as part of constructing the old gateways config |
|
| 1146 | + * |
|
| 1147 | + * @throws \EE_Error |
|
| 1148 | + */ |
|
| 1149 | + public static function insert_default_payment_methods() |
|
| 1150 | + { |
|
| 1151 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1152 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1153 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1154 | + } else { |
|
| 1155 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1156 | + } |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + /** |
|
| 1160 | + * insert_default_status_codes |
|
| 1161 | + * |
|
| 1162 | + * @access public |
|
| 1163 | + * @static |
|
| 1164 | + * @return void |
|
| 1165 | + */ |
|
| 1166 | + public static function insert_default_status_codes() |
|
| 1167 | + { |
|
| 1168 | + |
|
| 1169 | + global $wpdb; |
|
| 1170 | + |
|
| 1171 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1172 | + |
|
| 1173 | + $table_name = EEM_Status::instance()->table(); |
|
| 1174 | + |
|
| 1175 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1176 | + $wpdb->query($SQL); |
|
| 1177 | + |
|
| 1178 | + $SQL = "INSERT INTO $table_name |
|
| 1179 | 1179 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
| 1180 | 1180 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
| 1181 | 1181 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1215,521 +1215,521 @@ discard block |
||
| 1215 | 1215 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
| 1216 | 1216 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
| 1217 | 1217 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
| 1218 | - $wpdb->query($SQL); |
|
| 1219 | - |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - |
|
| 1225 | - /** |
|
| 1226 | - * create_upload_directories |
|
| 1227 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1228 | - * |
|
| 1229 | - * @access public |
|
| 1230 | - * @static |
|
| 1231 | - * @return boolean success of verifying upload directories exist |
|
| 1232 | - */ |
|
| 1233 | - public static function create_upload_directories() |
|
| 1234 | - { |
|
| 1235 | - // Create the required folders |
|
| 1236 | - $folders = array( |
|
| 1237 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1238 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1242 | - ); |
|
| 1243 | - foreach ($folders as $folder) { |
|
| 1244 | - try { |
|
| 1245 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1246 | - @ chmod($folder, 0755); |
|
| 1247 | - } catch (EE_Error $e) { |
|
| 1248 | - EE_Error::add_error( |
|
| 1249 | - sprintf( |
|
| 1250 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1251 | - $folder, |
|
| 1252 | - '<br />' . $e->getMessage() |
|
| 1253 | - ), |
|
| 1254 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1255 | - ); |
|
| 1256 | - //indicate we'll need to fix this later |
|
| 1257 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1258 | - return false; |
|
| 1259 | - } |
|
| 1260 | - } |
|
| 1261 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1262 | - //is disabled, there might be activation errors recorded in there |
|
| 1263 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1264 | - //remember EE's folders are all good |
|
| 1265 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1266 | - return true; |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - /** |
|
| 1270 | - * Whether the upload directories need to be fixed or not. |
|
| 1271 | - * If EE is installed but filesystem access isn't initially available, |
|
| 1272 | - * we need to get the user's filesystem credentials and THEN create them, |
|
| 1273 | - * so there might be period of time when EE is installed but its |
|
| 1274 | - * upload directories aren't available. This indicates such a state |
|
| 1275 | - * |
|
| 1276 | - * @return boolean |
|
| 1277 | - */ |
|
| 1278 | - public static function upload_directories_incomplete() |
|
| 1279 | - { |
|
| 1280 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - |
|
| 1284 | - /** |
|
| 1285 | - * generate_default_message_templates |
|
| 1286 | - * |
|
| 1287 | - * @static |
|
| 1288 | - * @throws EE_Error |
|
| 1289 | - * @return bool true means new templates were created. |
|
| 1290 | - * false means no templates were created. |
|
| 1291 | - * This is NOT an error flag. To check for errors you will want |
|
| 1292 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1293 | - */ |
|
| 1294 | - public static function generate_default_message_templates() |
|
| 1295 | - { |
|
| 1296 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1297 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1298 | - /* |
|
| 1218 | + $wpdb->query($SQL); |
|
| 1219 | + |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + |
|
| 1225 | + /** |
|
| 1226 | + * create_upload_directories |
|
| 1227 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1228 | + * |
|
| 1229 | + * @access public |
|
| 1230 | + * @static |
|
| 1231 | + * @return boolean success of verifying upload directories exist |
|
| 1232 | + */ |
|
| 1233 | + public static function create_upload_directories() |
|
| 1234 | + { |
|
| 1235 | + // Create the required folders |
|
| 1236 | + $folders = array( |
|
| 1237 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1238 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1239 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1240 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1241 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1242 | + ); |
|
| 1243 | + foreach ($folders as $folder) { |
|
| 1244 | + try { |
|
| 1245 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1246 | + @ chmod($folder, 0755); |
|
| 1247 | + } catch (EE_Error $e) { |
|
| 1248 | + EE_Error::add_error( |
|
| 1249 | + sprintf( |
|
| 1250 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1251 | + $folder, |
|
| 1252 | + '<br />' . $e->getMessage() |
|
| 1253 | + ), |
|
| 1254 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1255 | + ); |
|
| 1256 | + //indicate we'll need to fix this later |
|
| 1257 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1258 | + return false; |
|
| 1259 | + } |
|
| 1260 | + } |
|
| 1261 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1262 | + //is disabled, there might be activation errors recorded in there |
|
| 1263 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1264 | + //remember EE's folders are all good |
|
| 1265 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1266 | + return true; |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + /** |
|
| 1270 | + * Whether the upload directories need to be fixed or not. |
|
| 1271 | + * If EE is installed but filesystem access isn't initially available, |
|
| 1272 | + * we need to get the user's filesystem credentials and THEN create them, |
|
| 1273 | + * so there might be period of time when EE is installed but its |
|
| 1274 | + * upload directories aren't available. This indicates such a state |
|
| 1275 | + * |
|
| 1276 | + * @return boolean |
|
| 1277 | + */ |
|
| 1278 | + public static function upload_directories_incomplete() |
|
| 1279 | + { |
|
| 1280 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + |
|
| 1284 | + /** |
|
| 1285 | + * generate_default_message_templates |
|
| 1286 | + * |
|
| 1287 | + * @static |
|
| 1288 | + * @throws EE_Error |
|
| 1289 | + * @return bool true means new templates were created. |
|
| 1290 | + * false means no templates were created. |
|
| 1291 | + * This is NOT an error flag. To check for errors you will want |
|
| 1292 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1293 | + */ |
|
| 1294 | + public static function generate_default_message_templates() |
|
| 1295 | + { |
|
| 1296 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1297 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1298 | + /* |
|
| 1299 | 1299 | * This first method is taking care of ensuring any default messengers |
| 1300 | 1300 | * that should be made active and have templates generated are done. |
| 1301 | 1301 | */ |
| 1302 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1303 | - $message_resource_manager |
|
| 1304 | - ); |
|
| 1305 | - /** |
|
| 1306 | - * This method is verifying there are no NEW default message types |
|
| 1307 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1308 | - */ |
|
| 1309 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1310 | - $message_resource_manager |
|
| 1311 | - ); |
|
| 1312 | - //after all is done, let's persist these changes to the db. |
|
| 1313 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1314 | - $message_resource_manager->update_active_messengers_option(); |
|
| 1315 | - // will return true if either of these are true. Otherwise will return false. |
|
| 1316 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1323 | - * @return array|bool |
|
| 1324 | - * @throws \EE_Error |
|
| 1325 | - */ |
|
| 1326 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1327 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1328 | - ) { |
|
| 1329 | - /** @type EE_messenger[] $active_messengers */ |
|
| 1330 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1331 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1332 | - $templates_created = false; |
|
| 1333 | - foreach ($active_messengers as $active_messenger) { |
|
| 1334 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1335 | - $default_message_type_names_to_activate = array(); |
|
| 1336 | - // looping through each default message type reported by the messenger |
|
| 1337 | - // and setup the actual message types to activate. |
|
| 1338 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1339 | - // if already active or has already been activated before we skip |
|
| 1340 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1341 | - // we also skip if the message type is not installed. |
|
| 1342 | - if ( |
|
| 1343 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1344 | - $default_message_type_name_for_messenger, |
|
| 1345 | - $active_messenger->name |
|
| 1346 | - ) |
|
| 1347 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1348 | - $active_messenger->name, |
|
| 1349 | - $default_message_type_name_for_messenger |
|
| 1350 | - ) |
|
| 1351 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1352 | - ) { |
|
| 1353 | - continue; |
|
| 1354 | - } |
|
| 1355 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1356 | - } |
|
| 1357 | - //let's activate! |
|
| 1358 | - $message_resource_manager->ensure_message_types_are_active( |
|
| 1359 | - $default_message_type_names_to_activate, |
|
| 1360 | - $active_messenger->name, |
|
| 1361 | - false |
|
| 1362 | - ); |
|
| 1363 | - //activate the templates for these message types |
|
| 1364 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1365 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1366 | - $active_messenger->name, |
|
| 1367 | - $default_message_type_names_for_messenger, |
|
| 1368 | - '', |
|
| 1369 | - true |
|
| 1370 | - ); |
|
| 1371 | - } |
|
| 1372 | - } |
|
| 1373 | - return $templates_created; |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * This will activate and generate default messengers and default message types for those messengers. |
|
| 1380 | - * |
|
| 1381 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1382 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1383 | - * False means that there were no templates generated |
|
| 1384 | - * (which could simply mean there are no default message types for a messenger). |
|
| 1385 | - * @throws EE_Error |
|
| 1386 | - */ |
|
| 1387 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1388 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1389 | - ) { |
|
| 1390 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1391 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1392 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1393 | - $templates_generated = false; |
|
| 1394 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1395 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1396 | - //verify the default message types match an installed message type. |
|
| 1397 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1398 | - if ( |
|
| 1399 | - ! isset($installed_message_types[$name]) |
|
| 1400 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1401 | - $name, |
|
| 1402 | - $messenger_to_generate->name |
|
| 1403 | - ) |
|
| 1404 | - ) { |
|
| 1405 | - unset($default_message_type_names_for_messenger[$key]); |
|
| 1406 | - } |
|
| 1407 | - } |
|
| 1408 | - // in previous iterations, the active_messengers option in the db |
|
| 1409 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1410 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1411 | - // passing off to create templates (after the refactor is done). |
|
| 1412 | - // @todo remove this comment when determined not necessary. |
|
| 1413 | - $message_resource_manager->activate_messenger( |
|
| 1414 | - $messenger_to_generate->name, |
|
| 1415 | - $default_message_type_names_for_messenger, |
|
| 1416 | - false |
|
| 1417 | - ); |
|
| 1418 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1419 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1420 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1421 | - $messenger_to_generate->name, |
|
| 1422 | - $default_message_type_names_for_messenger, |
|
| 1423 | - '', |
|
| 1424 | - true |
|
| 1425 | - ); |
|
| 1426 | - } |
|
| 1427 | - } |
|
| 1428 | - return $templates_generated; |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - |
|
| 1432 | - /** |
|
| 1433 | - * This returns the default messengers to generate templates for on activation of EE. |
|
| 1434 | - * It considers: |
|
| 1435 | - * - whether a messenger is already active in the db. |
|
| 1436 | - * - whether a messenger has been made active at any time in the past. |
|
| 1437 | - * |
|
| 1438 | - * @static |
|
| 1439 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1440 | - * @return EE_messenger[] |
|
| 1441 | - */ |
|
| 1442 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1443 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1444 | - ) { |
|
| 1445 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1446 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1447 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1448 | - |
|
| 1449 | - $messengers_to_generate = array(); |
|
| 1450 | - foreach ($installed_messengers as $installed_messenger) { |
|
| 1451 | - //if installed messenger is a messenger that should be activated on install |
|
| 1452 | - //and is not already active |
|
| 1453 | - //and has never been activated |
|
| 1454 | - if ( |
|
| 1455 | - ! $installed_messenger->activate_on_install |
|
| 1456 | - || isset($active_messengers[$installed_messenger->name]) |
|
| 1457 | - || isset($has_activated[$installed_messenger->name]) |
|
| 1458 | - ) { |
|
| 1459 | - continue; |
|
| 1460 | - } |
|
| 1461 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1462 | - } |
|
| 1463 | - return $messengers_to_generate; |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * This simply validates active message types to ensure they actually match installed |
|
| 1469 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1470 | - * rows are set inactive. |
|
| 1471 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1472 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1473 | - * are still handled in here. |
|
| 1474 | - * |
|
| 1475 | - * @since 4.3.1 |
|
| 1476 | - * @return void |
|
| 1477 | - */ |
|
| 1478 | - public static function validate_messages_system() |
|
| 1479 | - { |
|
| 1480 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1481 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1482 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1483 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1484 | - } |
|
| 1485 | - |
|
| 1486 | - |
|
| 1487 | - /** |
|
| 1488 | - * create_no_ticket_prices_array |
|
| 1489 | - * |
|
| 1490 | - * @access public |
|
| 1491 | - * @static |
|
| 1492 | - * @return void |
|
| 1493 | - */ |
|
| 1494 | - public static function create_no_ticket_prices_array() |
|
| 1495 | - { |
|
| 1496 | - // this creates an array for tracking events that have no active ticket prices created |
|
| 1497 | - // this allows us to warn admins of the situation so that it can be corrected |
|
| 1498 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1499 | - if (! $espresso_no_ticket_prices) { |
|
| 1500 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1501 | - } |
|
| 1502 | - } |
|
| 1503 | - |
|
| 1504 | - |
|
| 1505 | - /** |
|
| 1506 | - * plugin_deactivation |
|
| 1507 | - * |
|
| 1508 | - * @access public |
|
| 1509 | - * @static |
|
| 1510 | - * @return void |
|
| 1511 | - */ |
|
| 1512 | - public static function plugin_deactivation() |
|
| 1513 | - { |
|
| 1514 | - } |
|
| 1515 | - |
|
| 1516 | - |
|
| 1517 | - /** |
|
| 1518 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1519 | - * (like post meta or term relations) |
|
| 1520 | - * |
|
| 1521 | - * @global wpdb $wpdb |
|
| 1522 | - * @throws \EE_Error |
|
| 1523 | - */ |
|
| 1524 | - public static function delete_all_espresso_cpt_data() |
|
| 1525 | - { |
|
| 1526 | - global $wpdb; |
|
| 1527 | - //get all the CPT post_types |
|
| 1528 | - $ee_post_types = array(); |
|
| 1529 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1530 | - if (method_exists($model_name, 'instance')) { |
|
| 1531 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1532 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1533 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1534 | - } |
|
| 1535 | - } |
|
| 1536 | - } |
|
| 1537 | - //get all our CPTs |
|
| 1538 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1539 | - $cpt_ids = $wpdb->get_col($query); |
|
| 1540 | - //delete each post meta and term relations too |
|
| 1541 | - foreach ($cpt_ids as $post_id) { |
|
| 1542 | - wp_delete_post($post_id, true); |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - /** |
|
| 1547 | - * Deletes all EE custom tables |
|
| 1548 | - * |
|
| 1549 | - * @return array |
|
| 1550 | - */ |
|
| 1551 | - public static function drop_espresso_tables() |
|
| 1552 | - { |
|
| 1553 | - $tables = array(); |
|
| 1554 | - // load registry |
|
| 1555 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1556 | - if (method_exists($model_name, 'instance')) { |
|
| 1557 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1558 | - if ($model_obj instanceof EEM_Base) { |
|
| 1559 | - foreach ($model_obj->get_tables() as $table) { |
|
| 1560 | - if (strpos($table->get_table_name(), 'esp_') |
|
| 1561 | - && |
|
| 1562 | - ( |
|
| 1563 | - is_main_site()//main site? nuke them all |
|
| 1564 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1565 | - ) |
|
| 1566 | - ) { |
|
| 1567 | - $tables[$table->get_table_name()] = $table->get_table_name(); |
|
| 1568 | - } |
|
| 1569 | - } |
|
| 1570 | - } |
|
| 1571 | - } |
|
| 1572 | - } |
|
| 1573 | - |
|
| 1574 | - //there are some tables whose models were removed. |
|
| 1575 | - //they should be removed when removing all EE core's data |
|
| 1576 | - $tables_without_models = array( |
|
| 1577 | - 'esp_promotion', |
|
| 1578 | - 'esp_promotion_applied', |
|
| 1579 | - 'esp_promotion_object', |
|
| 1580 | - 'esp_promotion_rule', |
|
| 1581 | - 'esp_rule', |
|
| 1582 | - ); |
|
| 1583 | - foreach ($tables_without_models as $table) { |
|
| 1584 | - $tables[$table] = $table; |
|
| 1585 | - } |
|
| 1586 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - |
|
| 1590 | - |
|
| 1591 | - /** |
|
| 1592 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1593 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1594 | - * Returns the list actually deleted |
|
| 1595 | - * |
|
| 1596 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1597 | - * @global WPDB $wpdb |
|
| 1598 | - * @param array $table_names |
|
| 1599 | - * @return array of table names which we deleted |
|
| 1600 | - */ |
|
| 1601 | - public static function drop_tables($table_names) |
|
| 1602 | - { |
|
| 1603 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - /** |
|
| 1609 | - * plugin_uninstall |
|
| 1610 | - * |
|
| 1611 | - * @access public |
|
| 1612 | - * @static |
|
| 1613 | - * @param bool $remove_all |
|
| 1614 | - * @return void |
|
| 1615 | - */ |
|
| 1616 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1617 | - { |
|
| 1618 | - global $wpdb; |
|
| 1619 | - self::drop_espresso_tables(); |
|
| 1620 | - $wp_options_to_delete = array( |
|
| 1621 | - 'ee_no_ticket_prices' => true, |
|
| 1622 | - 'ee_active_messengers' => true, |
|
| 1623 | - 'ee_has_activated_messenger' => true, |
|
| 1624 | - 'ee_flush_rewrite_rules' => true, |
|
| 1625 | - 'ee_config' => false, |
|
| 1626 | - 'ee_data_migration_current_db_state' => true, |
|
| 1627 | - 'ee_data_migration_mapping_' => false, |
|
| 1628 | - 'ee_data_migration_script_' => false, |
|
| 1629 | - 'ee_data_migrations' => true, |
|
| 1630 | - 'ee_dms_map' => false, |
|
| 1631 | - 'ee_notices' => true, |
|
| 1632 | - 'lang_file_check_' => false, |
|
| 1633 | - 'ee_maintenance_mode' => true, |
|
| 1634 | - 'ee_ueip_optin' => true, |
|
| 1635 | - 'ee_ueip_has_notified' => true, |
|
| 1636 | - 'ee_plugin_activation_errors' => true, |
|
| 1637 | - 'ee_id_mapping_from' => false, |
|
| 1638 | - 'espresso_persistent_admin_notices' => true, |
|
| 1639 | - 'ee_encryption_key' => true, |
|
| 1640 | - 'pue_force_upgrade_' => false, |
|
| 1641 | - 'pue_json_error_' => false, |
|
| 1642 | - 'pue_install_key_' => false, |
|
| 1643 | - 'pue_verification_error_' => false, |
|
| 1644 | - 'pu_dismissed_upgrade_' => false, |
|
| 1645 | - 'external_updates-' => false, |
|
| 1646 | - 'ee_extra_data' => true, |
|
| 1647 | - 'ee_ssn_' => false, |
|
| 1648 | - 'ee_rss_' => false, |
|
| 1649 | - 'ee_rte_n_tx_' => false, |
|
| 1650 | - 'ee_pers_admin_notices' => true, |
|
| 1651 | - 'ee_job_parameters_' => false, |
|
| 1652 | - 'ee_upload_directories_incomplete' => true, |
|
| 1653 | - 'ee_verified_db_collations' => true, |
|
| 1654 | - ); |
|
| 1655 | - if (is_main_site()) { |
|
| 1656 | - $wp_options_to_delete['ee_network_config'] = true; |
|
| 1657 | - } |
|
| 1658 | - $undeleted_options = array(); |
|
| 1659 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1660 | - if ($no_wildcard) { |
|
| 1661 | - if ( ! delete_option($option_name)) { |
|
| 1662 | - $undeleted_options[] = $option_name; |
|
| 1663 | - } |
|
| 1664 | - } else { |
|
| 1665 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1666 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1667 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1668 | - $undeleted_options[] = $option_name_from_wildcard; |
|
| 1669 | - } |
|
| 1670 | - } |
|
| 1671 | - } |
|
| 1672 | - } |
|
| 1673 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1674 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1675 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1676 | - $db_update_sans_ee4 = array(); |
|
| 1677 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1678 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1679 | - $db_update_sans_ee4[$version] = $times_activated; |
|
| 1680 | - } |
|
| 1681 | - } |
|
| 1682 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1683 | - } |
|
| 1684 | - $errors = ''; |
|
| 1685 | - if ( ! empty($undeleted_options)) { |
|
| 1686 | - $errors .= sprintf( |
|
| 1687 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1688 | - '<br/>', |
|
| 1689 | - implode(',<br/>', $undeleted_options) |
|
| 1690 | - ); |
|
| 1691 | - } |
|
| 1692 | - if ( ! empty($errors)) { |
|
| 1693 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1694 | - } |
|
| 1695 | - } |
|
| 1696 | - |
|
| 1697 | - /** |
|
| 1698 | - * Gets the mysql error code from the last used query by wpdb |
|
| 1699 | - * |
|
| 1700 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1701 | - */ |
|
| 1702 | - public static function last_wpdb_error_code() |
|
| 1703 | - { |
|
| 1704 | - global $wpdb; |
|
| 1705 | - if ($wpdb->use_mysqli) { |
|
| 1706 | - return mysqli_errno($wpdb->dbh); |
|
| 1707 | - } else { |
|
| 1708 | - return mysql_errno($wpdb->dbh); |
|
| 1709 | - } |
|
| 1710 | - } |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1714 | - * |
|
| 1715 | - * @global wpdb $wpdb |
|
| 1716 | - * @deprecated instead use TableAnalysis::tableExists() |
|
| 1717 | - * @param string $table_name with or without $wpdb->prefix |
|
| 1718 | - * @return boolean |
|
| 1719 | - */ |
|
| 1720 | - public static function table_exists($table_name) |
|
| 1721 | - { |
|
| 1722 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - /** |
|
| 1726 | - * Resets the cache on EEH_Activation |
|
| 1727 | - */ |
|
| 1728 | - public static function reset() |
|
| 1729 | - { |
|
| 1730 | - self::$_default_creator_id = null; |
|
| 1731 | - self::$_initialized_db_content_already_in_this_request = false; |
|
| 1732 | - } |
|
| 1302 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1303 | + $message_resource_manager |
|
| 1304 | + ); |
|
| 1305 | + /** |
|
| 1306 | + * This method is verifying there are no NEW default message types |
|
| 1307 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1308 | + */ |
|
| 1309 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1310 | + $message_resource_manager |
|
| 1311 | + ); |
|
| 1312 | + //after all is done, let's persist these changes to the db. |
|
| 1313 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1314 | + $message_resource_manager->update_active_messengers_option(); |
|
| 1315 | + // will return true if either of these are true. Otherwise will return false. |
|
| 1316 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1323 | + * @return array|bool |
|
| 1324 | + * @throws \EE_Error |
|
| 1325 | + */ |
|
| 1326 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1327 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1328 | + ) { |
|
| 1329 | + /** @type EE_messenger[] $active_messengers */ |
|
| 1330 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1331 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1332 | + $templates_created = false; |
|
| 1333 | + foreach ($active_messengers as $active_messenger) { |
|
| 1334 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1335 | + $default_message_type_names_to_activate = array(); |
|
| 1336 | + // looping through each default message type reported by the messenger |
|
| 1337 | + // and setup the actual message types to activate. |
|
| 1338 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1339 | + // if already active or has already been activated before we skip |
|
| 1340 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1341 | + // we also skip if the message type is not installed. |
|
| 1342 | + if ( |
|
| 1343 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1344 | + $default_message_type_name_for_messenger, |
|
| 1345 | + $active_messenger->name |
|
| 1346 | + ) |
|
| 1347 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1348 | + $active_messenger->name, |
|
| 1349 | + $default_message_type_name_for_messenger |
|
| 1350 | + ) |
|
| 1351 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1352 | + ) { |
|
| 1353 | + continue; |
|
| 1354 | + } |
|
| 1355 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1356 | + } |
|
| 1357 | + //let's activate! |
|
| 1358 | + $message_resource_manager->ensure_message_types_are_active( |
|
| 1359 | + $default_message_type_names_to_activate, |
|
| 1360 | + $active_messenger->name, |
|
| 1361 | + false |
|
| 1362 | + ); |
|
| 1363 | + //activate the templates for these message types |
|
| 1364 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1365 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1366 | + $active_messenger->name, |
|
| 1367 | + $default_message_type_names_for_messenger, |
|
| 1368 | + '', |
|
| 1369 | + true |
|
| 1370 | + ); |
|
| 1371 | + } |
|
| 1372 | + } |
|
| 1373 | + return $templates_created; |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * This will activate and generate default messengers and default message types for those messengers. |
|
| 1380 | + * |
|
| 1381 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1382 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1383 | + * False means that there were no templates generated |
|
| 1384 | + * (which could simply mean there are no default message types for a messenger). |
|
| 1385 | + * @throws EE_Error |
|
| 1386 | + */ |
|
| 1387 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1388 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1389 | + ) { |
|
| 1390 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1391 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1392 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1393 | + $templates_generated = false; |
|
| 1394 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1395 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1396 | + //verify the default message types match an installed message type. |
|
| 1397 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1398 | + if ( |
|
| 1399 | + ! isset($installed_message_types[$name]) |
|
| 1400 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1401 | + $name, |
|
| 1402 | + $messenger_to_generate->name |
|
| 1403 | + ) |
|
| 1404 | + ) { |
|
| 1405 | + unset($default_message_type_names_for_messenger[$key]); |
|
| 1406 | + } |
|
| 1407 | + } |
|
| 1408 | + // in previous iterations, the active_messengers option in the db |
|
| 1409 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1410 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1411 | + // passing off to create templates (after the refactor is done). |
|
| 1412 | + // @todo remove this comment when determined not necessary. |
|
| 1413 | + $message_resource_manager->activate_messenger( |
|
| 1414 | + $messenger_to_generate->name, |
|
| 1415 | + $default_message_type_names_for_messenger, |
|
| 1416 | + false |
|
| 1417 | + ); |
|
| 1418 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1419 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1420 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1421 | + $messenger_to_generate->name, |
|
| 1422 | + $default_message_type_names_for_messenger, |
|
| 1423 | + '', |
|
| 1424 | + true |
|
| 1425 | + ); |
|
| 1426 | + } |
|
| 1427 | + } |
|
| 1428 | + return $templates_generated; |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + |
|
| 1432 | + /** |
|
| 1433 | + * This returns the default messengers to generate templates for on activation of EE. |
|
| 1434 | + * It considers: |
|
| 1435 | + * - whether a messenger is already active in the db. |
|
| 1436 | + * - whether a messenger has been made active at any time in the past. |
|
| 1437 | + * |
|
| 1438 | + * @static |
|
| 1439 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1440 | + * @return EE_messenger[] |
|
| 1441 | + */ |
|
| 1442 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1443 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1444 | + ) { |
|
| 1445 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1446 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1447 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1448 | + |
|
| 1449 | + $messengers_to_generate = array(); |
|
| 1450 | + foreach ($installed_messengers as $installed_messenger) { |
|
| 1451 | + //if installed messenger is a messenger that should be activated on install |
|
| 1452 | + //and is not already active |
|
| 1453 | + //and has never been activated |
|
| 1454 | + if ( |
|
| 1455 | + ! $installed_messenger->activate_on_install |
|
| 1456 | + || isset($active_messengers[$installed_messenger->name]) |
|
| 1457 | + || isset($has_activated[$installed_messenger->name]) |
|
| 1458 | + ) { |
|
| 1459 | + continue; |
|
| 1460 | + } |
|
| 1461 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1462 | + } |
|
| 1463 | + return $messengers_to_generate; |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * This simply validates active message types to ensure they actually match installed |
|
| 1469 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1470 | + * rows are set inactive. |
|
| 1471 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1472 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1473 | + * are still handled in here. |
|
| 1474 | + * |
|
| 1475 | + * @since 4.3.1 |
|
| 1476 | + * @return void |
|
| 1477 | + */ |
|
| 1478 | + public static function validate_messages_system() |
|
| 1479 | + { |
|
| 1480 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1481 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1482 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1483 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1484 | + } |
|
| 1485 | + |
|
| 1486 | + |
|
| 1487 | + /** |
|
| 1488 | + * create_no_ticket_prices_array |
|
| 1489 | + * |
|
| 1490 | + * @access public |
|
| 1491 | + * @static |
|
| 1492 | + * @return void |
|
| 1493 | + */ |
|
| 1494 | + public static function create_no_ticket_prices_array() |
|
| 1495 | + { |
|
| 1496 | + // this creates an array for tracking events that have no active ticket prices created |
|
| 1497 | + // this allows us to warn admins of the situation so that it can be corrected |
|
| 1498 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1499 | + if (! $espresso_no_ticket_prices) { |
|
| 1500 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1501 | + } |
|
| 1502 | + } |
|
| 1503 | + |
|
| 1504 | + |
|
| 1505 | + /** |
|
| 1506 | + * plugin_deactivation |
|
| 1507 | + * |
|
| 1508 | + * @access public |
|
| 1509 | + * @static |
|
| 1510 | + * @return void |
|
| 1511 | + */ |
|
| 1512 | + public static function plugin_deactivation() |
|
| 1513 | + { |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + |
|
| 1517 | + /** |
|
| 1518 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1519 | + * (like post meta or term relations) |
|
| 1520 | + * |
|
| 1521 | + * @global wpdb $wpdb |
|
| 1522 | + * @throws \EE_Error |
|
| 1523 | + */ |
|
| 1524 | + public static function delete_all_espresso_cpt_data() |
|
| 1525 | + { |
|
| 1526 | + global $wpdb; |
|
| 1527 | + //get all the CPT post_types |
|
| 1528 | + $ee_post_types = array(); |
|
| 1529 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1530 | + if (method_exists($model_name, 'instance')) { |
|
| 1531 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1532 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1533 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1534 | + } |
|
| 1535 | + } |
|
| 1536 | + } |
|
| 1537 | + //get all our CPTs |
|
| 1538 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1539 | + $cpt_ids = $wpdb->get_col($query); |
|
| 1540 | + //delete each post meta and term relations too |
|
| 1541 | + foreach ($cpt_ids as $post_id) { |
|
| 1542 | + wp_delete_post($post_id, true); |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + /** |
|
| 1547 | + * Deletes all EE custom tables |
|
| 1548 | + * |
|
| 1549 | + * @return array |
|
| 1550 | + */ |
|
| 1551 | + public static function drop_espresso_tables() |
|
| 1552 | + { |
|
| 1553 | + $tables = array(); |
|
| 1554 | + // load registry |
|
| 1555 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1556 | + if (method_exists($model_name, 'instance')) { |
|
| 1557 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1558 | + if ($model_obj instanceof EEM_Base) { |
|
| 1559 | + foreach ($model_obj->get_tables() as $table) { |
|
| 1560 | + if (strpos($table->get_table_name(), 'esp_') |
|
| 1561 | + && |
|
| 1562 | + ( |
|
| 1563 | + is_main_site()//main site? nuke them all |
|
| 1564 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1565 | + ) |
|
| 1566 | + ) { |
|
| 1567 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
| 1568 | + } |
|
| 1569 | + } |
|
| 1570 | + } |
|
| 1571 | + } |
|
| 1572 | + } |
|
| 1573 | + |
|
| 1574 | + //there are some tables whose models were removed. |
|
| 1575 | + //they should be removed when removing all EE core's data |
|
| 1576 | + $tables_without_models = array( |
|
| 1577 | + 'esp_promotion', |
|
| 1578 | + 'esp_promotion_applied', |
|
| 1579 | + 'esp_promotion_object', |
|
| 1580 | + 'esp_promotion_rule', |
|
| 1581 | + 'esp_rule', |
|
| 1582 | + ); |
|
| 1583 | + foreach ($tables_without_models as $table) { |
|
| 1584 | + $tables[$table] = $table; |
|
| 1585 | + } |
|
| 1586 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + |
|
| 1590 | + |
|
| 1591 | + /** |
|
| 1592 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1593 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1594 | + * Returns the list actually deleted |
|
| 1595 | + * |
|
| 1596 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1597 | + * @global WPDB $wpdb |
|
| 1598 | + * @param array $table_names |
|
| 1599 | + * @return array of table names which we deleted |
|
| 1600 | + */ |
|
| 1601 | + public static function drop_tables($table_names) |
|
| 1602 | + { |
|
| 1603 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + /** |
|
| 1609 | + * plugin_uninstall |
|
| 1610 | + * |
|
| 1611 | + * @access public |
|
| 1612 | + * @static |
|
| 1613 | + * @param bool $remove_all |
|
| 1614 | + * @return void |
|
| 1615 | + */ |
|
| 1616 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1617 | + { |
|
| 1618 | + global $wpdb; |
|
| 1619 | + self::drop_espresso_tables(); |
|
| 1620 | + $wp_options_to_delete = array( |
|
| 1621 | + 'ee_no_ticket_prices' => true, |
|
| 1622 | + 'ee_active_messengers' => true, |
|
| 1623 | + 'ee_has_activated_messenger' => true, |
|
| 1624 | + 'ee_flush_rewrite_rules' => true, |
|
| 1625 | + 'ee_config' => false, |
|
| 1626 | + 'ee_data_migration_current_db_state' => true, |
|
| 1627 | + 'ee_data_migration_mapping_' => false, |
|
| 1628 | + 'ee_data_migration_script_' => false, |
|
| 1629 | + 'ee_data_migrations' => true, |
|
| 1630 | + 'ee_dms_map' => false, |
|
| 1631 | + 'ee_notices' => true, |
|
| 1632 | + 'lang_file_check_' => false, |
|
| 1633 | + 'ee_maintenance_mode' => true, |
|
| 1634 | + 'ee_ueip_optin' => true, |
|
| 1635 | + 'ee_ueip_has_notified' => true, |
|
| 1636 | + 'ee_plugin_activation_errors' => true, |
|
| 1637 | + 'ee_id_mapping_from' => false, |
|
| 1638 | + 'espresso_persistent_admin_notices' => true, |
|
| 1639 | + 'ee_encryption_key' => true, |
|
| 1640 | + 'pue_force_upgrade_' => false, |
|
| 1641 | + 'pue_json_error_' => false, |
|
| 1642 | + 'pue_install_key_' => false, |
|
| 1643 | + 'pue_verification_error_' => false, |
|
| 1644 | + 'pu_dismissed_upgrade_' => false, |
|
| 1645 | + 'external_updates-' => false, |
|
| 1646 | + 'ee_extra_data' => true, |
|
| 1647 | + 'ee_ssn_' => false, |
|
| 1648 | + 'ee_rss_' => false, |
|
| 1649 | + 'ee_rte_n_tx_' => false, |
|
| 1650 | + 'ee_pers_admin_notices' => true, |
|
| 1651 | + 'ee_job_parameters_' => false, |
|
| 1652 | + 'ee_upload_directories_incomplete' => true, |
|
| 1653 | + 'ee_verified_db_collations' => true, |
|
| 1654 | + ); |
|
| 1655 | + if (is_main_site()) { |
|
| 1656 | + $wp_options_to_delete['ee_network_config'] = true; |
|
| 1657 | + } |
|
| 1658 | + $undeleted_options = array(); |
|
| 1659 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1660 | + if ($no_wildcard) { |
|
| 1661 | + if ( ! delete_option($option_name)) { |
|
| 1662 | + $undeleted_options[] = $option_name; |
|
| 1663 | + } |
|
| 1664 | + } else { |
|
| 1665 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1666 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1667 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1668 | + $undeleted_options[] = $option_name_from_wildcard; |
|
| 1669 | + } |
|
| 1670 | + } |
|
| 1671 | + } |
|
| 1672 | + } |
|
| 1673 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1674 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1675 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1676 | + $db_update_sans_ee4 = array(); |
|
| 1677 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1678 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1679 | + $db_update_sans_ee4[$version] = $times_activated; |
|
| 1680 | + } |
|
| 1681 | + } |
|
| 1682 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1683 | + } |
|
| 1684 | + $errors = ''; |
|
| 1685 | + if ( ! empty($undeleted_options)) { |
|
| 1686 | + $errors .= sprintf( |
|
| 1687 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1688 | + '<br/>', |
|
| 1689 | + implode(',<br/>', $undeleted_options) |
|
| 1690 | + ); |
|
| 1691 | + } |
|
| 1692 | + if ( ! empty($errors)) { |
|
| 1693 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1694 | + } |
|
| 1695 | + } |
|
| 1696 | + |
|
| 1697 | + /** |
|
| 1698 | + * Gets the mysql error code from the last used query by wpdb |
|
| 1699 | + * |
|
| 1700 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1701 | + */ |
|
| 1702 | + public static function last_wpdb_error_code() |
|
| 1703 | + { |
|
| 1704 | + global $wpdb; |
|
| 1705 | + if ($wpdb->use_mysqli) { |
|
| 1706 | + return mysqli_errno($wpdb->dbh); |
|
| 1707 | + } else { |
|
| 1708 | + return mysql_errno($wpdb->dbh); |
|
| 1709 | + } |
|
| 1710 | + } |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1714 | + * |
|
| 1715 | + * @global wpdb $wpdb |
|
| 1716 | + * @deprecated instead use TableAnalysis::tableExists() |
|
| 1717 | + * @param string $table_name with or without $wpdb->prefix |
|
| 1718 | + * @return boolean |
|
| 1719 | + */ |
|
| 1720 | + public static function table_exists($table_name) |
|
| 1721 | + { |
|
| 1722 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1723 | + } |
|
| 1724 | + |
|
| 1725 | + /** |
|
| 1726 | + * Resets the cache on EEH_Activation |
|
| 1727 | + */ |
|
| 1728 | + public static function reset() |
|
| 1729 | + { |
|
| 1730 | + self::$_default_creator_id = null; |
|
| 1731 | + self::$_initialized_db_content_already_in_this_request = false; |
|
| 1732 | + } |
|
| 1733 | 1733 | } |
| 1734 | 1734 | // End of file EEH_Activation.helper.php |
| 1735 | 1735 | // Location: /helpers/EEH_Activation.core.php |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 9 | - exit('No direct script access allowed'); |
|
| 9 | + exit('No direct script access allowed'); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | |
@@ -23,1503 +23,1503 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 28 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 29 | - */ |
|
| 30 | - const req_type_normal = 0; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Indicates this is a brand new installation of EE so we should install |
|
| 34 | - * tables and default data etc |
|
| 35 | - */ |
|
| 36 | - const req_type_new_activation = 1; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 40 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 41 | - * and that default data is setup too |
|
| 42 | - */ |
|
| 43 | - const req_type_reactivation = 2; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * indicates that EE has been upgraded since its previous request. |
|
| 47 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 48 | - */ |
|
| 49 | - const req_type_upgrade = 3; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 53 | - */ |
|
| 54 | - const req_type_downgrade = 4; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @deprecated since version 4.6.0.dev.006 |
|
| 58 | - * Now whenever a new_activation is detected the request type is still just |
|
| 59 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 60 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 61 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 62 | - * (Specifically, when the migration manager indicates migrations are finished |
|
| 63 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 64 | - */ |
|
| 65 | - const req_type_activation_but_not_installed = 5; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 69 | - */ |
|
| 70 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var EE_System $_instance |
|
| 75 | - */ |
|
| 76 | - private static $_instance; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @var EE_Registry $registry |
|
| 80 | - */ |
|
| 81 | - protected $registry; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 85 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 86 | - * |
|
| 87 | - * @var int $_req_type |
|
| 88 | - */ |
|
| 89 | - private $_req_type; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
| 93 | - * |
|
| 94 | - * @var boolean $_major_version_change |
|
| 95 | - */ |
|
| 96 | - private $_major_version_change = false; |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @singleton method used to instantiate class object |
|
| 102 | - * @access public |
|
| 103 | - * @param EE_Registry $Registry |
|
| 104 | - * @return EE_System |
|
| 105 | - */ |
|
| 106 | - public static function instance(EE_Registry $Registry = null) |
|
| 107 | - { |
|
| 108 | - // check if class object is instantiated |
|
| 109 | - if ( ! self::$_instance instanceof EE_System) { |
|
| 110 | - self::$_instance = new self($Registry); |
|
| 111 | - } |
|
| 112 | - return self::$_instance; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * resets the instance and returns it |
|
| 119 | - * |
|
| 120 | - * @return EE_System |
|
| 121 | - */ |
|
| 122 | - public static function reset() |
|
| 123 | - { |
|
| 124 | - self::$_instance->_req_type = null; |
|
| 125 | - //make sure none of the old hooks are left hanging around |
|
| 126 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 127 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 128 | - EE_Data_Migration_Manager::reset(); |
|
| 129 | - self::instance()->detect_activations_or_upgrades(); |
|
| 130 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 131 | - return self::instance(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * sets hooks for running rest of system |
|
| 138 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 139 | - * starting EE Addons from any other point may lead to problems |
|
| 140 | - * |
|
| 141 | - * @access private |
|
| 142 | - * @param EE_Registry $Registry |
|
| 143 | - */ |
|
| 144 | - private function __construct(EE_Registry $Registry) |
|
| 145 | - { |
|
| 146 | - $this->registry = $Registry; |
|
| 147 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
| 148 | - add_action( |
|
| 149 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 150 | - array($this, 'loadCapabilities'), |
|
| 151 | - 5 |
|
| 152 | - ); |
|
| 153 | - add_action( |
|
| 154 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 155 | - array($this, 'loadCommandBus'), |
|
| 156 | - 7 |
|
| 157 | - ); |
|
| 158 | - add_action( |
|
| 159 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 160 | - array($this, 'loadPluginApi'), |
|
| 161 | - 9 |
|
| 162 | - ); |
|
| 163 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 164 | - add_action( |
|
| 165 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 166 | - array($this, 'load_espresso_addons') |
|
| 167 | - ); |
|
| 168 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
| 169 | - // because the newly-activated addon didn't get a chance to run at all |
|
| 170 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 171 | - // detect whether install or upgrade |
|
| 172 | - add_action( |
|
| 173 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 174 | - array($this, 'detect_activations_or_upgrades'), |
|
| 175 | - 3 |
|
| 176 | - ); |
|
| 177 | - // load EE_Config, EE_Textdomain, etc |
|
| 178 | - add_action( |
|
| 179 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 180 | - array($this, 'load_core_configuration'), |
|
| 181 | - 5 |
|
| 182 | - ); |
|
| 183 | - // load EE_Config, EE_Textdomain, etc |
|
| 184 | - add_action( |
|
| 185 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 186 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
| 187 | - 7 |
|
| 188 | - ); |
|
| 189 | - // you wanna get going? I wanna get going... let's get going! |
|
| 190 | - add_action( |
|
| 191 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 192 | - array($this, 'brew_espresso'), |
|
| 193 | - 9 |
|
| 194 | - ); |
|
| 195 | - //other housekeeping |
|
| 196 | - //exclude EE critical pages from wp_list_pages |
|
| 197 | - add_filter( |
|
| 198 | - 'wp_list_pages_excludes', |
|
| 199 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
| 200 | - 10 |
|
| 201 | - ); |
|
| 202 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 203 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 204 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * load and setup EE_Capabilities |
|
| 211 | - * |
|
| 212 | - * @return void |
|
| 213 | - * @throws EE_Error |
|
| 214 | - */ |
|
| 215 | - public function loadCapabilities() |
|
| 216 | - { |
|
| 217 | - $this->registry->load_core('EE_Capabilities'); |
|
| 218 | - add_action( |
|
| 219 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 220 | - function() { |
|
| 221 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 222 | - } |
|
| 223 | - ); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * create and cache the CommandBus, and also add middleware |
|
| 230 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
| 231 | - * which is why we need to load the CommandBus after Caps are set up |
|
| 232 | - * |
|
| 233 | - * @return void |
|
| 234 | - * @throws EE_Error |
|
| 235 | - */ |
|
| 236 | - public function loadCommandBus() |
|
| 237 | - { |
|
| 238 | - $this->registry->create( |
|
| 239 | - 'CommandBusInterface', |
|
| 240 | - array( |
|
| 241 | - null, |
|
| 242 | - apply_filters( |
|
| 243 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 244 | - array( |
|
| 245 | - $this->registry->create('CapChecker'), |
|
| 246 | - $this->registry->create('AddActionHook'), |
|
| 247 | - ) |
|
| 248 | - ), |
|
| 249 | - ), |
|
| 250 | - true |
|
| 251 | - ); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @return void |
|
| 258 | - * @throws EE_Error |
|
| 259 | - */ |
|
| 260 | - public function loadPluginApi() |
|
| 261 | - { |
|
| 262 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 263 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 264 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * load_espresso_addons |
|
| 271 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 272 | - * this is hooked into both: |
|
| 273 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 274 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 275 | - * and the WP 'activate_plugin' hook point |
|
| 276 | - * |
|
| 277 | - * @access public |
|
| 278 | - * @return void |
|
| 279 | - * @throws EE_Error |
|
| 280 | - */ |
|
| 281 | - public function load_espresso_addons() |
|
| 282 | - { |
|
| 283 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 284 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 285 | - //We want it for mobile apps. Just include the entire plugin |
|
| 286 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
| 287 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 288 | - //and causes a fatal error |
|
| 289 | - if ( |
|
| 290 | - ! (isset($_GET['activate']) && $_GET['activate'] === 'true') |
|
| 291 | - && ! function_exists('json_basic_auth_handler') |
|
| 292 | - && ! function_exists('json_basic_auth_error') |
|
| 293 | - && ! ( |
|
| 294 | - isset($_GET['action']) |
|
| 295 | - && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
| 296 | - ) |
|
| 297 | - ) { |
|
| 298 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 299 | - } |
|
| 300 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * detect_activations_or_upgrades |
|
| 307 | - * Checks for activation or upgrade of core first; |
|
| 308 | - * then also checks if any registered addons have been activated or upgraded |
|
| 309 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 310 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 311 | - * |
|
| 312 | - * @access public |
|
| 313 | - * @return void |
|
| 314 | - */ |
|
| 315 | - public function detect_activations_or_upgrades() |
|
| 316 | - { |
|
| 317 | - //first off: let's make sure to handle core |
|
| 318 | - $this->detect_if_activation_or_upgrade(); |
|
| 319 | - foreach ($this->registry->addons as $addon) { |
|
| 320 | - //detect teh request type for that addon |
|
| 321 | - $addon->detect_activation_or_upgrade(); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * detect_if_activation_or_upgrade |
|
| 329 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 330 | - * and either setting up the DB or setting up maintenance mode etc. |
|
| 331 | - * |
|
| 332 | - * @access public |
|
| 333 | - * @return void |
|
| 334 | - */ |
|
| 335 | - public function detect_if_activation_or_upgrade() |
|
| 336 | - { |
|
| 337 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 338 | - // load M-Mode class |
|
| 339 | - $this->registry->load_core('Maintenance_Mode'); |
|
| 340 | - // check if db has been updated, or if its a brand-new installation |
|
| 341 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 342 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
| 343 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 344 | - switch ($request_type) { |
|
| 345 | - case EE_System::req_type_new_activation: |
|
| 346 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 347 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 348 | - break; |
|
| 349 | - case EE_System::req_type_reactivation: |
|
| 350 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 351 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 352 | - break; |
|
| 353 | - case EE_System::req_type_upgrade: |
|
| 354 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 355 | - //migrations may be required now that we've upgraded |
|
| 356 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 357 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 358 | - // echo "done upgrade";die; |
|
| 359 | - break; |
|
| 360 | - case EE_System::req_type_downgrade: |
|
| 361 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 362 | - //its possible migrations are no longer required |
|
| 363 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 364 | - $this->_handle_core_version_change($espresso_db_update); |
|
| 365 | - break; |
|
| 366 | - case EE_System::req_type_normal: |
|
| 367 | - default: |
|
| 368 | - // $this->_maybe_redirect_to_ee_about(); |
|
| 369 | - break; |
|
| 370 | - } |
|
| 371 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Updates the list of installed versions and sets hooks for |
|
| 378 | - * initializing the database later during the request |
|
| 379 | - * |
|
| 380 | - * @param array $espresso_db_update |
|
| 381 | - */ |
|
| 382 | - protected function _handle_core_version_change($espresso_db_update) |
|
| 383 | - { |
|
| 384 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
| 385 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 386 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 387 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 394 | - * information about what versions of EE have been installed and activated, |
|
| 395 | - * NOT necessarily the state of the database |
|
| 396 | - * |
|
| 397 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 398 | - * If not supplied, fetches it from the options table |
|
| 399 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 400 | - */ |
|
| 401 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 402 | - { |
|
| 403 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 404 | - if ( ! $espresso_db_update) { |
|
| 405 | - $espresso_db_update = get_option('espresso_db_update'); |
|
| 406 | - } |
|
| 407 | - // check that option is an array |
|
| 408 | - if ( ! is_array($espresso_db_update)) { |
|
| 409 | - // if option is FALSE, then it never existed |
|
| 410 | - if ($espresso_db_update === false) { |
|
| 411 | - // make $espresso_db_update an array and save option with autoload OFF |
|
| 412 | - $espresso_db_update = array(); |
|
| 413 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 414 | - } else { |
|
| 415 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 416 | - $espresso_db_update = array($espresso_db_update => array()); |
|
| 417 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 418 | - } |
|
| 419 | - } else { |
|
| 420 | - $corrected_db_update = array(); |
|
| 421 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 422 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 423 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 424 | - //the key is an int, and the value IS NOT an array |
|
| 425 | - //so it must be numerically-indexed, where values are versions installed... |
|
| 426 | - //fix it! |
|
| 427 | - $version_string = $should_be_array; |
|
| 428 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 429 | - } else { |
|
| 430 | - //ok it checks out |
|
| 431 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - $espresso_db_update = $corrected_db_update; |
|
| 435 | - update_option('espresso_db_update', $espresso_db_update); |
|
| 436 | - } |
|
| 437 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 438 | - return $espresso_db_update; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 445 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 446 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 447 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 448 | - * so that it will be done when migrations are finished |
|
| 449 | - * |
|
| 450 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 451 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 452 | - * This is a resource-intensive job |
|
| 453 | - * so we prefer to only do it when necessary |
|
| 454 | - * @return void |
|
| 455 | - * @throws EE_Error |
|
| 456 | - */ |
|
| 457 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 458 | - { |
|
| 459 | - $request_type = $this->detect_req_type(); |
|
| 460 | - //only initialize system if we're not in maintenance mode. |
|
| 461 | - if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 462 | - update_option('ee_flush_rewrite_rules', true); |
|
| 463 | - if ($verify_schema) { |
|
| 464 | - EEH_Activation::initialize_db_and_folders(); |
|
| 465 | - } |
|
| 466 | - EEH_Activation::initialize_db_content(); |
|
| 467 | - EEH_Activation::system_initialization(); |
|
| 468 | - if ($initialize_addons_too) { |
|
| 469 | - $this->initialize_addons(); |
|
| 470 | - } |
|
| 471 | - } else { |
|
| 472 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 473 | - } |
|
| 474 | - if ($request_type === EE_System::req_type_new_activation |
|
| 475 | - || $request_type === EE_System::req_type_reactivation |
|
| 476 | - || ( |
|
| 477 | - $request_type === EE_System::req_type_upgrade |
|
| 478 | - && $this->is_major_version_change() |
|
| 479 | - ) |
|
| 480 | - ) { |
|
| 481 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Initializes the db for all registered addons |
|
| 489 | - * |
|
| 490 | - * @throws EE_Error |
|
| 491 | - */ |
|
| 492 | - public function initialize_addons() |
|
| 493 | - { |
|
| 494 | - //foreach registered addon, make sure its db is up-to-date too |
|
| 495 | - foreach ($this->registry->addons as $addon) { |
|
| 496 | - $addon->initialize_db_if_no_migrations_required(); |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 504 | - * |
|
| 505 | - * @param array $version_history |
|
| 506 | - * @param string $current_version_to_add version to be added to the version history |
|
| 507 | - * @return boolean success as to whether or not this option was changed |
|
| 508 | - */ |
|
| 509 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 510 | - { |
|
| 511 | - if ( ! $version_history) { |
|
| 512 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 513 | - } |
|
| 514 | - if ($current_version_to_add === null) { |
|
| 515 | - $current_version_to_add = espresso_version(); |
|
| 516 | - } |
|
| 517 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 518 | - // re-save |
|
| 519 | - return update_option('espresso_db_update', $version_history); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Detects if the current version indicated in the has existed in the list of |
|
| 526 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 527 | - * |
|
| 528 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 529 | - * If not supplied, fetches it from the options table. |
|
| 530 | - * Also, caches its result so later parts of the code can also know whether |
|
| 531 | - * there's been an update or not. This way we can add the current version to |
|
| 532 | - * espresso_db_update, but still know if this is a new install or not |
|
| 533 | - * @return int one of the constants on EE_System::req_type_ |
|
| 534 | - */ |
|
| 535 | - public function detect_req_type($espresso_db_update = null) |
|
| 536 | - { |
|
| 537 | - if ($this->_req_type === null) { |
|
| 538 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
| 539 | - : $this->fix_espresso_db_upgrade_option(); |
|
| 540 | - $this->_req_type = EE_System::detect_req_type_given_activation_history($espresso_db_update, |
|
| 541 | - 'ee_espresso_activation', espresso_version()); |
|
| 542 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 543 | - } |
|
| 544 | - return $this->_req_type; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 551 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 552 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 553 | - * |
|
| 554 | - * @param $activation_history |
|
| 555 | - * @return bool |
|
| 556 | - */ |
|
| 557 | - protected function _detect_major_version_change($activation_history) |
|
| 558 | - { |
|
| 559 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 560 | - $previous_version_parts = explode('.', $previous_version); |
|
| 561 | - $current_version_parts = explode('.', espresso_version()); |
|
| 562 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 563 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 564 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 565 | - ); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Returns true if either the major or minor version of EE changed during this request. |
|
| 572 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 573 | - * |
|
| 574 | - * @return bool |
|
| 575 | - */ |
|
| 576 | - public function is_major_version_change() |
|
| 577 | - { |
|
| 578 | - return $this->_major_version_change; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 585 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 586 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 587 | - * just activated to (for core that will always be espresso_version()) |
|
| 588 | - * |
|
| 589 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 590 | - * ee plugin. for core that's 'espresso_db_update' |
|
| 591 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 592 | - * indicate that this plugin was just activated |
|
| 593 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 594 | - * espresso_version()) |
|
| 595 | - * @return int one of the constants on EE_System::req_type_* |
|
| 596 | - */ |
|
| 597 | - public static function detect_req_type_given_activation_history( |
|
| 598 | - $activation_history_for_addon, |
|
| 599 | - $activation_indicator_option_name, |
|
| 600 | - $version_to_upgrade_to |
|
| 601 | - ) { |
|
| 602 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 603 | - if ($activation_history_for_addon) { |
|
| 604 | - //it exists, so this isn't a completely new install |
|
| 605 | - //check if this version already in that list of previously installed versions |
|
| 606 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 607 | - //it a version we haven't seen before |
|
| 608 | - if ($version_is_higher === 1) { |
|
| 609 | - $req_type = EE_System::req_type_upgrade; |
|
| 610 | - } else { |
|
| 611 | - $req_type = EE_System::req_type_downgrade; |
|
| 612 | - } |
|
| 613 | - delete_option($activation_indicator_option_name); |
|
| 614 | - } else { |
|
| 615 | - // its not an update. maybe a reactivation? |
|
| 616 | - if (get_option($activation_indicator_option_name, false)) { |
|
| 617 | - if ($version_is_higher === -1) { |
|
| 618 | - $req_type = EE_System::req_type_downgrade; |
|
| 619 | - } elseif ($version_is_higher === 0) { |
|
| 620 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
| 621 | - $req_type = EE_System::req_type_reactivation; |
|
| 622 | - } else {//$version_is_higher === 1 |
|
| 623 | - $req_type = EE_System::req_type_upgrade; |
|
| 624 | - } |
|
| 625 | - delete_option($activation_indicator_option_name); |
|
| 626 | - } else { |
|
| 627 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 628 | - if ($version_is_higher === -1) { |
|
| 629 | - $req_type = EE_System::req_type_downgrade; |
|
| 630 | - } elseif ($version_is_higher === 0) { |
|
| 631 | - //we've seen this version before and it's not an activation. its normal request |
|
| 632 | - $req_type = EE_System::req_type_normal; |
|
| 633 | - } else {//$version_is_higher === 1 |
|
| 634 | - $req_type = EE_System::req_type_upgrade; |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - } else { |
|
| 639 | - //brand new install |
|
| 640 | - $req_type = EE_System::req_type_new_activation; |
|
| 641 | - delete_option($activation_indicator_option_name); |
|
| 642 | - } |
|
| 643 | - return $req_type; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 650 | - * the $activation_history_for_addon |
|
| 651 | - * |
|
| 652 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 653 | - * sometimes containing 'unknown-date' |
|
| 654 | - * @param string $version_to_upgrade_to (current version) |
|
| 655 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 656 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 657 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 658 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 659 | - */ |
|
| 660 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 661 | - { |
|
| 662 | - //find the most recently-activated version |
|
| 663 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 664 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - /** |
|
| 670 | - * Gets the most recently active version listed in the activation history, |
|
| 671 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 672 | - * |
|
| 673 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 674 | - * sometimes containing 'unknown-date' |
|
| 675 | - * @return string |
|
| 676 | - */ |
|
| 677 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 678 | - { |
|
| 679 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 680 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
| 681 | - if (is_array($activation_history)) { |
|
| 682 | - foreach ($activation_history as $version => $times_activated) { |
|
| 683 | - //check there is a record of when this version was activated. Otherwise, |
|
| 684 | - //mark it as unknown |
|
| 685 | - if ( ! $times_activated) { |
|
| 686 | - $times_activated = array('unknown-date'); |
|
| 687 | - } |
|
| 688 | - if (is_string($times_activated)) { |
|
| 689 | - $times_activated = array($times_activated); |
|
| 690 | - } |
|
| 691 | - foreach ($times_activated as $an_activation) { |
|
| 692 | - if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 693 | - $most_recently_active_version = $version; |
|
| 694 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
| 695 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - return $most_recently_active_version; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * This redirects to the about EE page after activation |
|
| 707 | - * |
|
| 708 | - * @return void |
|
| 709 | - */ |
|
| 710 | - public function redirect_to_about_ee() |
|
| 711 | - { |
|
| 712 | - $notices = EE_Error::get_notices(false); |
|
| 713 | - //if current user is an admin and it's not an ajax or rest request |
|
| 714 | - if ( |
|
| 715 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 716 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 717 | - && ! isset($notices['errors']) |
|
| 718 | - && apply_filters( |
|
| 719 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 720 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
| 721 | - ) |
|
| 722 | - ) { |
|
| 723 | - $query_params = array('page' => 'espresso_about'); |
|
| 724 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 725 | - $query_params['new_activation'] = true; |
|
| 726 | - } |
|
| 727 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 728 | - $query_params['reactivation'] = true; |
|
| 729 | - } |
|
| 730 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 731 | - wp_safe_redirect($url); |
|
| 732 | - exit(); |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * load_core_configuration |
|
| 740 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 741 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 742 | - * |
|
| 743 | - * @return void |
|
| 744 | - * @throws \ReflectionException |
|
| 745 | - */ |
|
| 746 | - public function load_core_configuration() |
|
| 747 | - { |
|
| 748 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 749 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
| 750 | - //load textdomain |
|
| 751 | - EE_Load_Textdomain::load_textdomain(); |
|
| 752 | - // load and setup EE_Config and EE_Network_Config |
|
| 753 | - $this->registry->load_core('Config'); |
|
| 754 | - $this->registry->load_core('Network_Config'); |
|
| 755 | - // setup autoloaders |
|
| 756 | - // enable logging? |
|
| 757 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
| 758 | - $this->registry->load_core('Log'); |
|
| 759 | - } |
|
| 760 | - // check for activation errors |
|
| 761 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 762 | - if ($activation_errors) { |
|
| 763 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 764 | - update_option('ee_plugin_activation_errors', false); |
|
| 765 | - } |
|
| 766 | - // get model names |
|
| 767 | - $this->_parse_model_names(); |
|
| 768 | - //load caf stuff a chance to play during the activation process too. |
|
| 769 | - $this->_maybe_brew_regular(); |
|
| 770 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 777 | - * |
|
| 778 | - * @return void |
|
| 779 | - * @throws ReflectionException |
|
| 780 | - */ |
|
| 781 | - private function _parse_model_names() |
|
| 782 | - { |
|
| 783 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
| 784 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 785 | - $model_names = array(); |
|
| 786 | - $non_abstract_db_models = array(); |
|
| 787 | - foreach ($models as $model) { |
|
| 788 | - // get model classname |
|
| 789 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 790 | - $short_name = str_replace('EEM_', '', $classname); |
|
| 791 | - $reflectionClass = new ReflectionClass($classname); |
|
| 792 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 793 | - $non_abstract_db_models[$short_name] = $classname; |
|
| 794 | - } |
|
| 795 | - $model_names[$short_name] = $classname; |
|
| 796 | - } |
|
| 797 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 798 | - $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
| 799 | - $non_abstract_db_models); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - /** |
|
| 805 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 806 | - * that need to be setup before our EE_System launches. |
|
| 807 | - * |
|
| 808 | - * @return void |
|
| 809 | - */ |
|
| 810 | - private function _maybe_brew_regular() |
|
| 811 | - { |
|
| 812 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 813 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - |
|
| 818 | - |
|
| 819 | - /** |
|
| 820 | - * register_shortcodes_modules_and_widgets |
|
| 821 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
| 822 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 823 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 824 | - * |
|
| 825 | - * @access public |
|
| 826 | - * @return void |
|
| 827 | - */ |
|
| 828 | - public function register_shortcodes_modules_and_widgets() |
|
| 829 | - { |
|
| 830 | - try { |
|
| 831 | - // load, register, and add shortcodes the new way |
|
| 832 | - new ShortcodesManager( |
|
| 833 | - // and the old way, but we'll put it under control of the new system |
|
| 834 | - EE_Config::getLegacyShortcodesManager() |
|
| 835 | - ); |
|
| 836 | - } catch (Exception $exception) { |
|
| 837 | - new ExceptionStackTraceDisplay($exception); |
|
| 838 | - } |
|
| 839 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 840 | - // check for addons using old hook point |
|
| 841 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 842 | - $this->_incompatible_addon_error(); |
|
| 843 | - } |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * _incompatible_addon_error |
|
| 850 | - * |
|
| 851 | - * @access public |
|
| 852 | - * @return void |
|
| 853 | - */ |
|
| 854 | - private function _incompatible_addon_error() |
|
| 855 | - { |
|
| 856 | - // get array of classes hooking into here |
|
| 857 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
| 858 | - if ( ! empty($class_names)) { |
|
| 859 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 860 | - 'event_espresso'); |
|
| 861 | - $msg .= '<ul>'; |
|
| 862 | - foreach ($class_names as $class_name) { |
|
| 863 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 864 | - $class_name) . '</b></li>'; |
|
| 865 | - } |
|
| 866 | - $msg .= '</ul>'; |
|
| 867 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 868 | - 'event_espresso'); |
|
| 869 | - // save list of incompatible addons to wp-options for later use |
|
| 870 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 871 | - if (is_admin()) { |
|
| 872 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * brew_espresso |
|
| 881 | - * begins the process of setting hooks for initializing EE in the correct order |
|
| 882 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 883 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 884 | - * |
|
| 885 | - * @return void |
|
| 886 | - */ |
|
| 887 | - public function brew_espresso() |
|
| 888 | - { |
|
| 889 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 890 | - // load some final core systems |
|
| 891 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 892 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 893 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 894 | - add_action('init', array($this, 'load_controllers'), 7); |
|
| 895 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 896 | - add_action('init', array($this, 'initialize'), 10); |
|
| 897 | - add_action('init', array($this, 'initialize_last'), 100); |
|
| 898 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
| 899 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 900 | - // pew pew pew |
|
| 901 | - $this->registry->load_core('PUE'); |
|
| 902 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 903 | - } |
|
| 904 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * set_hooks_for_core |
|
| 911 | - * |
|
| 912 | - * @access public |
|
| 913 | - * @return void |
|
| 914 | - * @throws EE_Error |
|
| 915 | - */ |
|
| 916 | - public function set_hooks_for_core() |
|
| 917 | - { |
|
| 918 | - $this->_deactivate_incompatible_addons(); |
|
| 919 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 920 | - //caps need to be initialized on every request so that capability maps are set. |
|
| 921 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 922 | - $this->registry->CAP->init_caps(); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 929 | - * deactivates any addons considered incompatible with the current version of EE |
|
| 930 | - */ |
|
| 931 | - private function _deactivate_incompatible_addons() |
|
| 932 | - { |
|
| 933 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 934 | - if ( ! empty($incompatible_addons)) { |
|
| 935 | - $active_plugins = get_option('active_plugins', array()); |
|
| 936 | - foreach ($active_plugins as $active_plugin) { |
|
| 937 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
| 938 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 939 | - unset($_GET['activate']); |
|
| 940 | - espresso_deactivate_plugin($active_plugin); |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - |
|
| 948 | - |
|
| 949 | - /** |
|
| 950 | - * perform_activations_upgrades_and_migrations |
|
| 951 | - * |
|
| 952 | - * @access public |
|
| 953 | - * @return void |
|
| 954 | - */ |
|
| 955 | - public function perform_activations_upgrades_and_migrations() |
|
| 956 | - { |
|
| 957 | - //first check if we had previously attempted to setup EE's directories but failed |
|
| 958 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
| 959 | - EEH_Activation::create_upload_directories(); |
|
| 960 | - } |
|
| 961 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * load_CPTs_and_session |
|
| 968 | - * |
|
| 969 | - * @access public |
|
| 970 | - * @return void |
|
| 971 | - */ |
|
| 972 | - public function load_CPTs_and_session() |
|
| 973 | - { |
|
| 974 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 975 | - // register Custom Post Types |
|
| 976 | - $this->registry->load_core('Register_CPTs'); |
|
| 977 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * load_controllers |
|
| 984 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
| 985 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 986 | - * time |
|
| 987 | - * |
|
| 988 | - * @access public |
|
| 989 | - * @return void |
|
| 990 | - */ |
|
| 991 | - public function load_controllers() |
|
| 992 | - { |
|
| 993 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
| 994 | - // let's get it started |
|
| 995 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 996 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 997 | - $this->registry->load_core('Front_Controller'); |
|
| 998 | - } else if ( ! EE_FRONT_AJAX) { |
|
| 999 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 1000 | - EE_Registry::instance()->load_core('Admin'); |
|
| 1001 | - } |
|
| 1002 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - |
|
| 1006 | - |
|
| 1007 | - /** |
|
| 1008 | - * core_loaded_and_ready |
|
| 1009 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1010 | - * |
|
| 1011 | - * @access public |
|
| 1012 | - * @return void |
|
| 1013 | - */ |
|
| 1014 | - public function core_loaded_and_ready() |
|
| 1015 | - { |
|
| 1016 | - $this->registry->load_core('Session'); |
|
| 1017 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1018 | - // load_espresso_template_tags |
|
| 1019 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 1020 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 1021 | - } |
|
| 1022 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1023 | - $this->registry->create('EventEspresso\core\services\assets\Registry', array(), true); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * initialize |
|
| 1030 | - * this is the best place to begin initializing client code |
|
| 1031 | - * |
|
| 1032 | - * @access public |
|
| 1033 | - * @return void |
|
| 1034 | - */ |
|
| 1035 | - public function initialize() |
|
| 1036 | - { |
|
| 1037 | - do_action('AHEE__EE_System__initialize'); |
|
| 1038 | - } |
|
| 1039 | - |
|
| 1040 | - |
|
| 1041 | - |
|
| 1042 | - /** |
|
| 1043 | - * initialize_last |
|
| 1044 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1045 | - * initialize has done so |
|
| 1046 | - * |
|
| 1047 | - * @access public |
|
| 1048 | - * @return void |
|
| 1049 | - */ |
|
| 1050 | - public function initialize_last() |
|
| 1051 | - { |
|
| 1052 | - do_action('AHEE__EE_System__initialize_last'); |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - |
|
| 1057 | - /** |
|
| 1058 | - * set_hooks_for_shortcodes_modules_and_addons |
|
| 1059 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 1060 | - * this happens at the very beginning of the wp_loaded hook point |
|
| 1061 | - * |
|
| 1062 | - * @access public |
|
| 1063 | - * @return void |
|
| 1064 | - */ |
|
| 1065 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
| 1066 | - { |
|
| 1067 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - |
|
| 1071 | - |
|
| 1072 | - /** |
|
| 1073 | - * do_not_cache |
|
| 1074 | - * sets no cache headers and defines no cache constants for WP plugins |
|
| 1075 | - * |
|
| 1076 | - * @access public |
|
| 1077 | - * @return void |
|
| 1078 | - */ |
|
| 1079 | - public static function do_not_cache() |
|
| 1080 | - { |
|
| 1081 | - // set no cache constants |
|
| 1082 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
| 1083 | - define('DONOTCACHEPAGE', true); |
|
| 1084 | - } |
|
| 1085 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 1086 | - define('DONOTCACHCEOBJECT', true); |
|
| 1087 | - } |
|
| 1088 | - if ( ! defined('DONOTCACHEDB')) { |
|
| 1089 | - define('DONOTCACHEDB', true); |
|
| 1090 | - } |
|
| 1091 | - // add no cache headers |
|
| 1092 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 1093 | - // plus a little extra for nginx and Google Chrome |
|
| 1094 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1095 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1096 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - |
|
| 1100 | - |
|
| 1101 | - /** |
|
| 1102 | - * extra_nocache_headers |
|
| 1103 | - * |
|
| 1104 | - * @access public |
|
| 1105 | - * @param $headers |
|
| 1106 | - * @return array |
|
| 1107 | - */ |
|
| 1108 | - public static function extra_nocache_headers($headers) |
|
| 1109 | - { |
|
| 1110 | - // for NGINX |
|
| 1111 | - $headers['X-Accel-Expires'] = 0; |
|
| 1112 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1113 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1114 | - return $headers; |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - |
|
| 1119 | - /** |
|
| 1120 | - * nocache_headers |
|
| 1121 | - * |
|
| 1122 | - * @access public |
|
| 1123 | - * @return void |
|
| 1124 | - */ |
|
| 1125 | - public static function nocache_headers() |
|
| 1126 | - { |
|
| 1127 | - nocache_headers(); |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - |
|
| 1131 | - |
|
| 1132 | - /** |
|
| 1133 | - * espresso_toolbar_items |
|
| 1134 | - * |
|
| 1135 | - * @access public |
|
| 1136 | - * @param WP_Admin_Bar $admin_bar |
|
| 1137 | - * @return void |
|
| 1138 | - */ |
|
| 1139 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
| 1140 | - { |
|
| 1141 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
| 1142 | - if ( |
|
| 1143 | - defined('DOING_AJAX') |
|
| 1144 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 1145 | - || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1146 | - ) { |
|
| 1147 | - return; |
|
| 1148 | - } |
|
| 1149 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1150 | - $menu_class = 'espresso_menu_item_class'; |
|
| 1151 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 1152 | - //because they're only defined in each of their respective constructors |
|
| 1153 | - //and this might be a frontend request, in which case they aren't available |
|
| 1154 | - $events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
| 1155 | - $reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
| 1156 | - $extensions_admin_url = admin_url('admin.php?page=espresso_packages'); |
|
| 1157 | - //Top Level |
|
| 1158 | - $admin_bar->add_menu(array( |
|
| 1159 | - 'id' => 'espresso-toolbar', |
|
| 1160 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 1161 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 1162 | - . '</span>', |
|
| 1163 | - 'href' => $events_admin_url, |
|
| 1164 | - 'meta' => array( |
|
| 1165 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
| 1166 | - 'class' => $menu_class . 'first', |
|
| 1167 | - ), |
|
| 1168 | - )); |
|
| 1169 | - //Events |
|
| 1170 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
| 1171 | - $admin_bar->add_menu(array( |
|
| 1172 | - 'id' => 'espresso-toolbar-events', |
|
| 1173 | - 'parent' => 'espresso-toolbar', |
|
| 1174 | - 'title' => __('Events', 'event_espresso'), |
|
| 1175 | - 'href' => $events_admin_url, |
|
| 1176 | - 'meta' => array( |
|
| 1177 | - 'title' => __('Events', 'event_espresso'), |
|
| 1178 | - 'target' => '', |
|
| 1179 | - 'class' => $menu_class, |
|
| 1180 | - ), |
|
| 1181 | - )); |
|
| 1182 | - } |
|
| 1183 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
| 1184 | - //Events Add New |
|
| 1185 | - $admin_bar->add_menu(array( |
|
| 1186 | - 'id' => 'espresso-toolbar-events-new', |
|
| 1187 | - 'parent' => 'espresso-toolbar-events', |
|
| 1188 | - 'title' => __('Add New', 'event_espresso'), |
|
| 1189 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
| 1190 | - 'meta' => array( |
|
| 1191 | - 'title' => __('Add New', 'event_espresso'), |
|
| 1192 | - 'target' => '', |
|
| 1193 | - 'class' => $menu_class, |
|
| 1194 | - ), |
|
| 1195 | - )); |
|
| 1196 | - } |
|
| 1197 | - if (is_single() && (get_post_type() === 'espresso_events')) { |
|
| 1198 | - //Current post |
|
| 1199 | - global $post; |
|
| 1200 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
| 1201 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
| 1202 | - ) { |
|
| 1203 | - //Events Edit Current Event |
|
| 1204 | - $admin_bar->add_menu(array( |
|
| 1205 | - 'id' => 'espresso-toolbar-events-edit', |
|
| 1206 | - 'parent' => 'espresso-toolbar-events', |
|
| 1207 | - 'title' => __('Edit Event', 'event_espresso'), |
|
| 1208 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
| 1209 | - $events_admin_url), |
|
| 1210 | - 'meta' => array( |
|
| 1211 | - 'title' => __('Edit Event', 'event_espresso'), |
|
| 1212 | - 'target' => '', |
|
| 1213 | - 'class' => $menu_class, |
|
| 1214 | - ), |
|
| 1215 | - )); |
|
| 1216 | - } |
|
| 1217 | - } |
|
| 1218 | - //Events View |
|
| 1219 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1220 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
| 1221 | - ) { |
|
| 1222 | - $admin_bar->add_menu(array( |
|
| 1223 | - 'id' => 'espresso-toolbar-events-view', |
|
| 1224 | - 'parent' => 'espresso-toolbar-events', |
|
| 1225 | - 'title' => __('View', 'event_espresso'), |
|
| 1226 | - 'href' => $events_admin_url, |
|
| 1227 | - 'meta' => array( |
|
| 1228 | - 'title' => __('View', 'event_espresso'), |
|
| 1229 | - 'target' => '', |
|
| 1230 | - 'class' => $menu_class, |
|
| 1231 | - ), |
|
| 1232 | - )); |
|
| 1233 | - } |
|
| 1234 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
| 1235 | - //Events View All |
|
| 1236 | - $admin_bar->add_menu(array( |
|
| 1237 | - 'id' => 'espresso-toolbar-events-all', |
|
| 1238 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1239 | - 'title' => __('All', 'event_espresso'), |
|
| 1240 | - 'href' => $events_admin_url, |
|
| 1241 | - 'meta' => array( |
|
| 1242 | - 'title' => __('All', 'event_espresso'), |
|
| 1243 | - 'target' => '', |
|
| 1244 | - 'class' => $menu_class, |
|
| 1245 | - ), |
|
| 1246 | - )); |
|
| 1247 | - } |
|
| 1248 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1249 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
| 1250 | - ) { |
|
| 1251 | - //Events View Today |
|
| 1252 | - $admin_bar->add_menu(array( |
|
| 1253 | - 'id' => 'espresso-toolbar-events-today', |
|
| 1254 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1255 | - 'title' => __('Today', 'event_espresso'), |
|
| 1256 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1257 | - $events_admin_url), |
|
| 1258 | - 'meta' => array( |
|
| 1259 | - 'title' => __('Today', 'event_espresso'), |
|
| 1260 | - 'target' => '', |
|
| 1261 | - 'class' => $menu_class, |
|
| 1262 | - ), |
|
| 1263 | - )); |
|
| 1264 | - } |
|
| 1265 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1266 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
| 1267 | - ) { |
|
| 1268 | - //Events View This Month |
|
| 1269 | - $admin_bar->add_menu(array( |
|
| 1270 | - 'id' => 'espresso-toolbar-events-month', |
|
| 1271 | - 'parent' => 'espresso-toolbar-events-view', |
|
| 1272 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1273 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1274 | - $events_admin_url), |
|
| 1275 | - 'meta' => array( |
|
| 1276 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1277 | - 'target' => '', |
|
| 1278 | - 'class' => $menu_class, |
|
| 1279 | - ), |
|
| 1280 | - )); |
|
| 1281 | - } |
|
| 1282 | - //Registration Overview |
|
| 1283 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1284 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
| 1285 | - ) { |
|
| 1286 | - $admin_bar->add_menu(array( |
|
| 1287 | - 'id' => 'espresso-toolbar-registrations', |
|
| 1288 | - 'parent' => 'espresso-toolbar', |
|
| 1289 | - 'title' => __('Registrations', 'event_espresso'), |
|
| 1290 | - 'href' => $reg_admin_url, |
|
| 1291 | - 'meta' => array( |
|
| 1292 | - 'title' => __('Registrations', 'event_espresso'), |
|
| 1293 | - 'target' => '', |
|
| 1294 | - 'class' => $menu_class, |
|
| 1295 | - ), |
|
| 1296 | - )); |
|
| 1297 | - } |
|
| 1298 | - //Registration Overview Today |
|
| 1299 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1300 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
| 1301 | - ) { |
|
| 1302 | - $admin_bar->add_menu(array( |
|
| 1303 | - 'id' => 'espresso-toolbar-registrations-today', |
|
| 1304 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 1305 | - 'title' => __('Today', 'event_espresso'), |
|
| 1306 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1307 | - $reg_admin_url), |
|
| 1308 | - 'meta' => array( |
|
| 1309 | - 'title' => __('Today', 'event_espresso'), |
|
| 1310 | - 'target' => '', |
|
| 1311 | - 'class' => $menu_class, |
|
| 1312 | - ), |
|
| 1313 | - )); |
|
| 1314 | - } |
|
| 1315 | - //Registration Overview Today Completed |
|
| 1316 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1317 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
| 1318 | - ) { |
|
| 1319 | - $admin_bar->add_menu(array( |
|
| 1320 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 1321 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1322 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1323 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1324 | - 'action' => 'default', |
|
| 1325 | - 'status' => 'today', |
|
| 1326 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1327 | - ), $reg_admin_url), |
|
| 1328 | - 'meta' => array( |
|
| 1329 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1330 | - 'target' => '', |
|
| 1331 | - 'class' => $menu_class, |
|
| 1332 | - ), |
|
| 1333 | - )); |
|
| 1334 | - } |
|
| 1335 | - //Registration Overview Today Pending\ |
|
| 1336 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1337 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
| 1338 | - ) { |
|
| 1339 | - $admin_bar->add_menu(array( |
|
| 1340 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 1341 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1342 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1343 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1344 | - 'action' => 'default', |
|
| 1345 | - 'status' => 'today', |
|
| 1346 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1347 | - ), $reg_admin_url), |
|
| 1348 | - 'meta' => array( |
|
| 1349 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
| 1350 | - 'target' => '', |
|
| 1351 | - 'class' => $menu_class, |
|
| 1352 | - ), |
|
| 1353 | - )); |
|
| 1354 | - } |
|
| 1355 | - //Registration Overview Today Incomplete |
|
| 1356 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1357 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
| 1358 | - ) { |
|
| 1359 | - $admin_bar->add_menu(array( |
|
| 1360 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 1361 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1362 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1363 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1364 | - 'action' => 'default', |
|
| 1365 | - 'status' => 'today', |
|
| 1366 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1367 | - ), $reg_admin_url), |
|
| 1368 | - 'meta' => array( |
|
| 1369 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1370 | - 'target' => '', |
|
| 1371 | - 'class' => $menu_class, |
|
| 1372 | - ), |
|
| 1373 | - )); |
|
| 1374 | - } |
|
| 1375 | - //Registration Overview Today Incomplete |
|
| 1376 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1377 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
| 1378 | - ) { |
|
| 1379 | - $admin_bar->add_menu(array( |
|
| 1380 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 1381 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1382 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1383 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1384 | - 'action' => 'default', |
|
| 1385 | - 'status' => 'today', |
|
| 1386 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1387 | - ), $reg_admin_url), |
|
| 1388 | - 'meta' => array( |
|
| 1389 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1390 | - 'target' => '', |
|
| 1391 | - 'class' => $menu_class, |
|
| 1392 | - ), |
|
| 1393 | - )); |
|
| 1394 | - } |
|
| 1395 | - //Registration Overview This Month |
|
| 1396 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1397 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
| 1398 | - ) { |
|
| 1399 | - $admin_bar->add_menu(array( |
|
| 1400 | - 'id' => 'espresso-toolbar-registrations-month', |
|
| 1401 | - 'parent' => 'espresso-toolbar-registrations', |
|
| 1402 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1403 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1404 | - $reg_admin_url), |
|
| 1405 | - 'meta' => array( |
|
| 1406 | - 'title' => __('This Month', 'event_espresso'), |
|
| 1407 | - 'target' => '', |
|
| 1408 | - 'class' => $menu_class, |
|
| 1409 | - ), |
|
| 1410 | - )); |
|
| 1411 | - } |
|
| 1412 | - //Registration Overview This Month Approved |
|
| 1413 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1414 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
| 1415 | - ) { |
|
| 1416 | - $admin_bar->add_menu(array( |
|
| 1417 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 1418 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1419 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1420 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1421 | - 'action' => 'default', |
|
| 1422 | - 'status' => 'month', |
|
| 1423 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1424 | - ), $reg_admin_url), |
|
| 1425 | - 'meta' => array( |
|
| 1426 | - 'title' => __('Approved', 'event_espresso'), |
|
| 1427 | - 'target' => '', |
|
| 1428 | - 'class' => $menu_class, |
|
| 1429 | - ), |
|
| 1430 | - )); |
|
| 1431 | - } |
|
| 1432 | - //Registration Overview This Month Pending |
|
| 1433 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1434 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
| 1435 | - ) { |
|
| 1436 | - $admin_bar->add_menu(array( |
|
| 1437 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 1438 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1439 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1440 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1441 | - 'action' => 'default', |
|
| 1442 | - 'status' => 'month', |
|
| 1443 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1444 | - ), $reg_admin_url), |
|
| 1445 | - 'meta' => array( |
|
| 1446 | - 'title' => __('Pending', 'event_espresso'), |
|
| 1447 | - 'target' => '', |
|
| 1448 | - 'class' => $menu_class, |
|
| 1449 | - ), |
|
| 1450 | - )); |
|
| 1451 | - } |
|
| 1452 | - //Registration Overview This Month Not Approved |
|
| 1453 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1454 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
| 1455 | - ) { |
|
| 1456 | - $admin_bar->add_menu(array( |
|
| 1457 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 1458 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1459 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1460 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1461 | - 'action' => 'default', |
|
| 1462 | - 'status' => 'month', |
|
| 1463 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1464 | - ), $reg_admin_url), |
|
| 1465 | - 'meta' => array( |
|
| 1466 | - 'title' => __('Not Approved', 'event_espresso'), |
|
| 1467 | - 'target' => '', |
|
| 1468 | - 'class' => $menu_class, |
|
| 1469 | - ), |
|
| 1470 | - )); |
|
| 1471 | - } |
|
| 1472 | - //Registration Overview This Month Cancelled |
|
| 1473 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1474 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
| 1475 | - ) { |
|
| 1476 | - $admin_bar->add_menu(array( |
|
| 1477 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 1478 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1479 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1480 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1481 | - 'action' => 'default', |
|
| 1482 | - 'status' => 'month', |
|
| 1483 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1484 | - ), $reg_admin_url), |
|
| 1485 | - 'meta' => array( |
|
| 1486 | - 'title' => __('Cancelled', 'event_espresso'), |
|
| 1487 | - 'target' => '', |
|
| 1488 | - 'class' => $menu_class, |
|
| 1489 | - ), |
|
| 1490 | - )); |
|
| 1491 | - } |
|
| 1492 | - //Extensions & Services |
|
| 1493 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
| 1494 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
| 1495 | - ) { |
|
| 1496 | - $admin_bar->add_menu(array( |
|
| 1497 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 1498 | - 'parent' => 'espresso-toolbar', |
|
| 1499 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1500 | - 'href' => $extensions_admin_url, |
|
| 1501 | - 'meta' => array( |
|
| 1502 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1503 | - 'target' => '', |
|
| 1504 | - 'class' => $menu_class, |
|
| 1505 | - ), |
|
| 1506 | - )); |
|
| 1507 | - } |
|
| 1508 | - } |
|
| 1509 | - |
|
| 1510 | - |
|
| 1511 | - |
|
| 1512 | - /** |
|
| 1513 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1514 | - * never returned with the function. |
|
| 1515 | - * |
|
| 1516 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1517 | - * @return array |
|
| 1518 | - */ |
|
| 1519 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1520 | - { |
|
| 1521 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1522 | - } |
|
| 26 | + /** |
|
| 27 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
| 28 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
| 29 | + */ |
|
| 30 | + const req_type_normal = 0; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Indicates this is a brand new installation of EE so we should install |
|
| 34 | + * tables and default data etc |
|
| 35 | + */ |
|
| 36 | + const req_type_new_activation = 1; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
| 40 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
| 41 | + * and that default data is setup too |
|
| 42 | + */ |
|
| 43 | + const req_type_reactivation = 2; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * indicates that EE has been upgraded since its previous request. |
|
| 47 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
| 48 | + */ |
|
| 49 | + const req_type_upgrade = 3; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
| 53 | + */ |
|
| 54 | + const req_type_downgrade = 4; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @deprecated since version 4.6.0.dev.006 |
|
| 58 | + * Now whenever a new_activation is detected the request type is still just |
|
| 59 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
| 60 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
| 61 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
| 62 | + * (Specifically, when the migration manager indicates migrations are finished |
|
| 63 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
| 64 | + */ |
|
| 65 | + const req_type_activation_but_not_installed = 5; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
| 69 | + */ |
|
| 70 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var EE_System $_instance |
|
| 75 | + */ |
|
| 76 | + private static $_instance; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @var EE_Registry $registry |
|
| 80 | + */ |
|
| 81 | + protected $registry; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
| 85 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
| 86 | + * |
|
| 87 | + * @var int $_req_type |
|
| 88 | + */ |
|
| 89 | + private $_req_type; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
| 93 | + * |
|
| 94 | + * @var boolean $_major_version_change |
|
| 95 | + */ |
|
| 96 | + private $_major_version_change = false; |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @singleton method used to instantiate class object |
|
| 102 | + * @access public |
|
| 103 | + * @param EE_Registry $Registry |
|
| 104 | + * @return EE_System |
|
| 105 | + */ |
|
| 106 | + public static function instance(EE_Registry $Registry = null) |
|
| 107 | + { |
|
| 108 | + // check if class object is instantiated |
|
| 109 | + if ( ! self::$_instance instanceof EE_System) { |
|
| 110 | + self::$_instance = new self($Registry); |
|
| 111 | + } |
|
| 112 | + return self::$_instance; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * resets the instance and returns it |
|
| 119 | + * |
|
| 120 | + * @return EE_System |
|
| 121 | + */ |
|
| 122 | + public static function reset() |
|
| 123 | + { |
|
| 124 | + self::$_instance->_req_type = null; |
|
| 125 | + //make sure none of the old hooks are left hanging around |
|
| 126 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 127 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
| 128 | + EE_Data_Migration_Manager::reset(); |
|
| 129 | + self::instance()->detect_activations_or_upgrades(); |
|
| 130 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
| 131 | + return self::instance(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * sets hooks for running rest of system |
|
| 138 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 139 | + * starting EE Addons from any other point may lead to problems |
|
| 140 | + * |
|
| 141 | + * @access private |
|
| 142 | + * @param EE_Registry $Registry |
|
| 143 | + */ |
|
| 144 | + private function __construct(EE_Registry $Registry) |
|
| 145 | + { |
|
| 146 | + $this->registry = $Registry; |
|
| 147 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
| 148 | + add_action( |
|
| 149 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 150 | + array($this, 'loadCapabilities'), |
|
| 151 | + 5 |
|
| 152 | + ); |
|
| 153 | + add_action( |
|
| 154 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 155 | + array($this, 'loadCommandBus'), |
|
| 156 | + 7 |
|
| 157 | + ); |
|
| 158 | + add_action( |
|
| 159 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 160 | + array($this, 'loadPluginApi'), |
|
| 161 | + 9 |
|
| 162 | + ); |
|
| 163 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
| 164 | + add_action( |
|
| 165 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
| 166 | + array($this, 'load_espresso_addons') |
|
| 167 | + ); |
|
| 168 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
| 169 | + // because the newly-activated addon didn't get a chance to run at all |
|
| 170 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
| 171 | + // detect whether install or upgrade |
|
| 172 | + add_action( |
|
| 173 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
| 174 | + array($this, 'detect_activations_or_upgrades'), |
|
| 175 | + 3 |
|
| 176 | + ); |
|
| 177 | + // load EE_Config, EE_Textdomain, etc |
|
| 178 | + add_action( |
|
| 179 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
| 180 | + array($this, 'load_core_configuration'), |
|
| 181 | + 5 |
|
| 182 | + ); |
|
| 183 | + // load EE_Config, EE_Textdomain, etc |
|
| 184 | + add_action( |
|
| 185 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
| 186 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
| 187 | + 7 |
|
| 188 | + ); |
|
| 189 | + // you wanna get going? I wanna get going... let's get going! |
|
| 190 | + add_action( |
|
| 191 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
| 192 | + array($this, 'brew_espresso'), |
|
| 193 | + 9 |
|
| 194 | + ); |
|
| 195 | + //other housekeeping |
|
| 196 | + //exclude EE critical pages from wp_list_pages |
|
| 197 | + add_filter( |
|
| 198 | + 'wp_list_pages_excludes', |
|
| 199 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
| 200 | + 10 |
|
| 201 | + ); |
|
| 202 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
| 203 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
| 204 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * load and setup EE_Capabilities |
|
| 211 | + * |
|
| 212 | + * @return void |
|
| 213 | + * @throws EE_Error |
|
| 214 | + */ |
|
| 215 | + public function loadCapabilities() |
|
| 216 | + { |
|
| 217 | + $this->registry->load_core('EE_Capabilities'); |
|
| 218 | + add_action( |
|
| 219 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 220 | + function() { |
|
| 221 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 222 | + } |
|
| 223 | + ); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * create and cache the CommandBus, and also add middleware |
|
| 230 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
| 231 | + * which is why we need to load the CommandBus after Caps are set up |
|
| 232 | + * |
|
| 233 | + * @return void |
|
| 234 | + * @throws EE_Error |
|
| 235 | + */ |
|
| 236 | + public function loadCommandBus() |
|
| 237 | + { |
|
| 238 | + $this->registry->create( |
|
| 239 | + 'CommandBusInterface', |
|
| 240 | + array( |
|
| 241 | + null, |
|
| 242 | + apply_filters( |
|
| 243 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
| 244 | + array( |
|
| 245 | + $this->registry->create('CapChecker'), |
|
| 246 | + $this->registry->create('AddActionHook'), |
|
| 247 | + ) |
|
| 248 | + ), |
|
| 249 | + ), |
|
| 250 | + true |
|
| 251 | + ); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @return void |
|
| 258 | + * @throws EE_Error |
|
| 259 | + */ |
|
| 260 | + public function loadPluginApi() |
|
| 261 | + { |
|
| 262 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
| 263 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
| 264 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * load_espresso_addons |
|
| 271 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
| 272 | + * this is hooked into both: |
|
| 273 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 274 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 275 | + * and the WP 'activate_plugin' hook point |
|
| 276 | + * |
|
| 277 | + * @access public |
|
| 278 | + * @return void |
|
| 279 | + * @throws EE_Error |
|
| 280 | + */ |
|
| 281 | + public function load_espresso_addons() |
|
| 282 | + { |
|
| 283 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
| 284 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
| 285 | + //We want it for mobile apps. Just include the entire plugin |
|
| 286 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
| 287 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
| 288 | + //and causes a fatal error |
|
| 289 | + if ( |
|
| 290 | + ! (isset($_GET['activate']) && $_GET['activate'] === 'true') |
|
| 291 | + && ! function_exists('json_basic_auth_handler') |
|
| 292 | + && ! function_exists('json_basic_auth_error') |
|
| 293 | + && ! ( |
|
| 294 | + isset($_GET['action']) |
|
| 295 | + && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
| 296 | + ) |
|
| 297 | + ) { |
|
| 298 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 299 | + } |
|
| 300 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * detect_activations_or_upgrades |
|
| 307 | + * Checks for activation or upgrade of core first; |
|
| 308 | + * then also checks if any registered addons have been activated or upgraded |
|
| 309 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
| 310 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
| 311 | + * |
|
| 312 | + * @access public |
|
| 313 | + * @return void |
|
| 314 | + */ |
|
| 315 | + public function detect_activations_or_upgrades() |
|
| 316 | + { |
|
| 317 | + //first off: let's make sure to handle core |
|
| 318 | + $this->detect_if_activation_or_upgrade(); |
|
| 319 | + foreach ($this->registry->addons as $addon) { |
|
| 320 | + //detect teh request type for that addon |
|
| 321 | + $addon->detect_activation_or_upgrade(); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * detect_if_activation_or_upgrade |
|
| 329 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
| 330 | + * and either setting up the DB or setting up maintenance mode etc. |
|
| 331 | + * |
|
| 332 | + * @access public |
|
| 333 | + * @return void |
|
| 334 | + */ |
|
| 335 | + public function detect_if_activation_or_upgrade() |
|
| 336 | + { |
|
| 337 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
| 338 | + // load M-Mode class |
|
| 339 | + $this->registry->load_core('Maintenance_Mode'); |
|
| 340 | + // check if db has been updated, or if its a brand-new installation |
|
| 341 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
| 342 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
| 343 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
| 344 | + switch ($request_type) { |
|
| 345 | + case EE_System::req_type_new_activation: |
|
| 346 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
| 347 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 348 | + break; |
|
| 349 | + case EE_System::req_type_reactivation: |
|
| 350 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
| 351 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 352 | + break; |
|
| 353 | + case EE_System::req_type_upgrade: |
|
| 354 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
| 355 | + //migrations may be required now that we've upgraded |
|
| 356 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 357 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 358 | + // echo "done upgrade";die; |
|
| 359 | + break; |
|
| 360 | + case EE_System::req_type_downgrade: |
|
| 361 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
| 362 | + //its possible migrations are no longer required |
|
| 363 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 364 | + $this->_handle_core_version_change($espresso_db_update); |
|
| 365 | + break; |
|
| 366 | + case EE_System::req_type_normal: |
|
| 367 | + default: |
|
| 368 | + // $this->_maybe_redirect_to_ee_about(); |
|
| 369 | + break; |
|
| 370 | + } |
|
| 371 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Updates the list of installed versions and sets hooks for |
|
| 378 | + * initializing the database later during the request |
|
| 379 | + * |
|
| 380 | + * @param array $espresso_db_update |
|
| 381 | + */ |
|
| 382 | + protected function _handle_core_version_change($espresso_db_update) |
|
| 383 | + { |
|
| 384 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
| 385 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
| 386 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 387 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
| 394 | + * information about what versions of EE have been installed and activated, |
|
| 395 | + * NOT necessarily the state of the database |
|
| 396 | + * |
|
| 397 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
| 398 | + * If not supplied, fetches it from the options table |
|
| 399 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
| 400 | + */ |
|
| 401 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
| 402 | + { |
|
| 403 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
| 404 | + if ( ! $espresso_db_update) { |
|
| 405 | + $espresso_db_update = get_option('espresso_db_update'); |
|
| 406 | + } |
|
| 407 | + // check that option is an array |
|
| 408 | + if ( ! is_array($espresso_db_update)) { |
|
| 409 | + // if option is FALSE, then it never existed |
|
| 410 | + if ($espresso_db_update === false) { |
|
| 411 | + // make $espresso_db_update an array and save option with autoload OFF |
|
| 412 | + $espresso_db_update = array(); |
|
| 413 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
| 414 | + } else { |
|
| 415 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
| 416 | + $espresso_db_update = array($espresso_db_update => array()); |
|
| 417 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 418 | + } |
|
| 419 | + } else { |
|
| 420 | + $corrected_db_update = array(); |
|
| 421 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
| 422 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
| 423 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
| 424 | + //the key is an int, and the value IS NOT an array |
|
| 425 | + //so it must be numerically-indexed, where values are versions installed... |
|
| 426 | + //fix it! |
|
| 427 | + $version_string = $should_be_array; |
|
| 428 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
| 429 | + } else { |
|
| 430 | + //ok it checks out |
|
| 431 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + $espresso_db_update = $corrected_db_update; |
|
| 435 | + update_option('espresso_db_update', $espresso_db_update); |
|
| 436 | + } |
|
| 437 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
| 438 | + return $espresso_db_update; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
| 445 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
| 446 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
| 447 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
| 448 | + * so that it will be done when migrations are finished |
|
| 449 | + * |
|
| 450 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
| 451 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
| 452 | + * This is a resource-intensive job |
|
| 453 | + * so we prefer to only do it when necessary |
|
| 454 | + * @return void |
|
| 455 | + * @throws EE_Error |
|
| 456 | + */ |
|
| 457 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
| 458 | + { |
|
| 459 | + $request_type = $this->detect_req_type(); |
|
| 460 | + //only initialize system if we're not in maintenance mode. |
|
| 461 | + if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 462 | + update_option('ee_flush_rewrite_rules', true); |
|
| 463 | + if ($verify_schema) { |
|
| 464 | + EEH_Activation::initialize_db_and_folders(); |
|
| 465 | + } |
|
| 466 | + EEH_Activation::initialize_db_content(); |
|
| 467 | + EEH_Activation::system_initialization(); |
|
| 468 | + if ($initialize_addons_too) { |
|
| 469 | + $this->initialize_addons(); |
|
| 470 | + } |
|
| 471 | + } else { |
|
| 472 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
| 473 | + } |
|
| 474 | + if ($request_type === EE_System::req_type_new_activation |
|
| 475 | + || $request_type === EE_System::req_type_reactivation |
|
| 476 | + || ( |
|
| 477 | + $request_type === EE_System::req_type_upgrade |
|
| 478 | + && $this->is_major_version_change() |
|
| 479 | + ) |
|
| 480 | + ) { |
|
| 481 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Initializes the db for all registered addons |
|
| 489 | + * |
|
| 490 | + * @throws EE_Error |
|
| 491 | + */ |
|
| 492 | + public function initialize_addons() |
|
| 493 | + { |
|
| 494 | + //foreach registered addon, make sure its db is up-to-date too |
|
| 495 | + foreach ($this->registry->addons as $addon) { |
|
| 496 | + $addon->initialize_db_if_no_migrations_required(); |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
| 504 | + * |
|
| 505 | + * @param array $version_history |
|
| 506 | + * @param string $current_version_to_add version to be added to the version history |
|
| 507 | + * @return boolean success as to whether or not this option was changed |
|
| 508 | + */ |
|
| 509 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 510 | + { |
|
| 511 | + if ( ! $version_history) { |
|
| 512 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
| 513 | + } |
|
| 514 | + if ($current_version_to_add === null) { |
|
| 515 | + $current_version_to_add = espresso_version(); |
|
| 516 | + } |
|
| 517 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 518 | + // re-save |
|
| 519 | + return update_option('espresso_db_update', $version_history); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Detects if the current version indicated in the has existed in the list of |
|
| 526 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
| 527 | + * |
|
| 528 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
| 529 | + * If not supplied, fetches it from the options table. |
|
| 530 | + * Also, caches its result so later parts of the code can also know whether |
|
| 531 | + * there's been an update or not. This way we can add the current version to |
|
| 532 | + * espresso_db_update, but still know if this is a new install or not |
|
| 533 | + * @return int one of the constants on EE_System::req_type_ |
|
| 534 | + */ |
|
| 535 | + public function detect_req_type($espresso_db_update = null) |
|
| 536 | + { |
|
| 537 | + if ($this->_req_type === null) { |
|
| 538 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
| 539 | + : $this->fix_espresso_db_upgrade_option(); |
|
| 540 | + $this->_req_type = EE_System::detect_req_type_given_activation_history($espresso_db_update, |
|
| 541 | + 'ee_espresso_activation', espresso_version()); |
|
| 542 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
| 543 | + } |
|
| 544 | + return $this->_req_type; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
| 551 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
| 552 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 553 | + * |
|
| 554 | + * @param $activation_history |
|
| 555 | + * @return bool |
|
| 556 | + */ |
|
| 557 | + protected function _detect_major_version_change($activation_history) |
|
| 558 | + { |
|
| 559 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
| 560 | + $previous_version_parts = explode('.', $previous_version); |
|
| 561 | + $current_version_parts = explode('.', espresso_version()); |
|
| 562 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
| 563 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
| 564 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
| 565 | + ); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Returns true if either the major or minor version of EE changed during this request. |
|
| 572 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
| 573 | + * |
|
| 574 | + * @return bool |
|
| 575 | + */ |
|
| 576 | + public function is_major_version_change() |
|
| 577 | + { |
|
| 578 | + return $this->_major_version_change; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
| 585 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
| 586 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
| 587 | + * just activated to (for core that will always be espresso_version()) |
|
| 588 | + * |
|
| 589 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
| 590 | + * ee plugin. for core that's 'espresso_db_update' |
|
| 591 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
| 592 | + * indicate that this plugin was just activated |
|
| 593 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
| 594 | + * espresso_version()) |
|
| 595 | + * @return int one of the constants on EE_System::req_type_* |
|
| 596 | + */ |
|
| 597 | + public static function detect_req_type_given_activation_history( |
|
| 598 | + $activation_history_for_addon, |
|
| 599 | + $activation_indicator_option_name, |
|
| 600 | + $version_to_upgrade_to |
|
| 601 | + ) { |
|
| 602 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
| 603 | + if ($activation_history_for_addon) { |
|
| 604 | + //it exists, so this isn't a completely new install |
|
| 605 | + //check if this version already in that list of previously installed versions |
|
| 606 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
| 607 | + //it a version we haven't seen before |
|
| 608 | + if ($version_is_higher === 1) { |
|
| 609 | + $req_type = EE_System::req_type_upgrade; |
|
| 610 | + } else { |
|
| 611 | + $req_type = EE_System::req_type_downgrade; |
|
| 612 | + } |
|
| 613 | + delete_option($activation_indicator_option_name); |
|
| 614 | + } else { |
|
| 615 | + // its not an update. maybe a reactivation? |
|
| 616 | + if (get_option($activation_indicator_option_name, false)) { |
|
| 617 | + if ($version_is_higher === -1) { |
|
| 618 | + $req_type = EE_System::req_type_downgrade; |
|
| 619 | + } elseif ($version_is_higher === 0) { |
|
| 620 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
| 621 | + $req_type = EE_System::req_type_reactivation; |
|
| 622 | + } else {//$version_is_higher === 1 |
|
| 623 | + $req_type = EE_System::req_type_upgrade; |
|
| 624 | + } |
|
| 625 | + delete_option($activation_indicator_option_name); |
|
| 626 | + } else { |
|
| 627 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
| 628 | + if ($version_is_higher === -1) { |
|
| 629 | + $req_type = EE_System::req_type_downgrade; |
|
| 630 | + } elseif ($version_is_higher === 0) { |
|
| 631 | + //we've seen this version before and it's not an activation. its normal request |
|
| 632 | + $req_type = EE_System::req_type_normal; |
|
| 633 | + } else {//$version_is_higher === 1 |
|
| 634 | + $req_type = EE_System::req_type_upgrade; |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + } else { |
|
| 639 | + //brand new install |
|
| 640 | + $req_type = EE_System::req_type_new_activation; |
|
| 641 | + delete_option($activation_indicator_option_name); |
|
| 642 | + } |
|
| 643 | + return $req_type; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
| 650 | + * the $activation_history_for_addon |
|
| 651 | + * |
|
| 652 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
| 653 | + * sometimes containing 'unknown-date' |
|
| 654 | + * @param string $version_to_upgrade_to (current version) |
|
| 655 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
| 656 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
| 657 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
| 658 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
| 659 | + */ |
|
| 660 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
| 661 | + { |
|
| 662 | + //find the most recently-activated version |
|
| 663 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
| 664 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + /** |
|
| 670 | + * Gets the most recently active version listed in the activation history, |
|
| 671 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
| 672 | + * |
|
| 673 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
| 674 | + * sometimes containing 'unknown-date' |
|
| 675 | + * @return string |
|
| 676 | + */ |
|
| 677 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
| 678 | + { |
|
| 679 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
| 680 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
| 681 | + if (is_array($activation_history)) { |
|
| 682 | + foreach ($activation_history as $version => $times_activated) { |
|
| 683 | + //check there is a record of when this version was activated. Otherwise, |
|
| 684 | + //mark it as unknown |
|
| 685 | + if ( ! $times_activated) { |
|
| 686 | + $times_activated = array('unknown-date'); |
|
| 687 | + } |
|
| 688 | + if (is_string($times_activated)) { |
|
| 689 | + $times_activated = array($times_activated); |
|
| 690 | + } |
|
| 691 | + foreach ($times_activated as $an_activation) { |
|
| 692 | + if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
| 693 | + $most_recently_active_version = $version; |
|
| 694 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
| 695 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + return $most_recently_active_version; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * This redirects to the about EE page after activation |
|
| 707 | + * |
|
| 708 | + * @return void |
|
| 709 | + */ |
|
| 710 | + public function redirect_to_about_ee() |
|
| 711 | + { |
|
| 712 | + $notices = EE_Error::get_notices(false); |
|
| 713 | + //if current user is an admin and it's not an ajax or rest request |
|
| 714 | + if ( |
|
| 715 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
| 716 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
| 717 | + && ! isset($notices['errors']) |
|
| 718 | + && apply_filters( |
|
| 719 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
| 720 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
| 721 | + ) |
|
| 722 | + ) { |
|
| 723 | + $query_params = array('page' => 'espresso_about'); |
|
| 724 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
| 725 | + $query_params['new_activation'] = true; |
|
| 726 | + } |
|
| 727 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
| 728 | + $query_params['reactivation'] = true; |
|
| 729 | + } |
|
| 730 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
| 731 | + wp_safe_redirect($url); |
|
| 732 | + exit(); |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * load_core_configuration |
|
| 740 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
| 741 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
| 742 | + * |
|
| 743 | + * @return void |
|
| 744 | + * @throws \ReflectionException |
|
| 745 | + */ |
|
| 746 | + public function load_core_configuration() |
|
| 747 | + { |
|
| 748 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
| 749 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
| 750 | + //load textdomain |
|
| 751 | + EE_Load_Textdomain::load_textdomain(); |
|
| 752 | + // load and setup EE_Config and EE_Network_Config |
|
| 753 | + $this->registry->load_core('Config'); |
|
| 754 | + $this->registry->load_core('Network_Config'); |
|
| 755 | + // setup autoloaders |
|
| 756 | + // enable logging? |
|
| 757 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
| 758 | + $this->registry->load_core('Log'); |
|
| 759 | + } |
|
| 760 | + // check for activation errors |
|
| 761 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
| 762 | + if ($activation_errors) { |
|
| 763 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 764 | + update_option('ee_plugin_activation_errors', false); |
|
| 765 | + } |
|
| 766 | + // get model names |
|
| 767 | + $this->_parse_model_names(); |
|
| 768 | + //load caf stuff a chance to play during the activation process too. |
|
| 769 | + $this->_maybe_brew_regular(); |
|
| 770 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
| 777 | + * |
|
| 778 | + * @return void |
|
| 779 | + * @throws ReflectionException |
|
| 780 | + */ |
|
| 781 | + private function _parse_model_names() |
|
| 782 | + { |
|
| 783 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
| 784 | + $models = glob(EE_MODELS . '*.model.php'); |
|
| 785 | + $model_names = array(); |
|
| 786 | + $non_abstract_db_models = array(); |
|
| 787 | + foreach ($models as $model) { |
|
| 788 | + // get model classname |
|
| 789 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
| 790 | + $short_name = str_replace('EEM_', '', $classname); |
|
| 791 | + $reflectionClass = new ReflectionClass($classname); |
|
| 792 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
| 793 | + $non_abstract_db_models[$short_name] = $classname; |
|
| 794 | + } |
|
| 795 | + $model_names[$short_name] = $classname; |
|
| 796 | + } |
|
| 797 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
| 798 | + $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
| 799 | + $non_abstract_db_models); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + /** |
|
| 805 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
| 806 | + * that need to be setup before our EE_System launches. |
|
| 807 | + * |
|
| 808 | + * @return void |
|
| 809 | + */ |
|
| 810 | + private function _maybe_brew_regular() |
|
| 811 | + { |
|
| 812 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 813 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + |
|
| 818 | + |
|
| 819 | + /** |
|
| 820 | + * register_shortcodes_modules_and_widgets |
|
| 821 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
| 822 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
| 823 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
| 824 | + * |
|
| 825 | + * @access public |
|
| 826 | + * @return void |
|
| 827 | + */ |
|
| 828 | + public function register_shortcodes_modules_and_widgets() |
|
| 829 | + { |
|
| 830 | + try { |
|
| 831 | + // load, register, and add shortcodes the new way |
|
| 832 | + new ShortcodesManager( |
|
| 833 | + // and the old way, but we'll put it under control of the new system |
|
| 834 | + EE_Config::getLegacyShortcodesManager() |
|
| 835 | + ); |
|
| 836 | + } catch (Exception $exception) { |
|
| 837 | + new ExceptionStackTraceDisplay($exception); |
|
| 838 | + } |
|
| 839 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
| 840 | + // check for addons using old hook point |
|
| 841 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
| 842 | + $this->_incompatible_addon_error(); |
|
| 843 | + } |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * _incompatible_addon_error |
|
| 850 | + * |
|
| 851 | + * @access public |
|
| 852 | + * @return void |
|
| 853 | + */ |
|
| 854 | + private function _incompatible_addon_error() |
|
| 855 | + { |
|
| 856 | + // get array of classes hooking into here |
|
| 857 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
| 858 | + if ( ! empty($class_names)) { |
|
| 859 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
| 860 | + 'event_espresso'); |
|
| 861 | + $msg .= '<ul>'; |
|
| 862 | + foreach ($class_names as $class_name) { |
|
| 863 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 864 | + $class_name) . '</b></li>'; |
|
| 865 | + } |
|
| 866 | + $msg .= '</ul>'; |
|
| 867 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
| 868 | + 'event_espresso'); |
|
| 869 | + // save list of incompatible addons to wp-options for later use |
|
| 870 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
| 871 | + if (is_admin()) { |
|
| 872 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * brew_espresso |
|
| 881 | + * begins the process of setting hooks for initializing EE in the correct order |
|
| 882 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
| 883 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
| 884 | + * |
|
| 885 | + * @return void |
|
| 886 | + */ |
|
| 887 | + public function brew_espresso() |
|
| 888 | + { |
|
| 889 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
| 890 | + // load some final core systems |
|
| 891 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
| 892 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
| 893 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
| 894 | + add_action('init', array($this, 'load_controllers'), 7); |
|
| 895 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
| 896 | + add_action('init', array($this, 'initialize'), 10); |
|
| 897 | + add_action('init', array($this, 'initialize_last'), 100); |
|
| 898 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
| 899 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
| 900 | + // pew pew pew |
|
| 901 | + $this->registry->load_core('PUE'); |
|
| 902 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
| 903 | + } |
|
| 904 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * set_hooks_for_core |
|
| 911 | + * |
|
| 912 | + * @access public |
|
| 913 | + * @return void |
|
| 914 | + * @throws EE_Error |
|
| 915 | + */ |
|
| 916 | + public function set_hooks_for_core() |
|
| 917 | + { |
|
| 918 | + $this->_deactivate_incompatible_addons(); |
|
| 919 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
| 920 | + //caps need to be initialized on every request so that capability maps are set. |
|
| 921 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
| 922 | + $this->registry->CAP->init_caps(); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
| 929 | + * deactivates any addons considered incompatible with the current version of EE |
|
| 930 | + */ |
|
| 931 | + private function _deactivate_incompatible_addons() |
|
| 932 | + { |
|
| 933 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
| 934 | + if ( ! empty($incompatible_addons)) { |
|
| 935 | + $active_plugins = get_option('active_plugins', array()); |
|
| 936 | + foreach ($active_plugins as $active_plugin) { |
|
| 937 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
| 938 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
| 939 | + unset($_GET['activate']); |
|
| 940 | + espresso_deactivate_plugin($active_plugin); |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + |
|
| 948 | + |
|
| 949 | + /** |
|
| 950 | + * perform_activations_upgrades_and_migrations |
|
| 951 | + * |
|
| 952 | + * @access public |
|
| 953 | + * @return void |
|
| 954 | + */ |
|
| 955 | + public function perform_activations_upgrades_and_migrations() |
|
| 956 | + { |
|
| 957 | + //first check if we had previously attempted to setup EE's directories but failed |
|
| 958 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
| 959 | + EEH_Activation::create_upload_directories(); |
|
| 960 | + } |
|
| 961 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * load_CPTs_and_session |
|
| 968 | + * |
|
| 969 | + * @access public |
|
| 970 | + * @return void |
|
| 971 | + */ |
|
| 972 | + public function load_CPTs_and_session() |
|
| 973 | + { |
|
| 974 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
| 975 | + // register Custom Post Types |
|
| 976 | + $this->registry->load_core('Register_CPTs'); |
|
| 977 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * load_controllers |
|
| 984 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
| 985 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
| 986 | + * time |
|
| 987 | + * |
|
| 988 | + * @access public |
|
| 989 | + * @return void |
|
| 990 | + */ |
|
| 991 | + public function load_controllers() |
|
| 992 | + { |
|
| 993 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
| 994 | + // let's get it started |
|
| 995 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 996 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
| 997 | + $this->registry->load_core('Front_Controller'); |
|
| 998 | + } else if ( ! EE_FRONT_AJAX) { |
|
| 999 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
| 1000 | + EE_Registry::instance()->load_core('Admin'); |
|
| 1001 | + } |
|
| 1002 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + |
|
| 1006 | + |
|
| 1007 | + /** |
|
| 1008 | + * core_loaded_and_ready |
|
| 1009 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
| 1010 | + * |
|
| 1011 | + * @access public |
|
| 1012 | + * @return void |
|
| 1013 | + */ |
|
| 1014 | + public function core_loaded_and_ready() |
|
| 1015 | + { |
|
| 1016 | + $this->registry->load_core('Session'); |
|
| 1017 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
| 1018 | + // load_espresso_template_tags |
|
| 1019 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 1020 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 1021 | + } |
|
| 1022 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
| 1023 | + $this->registry->create('EventEspresso\core\services\assets\Registry', array(), true); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * initialize |
|
| 1030 | + * this is the best place to begin initializing client code |
|
| 1031 | + * |
|
| 1032 | + * @access public |
|
| 1033 | + * @return void |
|
| 1034 | + */ |
|
| 1035 | + public function initialize() |
|
| 1036 | + { |
|
| 1037 | + do_action('AHEE__EE_System__initialize'); |
|
| 1038 | + } |
|
| 1039 | + |
|
| 1040 | + |
|
| 1041 | + |
|
| 1042 | + /** |
|
| 1043 | + * initialize_last |
|
| 1044 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
| 1045 | + * initialize has done so |
|
| 1046 | + * |
|
| 1047 | + * @access public |
|
| 1048 | + * @return void |
|
| 1049 | + */ |
|
| 1050 | + public function initialize_last() |
|
| 1051 | + { |
|
| 1052 | + do_action('AHEE__EE_System__initialize_last'); |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + |
|
| 1057 | + /** |
|
| 1058 | + * set_hooks_for_shortcodes_modules_and_addons |
|
| 1059 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
| 1060 | + * this happens at the very beginning of the wp_loaded hook point |
|
| 1061 | + * |
|
| 1062 | + * @access public |
|
| 1063 | + * @return void |
|
| 1064 | + */ |
|
| 1065 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
| 1066 | + { |
|
| 1067 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + |
|
| 1071 | + |
|
| 1072 | + /** |
|
| 1073 | + * do_not_cache |
|
| 1074 | + * sets no cache headers and defines no cache constants for WP plugins |
|
| 1075 | + * |
|
| 1076 | + * @access public |
|
| 1077 | + * @return void |
|
| 1078 | + */ |
|
| 1079 | + public static function do_not_cache() |
|
| 1080 | + { |
|
| 1081 | + // set no cache constants |
|
| 1082 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
| 1083 | + define('DONOTCACHEPAGE', true); |
|
| 1084 | + } |
|
| 1085 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
| 1086 | + define('DONOTCACHCEOBJECT', true); |
|
| 1087 | + } |
|
| 1088 | + if ( ! defined('DONOTCACHEDB')) { |
|
| 1089 | + define('DONOTCACHEDB', true); |
|
| 1090 | + } |
|
| 1091 | + // add no cache headers |
|
| 1092 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
| 1093 | + // plus a little extra for nginx and Google Chrome |
|
| 1094 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
| 1095 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
| 1096 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + |
|
| 1100 | + |
|
| 1101 | + /** |
|
| 1102 | + * extra_nocache_headers |
|
| 1103 | + * |
|
| 1104 | + * @access public |
|
| 1105 | + * @param $headers |
|
| 1106 | + * @return array |
|
| 1107 | + */ |
|
| 1108 | + public static function extra_nocache_headers($headers) |
|
| 1109 | + { |
|
| 1110 | + // for NGINX |
|
| 1111 | + $headers['X-Accel-Expires'] = 0; |
|
| 1112 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
| 1113 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
| 1114 | + return $headers; |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + |
|
| 1119 | + /** |
|
| 1120 | + * nocache_headers |
|
| 1121 | + * |
|
| 1122 | + * @access public |
|
| 1123 | + * @return void |
|
| 1124 | + */ |
|
| 1125 | + public static function nocache_headers() |
|
| 1126 | + { |
|
| 1127 | + nocache_headers(); |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + |
|
| 1131 | + |
|
| 1132 | + /** |
|
| 1133 | + * espresso_toolbar_items |
|
| 1134 | + * |
|
| 1135 | + * @access public |
|
| 1136 | + * @param WP_Admin_Bar $admin_bar |
|
| 1137 | + * @return void |
|
| 1138 | + */ |
|
| 1139 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
| 1140 | + { |
|
| 1141 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
| 1142 | + if ( |
|
| 1143 | + defined('DOING_AJAX') |
|
| 1144 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
| 1145 | + || EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1146 | + ) { |
|
| 1147 | + return; |
|
| 1148 | + } |
|
| 1149 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1150 | + $menu_class = 'espresso_menu_item_class'; |
|
| 1151 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
| 1152 | + //because they're only defined in each of their respective constructors |
|
| 1153 | + //and this might be a frontend request, in which case they aren't available |
|
| 1154 | + $events_admin_url = admin_url('admin.php?page=espresso_events'); |
|
| 1155 | + $reg_admin_url = admin_url('admin.php?page=espresso_registrations'); |
|
| 1156 | + $extensions_admin_url = admin_url('admin.php?page=espresso_packages'); |
|
| 1157 | + //Top Level |
|
| 1158 | + $admin_bar->add_menu(array( |
|
| 1159 | + 'id' => 'espresso-toolbar', |
|
| 1160 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
| 1161 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
| 1162 | + . '</span>', |
|
| 1163 | + 'href' => $events_admin_url, |
|
| 1164 | + 'meta' => array( |
|
| 1165 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
| 1166 | + 'class' => $menu_class . 'first', |
|
| 1167 | + ), |
|
| 1168 | + )); |
|
| 1169 | + //Events |
|
| 1170 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
| 1171 | + $admin_bar->add_menu(array( |
|
| 1172 | + 'id' => 'espresso-toolbar-events', |
|
| 1173 | + 'parent' => 'espresso-toolbar', |
|
| 1174 | + 'title' => __('Events', 'event_espresso'), |
|
| 1175 | + 'href' => $events_admin_url, |
|
| 1176 | + 'meta' => array( |
|
| 1177 | + 'title' => __('Events', 'event_espresso'), |
|
| 1178 | + 'target' => '', |
|
| 1179 | + 'class' => $menu_class, |
|
| 1180 | + ), |
|
| 1181 | + )); |
|
| 1182 | + } |
|
| 1183 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
| 1184 | + //Events Add New |
|
| 1185 | + $admin_bar->add_menu(array( |
|
| 1186 | + 'id' => 'espresso-toolbar-events-new', |
|
| 1187 | + 'parent' => 'espresso-toolbar-events', |
|
| 1188 | + 'title' => __('Add New', 'event_espresso'), |
|
| 1189 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
| 1190 | + 'meta' => array( |
|
| 1191 | + 'title' => __('Add New', 'event_espresso'), |
|
| 1192 | + 'target' => '', |
|
| 1193 | + 'class' => $menu_class, |
|
| 1194 | + ), |
|
| 1195 | + )); |
|
| 1196 | + } |
|
| 1197 | + if (is_single() && (get_post_type() === 'espresso_events')) { |
|
| 1198 | + //Current post |
|
| 1199 | + global $post; |
|
| 1200 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
| 1201 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
| 1202 | + ) { |
|
| 1203 | + //Events Edit Current Event |
|
| 1204 | + $admin_bar->add_menu(array( |
|
| 1205 | + 'id' => 'espresso-toolbar-events-edit', |
|
| 1206 | + 'parent' => 'espresso-toolbar-events', |
|
| 1207 | + 'title' => __('Edit Event', 'event_espresso'), |
|
| 1208 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
| 1209 | + $events_admin_url), |
|
| 1210 | + 'meta' => array( |
|
| 1211 | + 'title' => __('Edit Event', 'event_espresso'), |
|
| 1212 | + 'target' => '', |
|
| 1213 | + 'class' => $menu_class, |
|
| 1214 | + ), |
|
| 1215 | + )); |
|
| 1216 | + } |
|
| 1217 | + } |
|
| 1218 | + //Events View |
|
| 1219 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1220 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
| 1221 | + ) { |
|
| 1222 | + $admin_bar->add_menu(array( |
|
| 1223 | + 'id' => 'espresso-toolbar-events-view', |
|
| 1224 | + 'parent' => 'espresso-toolbar-events', |
|
| 1225 | + 'title' => __('View', 'event_espresso'), |
|
| 1226 | + 'href' => $events_admin_url, |
|
| 1227 | + 'meta' => array( |
|
| 1228 | + 'title' => __('View', 'event_espresso'), |
|
| 1229 | + 'target' => '', |
|
| 1230 | + 'class' => $menu_class, |
|
| 1231 | + ), |
|
| 1232 | + )); |
|
| 1233 | + } |
|
| 1234 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
| 1235 | + //Events View All |
|
| 1236 | + $admin_bar->add_menu(array( |
|
| 1237 | + 'id' => 'espresso-toolbar-events-all', |
|
| 1238 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1239 | + 'title' => __('All', 'event_espresso'), |
|
| 1240 | + 'href' => $events_admin_url, |
|
| 1241 | + 'meta' => array( |
|
| 1242 | + 'title' => __('All', 'event_espresso'), |
|
| 1243 | + 'target' => '', |
|
| 1244 | + 'class' => $menu_class, |
|
| 1245 | + ), |
|
| 1246 | + )); |
|
| 1247 | + } |
|
| 1248 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1249 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
| 1250 | + ) { |
|
| 1251 | + //Events View Today |
|
| 1252 | + $admin_bar->add_menu(array( |
|
| 1253 | + 'id' => 'espresso-toolbar-events-today', |
|
| 1254 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1255 | + 'title' => __('Today', 'event_espresso'), |
|
| 1256 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1257 | + $events_admin_url), |
|
| 1258 | + 'meta' => array( |
|
| 1259 | + 'title' => __('Today', 'event_espresso'), |
|
| 1260 | + 'target' => '', |
|
| 1261 | + 'class' => $menu_class, |
|
| 1262 | + ), |
|
| 1263 | + )); |
|
| 1264 | + } |
|
| 1265 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
| 1266 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
| 1267 | + ) { |
|
| 1268 | + //Events View This Month |
|
| 1269 | + $admin_bar->add_menu(array( |
|
| 1270 | + 'id' => 'espresso-toolbar-events-month', |
|
| 1271 | + 'parent' => 'espresso-toolbar-events-view', |
|
| 1272 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1273 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1274 | + $events_admin_url), |
|
| 1275 | + 'meta' => array( |
|
| 1276 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1277 | + 'target' => '', |
|
| 1278 | + 'class' => $menu_class, |
|
| 1279 | + ), |
|
| 1280 | + )); |
|
| 1281 | + } |
|
| 1282 | + //Registration Overview |
|
| 1283 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1284 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
| 1285 | + ) { |
|
| 1286 | + $admin_bar->add_menu(array( |
|
| 1287 | + 'id' => 'espresso-toolbar-registrations', |
|
| 1288 | + 'parent' => 'espresso-toolbar', |
|
| 1289 | + 'title' => __('Registrations', 'event_espresso'), |
|
| 1290 | + 'href' => $reg_admin_url, |
|
| 1291 | + 'meta' => array( |
|
| 1292 | + 'title' => __('Registrations', 'event_espresso'), |
|
| 1293 | + 'target' => '', |
|
| 1294 | + 'class' => $menu_class, |
|
| 1295 | + ), |
|
| 1296 | + )); |
|
| 1297 | + } |
|
| 1298 | + //Registration Overview Today |
|
| 1299 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1300 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
| 1301 | + ) { |
|
| 1302 | + $admin_bar->add_menu(array( |
|
| 1303 | + 'id' => 'espresso-toolbar-registrations-today', |
|
| 1304 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 1305 | + 'title' => __('Today', 'event_espresso'), |
|
| 1306 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
| 1307 | + $reg_admin_url), |
|
| 1308 | + 'meta' => array( |
|
| 1309 | + 'title' => __('Today', 'event_espresso'), |
|
| 1310 | + 'target' => '', |
|
| 1311 | + 'class' => $menu_class, |
|
| 1312 | + ), |
|
| 1313 | + )); |
|
| 1314 | + } |
|
| 1315 | + //Registration Overview Today Completed |
|
| 1316 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1317 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
| 1318 | + ) { |
|
| 1319 | + $admin_bar->add_menu(array( |
|
| 1320 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
| 1321 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1322 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1323 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1324 | + 'action' => 'default', |
|
| 1325 | + 'status' => 'today', |
|
| 1326 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1327 | + ), $reg_admin_url), |
|
| 1328 | + 'meta' => array( |
|
| 1329 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1330 | + 'target' => '', |
|
| 1331 | + 'class' => $menu_class, |
|
| 1332 | + ), |
|
| 1333 | + )); |
|
| 1334 | + } |
|
| 1335 | + //Registration Overview Today Pending\ |
|
| 1336 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1337 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
| 1338 | + ) { |
|
| 1339 | + $admin_bar->add_menu(array( |
|
| 1340 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
| 1341 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1342 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1343 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1344 | + 'action' => 'default', |
|
| 1345 | + 'status' => 'today', |
|
| 1346 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1347 | + ), $reg_admin_url), |
|
| 1348 | + 'meta' => array( |
|
| 1349 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
| 1350 | + 'target' => '', |
|
| 1351 | + 'class' => $menu_class, |
|
| 1352 | + ), |
|
| 1353 | + )); |
|
| 1354 | + } |
|
| 1355 | + //Registration Overview Today Incomplete |
|
| 1356 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1357 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
| 1358 | + ) { |
|
| 1359 | + $admin_bar->add_menu(array( |
|
| 1360 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
| 1361 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1362 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1363 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1364 | + 'action' => 'default', |
|
| 1365 | + 'status' => 'today', |
|
| 1366 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1367 | + ), $reg_admin_url), |
|
| 1368 | + 'meta' => array( |
|
| 1369 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1370 | + 'target' => '', |
|
| 1371 | + 'class' => $menu_class, |
|
| 1372 | + ), |
|
| 1373 | + )); |
|
| 1374 | + } |
|
| 1375 | + //Registration Overview Today Incomplete |
|
| 1376 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1377 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
| 1378 | + ) { |
|
| 1379 | + $admin_bar->add_menu(array( |
|
| 1380 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
| 1381 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
| 1382 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1383 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1384 | + 'action' => 'default', |
|
| 1385 | + 'status' => 'today', |
|
| 1386 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1387 | + ), $reg_admin_url), |
|
| 1388 | + 'meta' => array( |
|
| 1389 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1390 | + 'target' => '', |
|
| 1391 | + 'class' => $menu_class, |
|
| 1392 | + ), |
|
| 1393 | + )); |
|
| 1394 | + } |
|
| 1395 | + //Registration Overview This Month |
|
| 1396 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1397 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
| 1398 | + ) { |
|
| 1399 | + $admin_bar->add_menu(array( |
|
| 1400 | + 'id' => 'espresso-toolbar-registrations-month', |
|
| 1401 | + 'parent' => 'espresso-toolbar-registrations', |
|
| 1402 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1403 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
| 1404 | + $reg_admin_url), |
|
| 1405 | + 'meta' => array( |
|
| 1406 | + 'title' => __('This Month', 'event_espresso'), |
|
| 1407 | + 'target' => '', |
|
| 1408 | + 'class' => $menu_class, |
|
| 1409 | + ), |
|
| 1410 | + )); |
|
| 1411 | + } |
|
| 1412 | + //Registration Overview This Month Approved |
|
| 1413 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1414 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
| 1415 | + ) { |
|
| 1416 | + $admin_bar->add_menu(array( |
|
| 1417 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
| 1418 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1419 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1420 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1421 | + 'action' => 'default', |
|
| 1422 | + 'status' => 'month', |
|
| 1423 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
| 1424 | + ), $reg_admin_url), |
|
| 1425 | + 'meta' => array( |
|
| 1426 | + 'title' => __('Approved', 'event_espresso'), |
|
| 1427 | + 'target' => '', |
|
| 1428 | + 'class' => $menu_class, |
|
| 1429 | + ), |
|
| 1430 | + )); |
|
| 1431 | + } |
|
| 1432 | + //Registration Overview This Month Pending |
|
| 1433 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1434 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
| 1435 | + ) { |
|
| 1436 | + $admin_bar->add_menu(array( |
|
| 1437 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
| 1438 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1439 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1440 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1441 | + 'action' => 'default', |
|
| 1442 | + 'status' => 'month', |
|
| 1443 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
| 1444 | + ), $reg_admin_url), |
|
| 1445 | + 'meta' => array( |
|
| 1446 | + 'title' => __('Pending', 'event_espresso'), |
|
| 1447 | + 'target' => '', |
|
| 1448 | + 'class' => $menu_class, |
|
| 1449 | + ), |
|
| 1450 | + )); |
|
| 1451 | + } |
|
| 1452 | + //Registration Overview This Month Not Approved |
|
| 1453 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1454 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
| 1455 | + ) { |
|
| 1456 | + $admin_bar->add_menu(array( |
|
| 1457 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
| 1458 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1459 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1460 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1461 | + 'action' => 'default', |
|
| 1462 | + 'status' => 'month', |
|
| 1463 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
| 1464 | + ), $reg_admin_url), |
|
| 1465 | + 'meta' => array( |
|
| 1466 | + 'title' => __('Not Approved', 'event_espresso'), |
|
| 1467 | + 'target' => '', |
|
| 1468 | + 'class' => $menu_class, |
|
| 1469 | + ), |
|
| 1470 | + )); |
|
| 1471 | + } |
|
| 1472 | + //Registration Overview This Month Cancelled |
|
| 1473 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
| 1474 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
| 1475 | + ) { |
|
| 1476 | + $admin_bar->add_menu(array( |
|
| 1477 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
| 1478 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
| 1479 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1480 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
| 1481 | + 'action' => 'default', |
|
| 1482 | + 'status' => 'month', |
|
| 1483 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
| 1484 | + ), $reg_admin_url), |
|
| 1485 | + 'meta' => array( |
|
| 1486 | + 'title' => __('Cancelled', 'event_espresso'), |
|
| 1487 | + 'target' => '', |
|
| 1488 | + 'class' => $menu_class, |
|
| 1489 | + ), |
|
| 1490 | + )); |
|
| 1491 | + } |
|
| 1492 | + //Extensions & Services |
|
| 1493 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
| 1494 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
| 1495 | + ) { |
|
| 1496 | + $admin_bar->add_menu(array( |
|
| 1497 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
| 1498 | + 'parent' => 'espresso-toolbar', |
|
| 1499 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1500 | + 'href' => $extensions_admin_url, |
|
| 1501 | + 'meta' => array( |
|
| 1502 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
| 1503 | + 'target' => '', |
|
| 1504 | + 'class' => $menu_class, |
|
| 1505 | + ), |
|
| 1506 | + )); |
|
| 1507 | + } |
|
| 1508 | + } |
|
| 1509 | + |
|
| 1510 | + |
|
| 1511 | + |
|
| 1512 | + /** |
|
| 1513 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
| 1514 | + * never returned with the function. |
|
| 1515 | + * |
|
| 1516 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
| 1517 | + * @return array |
|
| 1518 | + */ |
|
| 1519 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
| 1520 | + { |
|
| 1521 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
| 1522 | + } |
|
| 1523 | 1523 | |
| 1524 | 1524 | |
| 1525 | 1525 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | { |
| 262 | 262 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
| 263 | 263 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
| 264 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
| 264 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
| 296 | 296 | ) |
| 297 | 297 | ) { |
| 298 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
| 298 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
| 299 | 299 | } |
| 300 | 300 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
| 301 | 301 | } |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | private function _parse_model_names() |
| 782 | 782 | { |
| 783 | 783 | //get all the files in the EE_MODELS folder that end in .model.php |
| 784 | - $models = glob(EE_MODELS . '*.model.php'); |
|
| 784 | + $models = glob(EE_MODELS.'*.model.php'); |
|
| 785 | 785 | $model_names = array(); |
| 786 | 786 | $non_abstract_db_models = array(); |
| 787 | 787 | foreach ($models as $model) { |
@@ -809,8 +809,8 @@ discard block |
||
| 809 | 809 | */ |
| 810 | 810 | private function _maybe_brew_regular() |
| 811 | 811 | { |
| 812 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
| 813 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
| 812 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
| 813 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
| 814 | 814 | } |
| 815 | 815 | } |
| 816 | 816 | |
@@ -860,8 +860,8 @@ discard block |
||
| 860 | 860 | 'event_espresso'); |
| 861 | 861 | $msg .= '<ul>'; |
| 862 | 862 | foreach ($class_names as $class_name) { |
| 863 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 864 | - $class_name) . '</b></li>'; |
|
| 863 | + $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
| 864 | + $class_name).'</b></li>'; |
|
| 865 | 865 | } |
| 866 | 866 | $msg .= '</ul>'; |
| 867 | 867 | $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
@@ -1016,8 +1016,8 @@ discard block |
||
| 1016 | 1016 | $this->registry->load_core('Session'); |
| 1017 | 1017 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
| 1018 | 1018 | // load_espresso_template_tags |
| 1019 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 1020 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 1019 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
| 1020 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
| 1021 | 1021 | } |
| 1022 | 1022 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
| 1023 | 1023 | $this->registry->create('EventEspresso\core\services\assets\Registry', array(), true); |
@@ -1163,7 +1163,7 @@ discard block |
||
| 1163 | 1163 | 'href' => $events_admin_url, |
| 1164 | 1164 | 'meta' => array( |
| 1165 | 1165 | 'title' => __('Event Espresso', 'event_espresso'), |
| 1166 | - 'class' => $menu_class . 'first', |
|
| 1166 | + 'class' => $menu_class.'first', |
|
| 1167 | 1167 | ), |
| 1168 | 1168 | )); |
| 1169 | 1169 | //Events |
@@ -18,980 +18,980 @@ discard block |
||
| 18 | 18 | final class EE_Capabilities extends EE_Base |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * the name of the wp option used to store caps previously initialized |
|
| 23 | - */ |
|
| 24 | - const option_name = 'ee_caps_initialized'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * instance of EE_Capabilities object |
|
| 28 | - * |
|
| 29 | - * @var EE_Capabilities |
|
| 30 | - */ |
|
| 31 | - private static $_instance; |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | - * Array is indexed by Role and values are ee capabilities. |
|
| 37 | - * |
|
| 38 | - * @since 4.5.0 |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $capabilities_map = array(); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | - * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | - * |
|
| 48 | - * @var EE_Meta_Capability_Map[] |
|
| 49 | - */ |
|
| 50 | - private $_meta_caps = array(); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | - * This flag tracks whether that has happened or not. |
|
| 55 | - * But for this to work, we need three states to indicate: |
|
| 56 | - * initialization has not occurred at all |
|
| 57 | - * initialization has started but is not complete |
|
| 58 | - * initialization is complete |
|
| 59 | - * The reason this is needed is because the addCaps() method |
|
| 60 | - * normally requires the $capabilities_map to be initialized, |
|
| 61 | - * but is also used during the initialization process. |
|
| 62 | - * So: |
|
| 63 | - * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | - * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | - * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | - * |
|
| 67 | - * @var boolean|null $initialized |
|
| 68 | - */ |
|
| 69 | - private $initialized; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var boolean $reset |
|
| 73 | - */ |
|
| 74 | - private $reset = false; |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * singleton method used to instantiate class object |
|
| 80 | - * |
|
| 81 | - * @since 4.5.0 |
|
| 82 | - * |
|
| 83 | - * @return EE_Capabilities |
|
| 84 | - */ |
|
| 85 | - public static function instance() |
|
| 86 | - { |
|
| 87 | - //check if instantiated, and if not do so. |
|
| 88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | - self::$_instance = new self(); |
|
| 90 | - } |
|
| 91 | - return self::$_instance; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * private constructor |
|
| 98 | - * |
|
| 99 | - * @since 4.5.0 |
|
| 100 | - */ |
|
| 101 | - private function __construct() |
|
| 102 | - { |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | - * |
|
| 110 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | - * ensures that they are up to date. |
|
| 113 | - * |
|
| 114 | - * @since 4.5.0 |
|
| 115 | - * @return bool |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function init_caps($reset = false) |
|
| 119 | - { |
|
| 120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | - return false; |
|
| 122 | - } |
|
| 123 | - $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | - // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | - if ($this->reset) { |
|
| 126 | - $this->initialized = null; |
|
| 127 | - $this->capabilities_map = array(); |
|
| 128 | - delete_option(self::option_name); |
|
| 129 | - } |
|
| 130 | - if ($this->initialized === null) { |
|
| 131 | - $this->initialized = false; |
|
| 132 | - do_action( |
|
| 133 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | - $this->reset |
|
| 135 | - ); |
|
| 136 | - $this->addCaps($this->_init_caps_map()); |
|
| 137 | - $this->_set_meta_caps(); |
|
| 138 | - do_action( |
|
| 139 | - 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | - $this->capabilities_map |
|
| 141 | - ); |
|
| 142 | - $this->initialized = true; |
|
| 143 | - } |
|
| 144 | - // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | - $this->reset = false; |
|
| 146 | - return true; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * This sets the meta caps property. |
|
| 153 | - * |
|
| 154 | - * @since 4.5.0 |
|
| 155 | - * @return void |
|
| 156 | - * @throws EE_Error |
|
| 157 | - */ |
|
| 158 | - private function _set_meta_caps() |
|
| 159 | - { |
|
| 160 | - // get default meta caps and filter the returned array |
|
| 161 | - $this->_meta_caps = apply_filters( |
|
| 162 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 163 | - $this->_get_default_meta_caps_array() |
|
| 164 | - ); |
|
| 165 | - //add filter for map_meta_caps but only if models can query. |
|
| 166 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 167 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * This builds and returns the default meta_caps array only once. |
|
| 175 | - * |
|
| 176 | - * @since 4.8.28.rc.012 |
|
| 177 | - * @return array |
|
| 178 | - * @throws EE_Error |
|
| 179 | - */ |
|
| 180 | - private function _get_default_meta_caps_array() |
|
| 181 | - { |
|
| 182 | - static $default_meta_caps = array(); |
|
| 183 | - // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 184 | - if (empty($default_meta_caps)) { |
|
| 185 | - $default_meta_caps = array( |
|
| 186 | - //edits |
|
| 187 | - new EE_Meta_Capability_Map_Edit( |
|
| 188 | - 'ee_edit_event', |
|
| 189 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 190 | - ), |
|
| 191 | - new EE_Meta_Capability_Map_Edit( |
|
| 192 | - 'ee_edit_venue', |
|
| 193 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 194 | - ), |
|
| 195 | - new EE_Meta_Capability_Map_Edit( |
|
| 196 | - 'ee_edit_registration', |
|
| 197 | - array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 198 | - ), |
|
| 199 | - new EE_Meta_Capability_Map_Edit( |
|
| 200 | - 'ee_edit_checkin', |
|
| 201 | - array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 202 | - ), |
|
| 203 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 204 | - 'ee_edit_message', |
|
| 205 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 206 | - ), |
|
| 207 | - new EE_Meta_Capability_Map_Edit( |
|
| 208 | - 'ee_edit_default_ticket', |
|
| 209 | - array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 210 | - ), |
|
| 211 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 212 | - 'ee_edit_question', |
|
| 213 | - array('Question', '', '', 'ee_edit_system_questions') |
|
| 214 | - ), |
|
| 215 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 216 | - 'ee_edit_question_group', |
|
| 217 | - array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 218 | - ), |
|
| 219 | - new EE_Meta_Capability_Map_Edit( |
|
| 220 | - 'ee_edit_payment_method', |
|
| 221 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 222 | - ), |
|
| 223 | - //reads |
|
| 224 | - new EE_Meta_Capability_Map_Read( |
|
| 225 | - 'ee_read_event', |
|
| 226 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 227 | - ), |
|
| 228 | - new EE_Meta_Capability_Map_Read( |
|
| 229 | - 'ee_read_venue', |
|
| 230 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 231 | - ), |
|
| 232 | - new EE_Meta_Capability_Map_Read( |
|
| 233 | - 'ee_read_registration', |
|
| 234 | - array('Registration', '', 'ee_read_others_registrations', '') |
|
| 235 | - ), |
|
| 236 | - new EE_Meta_Capability_Map_Read( |
|
| 237 | - 'ee_read_checkin', |
|
| 238 | - array('Registration', '', 'ee_read_others_checkins', '') |
|
| 239 | - ), |
|
| 240 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 241 | - 'ee_read_message', |
|
| 242 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 243 | - ), |
|
| 244 | - new EE_Meta_Capability_Map_Read( |
|
| 245 | - 'ee_read_default_ticket', |
|
| 246 | - array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 247 | - ), |
|
| 248 | - new EE_Meta_Capability_Map_Read( |
|
| 249 | - 'ee_read_payment_method', |
|
| 250 | - array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 251 | - ), |
|
| 252 | - //deletes |
|
| 253 | - new EE_Meta_Capability_Map_Delete( |
|
| 254 | - 'ee_delete_event', |
|
| 255 | - array( |
|
| 256 | - 'Event', |
|
| 257 | - 'ee_delete_published_events', |
|
| 258 | - 'ee_delete_others_events', |
|
| 259 | - 'ee_delete_private_events', |
|
| 260 | - ) |
|
| 261 | - ), |
|
| 262 | - new EE_Meta_Capability_Map_Delete( |
|
| 263 | - 'ee_delete_venue', |
|
| 264 | - array( |
|
| 265 | - 'Venue', |
|
| 266 | - 'ee_delete_published_venues', |
|
| 267 | - 'ee_delete_others_venues', |
|
| 268 | - 'ee_delete_private_venues', |
|
| 269 | - ) |
|
| 270 | - ), |
|
| 271 | - new EE_Meta_Capability_Map_Delete( |
|
| 272 | - 'ee_delete_registration', |
|
| 273 | - array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 274 | - ), |
|
| 275 | - new EE_Meta_Capability_Map_Delete( |
|
| 276 | - 'ee_delete_checkin', |
|
| 277 | - array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 278 | - ), |
|
| 279 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
| 280 | - 'ee_delete_message', |
|
| 281 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 282 | - ), |
|
| 283 | - new EE_Meta_Capability_Map_Delete( |
|
| 284 | - 'ee_delete_default_ticket', |
|
| 285 | - array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 286 | - ), |
|
| 287 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 288 | - 'ee_delete_question', |
|
| 289 | - array('Question', '', '', 'delete_system_questions') |
|
| 290 | - ), |
|
| 291 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 292 | - 'ee_delete_question_group', |
|
| 293 | - array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 294 | - ), |
|
| 295 | - new EE_Meta_Capability_Map_Delete( |
|
| 296 | - 'ee_delete_payment_method', |
|
| 297 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 298 | - ), |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - return $default_meta_caps; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 308 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 309 | - * |
|
| 310 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 311 | - * |
|
| 312 | - * @since 4.5.0 |
|
| 313 | - * @see wp-includes/capabilities.php |
|
| 314 | - * |
|
| 315 | - * @param array $caps actual users capabilities |
|
| 316 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 317 | - * @param int $user_id The user id |
|
| 318 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 319 | - * @return array actual users capabilities |
|
| 320 | - * @throws EE_Error |
|
| 321 | - */ |
|
| 322 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 323 | - { |
|
| 324 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 325 | - //loop through our _meta_caps array |
|
| 326 | - foreach ($this->_meta_caps as $meta_map) { |
|
| 327 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 328 | - continue; |
|
| 329 | - } |
|
| 330 | - // don't load models if there is no object ID in the args |
|
| 331 | - if (! empty($args[0])) { |
|
| 332 | - $meta_map->ensure_is_model(); |
|
| 333 | - } |
|
| 334 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - return $caps; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
| 344 | - * Note this array is filtered. |
|
| 345 | - * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 346 | - * |
|
| 347 | - * @since 4.5.0 |
|
| 348 | - * |
|
| 349 | - * @return array |
|
| 350 | - */ |
|
| 351 | - private function _init_caps_map() |
|
| 352 | - { |
|
| 353 | - return apply_filters( |
|
| 354 | - 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 355 | - array( |
|
| 356 | - 'administrator' => array( |
|
| 357 | - //basic access |
|
| 358 | - 'ee_read_ee', |
|
| 359 | - //gateways |
|
| 360 | - /** |
|
| 361 | - * note that with payment method capabilities, although we've implemented |
|
| 362 | - * capability mapping which will be used for accessing payment methods owned by |
|
| 363 | - * other users. This is not fully implemented yet in the payment method ui. |
|
| 364 | - * Currently only the "plural" caps are in active use. |
|
| 365 | - * (Specific payment method caps are in use as well). |
|
| 366 | - **/ |
|
| 367 | - 'ee_manage_gateways', |
|
| 368 | - 'ee_read_payment_methods', |
|
| 369 | - 'ee_read_others_payment_methods', |
|
| 370 | - 'ee_edit_payment_methods', |
|
| 371 | - 'ee_edit_others_payment_methods', |
|
| 372 | - 'ee_delete_payment_methods', |
|
| 373 | - //events |
|
| 374 | - 'ee_publish_events', |
|
| 375 | - 'ee_read_private_events', |
|
| 376 | - 'ee_read_others_events', |
|
| 377 | - 'ee_read_events', |
|
| 378 | - 'ee_edit_events', |
|
| 379 | - 'ee_edit_published_events', |
|
| 380 | - 'ee_edit_others_events', |
|
| 381 | - 'ee_edit_private_events', |
|
| 382 | - 'ee_delete_published_events', |
|
| 383 | - 'ee_delete_private_events', |
|
| 384 | - 'ee_delete_events', |
|
| 385 | - 'ee_delete_others_events', |
|
| 386 | - //event categories |
|
| 387 | - 'ee_manage_event_categories', |
|
| 388 | - 'ee_edit_event_category', |
|
| 389 | - 'ee_delete_event_category', |
|
| 390 | - 'ee_assign_event_category', |
|
| 391 | - //venues |
|
| 392 | - 'ee_publish_venues', |
|
| 393 | - 'ee_read_venues', |
|
| 394 | - 'ee_read_others_venues', |
|
| 395 | - 'ee_read_private_venues', |
|
| 396 | - 'ee_edit_venues', |
|
| 397 | - 'ee_edit_others_venues', |
|
| 398 | - 'ee_edit_published_venues', |
|
| 399 | - 'ee_edit_private_venues', |
|
| 400 | - 'ee_delete_venues', |
|
| 401 | - 'ee_delete_others_venues', |
|
| 402 | - 'ee_delete_private_venues', |
|
| 403 | - 'ee_delete_published_venues', |
|
| 404 | - //venue categories |
|
| 405 | - 'ee_manage_venue_categories', |
|
| 406 | - 'ee_edit_venue_category', |
|
| 407 | - 'ee_delete_venue_category', |
|
| 408 | - 'ee_assign_venue_category', |
|
| 409 | - //contacts |
|
| 410 | - 'ee_read_contacts', |
|
| 411 | - 'ee_edit_contacts', |
|
| 412 | - 'ee_delete_contacts', |
|
| 413 | - //registrations |
|
| 414 | - 'ee_read_registrations', |
|
| 415 | - 'ee_read_others_registrations', |
|
| 416 | - 'ee_edit_registrations', |
|
| 417 | - 'ee_edit_others_registrations', |
|
| 418 | - 'ee_delete_registrations', |
|
| 419 | - //checkins |
|
| 420 | - 'ee_read_others_checkins', |
|
| 421 | - 'ee_read_checkins', |
|
| 422 | - 'ee_edit_checkins', |
|
| 423 | - 'ee_edit_others_checkins', |
|
| 424 | - 'ee_delete_checkins', |
|
| 425 | - 'ee_delete_others_checkins', |
|
| 426 | - //transactions && payments |
|
| 427 | - 'ee_read_transaction', |
|
| 428 | - 'ee_read_transactions', |
|
| 429 | - 'ee_edit_payments', |
|
| 430 | - 'ee_delete_payments', |
|
| 431 | - //messages |
|
| 432 | - 'ee_read_messages', |
|
| 433 | - 'ee_read_others_messages', |
|
| 434 | - 'ee_read_global_messages', |
|
| 435 | - 'ee_edit_global_messages', |
|
| 436 | - 'ee_edit_messages', |
|
| 437 | - 'ee_edit_others_messages', |
|
| 438 | - 'ee_delete_messages', |
|
| 439 | - 'ee_delete_others_messages', |
|
| 440 | - 'ee_delete_global_messages', |
|
| 441 | - 'ee_send_message', |
|
| 442 | - //tickets |
|
| 443 | - 'ee_read_default_tickets', |
|
| 444 | - 'ee_read_others_default_tickets', |
|
| 445 | - 'ee_edit_default_tickets', |
|
| 446 | - 'ee_edit_others_default_tickets', |
|
| 447 | - 'ee_delete_default_tickets', |
|
| 448 | - 'ee_delete_others_default_tickets', |
|
| 449 | - //prices |
|
| 450 | - 'ee_edit_default_price', |
|
| 451 | - 'ee_edit_default_prices', |
|
| 452 | - 'ee_delete_default_price', |
|
| 453 | - 'ee_delete_default_prices', |
|
| 454 | - 'ee_edit_default_price_type', |
|
| 455 | - 'ee_edit_default_price_types', |
|
| 456 | - 'ee_delete_default_price_type', |
|
| 457 | - 'ee_delete_default_price_types', |
|
| 458 | - 'ee_read_default_prices', |
|
| 459 | - 'ee_read_default_price_types', |
|
| 460 | - //registration form |
|
| 461 | - 'ee_edit_questions', |
|
| 462 | - 'ee_edit_system_questions', |
|
| 463 | - 'ee_read_questions', |
|
| 464 | - 'ee_delete_questions', |
|
| 465 | - 'ee_edit_question_groups', |
|
| 466 | - 'ee_read_question_groups', |
|
| 467 | - 'ee_edit_system_question_groups', |
|
| 468 | - 'ee_delete_question_groups', |
|
| 469 | - //event_type taxonomy |
|
| 470 | - 'ee_assign_event_type', |
|
| 471 | - 'ee_manage_event_types', |
|
| 472 | - 'ee_edit_event_type', |
|
| 473 | - 'ee_delete_event_type', |
|
| 474 | - ), |
|
| 475 | - 'ee_events_administrator' => array( |
|
| 476 | - //core wp caps |
|
| 477 | - 'read', |
|
| 478 | - 'read_private_pages', |
|
| 479 | - 'read_private_posts', |
|
| 480 | - 'edit_users', |
|
| 481 | - 'edit_posts', |
|
| 482 | - 'edit_pages', |
|
| 483 | - 'edit_published_posts', |
|
| 484 | - 'edit_published_pages', |
|
| 485 | - 'edit_private_pages', |
|
| 486 | - 'edit_private_posts', |
|
| 487 | - 'edit_others_posts', |
|
| 488 | - 'edit_others_pages', |
|
| 489 | - 'publish_posts', |
|
| 490 | - 'publish_pages', |
|
| 491 | - 'delete_posts', |
|
| 492 | - 'delete_pages', |
|
| 493 | - 'delete_private_pages', |
|
| 494 | - 'delete_private_posts', |
|
| 495 | - 'delete_published_pages', |
|
| 496 | - 'delete_published_posts', |
|
| 497 | - 'delete_others_posts', |
|
| 498 | - 'delete_others_pages', |
|
| 499 | - 'manage_categories', |
|
| 500 | - 'manage_links', |
|
| 501 | - 'moderate_comments', |
|
| 502 | - 'unfiltered_html', |
|
| 503 | - 'upload_files', |
|
| 504 | - 'export', |
|
| 505 | - 'import', |
|
| 506 | - 'list_users', |
|
| 507 | - 'level_1', //required if user with this role shows up in author dropdowns |
|
| 508 | - //basic ee access |
|
| 509 | - 'ee_read_ee', |
|
| 510 | - //events |
|
| 511 | - 'ee_publish_events', |
|
| 512 | - 'ee_read_private_events', |
|
| 513 | - 'ee_read_others_events', |
|
| 514 | - 'ee_read_event', |
|
| 515 | - 'ee_read_events', |
|
| 516 | - 'ee_edit_event', |
|
| 517 | - 'ee_edit_events', |
|
| 518 | - 'ee_edit_published_events', |
|
| 519 | - 'ee_edit_others_events', |
|
| 520 | - 'ee_edit_private_events', |
|
| 521 | - 'ee_delete_published_events', |
|
| 522 | - 'ee_delete_private_events', |
|
| 523 | - 'ee_delete_event', |
|
| 524 | - 'ee_delete_events', |
|
| 525 | - 'ee_delete_others_events', |
|
| 526 | - //event categories |
|
| 527 | - 'ee_manage_event_categories', |
|
| 528 | - 'ee_edit_event_category', |
|
| 529 | - 'ee_delete_event_category', |
|
| 530 | - 'ee_assign_event_category', |
|
| 531 | - //venues |
|
| 532 | - 'ee_publish_venues', |
|
| 533 | - 'ee_read_venue', |
|
| 534 | - 'ee_read_venues', |
|
| 535 | - 'ee_read_others_venues', |
|
| 536 | - 'ee_read_private_venues', |
|
| 537 | - 'ee_edit_venue', |
|
| 538 | - 'ee_edit_venues', |
|
| 539 | - 'ee_edit_others_venues', |
|
| 540 | - 'ee_edit_published_venues', |
|
| 541 | - 'ee_edit_private_venues', |
|
| 542 | - 'ee_delete_venue', |
|
| 543 | - 'ee_delete_venues', |
|
| 544 | - 'ee_delete_others_venues', |
|
| 545 | - 'ee_delete_private_venues', |
|
| 546 | - 'ee_delete_published_venues', |
|
| 547 | - //venue categories |
|
| 548 | - 'ee_manage_venue_categories', |
|
| 549 | - 'ee_edit_venue_category', |
|
| 550 | - 'ee_delete_venue_category', |
|
| 551 | - 'ee_assign_venue_category', |
|
| 552 | - //contacts |
|
| 553 | - 'ee_read_contacts', |
|
| 554 | - 'ee_edit_contacts', |
|
| 555 | - 'ee_delete_contacts', |
|
| 556 | - //registrations |
|
| 557 | - 'ee_read_registrations', |
|
| 558 | - 'ee_read_others_registrations', |
|
| 559 | - 'ee_edit_registration', |
|
| 560 | - 'ee_edit_registrations', |
|
| 561 | - 'ee_edit_others_registrations', |
|
| 562 | - 'ee_delete_registration', |
|
| 563 | - 'ee_delete_registrations', |
|
| 564 | - //checkins |
|
| 565 | - 'ee_read_others_checkins', |
|
| 566 | - 'ee_read_checkins', |
|
| 567 | - 'ee_edit_checkins', |
|
| 568 | - 'ee_edit_others_checkins', |
|
| 569 | - 'ee_delete_checkins', |
|
| 570 | - 'ee_delete_others_checkins', |
|
| 571 | - //transactions && payments |
|
| 572 | - 'ee_read_transaction', |
|
| 573 | - 'ee_read_transactions', |
|
| 574 | - 'ee_edit_payments', |
|
| 575 | - 'ee_delete_payments', |
|
| 576 | - //messages |
|
| 577 | - 'ee_read_messages', |
|
| 578 | - 'ee_read_others_messages', |
|
| 579 | - 'ee_read_global_messages', |
|
| 580 | - 'ee_edit_global_messages', |
|
| 581 | - 'ee_edit_messages', |
|
| 582 | - 'ee_edit_others_messages', |
|
| 583 | - 'ee_delete_messages', |
|
| 584 | - 'ee_delete_others_messages', |
|
| 585 | - 'ee_delete_global_messages', |
|
| 586 | - 'ee_send_message', |
|
| 587 | - //tickets |
|
| 588 | - 'ee_read_default_tickets', |
|
| 589 | - 'ee_read_others_default_tickets', |
|
| 590 | - 'ee_edit_default_tickets', |
|
| 591 | - 'ee_edit_others_default_tickets', |
|
| 592 | - 'ee_delete_default_tickets', |
|
| 593 | - 'ee_delete_others_default_tickets', |
|
| 594 | - //prices |
|
| 595 | - 'ee_edit_default_price', |
|
| 596 | - 'ee_edit_default_prices', |
|
| 597 | - 'ee_delete_default_price', |
|
| 598 | - 'ee_delete_default_prices', |
|
| 599 | - 'ee_edit_default_price_type', |
|
| 600 | - 'ee_edit_default_price_types', |
|
| 601 | - 'ee_delete_default_price_type', |
|
| 602 | - 'ee_delete_default_price_types', |
|
| 603 | - 'ee_read_default_prices', |
|
| 604 | - 'ee_read_default_price_types', |
|
| 605 | - //registration form |
|
| 606 | - 'ee_edit_questions', |
|
| 607 | - 'ee_edit_system_questions', |
|
| 608 | - 'ee_read_questions', |
|
| 609 | - 'ee_delete_questions', |
|
| 610 | - 'ee_edit_question_groups', |
|
| 611 | - 'ee_read_question_groups', |
|
| 612 | - 'ee_edit_system_question_groups', |
|
| 613 | - 'ee_delete_question_groups', |
|
| 614 | - //event_type taxonomy |
|
| 615 | - 'ee_assign_event_type', |
|
| 616 | - 'ee_manage_event_types', |
|
| 617 | - 'ee_edit_event_type', |
|
| 618 | - 'ee_delete_event_type', |
|
| 619 | - ) |
|
| 620 | - ) |
|
| 621 | - ); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * @return bool |
|
| 628 | - * @throws EE_Error |
|
| 629 | - */ |
|
| 630 | - private function setupCapabilitiesMap() |
|
| 631 | - { |
|
| 632 | - // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 633 | - if($this->initialized === null) { |
|
| 634 | - return $this->init_caps(); |
|
| 635 | - } |
|
| 636 | - // unless resetting, get caps from db if we haven't already |
|
| 637 | - $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 638 | - ? $this->capabilities_map |
|
| 639 | - : get_option(self::option_name, array()); |
|
| 640 | - return true; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * @param bool $update |
|
| 647 | - * @return bool |
|
| 648 | - */ |
|
| 649 | - private function updateCapabilitiesMap($update = true) |
|
| 650 | - { |
|
| 651 | - return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Adds capabilities to roles. |
|
| 658 | - * |
|
| 659 | - * @since 4.9.42 |
|
| 660 | - * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 661 | - * Note that this should ONLY be called on activation hook |
|
| 662 | - * otherwise the caps will be added on every request. |
|
| 663 | - * @return bool |
|
| 664 | - * @throws \EE_Error |
|
| 665 | - */ |
|
| 666 | - public function addCaps(array $capabilities_to_add) |
|
| 667 | - { |
|
| 668 | - // don't do anything if the capabilities map can not be initialized |
|
| 669 | - if (! $this->setupCapabilitiesMap()) { |
|
| 670 | - return false; |
|
| 671 | - } |
|
| 672 | - // and filter the array so others can get in on the fun during resets |
|
| 673 | - $capabilities_to_add = apply_filters( |
|
| 674 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 675 | - $capabilities_to_add, |
|
| 676 | - $this->reset, |
|
| 677 | - $this->capabilities_map |
|
| 678 | - ); |
|
| 679 | - $update_capabilities_map = false; |
|
| 680 | - // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 681 | - foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 682 | - if (is_array($caps_for_role)) { |
|
| 683 | - foreach ($caps_for_role as $cap) { |
|
| 684 | - if ( |
|
| 685 | - ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 686 | - && $this->add_cap_to_role($role, $cap, true, false) |
|
| 687 | - ) { |
|
| 688 | - $update_capabilities_map = true; |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - // now let's just save the cap that has been set but only if there's been a change. |
|
| 694 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 695 | - do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 696 | - return $updated; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 703 | - * |
|
| 704 | - * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 705 | - * @return bool |
|
| 706 | - * @throws \EE_Error |
|
| 707 | - */ |
|
| 708 | - public function removeCaps($caps_map) |
|
| 709 | - { |
|
| 710 | - // don't do anything if the capabilities map can not be initialized |
|
| 711 | - if (! $this->setupCapabilitiesMap()) { |
|
| 712 | - return false; |
|
| 713 | - } |
|
| 714 | - $update_capabilities_map = false; |
|
| 715 | - foreach ($caps_map as $role => $caps_for_role) { |
|
| 716 | - if (is_array($caps_for_role)) { |
|
| 717 | - foreach ($caps_for_role as $cap) { |
|
| 718 | - if ( |
|
| 719 | - $this->capHasBeenAddedToRole($role, $cap) |
|
| 720 | - && $this->remove_cap_from_role($role, $cap, false) |
|
| 721 | - ) { |
|
| 722 | - $update_capabilities_map = true; |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - // maybe resave the caps |
|
| 728 | - return $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 735 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 736 | - * this is a wrapper for $wp_role->add_cap() |
|
| 737 | - * |
|
| 738 | - * @see wp-includes/capabilities.php |
|
| 739 | - * @since 4.5.0 |
|
| 740 | - * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 741 | - * @param string $cap The capability being added to the role |
|
| 742 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
| 743 | - * @param bool $update_capabilities_map |
|
| 744 | - * @return bool |
|
| 745 | - * @throws \EE_Error |
|
| 746 | - */ |
|
| 747 | - public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 748 | - { |
|
| 749 | - // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 750 | - $orig_role = $role; |
|
| 751 | - $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 752 | - //if the role isn't available then we create it. |
|
| 753 | - if (! $role instanceof WP_Role) { |
|
| 754 | - // if a plugin wants to create a specific role name then they should create the role before |
|
| 755 | - // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 756 | - // - removes any `ee_` namespacing from the start of the slug. |
|
| 757 | - // - replaces `_` with ` ` (empty space). |
|
| 758 | - // - sentence case on the resulting string. |
|
| 759 | - $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 760 | - $role = add_role($orig_role, $role_label); |
|
| 761 | - } |
|
| 762 | - if ($role instanceof WP_Role) { |
|
| 763 | - // don't do anything if the capabilities map can not be initialized |
|
| 764 | - if (! $this->setupCapabilitiesMap()) { |
|
| 765 | - return false; |
|
| 766 | - } |
|
| 767 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 768 | - $role->add_cap($cap, $grant); |
|
| 769 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
| 770 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 771 | - return true; |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - return false; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 781 | - * Wrapper for $wp_role->remove_cap() |
|
| 782 | - * |
|
| 783 | - * @see wp-includes/capabilities.php |
|
| 784 | - * @since 4.5.0 |
|
| 785 | - * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 786 | - * @param string $cap The capability being removed |
|
| 787 | - * @param bool $update_capabilities_map |
|
| 788 | - * @return bool |
|
| 789 | - * @throws \EE_Error |
|
| 790 | - */ |
|
| 791 | - public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 792 | - { |
|
| 793 | - // don't do anything if the capabilities map can not be initialized |
|
| 794 | - if (! $this->setupCapabilitiesMap()) { |
|
| 795 | - return false; |
|
| 796 | - } |
|
| 797 | - $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 798 | - if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 799 | - $role->remove_cap($cap); |
|
| 800 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 801 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 802 | - return true; |
|
| 803 | - } |
|
| 804 | - return false; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * @param string $role_name |
|
| 811 | - * @param string $cap |
|
| 812 | - * @param bool $get_index |
|
| 813 | - * @return bool|mixed |
|
| 814 | - */ |
|
| 815 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 816 | - { |
|
| 817 | - if ( |
|
| 818 | - isset($this->capabilities_map[$role_name]) |
|
| 819 | - && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 820 | - ) { |
|
| 821 | - return $get_index ? $index : true; |
|
| 822 | - } |
|
| 823 | - return false; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * Wrapper for the native WP current_user_can() method. |
|
| 830 | - * This is provided as a handy method for a couple things: |
|
| 831 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 832 | - * write those filters wherever current_user_can is called). |
|
| 833 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 834 | - * |
|
| 835 | - * @since 4.5.0 |
|
| 836 | - * |
|
| 837 | - * @param string $cap The cap being checked. |
|
| 838 | - * @param string $context The context where the current_user_can is being called from. |
|
| 839 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 840 | - * filters. |
|
| 841 | - * |
|
| 842 | - * @return bool Whether user can or not. |
|
| 843 | - */ |
|
| 844 | - public function current_user_can($cap, $context, $id = 0) |
|
| 845 | - { |
|
| 846 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 847 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 848 | - $filtered_cap = apply_filters( |
|
| 849 | - 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 850 | - $filtered_cap, |
|
| 851 | - $context, |
|
| 852 | - $cap, |
|
| 853 | - $id |
|
| 854 | - ); |
|
| 855 | - return ! empty($id) |
|
| 856 | - ? current_user_can($filtered_cap, $id) |
|
| 857 | - : current_user_can($filtered_cap); |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 864 | - * |
|
| 865 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 866 | - * @param string $cap The capability string being checked |
|
| 867 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
| 868 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 869 | - * filters) |
|
| 870 | - * |
|
| 871 | - * @return bool Whether user can or not. |
|
| 872 | - */ |
|
| 873 | - public function user_can($user, $cap, $context, $id = 0) |
|
| 874 | - { |
|
| 875 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 876 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 877 | - $filtered_cap = apply_filters( |
|
| 878 | - 'FHEE__EE_Capabilities__user_can__cap', |
|
| 879 | - $filtered_cap, |
|
| 880 | - $context, |
|
| 881 | - $cap, |
|
| 882 | - $user, |
|
| 883 | - $id |
|
| 884 | - ); |
|
| 885 | - return ! empty($id) |
|
| 886 | - ? user_can($user, $filtered_cap, $id) |
|
| 887 | - : user_can($user, $filtered_cap); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 894 | - * This is provided as a handy method for a couple things: |
|
| 895 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 896 | - * write those filters wherever current_user_can is called). |
|
| 897 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 898 | - * |
|
| 899 | - * @since 4.5.0 |
|
| 900 | - * |
|
| 901 | - * @param int $blog_id The blog id that is being checked for. |
|
| 902 | - * @param string $cap The cap being checked. |
|
| 903 | - * @param string $context The context where the current_user_can is being called from. |
|
| 904 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 905 | - * filters. |
|
| 906 | - * |
|
| 907 | - * @return bool Whether user can or not. |
|
| 908 | - */ |
|
| 909 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 910 | - { |
|
| 911 | - $user_can = ! empty($id) |
|
| 912 | - ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 913 | - : current_user_can($blog_id, $cap); |
|
| 914 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 915 | - $user_can = apply_filters( |
|
| 916 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 917 | - $user_can, |
|
| 918 | - $blog_id, |
|
| 919 | - $cap, |
|
| 920 | - $id |
|
| 921 | - ); |
|
| 922 | - $user_can = apply_filters( |
|
| 923 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 924 | - $user_can, |
|
| 925 | - $context, |
|
| 926 | - $blog_id, |
|
| 927 | - $cap, |
|
| 928 | - $id |
|
| 929 | - ); |
|
| 930 | - return $user_can; |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - /** |
|
| 936 | - * This helper method just returns an array of registered EE capabilities. |
|
| 937 | - * |
|
| 938 | - * @since 4.5.0 |
|
| 939 | - * @param string $role If empty then the entire role/capability map is returned. |
|
| 940 | - * Otherwise just the capabilities for the given role are returned. |
|
| 941 | - * @return array |
|
| 942 | - * @throws EE_Error |
|
| 943 | - */ |
|
| 944 | - public function get_ee_capabilities($role = 'administrator') |
|
| 945 | - { |
|
| 946 | - if (! $this->initialized) { |
|
| 947 | - $this->init_caps(); |
|
| 948 | - } |
|
| 949 | - if (empty($role)) { |
|
| 950 | - return $this->capabilities_map; |
|
| 951 | - } |
|
| 952 | - return isset($this->capabilities_map[ $role ]) |
|
| 953 | - ? $this->capabilities_map[ $role ] |
|
| 954 | - : array(); |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * @deprecated 4.9.42 |
|
| 961 | - * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 962 | - * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 963 | - * @param array $caps_map Optional. |
|
| 964 | - * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 965 | - * Note that this should ONLY be called on activation hook or some other one-time |
|
| 966 | - * task otherwise the caps will be added on every request. |
|
| 967 | - * @return void |
|
| 968 | - * @throws EE_Error |
|
| 969 | - */ |
|
| 970 | - public function init_role_caps($reset = false, $caps_map = array()) |
|
| 971 | - { |
|
| 972 | - // If this method is called directly and reset is set as 'true', |
|
| 973 | - // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 974 | - // to guarantee that everything is set up correctly. |
|
| 975 | - // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 976 | - if ($reset) { |
|
| 977 | - EE_Error::doing_it_wrong( |
|
| 978 | - __METHOD__, |
|
| 979 | - sprintf( |
|
| 980 | - esc_html__( |
|
| 981 | - 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 982 | - 'event_espresso' |
|
| 983 | - ), |
|
| 984 | - '$reset', |
|
| 985 | - __METHOD__ . '()', |
|
| 986 | - 'EE_Capabilities::init_caps()', |
|
| 987 | - 'true' |
|
| 988 | - ), |
|
| 989 | - '4.9.42', |
|
| 990 | - '5.0.0' |
|
| 991 | - ); |
|
| 992 | - } |
|
| 993 | - $this->addCaps($caps_map); |
|
| 994 | - } |
|
| 21 | + /** |
|
| 22 | + * the name of the wp option used to store caps previously initialized |
|
| 23 | + */ |
|
| 24 | + const option_name = 'ee_caps_initialized'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * instance of EE_Capabilities object |
|
| 28 | + * |
|
| 29 | + * @var EE_Capabilities |
|
| 30 | + */ |
|
| 31 | + private static $_instance; |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * This is a map of caps that correspond to a default WP_Role. |
|
| 36 | + * Array is indexed by Role and values are ee capabilities. |
|
| 37 | + * |
|
| 38 | + * @since 4.5.0 |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $capabilities_map = array(); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * This used to hold an array of EE_Meta_Capability_Map objects |
|
| 46 | + * that define the granular capabilities mapped to for a user depending on context. |
|
| 47 | + * |
|
| 48 | + * @var EE_Meta_Capability_Map[] |
|
| 49 | + */ |
|
| 50 | + private $_meta_caps = array(); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The internal $capabilities_map needs to be initialized before it can be used. |
|
| 54 | + * This flag tracks whether that has happened or not. |
|
| 55 | + * But for this to work, we need three states to indicate: |
|
| 56 | + * initialization has not occurred at all |
|
| 57 | + * initialization has started but is not complete |
|
| 58 | + * initialization is complete |
|
| 59 | + * The reason this is needed is because the addCaps() method |
|
| 60 | + * normally requires the $capabilities_map to be initialized, |
|
| 61 | + * but is also used during the initialization process. |
|
| 62 | + * So: |
|
| 63 | + * If initialized === null, init_caps() will be called before any other methods will run. |
|
| 64 | + * If initialized === false, then init_caps() is in the process of running it's logic. |
|
| 65 | + * If initialized === true, then init_caps() has completed the initialization process. |
|
| 66 | + * |
|
| 67 | + * @var boolean|null $initialized |
|
| 68 | + */ |
|
| 69 | + private $initialized; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var boolean $reset |
|
| 73 | + */ |
|
| 74 | + private $reset = false; |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * singleton method used to instantiate class object |
|
| 80 | + * |
|
| 81 | + * @since 4.5.0 |
|
| 82 | + * |
|
| 83 | + * @return EE_Capabilities |
|
| 84 | + */ |
|
| 85 | + public static function instance() |
|
| 86 | + { |
|
| 87 | + //check if instantiated, and if not do so. |
|
| 88 | + if (! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | + self::$_instance = new self(); |
|
| 90 | + } |
|
| 91 | + return self::$_instance; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * private constructor |
|
| 98 | + * |
|
| 99 | + * @since 4.5.0 |
|
| 100 | + */ |
|
| 101 | + private function __construct() |
|
| 102 | + { |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
| 109 | + * |
|
| 110 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
| 111 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
| 112 | + * ensures that they are up to date. |
|
| 113 | + * |
|
| 114 | + * @since 4.5.0 |
|
| 115 | + * @return bool |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function init_caps($reset = false) |
|
| 119 | + { |
|
| 120 | + if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 123 | + $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
| 124 | + // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
| 125 | + if ($this->reset) { |
|
| 126 | + $this->initialized = null; |
|
| 127 | + $this->capabilities_map = array(); |
|
| 128 | + delete_option(self::option_name); |
|
| 129 | + } |
|
| 130 | + if ($this->initialized === null) { |
|
| 131 | + $this->initialized = false; |
|
| 132 | + do_action( |
|
| 133 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
| 134 | + $this->reset |
|
| 135 | + ); |
|
| 136 | + $this->addCaps($this->_init_caps_map()); |
|
| 137 | + $this->_set_meta_caps(); |
|
| 138 | + do_action( |
|
| 139 | + 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
| 140 | + $this->capabilities_map |
|
| 141 | + ); |
|
| 142 | + $this->initialized = true; |
|
| 143 | + } |
|
| 144 | + // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
| 145 | + $this->reset = false; |
|
| 146 | + return true; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * This sets the meta caps property. |
|
| 153 | + * |
|
| 154 | + * @since 4.5.0 |
|
| 155 | + * @return void |
|
| 156 | + * @throws EE_Error |
|
| 157 | + */ |
|
| 158 | + private function _set_meta_caps() |
|
| 159 | + { |
|
| 160 | + // get default meta caps and filter the returned array |
|
| 161 | + $this->_meta_caps = apply_filters( |
|
| 162 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
| 163 | + $this->_get_default_meta_caps_array() |
|
| 164 | + ); |
|
| 165 | + //add filter for map_meta_caps but only if models can query. |
|
| 166 | + if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 167 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * This builds and returns the default meta_caps array only once. |
|
| 175 | + * |
|
| 176 | + * @since 4.8.28.rc.012 |
|
| 177 | + * @return array |
|
| 178 | + * @throws EE_Error |
|
| 179 | + */ |
|
| 180 | + private function _get_default_meta_caps_array() |
|
| 181 | + { |
|
| 182 | + static $default_meta_caps = array(); |
|
| 183 | + // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
| 184 | + if (empty($default_meta_caps)) { |
|
| 185 | + $default_meta_caps = array( |
|
| 186 | + //edits |
|
| 187 | + new EE_Meta_Capability_Map_Edit( |
|
| 188 | + 'ee_edit_event', |
|
| 189 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
| 190 | + ), |
|
| 191 | + new EE_Meta_Capability_Map_Edit( |
|
| 192 | + 'ee_edit_venue', |
|
| 193 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
| 194 | + ), |
|
| 195 | + new EE_Meta_Capability_Map_Edit( |
|
| 196 | + 'ee_edit_registration', |
|
| 197 | + array('Registration', '', 'ee_edit_others_registrations', '') |
|
| 198 | + ), |
|
| 199 | + new EE_Meta_Capability_Map_Edit( |
|
| 200 | + 'ee_edit_checkin', |
|
| 201 | + array('Registration', '', 'ee_edit_others_checkins', '') |
|
| 202 | + ), |
|
| 203 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 204 | + 'ee_edit_message', |
|
| 205 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
| 206 | + ), |
|
| 207 | + new EE_Meta_Capability_Map_Edit( |
|
| 208 | + 'ee_edit_default_ticket', |
|
| 209 | + array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
| 210 | + ), |
|
| 211 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 212 | + 'ee_edit_question', |
|
| 213 | + array('Question', '', '', 'ee_edit_system_questions') |
|
| 214 | + ), |
|
| 215 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 216 | + 'ee_edit_question_group', |
|
| 217 | + array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
| 218 | + ), |
|
| 219 | + new EE_Meta_Capability_Map_Edit( |
|
| 220 | + 'ee_edit_payment_method', |
|
| 221 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
| 222 | + ), |
|
| 223 | + //reads |
|
| 224 | + new EE_Meta_Capability_Map_Read( |
|
| 225 | + 'ee_read_event', |
|
| 226 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
| 227 | + ), |
|
| 228 | + new EE_Meta_Capability_Map_Read( |
|
| 229 | + 'ee_read_venue', |
|
| 230 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
| 231 | + ), |
|
| 232 | + new EE_Meta_Capability_Map_Read( |
|
| 233 | + 'ee_read_registration', |
|
| 234 | + array('Registration', '', 'ee_read_others_registrations', '') |
|
| 235 | + ), |
|
| 236 | + new EE_Meta_Capability_Map_Read( |
|
| 237 | + 'ee_read_checkin', |
|
| 238 | + array('Registration', '', 'ee_read_others_checkins', '') |
|
| 239 | + ), |
|
| 240 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 241 | + 'ee_read_message', |
|
| 242 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
| 243 | + ), |
|
| 244 | + new EE_Meta_Capability_Map_Read( |
|
| 245 | + 'ee_read_default_ticket', |
|
| 246 | + array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
| 247 | + ), |
|
| 248 | + new EE_Meta_Capability_Map_Read( |
|
| 249 | + 'ee_read_payment_method', |
|
| 250 | + array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
| 251 | + ), |
|
| 252 | + //deletes |
|
| 253 | + new EE_Meta_Capability_Map_Delete( |
|
| 254 | + 'ee_delete_event', |
|
| 255 | + array( |
|
| 256 | + 'Event', |
|
| 257 | + 'ee_delete_published_events', |
|
| 258 | + 'ee_delete_others_events', |
|
| 259 | + 'ee_delete_private_events', |
|
| 260 | + ) |
|
| 261 | + ), |
|
| 262 | + new EE_Meta_Capability_Map_Delete( |
|
| 263 | + 'ee_delete_venue', |
|
| 264 | + array( |
|
| 265 | + 'Venue', |
|
| 266 | + 'ee_delete_published_venues', |
|
| 267 | + 'ee_delete_others_venues', |
|
| 268 | + 'ee_delete_private_venues', |
|
| 269 | + ) |
|
| 270 | + ), |
|
| 271 | + new EE_Meta_Capability_Map_Delete( |
|
| 272 | + 'ee_delete_registration', |
|
| 273 | + array('Registration', '', 'ee_delete_others_registrations', '') |
|
| 274 | + ), |
|
| 275 | + new EE_Meta_Capability_Map_Delete( |
|
| 276 | + 'ee_delete_checkin', |
|
| 277 | + array('Registration', '', 'ee_delete_others_checkins', '') |
|
| 278 | + ), |
|
| 279 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
| 280 | + 'ee_delete_message', |
|
| 281 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
| 282 | + ), |
|
| 283 | + new EE_Meta_Capability_Map_Delete( |
|
| 284 | + 'ee_delete_default_ticket', |
|
| 285 | + array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
| 286 | + ), |
|
| 287 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 288 | + 'ee_delete_question', |
|
| 289 | + array('Question', '', '', 'delete_system_questions') |
|
| 290 | + ), |
|
| 291 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
| 292 | + 'ee_delete_question_group', |
|
| 293 | + array('Question_Group', '', '', 'delete_system_question_groups') |
|
| 294 | + ), |
|
| 295 | + new EE_Meta_Capability_Map_Delete( |
|
| 296 | + 'ee_delete_payment_method', |
|
| 297 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
| 298 | + ), |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + return $default_meta_caps; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 308 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 309 | + * |
|
| 310 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
| 311 | + * |
|
| 312 | + * @since 4.5.0 |
|
| 313 | + * @see wp-includes/capabilities.php |
|
| 314 | + * |
|
| 315 | + * @param array $caps actual users capabilities |
|
| 316 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 317 | + * @param int $user_id The user id |
|
| 318 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 319 | + * @return array actual users capabilities |
|
| 320 | + * @throws EE_Error |
|
| 321 | + */ |
|
| 322 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 323 | + { |
|
| 324 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
| 325 | + //loop through our _meta_caps array |
|
| 326 | + foreach ($this->_meta_caps as $meta_map) { |
|
| 327 | + if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 328 | + continue; |
|
| 329 | + } |
|
| 330 | + // don't load models if there is no object ID in the args |
|
| 331 | + if (! empty($args[0])) { |
|
| 332 | + $meta_map->ensure_is_model(); |
|
| 333 | + } |
|
| 334 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + return $caps; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
| 344 | + * Note this array is filtered. |
|
| 345 | + * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
| 346 | + * |
|
| 347 | + * @since 4.5.0 |
|
| 348 | + * |
|
| 349 | + * @return array |
|
| 350 | + */ |
|
| 351 | + private function _init_caps_map() |
|
| 352 | + { |
|
| 353 | + return apply_filters( |
|
| 354 | + 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
| 355 | + array( |
|
| 356 | + 'administrator' => array( |
|
| 357 | + //basic access |
|
| 358 | + 'ee_read_ee', |
|
| 359 | + //gateways |
|
| 360 | + /** |
|
| 361 | + * note that with payment method capabilities, although we've implemented |
|
| 362 | + * capability mapping which will be used for accessing payment methods owned by |
|
| 363 | + * other users. This is not fully implemented yet in the payment method ui. |
|
| 364 | + * Currently only the "plural" caps are in active use. |
|
| 365 | + * (Specific payment method caps are in use as well). |
|
| 366 | + **/ |
|
| 367 | + 'ee_manage_gateways', |
|
| 368 | + 'ee_read_payment_methods', |
|
| 369 | + 'ee_read_others_payment_methods', |
|
| 370 | + 'ee_edit_payment_methods', |
|
| 371 | + 'ee_edit_others_payment_methods', |
|
| 372 | + 'ee_delete_payment_methods', |
|
| 373 | + //events |
|
| 374 | + 'ee_publish_events', |
|
| 375 | + 'ee_read_private_events', |
|
| 376 | + 'ee_read_others_events', |
|
| 377 | + 'ee_read_events', |
|
| 378 | + 'ee_edit_events', |
|
| 379 | + 'ee_edit_published_events', |
|
| 380 | + 'ee_edit_others_events', |
|
| 381 | + 'ee_edit_private_events', |
|
| 382 | + 'ee_delete_published_events', |
|
| 383 | + 'ee_delete_private_events', |
|
| 384 | + 'ee_delete_events', |
|
| 385 | + 'ee_delete_others_events', |
|
| 386 | + //event categories |
|
| 387 | + 'ee_manage_event_categories', |
|
| 388 | + 'ee_edit_event_category', |
|
| 389 | + 'ee_delete_event_category', |
|
| 390 | + 'ee_assign_event_category', |
|
| 391 | + //venues |
|
| 392 | + 'ee_publish_venues', |
|
| 393 | + 'ee_read_venues', |
|
| 394 | + 'ee_read_others_venues', |
|
| 395 | + 'ee_read_private_venues', |
|
| 396 | + 'ee_edit_venues', |
|
| 397 | + 'ee_edit_others_venues', |
|
| 398 | + 'ee_edit_published_venues', |
|
| 399 | + 'ee_edit_private_venues', |
|
| 400 | + 'ee_delete_venues', |
|
| 401 | + 'ee_delete_others_venues', |
|
| 402 | + 'ee_delete_private_venues', |
|
| 403 | + 'ee_delete_published_venues', |
|
| 404 | + //venue categories |
|
| 405 | + 'ee_manage_venue_categories', |
|
| 406 | + 'ee_edit_venue_category', |
|
| 407 | + 'ee_delete_venue_category', |
|
| 408 | + 'ee_assign_venue_category', |
|
| 409 | + //contacts |
|
| 410 | + 'ee_read_contacts', |
|
| 411 | + 'ee_edit_contacts', |
|
| 412 | + 'ee_delete_contacts', |
|
| 413 | + //registrations |
|
| 414 | + 'ee_read_registrations', |
|
| 415 | + 'ee_read_others_registrations', |
|
| 416 | + 'ee_edit_registrations', |
|
| 417 | + 'ee_edit_others_registrations', |
|
| 418 | + 'ee_delete_registrations', |
|
| 419 | + //checkins |
|
| 420 | + 'ee_read_others_checkins', |
|
| 421 | + 'ee_read_checkins', |
|
| 422 | + 'ee_edit_checkins', |
|
| 423 | + 'ee_edit_others_checkins', |
|
| 424 | + 'ee_delete_checkins', |
|
| 425 | + 'ee_delete_others_checkins', |
|
| 426 | + //transactions && payments |
|
| 427 | + 'ee_read_transaction', |
|
| 428 | + 'ee_read_transactions', |
|
| 429 | + 'ee_edit_payments', |
|
| 430 | + 'ee_delete_payments', |
|
| 431 | + //messages |
|
| 432 | + 'ee_read_messages', |
|
| 433 | + 'ee_read_others_messages', |
|
| 434 | + 'ee_read_global_messages', |
|
| 435 | + 'ee_edit_global_messages', |
|
| 436 | + 'ee_edit_messages', |
|
| 437 | + 'ee_edit_others_messages', |
|
| 438 | + 'ee_delete_messages', |
|
| 439 | + 'ee_delete_others_messages', |
|
| 440 | + 'ee_delete_global_messages', |
|
| 441 | + 'ee_send_message', |
|
| 442 | + //tickets |
|
| 443 | + 'ee_read_default_tickets', |
|
| 444 | + 'ee_read_others_default_tickets', |
|
| 445 | + 'ee_edit_default_tickets', |
|
| 446 | + 'ee_edit_others_default_tickets', |
|
| 447 | + 'ee_delete_default_tickets', |
|
| 448 | + 'ee_delete_others_default_tickets', |
|
| 449 | + //prices |
|
| 450 | + 'ee_edit_default_price', |
|
| 451 | + 'ee_edit_default_prices', |
|
| 452 | + 'ee_delete_default_price', |
|
| 453 | + 'ee_delete_default_prices', |
|
| 454 | + 'ee_edit_default_price_type', |
|
| 455 | + 'ee_edit_default_price_types', |
|
| 456 | + 'ee_delete_default_price_type', |
|
| 457 | + 'ee_delete_default_price_types', |
|
| 458 | + 'ee_read_default_prices', |
|
| 459 | + 'ee_read_default_price_types', |
|
| 460 | + //registration form |
|
| 461 | + 'ee_edit_questions', |
|
| 462 | + 'ee_edit_system_questions', |
|
| 463 | + 'ee_read_questions', |
|
| 464 | + 'ee_delete_questions', |
|
| 465 | + 'ee_edit_question_groups', |
|
| 466 | + 'ee_read_question_groups', |
|
| 467 | + 'ee_edit_system_question_groups', |
|
| 468 | + 'ee_delete_question_groups', |
|
| 469 | + //event_type taxonomy |
|
| 470 | + 'ee_assign_event_type', |
|
| 471 | + 'ee_manage_event_types', |
|
| 472 | + 'ee_edit_event_type', |
|
| 473 | + 'ee_delete_event_type', |
|
| 474 | + ), |
|
| 475 | + 'ee_events_administrator' => array( |
|
| 476 | + //core wp caps |
|
| 477 | + 'read', |
|
| 478 | + 'read_private_pages', |
|
| 479 | + 'read_private_posts', |
|
| 480 | + 'edit_users', |
|
| 481 | + 'edit_posts', |
|
| 482 | + 'edit_pages', |
|
| 483 | + 'edit_published_posts', |
|
| 484 | + 'edit_published_pages', |
|
| 485 | + 'edit_private_pages', |
|
| 486 | + 'edit_private_posts', |
|
| 487 | + 'edit_others_posts', |
|
| 488 | + 'edit_others_pages', |
|
| 489 | + 'publish_posts', |
|
| 490 | + 'publish_pages', |
|
| 491 | + 'delete_posts', |
|
| 492 | + 'delete_pages', |
|
| 493 | + 'delete_private_pages', |
|
| 494 | + 'delete_private_posts', |
|
| 495 | + 'delete_published_pages', |
|
| 496 | + 'delete_published_posts', |
|
| 497 | + 'delete_others_posts', |
|
| 498 | + 'delete_others_pages', |
|
| 499 | + 'manage_categories', |
|
| 500 | + 'manage_links', |
|
| 501 | + 'moderate_comments', |
|
| 502 | + 'unfiltered_html', |
|
| 503 | + 'upload_files', |
|
| 504 | + 'export', |
|
| 505 | + 'import', |
|
| 506 | + 'list_users', |
|
| 507 | + 'level_1', //required if user with this role shows up in author dropdowns |
|
| 508 | + //basic ee access |
|
| 509 | + 'ee_read_ee', |
|
| 510 | + //events |
|
| 511 | + 'ee_publish_events', |
|
| 512 | + 'ee_read_private_events', |
|
| 513 | + 'ee_read_others_events', |
|
| 514 | + 'ee_read_event', |
|
| 515 | + 'ee_read_events', |
|
| 516 | + 'ee_edit_event', |
|
| 517 | + 'ee_edit_events', |
|
| 518 | + 'ee_edit_published_events', |
|
| 519 | + 'ee_edit_others_events', |
|
| 520 | + 'ee_edit_private_events', |
|
| 521 | + 'ee_delete_published_events', |
|
| 522 | + 'ee_delete_private_events', |
|
| 523 | + 'ee_delete_event', |
|
| 524 | + 'ee_delete_events', |
|
| 525 | + 'ee_delete_others_events', |
|
| 526 | + //event categories |
|
| 527 | + 'ee_manage_event_categories', |
|
| 528 | + 'ee_edit_event_category', |
|
| 529 | + 'ee_delete_event_category', |
|
| 530 | + 'ee_assign_event_category', |
|
| 531 | + //venues |
|
| 532 | + 'ee_publish_venues', |
|
| 533 | + 'ee_read_venue', |
|
| 534 | + 'ee_read_venues', |
|
| 535 | + 'ee_read_others_venues', |
|
| 536 | + 'ee_read_private_venues', |
|
| 537 | + 'ee_edit_venue', |
|
| 538 | + 'ee_edit_venues', |
|
| 539 | + 'ee_edit_others_venues', |
|
| 540 | + 'ee_edit_published_venues', |
|
| 541 | + 'ee_edit_private_venues', |
|
| 542 | + 'ee_delete_venue', |
|
| 543 | + 'ee_delete_venues', |
|
| 544 | + 'ee_delete_others_venues', |
|
| 545 | + 'ee_delete_private_venues', |
|
| 546 | + 'ee_delete_published_venues', |
|
| 547 | + //venue categories |
|
| 548 | + 'ee_manage_venue_categories', |
|
| 549 | + 'ee_edit_venue_category', |
|
| 550 | + 'ee_delete_venue_category', |
|
| 551 | + 'ee_assign_venue_category', |
|
| 552 | + //contacts |
|
| 553 | + 'ee_read_contacts', |
|
| 554 | + 'ee_edit_contacts', |
|
| 555 | + 'ee_delete_contacts', |
|
| 556 | + //registrations |
|
| 557 | + 'ee_read_registrations', |
|
| 558 | + 'ee_read_others_registrations', |
|
| 559 | + 'ee_edit_registration', |
|
| 560 | + 'ee_edit_registrations', |
|
| 561 | + 'ee_edit_others_registrations', |
|
| 562 | + 'ee_delete_registration', |
|
| 563 | + 'ee_delete_registrations', |
|
| 564 | + //checkins |
|
| 565 | + 'ee_read_others_checkins', |
|
| 566 | + 'ee_read_checkins', |
|
| 567 | + 'ee_edit_checkins', |
|
| 568 | + 'ee_edit_others_checkins', |
|
| 569 | + 'ee_delete_checkins', |
|
| 570 | + 'ee_delete_others_checkins', |
|
| 571 | + //transactions && payments |
|
| 572 | + 'ee_read_transaction', |
|
| 573 | + 'ee_read_transactions', |
|
| 574 | + 'ee_edit_payments', |
|
| 575 | + 'ee_delete_payments', |
|
| 576 | + //messages |
|
| 577 | + 'ee_read_messages', |
|
| 578 | + 'ee_read_others_messages', |
|
| 579 | + 'ee_read_global_messages', |
|
| 580 | + 'ee_edit_global_messages', |
|
| 581 | + 'ee_edit_messages', |
|
| 582 | + 'ee_edit_others_messages', |
|
| 583 | + 'ee_delete_messages', |
|
| 584 | + 'ee_delete_others_messages', |
|
| 585 | + 'ee_delete_global_messages', |
|
| 586 | + 'ee_send_message', |
|
| 587 | + //tickets |
|
| 588 | + 'ee_read_default_tickets', |
|
| 589 | + 'ee_read_others_default_tickets', |
|
| 590 | + 'ee_edit_default_tickets', |
|
| 591 | + 'ee_edit_others_default_tickets', |
|
| 592 | + 'ee_delete_default_tickets', |
|
| 593 | + 'ee_delete_others_default_tickets', |
|
| 594 | + //prices |
|
| 595 | + 'ee_edit_default_price', |
|
| 596 | + 'ee_edit_default_prices', |
|
| 597 | + 'ee_delete_default_price', |
|
| 598 | + 'ee_delete_default_prices', |
|
| 599 | + 'ee_edit_default_price_type', |
|
| 600 | + 'ee_edit_default_price_types', |
|
| 601 | + 'ee_delete_default_price_type', |
|
| 602 | + 'ee_delete_default_price_types', |
|
| 603 | + 'ee_read_default_prices', |
|
| 604 | + 'ee_read_default_price_types', |
|
| 605 | + //registration form |
|
| 606 | + 'ee_edit_questions', |
|
| 607 | + 'ee_edit_system_questions', |
|
| 608 | + 'ee_read_questions', |
|
| 609 | + 'ee_delete_questions', |
|
| 610 | + 'ee_edit_question_groups', |
|
| 611 | + 'ee_read_question_groups', |
|
| 612 | + 'ee_edit_system_question_groups', |
|
| 613 | + 'ee_delete_question_groups', |
|
| 614 | + //event_type taxonomy |
|
| 615 | + 'ee_assign_event_type', |
|
| 616 | + 'ee_manage_event_types', |
|
| 617 | + 'ee_edit_event_type', |
|
| 618 | + 'ee_delete_event_type', |
|
| 619 | + ) |
|
| 620 | + ) |
|
| 621 | + ); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * @return bool |
|
| 628 | + * @throws EE_Error |
|
| 629 | + */ |
|
| 630 | + private function setupCapabilitiesMap() |
|
| 631 | + { |
|
| 632 | + // if the initialization process hasn't even started, then we need to call init_caps() |
|
| 633 | + if($this->initialized === null) { |
|
| 634 | + return $this->init_caps(); |
|
| 635 | + } |
|
| 636 | + // unless resetting, get caps from db if we haven't already |
|
| 637 | + $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
| 638 | + ? $this->capabilities_map |
|
| 639 | + : get_option(self::option_name, array()); |
|
| 640 | + return true; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * @param bool $update |
|
| 647 | + * @return bool |
|
| 648 | + */ |
|
| 649 | + private function updateCapabilitiesMap($update = true) |
|
| 650 | + { |
|
| 651 | + return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Adds capabilities to roles. |
|
| 658 | + * |
|
| 659 | + * @since 4.9.42 |
|
| 660 | + * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
| 661 | + * Note that this should ONLY be called on activation hook |
|
| 662 | + * otherwise the caps will be added on every request. |
|
| 663 | + * @return bool |
|
| 664 | + * @throws \EE_Error |
|
| 665 | + */ |
|
| 666 | + public function addCaps(array $capabilities_to_add) |
|
| 667 | + { |
|
| 668 | + // don't do anything if the capabilities map can not be initialized |
|
| 669 | + if (! $this->setupCapabilitiesMap()) { |
|
| 670 | + return false; |
|
| 671 | + } |
|
| 672 | + // and filter the array so others can get in on the fun during resets |
|
| 673 | + $capabilities_to_add = apply_filters( |
|
| 674 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
| 675 | + $capabilities_to_add, |
|
| 676 | + $this->reset, |
|
| 677 | + $this->capabilities_map |
|
| 678 | + ); |
|
| 679 | + $update_capabilities_map = false; |
|
| 680 | + // if not reset, see what caps are new for each role. if they're new, add them. |
|
| 681 | + foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
| 682 | + if (is_array($caps_for_role)) { |
|
| 683 | + foreach ($caps_for_role as $cap) { |
|
| 684 | + if ( |
|
| 685 | + ! $this->capHasBeenAddedToRole($role, $cap) |
|
| 686 | + && $this->add_cap_to_role($role, $cap, true, false) |
|
| 687 | + ) { |
|
| 688 | + $update_capabilities_map = true; |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + // now let's just save the cap that has been set but only if there's been a change. |
|
| 694 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 695 | + do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
| 696 | + return $updated; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
| 703 | + * |
|
| 704 | + * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
| 705 | + * @return bool |
|
| 706 | + * @throws \EE_Error |
|
| 707 | + */ |
|
| 708 | + public function removeCaps($caps_map) |
|
| 709 | + { |
|
| 710 | + // don't do anything if the capabilities map can not be initialized |
|
| 711 | + if (! $this->setupCapabilitiesMap()) { |
|
| 712 | + return false; |
|
| 713 | + } |
|
| 714 | + $update_capabilities_map = false; |
|
| 715 | + foreach ($caps_map as $role => $caps_for_role) { |
|
| 716 | + if (is_array($caps_for_role)) { |
|
| 717 | + foreach ($caps_for_role as $cap) { |
|
| 718 | + if ( |
|
| 719 | + $this->capHasBeenAddedToRole($role, $cap) |
|
| 720 | + && $this->remove_cap_from_role($role, $cap, false) |
|
| 721 | + ) { |
|
| 722 | + $update_capabilities_map = true; |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + // maybe resave the caps |
|
| 728 | + return $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
| 735 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
| 736 | + * this is a wrapper for $wp_role->add_cap() |
|
| 737 | + * |
|
| 738 | + * @see wp-includes/capabilities.php |
|
| 739 | + * @since 4.5.0 |
|
| 740 | + * @param string|WP_Role $role A WordPress role the capability is being added to |
|
| 741 | + * @param string $cap The capability being added to the role |
|
| 742 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
| 743 | + * @param bool $update_capabilities_map |
|
| 744 | + * @return bool |
|
| 745 | + * @throws \EE_Error |
|
| 746 | + */ |
|
| 747 | + public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
| 748 | + { |
|
| 749 | + // capture incoming value for $role because we may need it to create a new WP_Role |
|
| 750 | + $orig_role = $role; |
|
| 751 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 752 | + //if the role isn't available then we create it. |
|
| 753 | + if (! $role instanceof WP_Role) { |
|
| 754 | + // if a plugin wants to create a specific role name then they should create the role before |
|
| 755 | + // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
| 756 | + // - removes any `ee_` namespacing from the start of the slug. |
|
| 757 | + // - replaces `_` with ` ` (empty space). |
|
| 758 | + // - sentence case on the resulting string. |
|
| 759 | + $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
| 760 | + $role = add_role($orig_role, $role_label); |
|
| 761 | + } |
|
| 762 | + if ($role instanceof WP_Role) { |
|
| 763 | + // don't do anything if the capabilities map can not be initialized |
|
| 764 | + if (! $this->setupCapabilitiesMap()) { |
|
| 765 | + return false; |
|
| 766 | + } |
|
| 767 | + if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 768 | + $role->add_cap($cap, $grant); |
|
| 769 | + $this->capabilities_map[ $role->name ][] = $cap; |
|
| 770 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 771 | + return true; |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + return false; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
| 781 | + * Wrapper for $wp_role->remove_cap() |
|
| 782 | + * |
|
| 783 | + * @see wp-includes/capabilities.php |
|
| 784 | + * @since 4.5.0 |
|
| 785 | + * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
| 786 | + * @param string $cap The capability being removed |
|
| 787 | + * @param bool $update_capabilities_map |
|
| 788 | + * @return bool |
|
| 789 | + * @throws \EE_Error |
|
| 790 | + */ |
|
| 791 | + public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
| 792 | + { |
|
| 793 | + // don't do anything if the capabilities map can not be initialized |
|
| 794 | + if (! $this->setupCapabilitiesMap()) { |
|
| 795 | + return false; |
|
| 796 | + } |
|
| 797 | + $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 798 | + if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
| 799 | + $role->remove_cap($cap); |
|
| 800 | + unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 801 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
| 802 | + return true; |
|
| 803 | + } |
|
| 804 | + return false; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * @param string $role_name |
|
| 811 | + * @param string $cap |
|
| 812 | + * @param bool $get_index |
|
| 813 | + * @return bool|mixed |
|
| 814 | + */ |
|
| 815 | + private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 816 | + { |
|
| 817 | + if ( |
|
| 818 | + isset($this->capabilities_map[$role_name]) |
|
| 819 | + && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
| 820 | + ) { |
|
| 821 | + return $get_index ? $index : true; |
|
| 822 | + } |
|
| 823 | + return false; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * Wrapper for the native WP current_user_can() method. |
|
| 830 | + * This is provided as a handy method for a couple things: |
|
| 831 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 832 | + * write those filters wherever current_user_can is called). |
|
| 833 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 834 | + * |
|
| 835 | + * @since 4.5.0 |
|
| 836 | + * |
|
| 837 | + * @param string $cap The cap being checked. |
|
| 838 | + * @param string $context The context where the current_user_can is being called from. |
|
| 839 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 840 | + * filters. |
|
| 841 | + * |
|
| 842 | + * @return bool Whether user can or not. |
|
| 843 | + */ |
|
| 844 | + public function current_user_can($cap, $context, $id = 0) |
|
| 845 | + { |
|
| 846 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 847 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 848 | + $filtered_cap = apply_filters( |
|
| 849 | + 'FHEE__EE_Capabilities__current_user_can__cap', |
|
| 850 | + $filtered_cap, |
|
| 851 | + $context, |
|
| 852 | + $cap, |
|
| 853 | + $id |
|
| 854 | + ); |
|
| 855 | + return ! empty($id) |
|
| 856 | + ? current_user_can($filtered_cap, $id) |
|
| 857 | + : current_user_can($filtered_cap); |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
| 864 | + * |
|
| 865 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
| 866 | + * @param string $cap The capability string being checked |
|
| 867 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
| 868 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
| 869 | + * filters) |
|
| 870 | + * |
|
| 871 | + * @return bool Whether user can or not. |
|
| 872 | + */ |
|
| 873 | + public function user_can($user, $cap, $context, $id = 0) |
|
| 874 | + { |
|
| 875 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 876 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 877 | + $filtered_cap = apply_filters( |
|
| 878 | + 'FHEE__EE_Capabilities__user_can__cap', |
|
| 879 | + $filtered_cap, |
|
| 880 | + $context, |
|
| 881 | + $cap, |
|
| 882 | + $user, |
|
| 883 | + $id |
|
| 884 | + ); |
|
| 885 | + return ! empty($id) |
|
| 886 | + ? user_can($user, $filtered_cap, $id) |
|
| 887 | + : user_can($user, $filtered_cap); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
| 894 | + * This is provided as a handy method for a couple things: |
|
| 895 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
| 896 | + * write those filters wherever current_user_can is called). |
|
| 897 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
| 898 | + * |
|
| 899 | + * @since 4.5.0 |
|
| 900 | + * |
|
| 901 | + * @param int $blog_id The blog id that is being checked for. |
|
| 902 | + * @param string $cap The cap being checked. |
|
| 903 | + * @param string $context The context where the current_user_can is being called from. |
|
| 904 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
| 905 | + * filters. |
|
| 906 | + * |
|
| 907 | + * @return bool Whether user can or not. |
|
| 908 | + */ |
|
| 909 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
| 910 | + { |
|
| 911 | + $user_can = ! empty($id) |
|
| 912 | + ? current_user_can_for_blog($blog_id, $cap, $id) |
|
| 913 | + : current_user_can($blog_id, $cap); |
|
| 914 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
| 915 | + $user_can = apply_filters( |
|
| 916 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 917 | + $user_can, |
|
| 918 | + $blog_id, |
|
| 919 | + $cap, |
|
| 920 | + $id |
|
| 921 | + ); |
|
| 922 | + $user_can = apply_filters( |
|
| 923 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
| 924 | + $user_can, |
|
| 925 | + $context, |
|
| 926 | + $blog_id, |
|
| 927 | + $cap, |
|
| 928 | + $id |
|
| 929 | + ); |
|
| 930 | + return $user_can; |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + /** |
|
| 936 | + * This helper method just returns an array of registered EE capabilities. |
|
| 937 | + * |
|
| 938 | + * @since 4.5.0 |
|
| 939 | + * @param string $role If empty then the entire role/capability map is returned. |
|
| 940 | + * Otherwise just the capabilities for the given role are returned. |
|
| 941 | + * @return array |
|
| 942 | + * @throws EE_Error |
|
| 943 | + */ |
|
| 944 | + public function get_ee_capabilities($role = 'administrator') |
|
| 945 | + { |
|
| 946 | + if (! $this->initialized) { |
|
| 947 | + $this->init_caps(); |
|
| 948 | + } |
|
| 949 | + if (empty($role)) { |
|
| 950 | + return $this->capabilities_map; |
|
| 951 | + } |
|
| 952 | + return isset($this->capabilities_map[ $role ]) |
|
| 953 | + ? $this->capabilities_map[ $role ] |
|
| 954 | + : array(); |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * @deprecated 4.9.42 |
|
| 961 | + * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
| 962 | + * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
| 963 | + * @param array $caps_map Optional. |
|
| 964 | + * Can be used to send a custom map of roles and capabilities for setting them up. |
|
| 965 | + * Note that this should ONLY be called on activation hook or some other one-time |
|
| 966 | + * task otherwise the caps will be added on every request. |
|
| 967 | + * @return void |
|
| 968 | + * @throws EE_Error |
|
| 969 | + */ |
|
| 970 | + public function init_role_caps($reset = false, $caps_map = array()) |
|
| 971 | + { |
|
| 972 | + // If this method is called directly and reset is set as 'true', |
|
| 973 | + // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
| 974 | + // to guarantee that everything is set up correctly. |
|
| 975 | + // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
| 976 | + if ($reset) { |
|
| 977 | + EE_Error::doing_it_wrong( |
|
| 978 | + __METHOD__, |
|
| 979 | + sprintf( |
|
| 980 | + esc_html__( |
|
| 981 | + 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
| 982 | + 'event_espresso' |
|
| 983 | + ), |
|
| 984 | + '$reset', |
|
| 985 | + __METHOD__ . '()', |
|
| 986 | + 'EE_Capabilities::init_caps()', |
|
| 987 | + 'true' |
|
| 988 | + ), |
|
| 989 | + '4.9.42', |
|
| 990 | + '5.0.0' |
|
| 991 | + ); |
|
| 992 | + } |
|
| 993 | + $this->addCaps($caps_map); |
|
| 994 | + } |
|
| 995 | 995 | |
| 996 | 996 | |
| 997 | 997 | |
@@ -1012,142 +1012,142 @@ discard block |
||
| 1012 | 1012 | abstract class EE_Meta_Capability_Map |
| 1013 | 1013 | { |
| 1014 | 1014 | |
| 1015 | - public $meta_cap; |
|
| 1016 | - |
|
| 1017 | - /** |
|
| 1018 | - * @var EEM_Base |
|
| 1019 | - */ |
|
| 1020 | - protected $_model; |
|
| 1021 | - |
|
| 1022 | - protected $_model_name; |
|
| 1023 | - |
|
| 1024 | - public $published_cap = ''; |
|
| 1025 | - |
|
| 1026 | - public $others_cap = ''; |
|
| 1027 | - |
|
| 1028 | - public $private_cap = ''; |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * constructor. |
|
| 1033 | - * Receives the setup arguments for the map. |
|
| 1034 | - * |
|
| 1035 | - * @since 4.5.0 |
|
| 1036 | - * |
|
| 1037 | - * @param string $meta_cap What meta capability is this mapping. |
|
| 1038 | - * @param array $map_values array { |
|
| 1039 | - * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1040 | - * capabilities that don't get mapped to. |
|
| 1041 | - * |
|
| 1042 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1043 | - * should always be used when Menu Maps are registered via the |
|
| 1044 | - * plugin API as models are not allowed to be instantiated when |
|
| 1045 | - * in maintenance mode 2 (migrations). |
|
| 1046 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1047 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1048 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1049 | - * } |
|
| 1050 | - * @throws EE_Error |
|
| 1051 | - */ |
|
| 1052 | - public function __construct($meta_cap, $map_values) |
|
| 1053 | - { |
|
| 1054 | - $this->meta_cap = $meta_cap; |
|
| 1055 | - //verify there are four args in the $map_values array; |
|
| 1056 | - if (count($map_values) !== 4) { |
|
| 1057 | - throw new EE_Error( |
|
| 1058 | - sprintf( |
|
| 1059 | - __( |
|
| 1060 | - 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1061 | - 'event_espresso' |
|
| 1062 | - ), |
|
| 1063 | - '<br>' . print_r($map_values, true) |
|
| 1064 | - ) |
|
| 1065 | - ); |
|
| 1066 | - } |
|
| 1067 | - //set properties |
|
| 1068 | - $this->_model = null; |
|
| 1069 | - $this->_model_name = $map_values[0]; |
|
| 1070 | - $this->published_cap = (string)$map_values[1]; |
|
| 1071 | - $this->others_cap = (string)$map_values[2]; |
|
| 1072 | - $this->private_cap = (string)$map_values[3]; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * Makes it so this object stops filtering caps |
|
| 1077 | - */ |
|
| 1078 | - public function remove_filters() |
|
| 1079 | - { |
|
| 1080 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - |
|
| 1084 | - /** |
|
| 1085 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1086 | - * |
|
| 1087 | - * @since 4.5.0 |
|
| 1088 | - * @throws EE_Error |
|
| 1089 | - * |
|
| 1090 | - * @return void |
|
| 1091 | - */ |
|
| 1092 | - public function ensure_is_model() |
|
| 1093 | - { |
|
| 1094 | - //is it already instantiated? |
|
| 1095 | - if ($this->_model instanceof EEM_Base) { |
|
| 1096 | - return; |
|
| 1097 | - } |
|
| 1098 | - //ensure model name is string |
|
| 1099 | - $this->_model_name = (string)$this->_model_name; |
|
| 1100 | - //error proof if the name has EEM in it |
|
| 1101 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1102 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1103 | - if (! $this->_model instanceof EEM_Base) { |
|
| 1104 | - throw new EE_Error( |
|
| 1105 | - sprintf( |
|
| 1106 | - __( |
|
| 1107 | - 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1108 | - 'event_espresso' |
|
| 1109 | - ), |
|
| 1110 | - get_class($this), |
|
| 1111 | - $this->_model |
|
| 1112 | - ) |
|
| 1113 | - ); |
|
| 1114 | - } |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * |
|
| 1120 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1121 | - * @since 4.6.x |
|
| 1122 | - * |
|
| 1123 | - * @param $caps |
|
| 1124 | - * @param $cap |
|
| 1125 | - * @param $user_id |
|
| 1126 | - * @param $args |
|
| 1127 | - * |
|
| 1128 | - * @return array |
|
| 1129 | - */ |
|
| 1130 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1131 | - { |
|
| 1132 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - |
|
| 1136 | - /** |
|
| 1137 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1138 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1139 | - * |
|
| 1140 | - * @since 4.5.0 |
|
| 1141 | - * @see wp-includes/capabilities.php |
|
| 1142 | - * |
|
| 1143 | - * @param array $caps actual users capabilities |
|
| 1144 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1145 | - * @param int $user_id The user id |
|
| 1146 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1147 | - * |
|
| 1148 | - * @return array actual users capabilities |
|
| 1149 | - */ |
|
| 1150 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1015 | + public $meta_cap; |
|
| 1016 | + |
|
| 1017 | + /** |
|
| 1018 | + * @var EEM_Base |
|
| 1019 | + */ |
|
| 1020 | + protected $_model; |
|
| 1021 | + |
|
| 1022 | + protected $_model_name; |
|
| 1023 | + |
|
| 1024 | + public $published_cap = ''; |
|
| 1025 | + |
|
| 1026 | + public $others_cap = ''; |
|
| 1027 | + |
|
| 1028 | + public $private_cap = ''; |
|
| 1029 | + |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * constructor. |
|
| 1033 | + * Receives the setup arguments for the map. |
|
| 1034 | + * |
|
| 1035 | + * @since 4.5.0 |
|
| 1036 | + * |
|
| 1037 | + * @param string $meta_cap What meta capability is this mapping. |
|
| 1038 | + * @param array $map_values array { |
|
| 1039 | + * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
| 1040 | + * capabilities that don't get mapped to. |
|
| 1041 | + * |
|
| 1042 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
| 1043 | + * should always be used when Menu Maps are registered via the |
|
| 1044 | + * plugin API as models are not allowed to be instantiated when |
|
| 1045 | + * in maintenance mode 2 (migrations). |
|
| 1046 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
| 1047 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
| 1048 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
| 1049 | + * } |
|
| 1050 | + * @throws EE_Error |
|
| 1051 | + */ |
|
| 1052 | + public function __construct($meta_cap, $map_values) |
|
| 1053 | + { |
|
| 1054 | + $this->meta_cap = $meta_cap; |
|
| 1055 | + //verify there are four args in the $map_values array; |
|
| 1056 | + if (count($map_values) !== 4) { |
|
| 1057 | + throw new EE_Error( |
|
| 1058 | + sprintf( |
|
| 1059 | + __( |
|
| 1060 | + 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
| 1061 | + 'event_espresso' |
|
| 1062 | + ), |
|
| 1063 | + '<br>' . print_r($map_values, true) |
|
| 1064 | + ) |
|
| 1065 | + ); |
|
| 1066 | + } |
|
| 1067 | + //set properties |
|
| 1068 | + $this->_model = null; |
|
| 1069 | + $this->_model_name = $map_values[0]; |
|
| 1070 | + $this->published_cap = (string)$map_values[1]; |
|
| 1071 | + $this->others_cap = (string)$map_values[2]; |
|
| 1072 | + $this->private_cap = (string)$map_values[3]; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * Makes it so this object stops filtering caps |
|
| 1077 | + */ |
|
| 1078 | + public function remove_filters() |
|
| 1079 | + { |
|
| 1080 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + |
|
| 1084 | + /** |
|
| 1085 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
| 1086 | + * |
|
| 1087 | + * @since 4.5.0 |
|
| 1088 | + * @throws EE_Error |
|
| 1089 | + * |
|
| 1090 | + * @return void |
|
| 1091 | + */ |
|
| 1092 | + public function ensure_is_model() |
|
| 1093 | + { |
|
| 1094 | + //is it already instantiated? |
|
| 1095 | + if ($this->_model instanceof EEM_Base) { |
|
| 1096 | + return; |
|
| 1097 | + } |
|
| 1098 | + //ensure model name is string |
|
| 1099 | + $this->_model_name = (string)$this->_model_name; |
|
| 1100 | + //error proof if the name has EEM in it |
|
| 1101 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
| 1102 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
| 1103 | + if (! $this->_model instanceof EEM_Base) { |
|
| 1104 | + throw new EE_Error( |
|
| 1105 | + sprintf( |
|
| 1106 | + __( |
|
| 1107 | + 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
| 1108 | + 'event_espresso' |
|
| 1109 | + ), |
|
| 1110 | + get_class($this), |
|
| 1111 | + $this->_model |
|
| 1112 | + ) |
|
| 1113 | + ); |
|
| 1114 | + } |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * |
|
| 1120 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
| 1121 | + * @since 4.6.x |
|
| 1122 | + * |
|
| 1123 | + * @param $caps |
|
| 1124 | + * @param $cap |
|
| 1125 | + * @param $user_id |
|
| 1126 | + * @param $args |
|
| 1127 | + * |
|
| 1128 | + * @return array |
|
| 1129 | + */ |
|
| 1130 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1131 | + { |
|
| 1132 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + |
|
| 1136 | + /** |
|
| 1137 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1138 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1139 | + * |
|
| 1140 | + * @since 4.5.0 |
|
| 1141 | + * @see wp-includes/capabilities.php |
|
| 1142 | + * |
|
| 1143 | + * @param array $caps actual users capabilities |
|
| 1144 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1145 | + * @param int $user_id The user id |
|
| 1146 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1147 | + * |
|
| 1148 | + * @return array actual users capabilities |
|
| 1149 | + */ |
|
| 1150 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | |
@@ -1163,81 +1163,81 @@ discard block |
||
| 1163 | 1163 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
| 1164 | 1164 | { |
| 1165 | 1165 | |
| 1166 | - /** |
|
| 1167 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1168 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1169 | - * |
|
| 1170 | - * @since 4.5.0 |
|
| 1171 | - * @see wp-includes/capabilities.php |
|
| 1172 | - * |
|
| 1173 | - * @param array $caps actual users capabilities |
|
| 1174 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1175 | - * @param int $user_id The user id |
|
| 1176 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1177 | - * |
|
| 1178 | - * @return array actual users capabilities |
|
| 1179 | - */ |
|
| 1180 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1181 | - { |
|
| 1182 | - //only process if we're checking our mapped_cap |
|
| 1183 | - if ($cap !== $this->meta_cap) { |
|
| 1184 | - return $caps; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1188 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1189 | - unset($caps[$key]); |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - //cast $user_id to int for later explicit comparisons |
|
| 1193 | - $user_id = (int) $user_id; |
|
| 1194 | - |
|
| 1195 | - /** @var EE_Base_Class $obj */ |
|
| 1196 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1197 | - //if no obj then let's just do cap |
|
| 1198 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1199 | - $caps[] = 'do_not_allow'; |
|
| 1200 | - return $caps; |
|
| 1201 | - } |
|
| 1202 | - $caps[] = $cap . 's'; |
|
| 1203 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1204 | - //if the item author is set and the user is the author... |
|
| 1205 | - if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1206 | - //if obj is published... |
|
| 1207 | - if ($obj->status() === 'publish') { |
|
| 1208 | - $caps[] = $this->published_cap; |
|
| 1209 | - } |
|
| 1210 | - } else { |
|
| 1211 | - //the user is trying to edit someone else's obj |
|
| 1212 | - if (! empty($this->others_cap)) { |
|
| 1213 | - $caps[] = $this->others_cap; |
|
| 1214 | - } |
|
| 1215 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1216 | - $caps[] = $this->published_cap; |
|
| 1217 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1218 | - $caps[] = $this->private_cap; |
|
| 1219 | - } |
|
| 1220 | - } |
|
| 1221 | - } else { |
|
| 1222 | - //not a cpt object so handled differently |
|
| 1223 | - $has_cap = false; |
|
| 1224 | - try { |
|
| 1225 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1226 | - && $obj->wp_user() |
|
| 1227 | - && $obj->wp_user() === $user_id; |
|
| 1228 | - } catch (Exception $e) { |
|
| 1229 | - if (WP_DEBUG) { |
|
| 1230 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - if (! $has_cap) { |
|
| 1234 | - if (! empty($this->others_cap)) { |
|
| 1235 | - $caps[] = $this->others_cap; |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - return $caps; |
|
| 1240 | - } |
|
| 1166 | + /** |
|
| 1167 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1168 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1169 | + * |
|
| 1170 | + * @since 4.5.0 |
|
| 1171 | + * @see wp-includes/capabilities.php |
|
| 1172 | + * |
|
| 1173 | + * @param array $caps actual users capabilities |
|
| 1174 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1175 | + * @param int $user_id The user id |
|
| 1176 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1177 | + * |
|
| 1178 | + * @return array actual users capabilities |
|
| 1179 | + */ |
|
| 1180 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1181 | + { |
|
| 1182 | + //only process if we're checking our mapped_cap |
|
| 1183 | + if ($cap !== $this->meta_cap) { |
|
| 1184 | + return $caps; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1188 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1189 | + unset($caps[$key]); |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + //cast $user_id to int for later explicit comparisons |
|
| 1193 | + $user_id = (int) $user_id; |
|
| 1194 | + |
|
| 1195 | + /** @var EE_Base_Class $obj */ |
|
| 1196 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1197 | + //if no obj then let's just do cap |
|
| 1198 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1199 | + $caps[] = 'do_not_allow'; |
|
| 1200 | + return $caps; |
|
| 1201 | + } |
|
| 1202 | + $caps[] = $cap . 's'; |
|
| 1203 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1204 | + //if the item author is set and the user is the author... |
|
| 1205 | + if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
| 1206 | + //if obj is published... |
|
| 1207 | + if ($obj->status() === 'publish') { |
|
| 1208 | + $caps[] = $this->published_cap; |
|
| 1209 | + } |
|
| 1210 | + } else { |
|
| 1211 | + //the user is trying to edit someone else's obj |
|
| 1212 | + if (! empty($this->others_cap)) { |
|
| 1213 | + $caps[] = $this->others_cap; |
|
| 1214 | + } |
|
| 1215 | + if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1216 | + $caps[] = $this->published_cap; |
|
| 1217 | + } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1218 | + $caps[] = $this->private_cap; |
|
| 1219 | + } |
|
| 1220 | + } |
|
| 1221 | + } else { |
|
| 1222 | + //not a cpt object so handled differently |
|
| 1223 | + $has_cap = false; |
|
| 1224 | + try { |
|
| 1225 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1226 | + && $obj->wp_user() |
|
| 1227 | + && $obj->wp_user() === $user_id; |
|
| 1228 | + } catch (Exception $e) { |
|
| 1229 | + if (WP_DEBUG) { |
|
| 1230 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + if (! $has_cap) { |
|
| 1234 | + if (! empty($this->others_cap)) { |
|
| 1235 | + $caps[] = $this->others_cap; |
|
| 1236 | + } |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + return $caps; |
|
| 1240 | + } |
|
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | |
@@ -1254,24 +1254,24 @@ discard block |
||
| 1254 | 1254 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
| 1255 | 1255 | { |
| 1256 | 1256 | |
| 1257 | - /** |
|
| 1258 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1259 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1260 | - * |
|
| 1261 | - * @since 4.5.0 |
|
| 1262 | - * @see wp-includes/capabilities.php |
|
| 1263 | - * |
|
| 1264 | - * @param array $caps actual users capabilities |
|
| 1265 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1266 | - * @param int $user_id The user id |
|
| 1267 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1268 | - * |
|
| 1269 | - * @return array actual users capabilities |
|
| 1270 | - */ |
|
| 1271 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1272 | - { |
|
| 1273 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1274 | - } |
|
| 1257 | + /** |
|
| 1258 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1259 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1260 | + * |
|
| 1261 | + * @since 4.5.0 |
|
| 1262 | + * @see wp-includes/capabilities.php |
|
| 1263 | + * |
|
| 1264 | + * @param array $caps actual users capabilities |
|
| 1265 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1266 | + * @param int $user_id The user id |
|
| 1267 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1268 | + * |
|
| 1269 | + * @return array actual users capabilities |
|
| 1270 | + */ |
|
| 1271 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1272 | + { |
|
| 1273 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
| 1274 | + } |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | 1277 | |
@@ -1287,85 +1287,85 @@ discard block |
||
| 1287 | 1287 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
| 1288 | 1288 | { |
| 1289 | 1289 | |
| 1290 | - /** |
|
| 1291 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1292 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1293 | - * |
|
| 1294 | - * @since 4.5.0 |
|
| 1295 | - * @see wp-includes/capabilities.php |
|
| 1296 | - * |
|
| 1297 | - * @param array $caps actual users capabilities |
|
| 1298 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1299 | - * @param int $user_id The user id |
|
| 1300 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1301 | - * |
|
| 1302 | - * @return array actual users capabilities |
|
| 1303 | - */ |
|
| 1304 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1305 | - { |
|
| 1306 | - //only process if we're checking our mapped cap; |
|
| 1307 | - if ($cap !== $this->meta_cap) { |
|
| 1308 | - return $caps; |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1312 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1313 | - unset($caps[$key]); |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - //cast $user_id to int for later explicit comparisons |
|
| 1317 | - $user_id = (int) $user_id; |
|
| 1318 | - |
|
| 1319 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1320 | - //if no obj then let's just do cap |
|
| 1321 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1322 | - $caps[] = 'do_not_allow'; |
|
| 1323 | - return $caps; |
|
| 1324 | - } |
|
| 1325 | - |
|
| 1326 | - $caps[] = $cap . 's'; |
|
| 1327 | - if ($obj instanceof EE_CPT_Base) { |
|
| 1328 | - $status_obj = get_post_status_object($obj->status()); |
|
| 1329 | - if ($status_obj->public) { |
|
| 1330 | - return $caps; |
|
| 1331 | - } |
|
| 1332 | - //if the item author is set and the user is not the author... |
|
| 1333 | - if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1334 | - if (! empty($this->others_cap)) { |
|
| 1335 | - $caps[] = $this->others_cap; |
|
| 1336 | - } |
|
| 1337 | - } |
|
| 1338 | - //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1339 | - if ($status_obj->private |
|
| 1340 | - && ! empty($this->private_cap) |
|
| 1341 | - && $obj->wp_user() !== $user_id |
|
| 1342 | - ) { |
|
| 1343 | - //the user is trying to view a private object for an object they don't own. |
|
| 1344 | - $caps[] = $this->private_cap; |
|
| 1345 | - } |
|
| 1346 | - } else { |
|
| 1347 | - //not a cpt object so handled differently |
|
| 1348 | - $has_cap = false; |
|
| 1349 | - try { |
|
| 1350 | - $has_cap = method_exists($obj, 'wp_user') |
|
| 1351 | - && $obj->wp_user() |
|
| 1352 | - && $obj->wp_user() === $user_id; |
|
| 1353 | - } catch (Exception $e) { |
|
| 1354 | - if (WP_DEBUG) { |
|
| 1355 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1356 | - } |
|
| 1357 | - } |
|
| 1358 | - if (! $has_cap) { |
|
| 1359 | - if (! empty($this->private_cap)) { |
|
| 1360 | - $caps[] = $this->private_cap; |
|
| 1361 | - } |
|
| 1362 | - if (! empty($this->others_cap)) { |
|
| 1363 | - $caps[] = $this->others_cap; |
|
| 1364 | - } |
|
| 1365 | - } |
|
| 1366 | - } |
|
| 1367 | - return $caps; |
|
| 1368 | - } |
|
| 1290 | + /** |
|
| 1291 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1292 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1293 | + * |
|
| 1294 | + * @since 4.5.0 |
|
| 1295 | + * @see wp-includes/capabilities.php |
|
| 1296 | + * |
|
| 1297 | + * @param array $caps actual users capabilities |
|
| 1298 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1299 | + * @param int $user_id The user id |
|
| 1300 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1301 | + * |
|
| 1302 | + * @return array actual users capabilities |
|
| 1303 | + */ |
|
| 1304 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1305 | + { |
|
| 1306 | + //only process if we're checking our mapped cap; |
|
| 1307 | + if ($cap !== $this->meta_cap) { |
|
| 1308 | + return $caps; |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1312 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1313 | + unset($caps[$key]); |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + //cast $user_id to int for later explicit comparisons |
|
| 1317 | + $user_id = (int) $user_id; |
|
| 1318 | + |
|
| 1319 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1320 | + //if no obj then let's just do cap |
|
| 1321 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1322 | + $caps[] = 'do_not_allow'; |
|
| 1323 | + return $caps; |
|
| 1324 | + } |
|
| 1325 | + |
|
| 1326 | + $caps[] = $cap . 's'; |
|
| 1327 | + if ($obj instanceof EE_CPT_Base) { |
|
| 1328 | + $status_obj = get_post_status_object($obj->status()); |
|
| 1329 | + if ($status_obj->public) { |
|
| 1330 | + return $caps; |
|
| 1331 | + } |
|
| 1332 | + //if the item author is set and the user is not the author... |
|
| 1333 | + if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
| 1334 | + if (! empty($this->others_cap)) { |
|
| 1335 | + $caps[] = $this->others_cap; |
|
| 1336 | + } |
|
| 1337 | + } |
|
| 1338 | + //yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
| 1339 | + if ($status_obj->private |
|
| 1340 | + && ! empty($this->private_cap) |
|
| 1341 | + && $obj->wp_user() !== $user_id |
|
| 1342 | + ) { |
|
| 1343 | + //the user is trying to view a private object for an object they don't own. |
|
| 1344 | + $caps[] = $this->private_cap; |
|
| 1345 | + } |
|
| 1346 | + } else { |
|
| 1347 | + //not a cpt object so handled differently |
|
| 1348 | + $has_cap = false; |
|
| 1349 | + try { |
|
| 1350 | + $has_cap = method_exists($obj, 'wp_user') |
|
| 1351 | + && $obj->wp_user() |
|
| 1352 | + && $obj->wp_user() === $user_id; |
|
| 1353 | + } catch (Exception $e) { |
|
| 1354 | + if (WP_DEBUG) { |
|
| 1355 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1356 | + } |
|
| 1357 | + } |
|
| 1358 | + if (! $has_cap) { |
|
| 1359 | + if (! empty($this->private_cap)) { |
|
| 1360 | + $caps[] = $this->private_cap; |
|
| 1361 | + } |
|
| 1362 | + if (! empty($this->others_cap)) { |
|
| 1363 | + $caps[] = $this->others_cap; |
|
| 1364 | + } |
|
| 1365 | + } |
|
| 1366 | + } |
|
| 1367 | + return $caps; |
|
| 1368 | + } |
|
| 1369 | 1369 | } |
| 1370 | 1370 | |
| 1371 | 1371 | |
@@ -1382,56 +1382,56 @@ discard block |
||
| 1382 | 1382 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
| 1383 | 1383 | { |
| 1384 | 1384 | |
| 1385 | - /** |
|
| 1386 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1387 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1388 | - * |
|
| 1389 | - * @since 4.5.0 |
|
| 1390 | - * @see wp-includes/capabilities.php |
|
| 1391 | - * |
|
| 1392 | - * @param array $caps actual users capabilities |
|
| 1393 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1394 | - * @param int $user_id The user id |
|
| 1395 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1396 | - * |
|
| 1397 | - * @return array actual users capabilities |
|
| 1398 | - */ |
|
| 1399 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1400 | - { |
|
| 1401 | - //only process if we're checking our mapped_cap |
|
| 1402 | - if ($cap !== $this->meta_cap) { |
|
| 1403 | - return $caps; |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1407 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1408 | - unset($caps[$key]); |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - //cast $user_id to int for later explicit comparisons |
|
| 1412 | - $user_id = (int) $user_id; |
|
| 1413 | - |
|
| 1414 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1415 | - //if no obj then let's just do cap |
|
| 1416 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1417 | - $caps[] = 'do_not_allow'; |
|
| 1418 | - return $caps; |
|
| 1419 | - } |
|
| 1420 | - $caps[] = $cap . 's'; |
|
| 1421 | - $is_global = $obj->is_global(); |
|
| 1422 | - if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1423 | - if ($is_global) { |
|
| 1424 | - $caps[] = $this->private_cap; |
|
| 1425 | - } |
|
| 1426 | - } else { |
|
| 1427 | - if ($is_global) { |
|
| 1428 | - $caps[] = $this->private_cap; |
|
| 1429 | - } else { |
|
| 1430 | - $caps[] = $this->others_cap; |
|
| 1431 | - } |
|
| 1432 | - } |
|
| 1433 | - return $caps; |
|
| 1434 | - } |
|
| 1385 | + /** |
|
| 1386 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1387 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1388 | + * |
|
| 1389 | + * @since 4.5.0 |
|
| 1390 | + * @see wp-includes/capabilities.php |
|
| 1391 | + * |
|
| 1392 | + * @param array $caps actual users capabilities |
|
| 1393 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1394 | + * @param int $user_id The user id |
|
| 1395 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1396 | + * |
|
| 1397 | + * @return array actual users capabilities |
|
| 1398 | + */ |
|
| 1399 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1400 | + { |
|
| 1401 | + //only process if we're checking our mapped_cap |
|
| 1402 | + if ($cap !== $this->meta_cap) { |
|
| 1403 | + return $caps; |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1407 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1408 | + unset($caps[$key]); |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + //cast $user_id to int for later explicit comparisons |
|
| 1412 | + $user_id = (int) $user_id; |
|
| 1413 | + |
|
| 1414 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1415 | + //if no obj then let's just do cap |
|
| 1416 | + if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1417 | + $caps[] = 'do_not_allow'; |
|
| 1418 | + return $caps; |
|
| 1419 | + } |
|
| 1420 | + $caps[] = $cap . 's'; |
|
| 1421 | + $is_global = $obj->is_global(); |
|
| 1422 | + if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
| 1423 | + if ($is_global) { |
|
| 1424 | + $caps[] = $this->private_cap; |
|
| 1425 | + } |
|
| 1426 | + } else { |
|
| 1427 | + if ($is_global) { |
|
| 1428 | + $caps[] = $this->private_cap; |
|
| 1429 | + } else { |
|
| 1430 | + $caps[] = $this->others_cap; |
|
| 1431 | + } |
|
| 1432 | + } |
|
| 1433 | + return $caps; |
|
| 1434 | + } |
|
| 1435 | 1435 | } |
| 1436 | 1436 | |
| 1437 | 1437 | |
@@ -1448,40 +1448,40 @@ discard block |
||
| 1448 | 1448 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
| 1449 | 1449 | { |
| 1450 | 1450 | |
| 1451 | - /** |
|
| 1452 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1453 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1454 | - * |
|
| 1455 | - * @since 4.5.0 |
|
| 1456 | - * @see wp-includes/capabilities.php |
|
| 1457 | - * @param array $caps actual users capabilities |
|
| 1458 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1459 | - * @param int $user_id The user id |
|
| 1460 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1461 | - * @return array actual users capabilities |
|
| 1462 | - */ |
|
| 1463 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1464 | - { |
|
| 1465 | - //only process if we're checking our mapped_cap |
|
| 1466 | - if ($cap !== $this->meta_cap) { |
|
| 1467 | - return $caps; |
|
| 1468 | - } |
|
| 1469 | - //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1470 | - if (($key = array_search($cap, $caps)) !== false) { |
|
| 1471 | - unset($caps[$key]); |
|
| 1472 | - } |
|
| 1473 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1474 | - //if no obj then let's just do cap |
|
| 1475 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1476 | - $caps[] = 'do_not_allow'; |
|
| 1477 | - return $caps; |
|
| 1478 | - } |
|
| 1479 | - $caps[] = $cap . 's'; |
|
| 1480 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1481 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1482 | - if ($is_system) { |
|
| 1483 | - $caps[] = $this->private_cap; |
|
| 1484 | - } |
|
| 1485 | - return $caps; |
|
| 1486 | - } |
|
| 1451 | + /** |
|
| 1452 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
| 1453 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
| 1454 | + * |
|
| 1455 | + * @since 4.5.0 |
|
| 1456 | + * @see wp-includes/capabilities.php |
|
| 1457 | + * @param array $caps actual users capabilities |
|
| 1458 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
| 1459 | + * @param int $user_id The user id |
|
| 1460 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
| 1461 | + * @return array actual users capabilities |
|
| 1462 | + */ |
|
| 1463 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
| 1464 | + { |
|
| 1465 | + //only process if we're checking our mapped_cap |
|
| 1466 | + if ($cap !== $this->meta_cap) { |
|
| 1467 | + return $caps; |
|
| 1468 | + } |
|
| 1469 | + //okay it is a meta cap so let's first remove that cap from the $caps array. |
|
| 1470 | + if (($key = array_search($cap, $caps)) !== false) { |
|
| 1471 | + unset($caps[$key]); |
|
| 1472 | + } |
|
| 1473 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
| 1474 | + //if no obj then let's just do cap |
|
| 1475 | + if (! $obj instanceof EE_Base_Class) { |
|
| 1476 | + $caps[] = 'do_not_allow'; |
|
| 1477 | + return $caps; |
|
| 1478 | + } |
|
| 1479 | + $caps[] = $cap . 's'; |
|
| 1480 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
| 1481 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
| 1482 | + if ($is_system) { |
|
| 1483 | + $caps[] = $this->private_cap; |
|
| 1484 | + } |
|
| 1485 | + return $caps; |
|
| 1486 | + } |
|
| 1487 | 1487 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | public static function instance() |
| 86 | 86 | { |
| 87 | 87 | //check if instantiated, and if not do so. |
| 88 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
| 88 | + if ( ! self::$_instance instanceof EE_Capabilities) { |
|
| 89 | 89 | self::$_instance = new self(); |
| 90 | 90 | } |
| 91 | 91 | return self::$_instance; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public function init_caps($reset = false) |
| 119 | 119 | { |
| 120 | - if(! EE_Maintenance_Mode::instance()->models_can_query()){ |
|
| 120 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 121 | 121 | return false; |
| 122 | 122 | } |
| 123 | 123 | $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $this->_get_default_meta_caps_array() |
| 164 | 164 | ); |
| 165 | 165 | //add filter for map_meta_caps but only if models can query. |
| 166 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 166 | + if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
| 167 | 167 | add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -324,11 +324,11 @@ discard block |
||
| 324 | 324 | if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
| 325 | 325 | //loop through our _meta_caps array |
| 326 | 326 | foreach ($this->_meta_caps as $meta_map) { |
| 327 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 327 | + if ( ! $meta_map instanceof EE_Meta_Capability_Map) { |
|
| 328 | 328 | continue; |
| 329 | 329 | } |
| 330 | 330 | // don't load models if there is no object ID in the args |
| 331 | - if (! empty($args[0])) { |
|
| 331 | + if ( ! empty($args[0])) { |
|
| 332 | 332 | $meta_map->ensure_is_model(); |
| 333 | 333 | } |
| 334 | 334 | $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | private function setupCapabilitiesMap() |
| 631 | 631 | { |
| 632 | 632 | // if the initialization process hasn't even started, then we need to call init_caps() |
| 633 | - if($this->initialized === null) { |
|
| 633 | + if ($this->initialized === null) { |
|
| 634 | 634 | return $this->init_caps(); |
| 635 | 635 | } |
| 636 | 636 | // unless resetting, get caps from db if we haven't already |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | public function addCaps(array $capabilities_to_add) |
| 667 | 667 | { |
| 668 | 668 | // don't do anything if the capabilities map can not be initialized |
| 669 | - if (! $this->setupCapabilitiesMap()) { |
|
| 669 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 670 | 670 | return false; |
| 671 | 671 | } |
| 672 | 672 | // and filter the array so others can get in on the fun during resets |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | public function removeCaps($caps_map) |
| 709 | 709 | { |
| 710 | 710 | // don't do anything if the capabilities map can not be initialized |
| 711 | - if (! $this->setupCapabilitiesMap()) { |
|
| 711 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 712 | 712 | return false; |
| 713 | 713 | } |
| 714 | 714 | $update_capabilities_map = false; |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | $orig_role = $role; |
| 751 | 751 | $role = $role instanceof WP_Role ? $role : get_role($role); |
| 752 | 752 | //if the role isn't available then we create it. |
| 753 | - if (! $role instanceof WP_Role) { |
|
| 753 | + if ( ! $role instanceof WP_Role) { |
|
| 754 | 754 | // if a plugin wants to create a specific role name then they should create the role before |
| 755 | 755 | // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
| 756 | 756 | // - removes any `ee_` namespacing from the start of the slug. |
@@ -761,12 +761,12 @@ discard block |
||
| 761 | 761 | } |
| 762 | 762 | if ($role instanceof WP_Role) { |
| 763 | 763 | // don't do anything if the capabilities map can not be initialized |
| 764 | - if (! $this->setupCapabilitiesMap()) { |
|
| 764 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 765 | 765 | return false; |
| 766 | 766 | } |
| 767 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 767 | + if ( ! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
| 768 | 768 | $role->add_cap($cap, $grant); |
| 769 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
| 769 | + $this->capabilities_map[$role->name][] = $cap; |
|
| 770 | 770 | $this->updateCapabilitiesMap($update_capabilities_map); |
| 771 | 771 | return true; |
| 772 | 772 | } |
@@ -791,13 +791,13 @@ discard block |
||
| 791 | 791 | public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
| 792 | 792 | { |
| 793 | 793 | // don't do anything if the capabilities map can not be initialized |
| 794 | - if (! $this->setupCapabilitiesMap()) { |
|
| 794 | + if ( ! $this->setupCapabilitiesMap()) { |
|
| 795 | 795 | return false; |
| 796 | 796 | } |
| 797 | - $role = $role instanceof WP_Role ? $role :get_role($role); |
|
| 797 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
| 798 | 798 | if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
| 799 | 799 | $role->remove_cap($cap); |
| 800 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
| 800 | + unset($this->capabilities_map[$role->name][$index]); |
|
| 801 | 801 | $this->updateCapabilitiesMap($update_capabilities_map); |
| 802 | 802 | return true; |
| 803 | 803 | } |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | * @param bool $get_index |
| 813 | 813 | * @return bool|mixed |
| 814 | 814 | */ |
| 815 | - private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false) |
|
| 815 | + private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false) |
|
| 816 | 816 | { |
| 817 | 817 | if ( |
| 818 | 818 | isset($this->capabilities_map[$role_name]) |
@@ -844,7 +844,7 @@ discard block |
||
| 844 | 844 | public function current_user_can($cap, $context, $id = 0) |
| 845 | 845 | { |
| 846 | 846 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 847 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
| 847 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id); |
|
| 848 | 848 | $filtered_cap = apply_filters( |
| 849 | 849 | 'FHEE__EE_Capabilities__current_user_can__cap', |
| 850 | 850 | $filtered_cap, |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | public function user_can($user, $cap, $context, $id = 0) |
| 874 | 874 | { |
| 875 | 875 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 876 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
| 876 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id); |
|
| 877 | 877 | $filtered_cap = apply_filters( |
| 878 | 878 | 'FHEE__EE_Capabilities__user_can__cap', |
| 879 | 879 | $filtered_cap, |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | : current_user_can($blog_id, $cap); |
| 914 | 914 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
| 915 | 915 | $user_can = apply_filters( |
| 916 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
| 916 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context, |
|
| 917 | 917 | $user_can, |
| 918 | 918 | $blog_id, |
| 919 | 919 | $cap, |
@@ -943,14 +943,14 @@ discard block |
||
| 943 | 943 | */ |
| 944 | 944 | public function get_ee_capabilities($role = 'administrator') |
| 945 | 945 | { |
| 946 | - if (! $this->initialized) { |
|
| 946 | + if ( ! $this->initialized) { |
|
| 947 | 947 | $this->init_caps(); |
| 948 | 948 | } |
| 949 | 949 | if (empty($role)) { |
| 950 | 950 | return $this->capabilities_map; |
| 951 | 951 | } |
| 952 | - return isset($this->capabilities_map[ $role ]) |
|
| 953 | - ? $this->capabilities_map[ $role ] |
|
| 952 | + return isset($this->capabilities_map[$role]) |
|
| 953 | + ? $this->capabilities_map[$role] |
|
| 954 | 954 | : array(); |
| 955 | 955 | } |
| 956 | 956 | |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | 'event_espresso' |
| 983 | 983 | ), |
| 984 | 984 | '$reset', |
| 985 | - __METHOD__ . '()', |
|
| 985 | + __METHOD__.'()', |
|
| 986 | 986 | 'EE_Capabilities::init_caps()', |
| 987 | 987 | 'true' |
| 988 | 988 | ), |
@@ -1060,16 +1060,16 @@ discard block |
||
| 1060 | 1060 | 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
| 1061 | 1061 | 'event_espresso' |
| 1062 | 1062 | ), |
| 1063 | - '<br>' . print_r($map_values, true) |
|
| 1063 | + '<br>'.print_r($map_values, true) |
|
| 1064 | 1064 | ) |
| 1065 | 1065 | ); |
| 1066 | 1066 | } |
| 1067 | 1067 | //set properties |
| 1068 | 1068 | $this->_model = null; |
| 1069 | 1069 | $this->_model_name = $map_values[0]; |
| 1070 | - $this->published_cap = (string)$map_values[1]; |
|
| 1071 | - $this->others_cap = (string)$map_values[2]; |
|
| 1072 | - $this->private_cap = (string)$map_values[3]; |
|
| 1070 | + $this->published_cap = (string) $map_values[1]; |
|
| 1071 | + $this->others_cap = (string) $map_values[2]; |
|
| 1072 | + $this->private_cap = (string) $map_values[3]; |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | /** |
@@ -1096,11 +1096,11 @@ discard block |
||
| 1096 | 1096 | return; |
| 1097 | 1097 | } |
| 1098 | 1098 | //ensure model name is string |
| 1099 | - $this->_model_name = (string)$this->_model_name; |
|
| 1099 | + $this->_model_name = (string) $this->_model_name; |
|
| 1100 | 1100 | //error proof if the name has EEM in it |
| 1101 | 1101 | $this->_model_name = str_replace('EEM', '', $this->_model_name); |
| 1102 | 1102 | $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
| 1103 | - if (! $this->_model instanceof EEM_Base) { |
|
| 1103 | + if ( ! $this->_model instanceof EEM_Base) { |
|
| 1104 | 1104 | throw new EE_Error( |
| 1105 | 1105 | sprintf( |
| 1106 | 1106 | __( |
@@ -1195,11 +1195,11 @@ discard block |
||
| 1195 | 1195 | /** @var EE_Base_Class $obj */ |
| 1196 | 1196 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1197 | 1197 | //if no obj then let's just do cap |
| 1198 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1198 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1199 | 1199 | $caps[] = 'do_not_allow'; |
| 1200 | 1200 | return $caps; |
| 1201 | 1201 | } |
| 1202 | - $caps[] = $cap . 's'; |
|
| 1202 | + $caps[] = $cap.'s'; |
|
| 1203 | 1203 | if ($obj instanceof EE_CPT_Base) { |
| 1204 | 1204 | //if the item author is set and the user is the author... |
| 1205 | 1205 | if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
@@ -1209,12 +1209,12 @@ discard block |
||
| 1209 | 1209 | } |
| 1210 | 1210 | } else { |
| 1211 | 1211 | //the user is trying to edit someone else's obj |
| 1212 | - if (! empty($this->others_cap)) { |
|
| 1212 | + if ( ! empty($this->others_cap)) { |
|
| 1213 | 1213 | $caps[] = $this->others_cap; |
| 1214 | 1214 | } |
| 1215 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1215 | + if ( ! empty($this->published_cap) && $obj->status() === 'publish') { |
|
| 1216 | 1216 | $caps[] = $this->published_cap; |
| 1217 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1217 | + } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') { |
|
| 1218 | 1218 | $caps[] = $this->private_cap; |
| 1219 | 1219 | } |
| 1220 | 1220 | } |
@@ -1230,8 +1230,8 @@ discard block |
||
| 1230 | 1230 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1231 | 1231 | } |
| 1232 | 1232 | } |
| 1233 | - if (! $has_cap) { |
|
| 1234 | - if (! empty($this->others_cap)) { |
|
| 1233 | + if ( ! $has_cap) { |
|
| 1234 | + if ( ! empty($this->others_cap)) { |
|
| 1235 | 1235 | $caps[] = $this->others_cap; |
| 1236 | 1236 | } |
| 1237 | 1237 | } |
@@ -1318,12 +1318,12 @@ discard block |
||
| 1318 | 1318 | |
| 1319 | 1319 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1320 | 1320 | //if no obj then let's just do cap |
| 1321 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1321 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1322 | 1322 | $caps[] = 'do_not_allow'; |
| 1323 | 1323 | return $caps; |
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | - $caps[] = $cap . 's'; |
|
| 1326 | + $caps[] = $cap.'s'; |
|
| 1327 | 1327 | if ($obj instanceof EE_CPT_Base) { |
| 1328 | 1328 | $status_obj = get_post_status_object($obj->status()); |
| 1329 | 1329 | if ($status_obj->public) { |
@@ -1331,7 +1331,7 @@ discard block |
||
| 1331 | 1331 | } |
| 1332 | 1332 | //if the item author is set and the user is not the author... |
| 1333 | 1333 | if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
| 1334 | - if (! empty($this->others_cap)) { |
|
| 1334 | + if ( ! empty($this->others_cap)) { |
|
| 1335 | 1335 | $caps[] = $this->others_cap; |
| 1336 | 1336 | } |
| 1337 | 1337 | } |
@@ -1355,11 +1355,11 @@ discard block |
||
| 1355 | 1355 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1356 | 1356 | } |
| 1357 | 1357 | } |
| 1358 | - if (! $has_cap) { |
|
| 1359 | - if (! empty($this->private_cap)) { |
|
| 1358 | + if ( ! $has_cap) { |
|
| 1359 | + if ( ! empty($this->private_cap)) { |
|
| 1360 | 1360 | $caps[] = $this->private_cap; |
| 1361 | 1361 | } |
| 1362 | - if (! empty($this->others_cap)) { |
|
| 1362 | + if ( ! empty($this->others_cap)) { |
|
| 1363 | 1363 | $caps[] = $this->others_cap; |
| 1364 | 1364 | } |
| 1365 | 1365 | } |
@@ -1413,11 +1413,11 @@ discard block |
||
| 1413 | 1413 | |
| 1414 | 1414 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1415 | 1415 | //if no obj then let's just do cap |
| 1416 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
| 1416 | + if ( ! $obj instanceof EE_Message_Template_Group) { |
|
| 1417 | 1417 | $caps[] = 'do_not_allow'; |
| 1418 | 1418 | return $caps; |
| 1419 | 1419 | } |
| 1420 | - $caps[] = $cap . 's'; |
|
| 1420 | + $caps[] = $cap.'s'; |
|
| 1421 | 1421 | $is_global = $obj->is_global(); |
| 1422 | 1422 | if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
| 1423 | 1423 | if ($is_global) { |
@@ -1472,11 +1472,11 @@ discard block |
||
| 1472 | 1472 | } |
| 1473 | 1473 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
| 1474 | 1474 | //if no obj then let's just do cap |
| 1475 | - if (! $obj instanceof EE_Base_Class) { |
|
| 1475 | + if ( ! $obj instanceof EE_Base_Class) { |
|
| 1476 | 1476 | $caps[] = 'do_not_allow'; |
| 1477 | 1477 | return $caps; |
| 1478 | 1478 | } |
| 1479 | - $caps[] = $cap . 's'; |
|
| 1479 | + $caps[] = $cap.'s'; |
|
| 1480 | 1480 | $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
| 1481 | 1481 | $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
| 1482 | 1482 | if ($is_system) { |
@@ -11,104 +11,104 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Extend_EE_Registrations_List_Table extends EE_Registrations_List_Table |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * REG_date |
|
| 16 | - */ |
|
| 17 | - function column__REG_date(EE_Registration $item) |
|
| 18 | - { |
|
| 19 | - $date_linked = parent::column__REG_date($item); |
|
| 20 | - $actions = array(); |
|
| 21 | - //Build row actions |
|
| 22 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 23 | - 'action' => 'event_registrations', |
|
| 24 | - 'event_id' => $item->event_ID(), |
|
| 25 | - ), REG_ADMIN_URL); |
|
| 26 | - $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 27 | - 'ee_read_registration', |
|
| 28 | - 'espresso_registrations_registration_checkins', |
|
| 29 | - $item->ID() |
|
| 30 | - ) |
|
| 31 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 32 | - 'ee_read_checkins', |
|
| 33 | - 'espresso_registrations_registration_checkins' |
|
| 34 | - ) |
|
| 35 | - ? '<a href="' . $check_in_url . '"' |
|
| 36 | - . ' title="' . esc_attr__( |
|
| 37 | - 'The Check-In List allows you to easily toggle check-in status for this event', |
|
| 38 | - 'event_espresso' |
|
| 39 | - ) |
|
| 40 | - . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
| 41 | - : esc_html__('View Check-ins', 'event_espresso'); |
|
| 14 | + /** |
|
| 15 | + * REG_date |
|
| 16 | + */ |
|
| 17 | + function column__REG_date(EE_Registration $item) |
|
| 18 | + { |
|
| 19 | + $date_linked = parent::column__REG_date($item); |
|
| 20 | + $actions = array(); |
|
| 21 | + //Build row actions |
|
| 22 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 23 | + 'action' => 'event_registrations', |
|
| 24 | + 'event_id' => $item->event_ID(), |
|
| 25 | + ), REG_ADMIN_URL); |
|
| 26 | + $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 27 | + 'ee_read_registration', |
|
| 28 | + 'espresso_registrations_registration_checkins', |
|
| 29 | + $item->ID() |
|
| 30 | + ) |
|
| 31 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 32 | + 'ee_read_checkins', |
|
| 33 | + 'espresso_registrations_registration_checkins' |
|
| 34 | + ) |
|
| 35 | + ? '<a href="' . $check_in_url . '"' |
|
| 36 | + . ' title="' . esc_attr__( |
|
| 37 | + 'The Check-In List allows you to easily toggle check-in status for this event', |
|
| 38 | + 'event_espresso' |
|
| 39 | + ) |
|
| 40 | + . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
| 41 | + : esc_html__('View Check-ins', 'event_espresso'); |
|
| 42 | 42 | |
| 43 | - return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
| 44 | - } |
|
| 43 | + return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * column_default |
|
| 49 | - * |
|
| 50 | - * @param \EE_Registration $item |
|
| 51 | - * @return string |
|
| 52 | - * @throws EE_Error |
|
| 53 | - */ |
|
| 54 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
| 55 | - { |
|
| 56 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 57 | - $ticket = $item->ticket(); |
|
| 58 | - $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
| 59 | - $EVT_ID = $item->event_ID(); |
|
| 60 | - $datetime_string = ''; |
|
| 61 | - foreach ($datetimes as $datetime) { |
|
| 62 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 63 | - 'ee_read_checkin', |
|
| 64 | - 'espresso_registrations_registration_checkins', |
|
| 65 | - $item->ID() |
|
| 66 | - )) { |
|
| 67 | - // open "a" tag and "href" |
|
| 68 | - $datetime_string .= '<a href="'; |
|
| 69 | - // checkin URL |
|
| 70 | - $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 71 | - array( |
|
| 72 | - 'action' => 'event_registrations', |
|
| 73 | - 'event_id' => $EVT_ID, |
|
| 74 | - 'DTT_ID' => $datetime->ID(), |
|
| 75 | - ), |
|
| 76 | - REG_ADMIN_URL |
|
| 77 | - ); |
|
| 78 | - // close "href" |
|
| 79 | - $datetime_string .= '"'; |
|
| 80 | - // open "title" tag |
|
| 81 | - $datetime_string .= ' title="'; |
|
| 82 | - // link title text |
|
| 83 | - $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
| 84 | - // close "title" tag and end of "a" tag opening |
|
| 85 | - $datetime_string .= '">'; |
|
| 86 | - // link text |
|
| 87 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 88 | - // close "a" tag |
|
| 89 | - $datetime_string .= '</a>'; |
|
| 90 | - } else { |
|
| 91 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 92 | - } |
|
| 93 | - // add a "View Registrations" link that filters list by event AND datetime |
|
| 94 | - $datetime_string .= $this->row_actions( |
|
| 95 | - array( |
|
| 96 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 97 | - array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
| 98 | - REG_ADMIN_URL |
|
| 99 | - ) |
|
| 100 | - . '" title="' . sprintf( |
|
| 101 | - esc_attr__( |
|
| 102 | - 'Filter this list to only show registrations for this datetime %s', |
|
| 103 | - 'event_espresso' |
|
| 104 | - ), |
|
| 105 | - $datetime->name() |
|
| 106 | - ) . '">' |
|
| 107 | - . esc_html__('View Registrations', 'event_espresso') |
|
| 108 | - . '</a>', |
|
| 109 | - ) |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - return $datetime_string; |
|
| 113 | - } |
|
| 47 | + /** |
|
| 48 | + * column_default |
|
| 49 | + * |
|
| 50 | + * @param \EE_Registration $item |
|
| 51 | + * @return string |
|
| 52 | + * @throws EE_Error |
|
| 53 | + */ |
|
| 54 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
| 55 | + { |
|
| 56 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
| 57 | + $ticket = $item->ticket(); |
|
| 58 | + $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
| 59 | + $EVT_ID = $item->event_ID(); |
|
| 60 | + $datetime_string = ''; |
|
| 61 | + foreach ($datetimes as $datetime) { |
|
| 62 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 63 | + 'ee_read_checkin', |
|
| 64 | + 'espresso_registrations_registration_checkins', |
|
| 65 | + $item->ID() |
|
| 66 | + )) { |
|
| 67 | + // open "a" tag and "href" |
|
| 68 | + $datetime_string .= '<a href="'; |
|
| 69 | + // checkin URL |
|
| 70 | + $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 71 | + array( |
|
| 72 | + 'action' => 'event_registrations', |
|
| 73 | + 'event_id' => $EVT_ID, |
|
| 74 | + 'DTT_ID' => $datetime->ID(), |
|
| 75 | + ), |
|
| 76 | + REG_ADMIN_URL |
|
| 77 | + ); |
|
| 78 | + // close "href" |
|
| 79 | + $datetime_string .= '"'; |
|
| 80 | + // open "title" tag |
|
| 81 | + $datetime_string .= ' title="'; |
|
| 82 | + // link title text |
|
| 83 | + $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
| 84 | + // close "title" tag and end of "a" tag opening |
|
| 85 | + $datetime_string .= '">'; |
|
| 86 | + // link text |
|
| 87 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 88 | + // close "a" tag |
|
| 89 | + $datetime_string .= '</a>'; |
|
| 90 | + } else { |
|
| 91 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
| 92 | + } |
|
| 93 | + // add a "View Registrations" link that filters list by event AND datetime |
|
| 94 | + $datetime_string .= $this->row_actions( |
|
| 95 | + array( |
|
| 96 | + 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 97 | + array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
| 98 | + REG_ADMIN_URL |
|
| 99 | + ) |
|
| 100 | + . '" title="' . sprintf( |
|
| 101 | + esc_attr__( |
|
| 102 | + 'Filter this list to only show registrations for this datetime %s', |
|
| 103 | + 'event_espresso' |
|
| 104 | + ), |
|
| 105 | + $datetime->name() |
|
| 106 | + ) . '">' |
|
| 107 | + . esc_html__('View Registrations', 'event_espresso') |
|
| 108 | + . '</a>', |
|
| 109 | + ) |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + return $datetime_string; |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $date_linked = parent::column__REG_date($item); |
| 20 | 20 | $actions = array(); |
| 21 | 21 | //Build row actions |
| 22 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 22 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 23 | 23 | 'action' => 'event_registrations', |
| 24 | 24 | 'event_id' => $item->event_ID(), |
| 25 | 25 | ), REG_ADMIN_URL); |
@@ -32,12 +32,12 @@ discard block |
||
| 32 | 32 | 'ee_read_checkins', |
| 33 | 33 | 'espresso_registrations_registration_checkins' |
| 34 | 34 | ) |
| 35 | - ? '<a href="' . $check_in_url . '"' |
|
| 36 | - . ' title="' . esc_attr__( |
|
| 35 | + ? '<a href="'.$check_in_url.'"' |
|
| 36 | + . ' title="'.esc_attr__( |
|
| 37 | 37 | 'The Check-In List allows you to easily toggle check-in status for this event', |
| 38 | 38 | 'event_espresso' |
| 39 | 39 | ) |
| 40 | - . '">' . esc_html__('View Check-ins', 'event_espresso') . '</a>' |
|
| 40 | + . '">'.esc_html__('View Check-ins', 'event_espresso').'</a>' |
|
| 41 | 41 | : esc_html__('View Check-ins', 'event_espresso'); |
| 42 | 42 | |
| 43 | 43 | return sprintf('%1$s %2$s', $date_linked, $this->row_actions($actions)); |
@@ -93,17 +93,17 @@ discard block |
||
| 93 | 93 | // add a "View Registrations" link that filters list by event AND datetime |
| 94 | 94 | $datetime_string .= $this->row_actions( |
| 95 | 95 | array( |
| 96 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 96 | + 'event_datetime_filter' => '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
| 97 | 97 | array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
| 98 | 98 | REG_ADMIN_URL |
| 99 | 99 | ) |
| 100 | - . '" title="' . sprintf( |
|
| 100 | + . '" title="'.sprintf( |
|
| 101 | 101 | esc_attr__( |
| 102 | 102 | 'Filter this list to only show registrations for this datetime %s', |
| 103 | 103 | 'event_espresso' |
| 104 | 104 | ), |
| 105 | 105 | $datetime->name() |
| 106 | - ) . '">' |
|
| 106 | + ).'">' |
|
| 107 | 107 | . esc_html__('View Registrations', 'event_espresso') |
| 108 | 108 | . '</a>', |
| 109 | 109 | ) |