@@ -12,121 +12,121 @@ |
||
12 | 12 | class EE_Register_Model_Extensions implements EEI_Plugin_API |
13 | 13 | { |
14 | 14 | |
15 | - protected static $_registry; |
|
16 | - protected static $_extensions = array(); |
|
15 | + protected static $_registry; |
|
16 | + protected static $_extensions = array(); |
|
17 | 17 | |
18 | - /** |
|
19 | - * register method for setting up model extensions |
|
20 | - * |
|
21 | - * @param string $model_id unique id for the extensions being setup |
|
22 | - * @param array $config { |
|
23 | - * @throws EE_Error |
|
24 | - * @type array $model_extension_paths array of folders containing DB model extensions, where each file follows |
|
25 | - * the models naming convention, which is: EEME_{your_plugin_slug}_model_name_extended}.model_ext.php. Where |
|
26 | - * your_plugin_slug} is really anything you want (but something having to do with your addon, like |
|
27 | - * 'Calendar' or '3D_View') and model_name_extended} is the model extended. The class contained in teh file |
|
28 | - * should extend EEME_Base_{model_name_extended}.model_ext.php. Where {your_plugin_slug} is really anything |
|
29 | - * you want (but something having to do with your addon, like 'Calendar' or '3D_View') and |
|
30 | - * {model_name_extended} is the model extended. The class contained in teh file should extend EEME_Base |
|
31 | - * @type array $class_extension_paths array of folders containing DB class extensions, where each file follows |
|
32 | - * the model class extension naming convention, which is: |
|
33 | - * EEE_{your_plugin_slug}_model_name_extended}.class_ext.php. Where your_plugin_slug} is something like |
|
34 | - * 'Calendar','MailChimp',etc, and model_name_extended} is the name of the model extended, eg |
|
35 | - * 'Attendee','Event',etc. The class contained in the file should extend |
|
36 | - * EEE_Base_Class._{model_name_extended}.class_ext.php. Where {your_plugin_slug} is something like |
|
37 | - * 'Calendar','MailChimp',etc, and {model_name_extended} is the name of the model extended, eg |
|
38 | - * 'Attendee','Event',etc. The class contained in the file should extend EEE_Base_Class. |
|
39 | - * } |
|
40 | - * |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public static function register($model_id = null, $config = array()) |
|
44 | - { |
|
45 | - // required fields MUST be present, so let's make sure they are. |
|
46 | - if (empty($model_id) |
|
47 | - || ! is_array($config) |
|
48 | - || (empty($config['model_extension_paths']) && empty($config['class_extension_paths'])) |
|
49 | - ) { |
|
50 | - throw new EE_Error( |
|
51 | - __( |
|
52 | - 'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)', |
|
53 | - 'event_espresso' |
|
54 | - ) |
|
55 | - ); |
|
56 | - } |
|
18 | + /** |
|
19 | + * register method for setting up model extensions |
|
20 | + * |
|
21 | + * @param string $model_id unique id for the extensions being setup |
|
22 | + * @param array $config { |
|
23 | + * @throws EE_Error |
|
24 | + * @type array $model_extension_paths array of folders containing DB model extensions, where each file follows |
|
25 | + * the models naming convention, which is: EEME_{your_plugin_slug}_model_name_extended}.model_ext.php. Where |
|
26 | + * your_plugin_slug} is really anything you want (but something having to do with your addon, like |
|
27 | + * 'Calendar' or '3D_View') and model_name_extended} is the model extended. The class contained in teh file |
|
28 | + * should extend EEME_Base_{model_name_extended}.model_ext.php. Where {your_plugin_slug} is really anything |
|
29 | + * you want (but something having to do with your addon, like 'Calendar' or '3D_View') and |
|
30 | + * {model_name_extended} is the model extended. The class contained in teh file should extend EEME_Base |
|
31 | + * @type array $class_extension_paths array of folders containing DB class extensions, where each file follows |
|
32 | + * the model class extension naming convention, which is: |
|
33 | + * EEE_{your_plugin_slug}_model_name_extended}.class_ext.php. Where your_plugin_slug} is something like |
|
34 | + * 'Calendar','MailChimp',etc, and model_name_extended} is the name of the model extended, eg |
|
35 | + * 'Attendee','Event',etc. The class contained in the file should extend |
|
36 | + * EEE_Base_Class._{model_name_extended}.class_ext.php. Where {your_plugin_slug} is something like |
|
37 | + * 'Calendar','MailChimp',etc, and {model_name_extended} is the name of the model extended, eg |
|
38 | + * 'Attendee','Event',etc. The class contained in the file should extend EEE_Base_Class. |
|
39 | + * } |
|
40 | + * |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public static function register($model_id = null, $config = array()) |
|
44 | + { |
|
45 | + // required fields MUST be present, so let's make sure they are. |
|
46 | + if (empty($model_id) |
|
47 | + || ! is_array($config) |
|
48 | + || (empty($config['model_extension_paths']) && empty($config['class_extension_paths'])) |
|
49 | + ) { |
|
50 | + throw new EE_Error( |
|
51 | + __( |
|
52 | + 'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)', |
|
53 | + 'event_espresso' |
|
54 | + ) |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | |
58 | - // make sure we don't register twice |
|
59 | - if (isset(self::$_registry[ $model_id ])) { |
|
60 | - return; |
|
61 | - } |
|
62 | - // check correct loading |
|
63 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
64 | - EE_Error::doing_it_wrong( |
|
65 | - __METHOD__, |
|
66 | - sprintf( |
|
67 | - __( |
|
68 | - 'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s', |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - $model_id, |
|
72 | - '<br />', |
|
73 | - did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done', |
|
74 | - did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done' |
|
75 | - ), |
|
76 | - '4.3' |
|
77 | - ); |
|
78 | - } |
|
58 | + // make sure we don't register twice |
|
59 | + if (isset(self::$_registry[ $model_id ])) { |
|
60 | + return; |
|
61 | + } |
|
62 | + // check correct loading |
|
63 | + if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
64 | + EE_Error::doing_it_wrong( |
|
65 | + __METHOD__, |
|
66 | + sprintf( |
|
67 | + __( |
|
68 | + 'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s', |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + $model_id, |
|
72 | + '<br />', |
|
73 | + did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done', |
|
74 | + did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done' |
|
75 | + ), |
|
76 | + '4.3' |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | - self::$_registry[ $model_id ] = $config; |
|
81 | - self::$_extensions[ $model_id ] = array(); |
|
80 | + self::$_registry[ $model_id ] = $config; |
|
81 | + self::$_extensions[ $model_id ] = array(); |
|
82 | 82 | |
83 | - if (isset($config['model_extension_paths'])) { |
|
84 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
85 | - $class_to_filepath_map = EEH_File::get_contents_of_folders($config['model_extension_paths']); |
|
86 | - // remove all files that are not PHP |
|
87 | - foreach ($class_to_filepath_map as $class => $path) { |
|
88 | - if (substr($path, strlen($path) - 3) !== 'php') { |
|
89 | - unset($class_to_filepath_map[ $class ]); |
|
90 | - continue; |
|
91 | - } |
|
92 | - } |
|
93 | - EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
94 | - foreach (array_keys($class_to_filepath_map) as $classname) { |
|
95 | - self::$_extensions[ $model_id ]['models'][ $classname ] = new $classname; |
|
96 | - } |
|
97 | - unset($config['model_extension_paths']); |
|
98 | - } |
|
99 | - if (isset($config['class_extension_paths'])) { |
|
100 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
101 | - $class_to_filepath_map = EEH_File::get_contents_of_folders($config['class_extension_paths']); |
|
102 | - EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
103 | - foreach (array_keys($class_to_filepath_map) as $classname) { |
|
104 | - self::$_extensions[ $model_id ]['classes'][ $classname ] = new $classname; |
|
105 | - } |
|
106 | - unset($config['class_extension_paths']); |
|
107 | - } |
|
108 | - foreach ($config as $unknown_key => $unknown_config) { |
|
109 | - throw new EE_Error( |
|
110 | - sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key) |
|
111 | - ); |
|
112 | - } |
|
113 | - } |
|
83 | + if (isset($config['model_extension_paths'])) { |
|
84 | + require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
85 | + $class_to_filepath_map = EEH_File::get_contents_of_folders($config['model_extension_paths']); |
|
86 | + // remove all files that are not PHP |
|
87 | + foreach ($class_to_filepath_map as $class => $path) { |
|
88 | + if (substr($path, strlen($path) - 3) !== 'php') { |
|
89 | + unset($class_to_filepath_map[ $class ]); |
|
90 | + continue; |
|
91 | + } |
|
92 | + } |
|
93 | + EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
94 | + foreach (array_keys($class_to_filepath_map) as $classname) { |
|
95 | + self::$_extensions[ $model_id ]['models'][ $classname ] = new $classname; |
|
96 | + } |
|
97 | + unset($config['model_extension_paths']); |
|
98 | + } |
|
99 | + if (isset($config['class_extension_paths'])) { |
|
100 | + require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
101 | + $class_to_filepath_map = EEH_File::get_contents_of_folders($config['class_extension_paths']); |
|
102 | + EEH_Autoloader::register_autoloader($class_to_filepath_map); |
|
103 | + foreach (array_keys($class_to_filepath_map) as $classname) { |
|
104 | + self::$_extensions[ $model_id ]['classes'][ $classname ] = new $classname; |
|
105 | + } |
|
106 | + unset($config['class_extension_paths']); |
|
107 | + } |
|
108 | + foreach ($config as $unknown_key => $unknown_config) { |
|
109 | + throw new EE_Error( |
|
110 | + sprintf(__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key) |
|
111 | + ); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * deregister |
|
118 | - * |
|
119 | - * @param string $model_id |
|
120 | - */ |
|
121 | - public static function deregister($model_id = null) |
|
122 | - { |
|
123 | - if (isset(self::$_registry[ $model_id ])) { |
|
124 | - unset(self::$_registry[ $model_id ]); |
|
125 | - foreach (self::$_extensions[ $model_id ] as $extension_of_type) { |
|
126 | - foreach ($extension_of_type as $extension) { |
|
127 | - $extension->deregister(); |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
116 | + /** |
|
117 | + * deregister |
|
118 | + * |
|
119 | + * @param string $model_id |
|
120 | + */ |
|
121 | + public static function deregister($model_id = null) |
|
122 | + { |
|
123 | + if (isset(self::$_registry[ $model_id ])) { |
|
124 | + unset(self::$_registry[ $model_id ]); |
|
125 | + foreach (self::$_extensions[ $model_id ] as $extension_of_type) { |
|
126 | + foreach ($extension_of_type as $extension) { |
|
127 | + $extension->deregister(); |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | 132 | } |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | // make sure we don't register twice |
59 | - if (isset(self::$_registry[ $model_id ])) { |
|
59 | + if (isset(self::$_registry[$model_id])) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | // check correct loading |
63 | - if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
63 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) { |
|
64 | 64 | EE_Error::doing_it_wrong( |
65 | 65 | __METHOD__, |
66 | 66 | sprintf( |
@@ -77,31 +77,31 @@ discard block |
||
77 | 77 | ); |
78 | 78 | } |
79 | 79 | |
80 | - self::$_registry[ $model_id ] = $config; |
|
81 | - self::$_extensions[ $model_id ] = array(); |
|
80 | + self::$_registry[$model_id] = $config; |
|
81 | + self::$_extensions[$model_id] = array(); |
|
82 | 82 | |
83 | 83 | if (isset($config['model_extension_paths'])) { |
84 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php'); |
|
84 | + require_once(EE_LIBRARIES.'plugin_api/db/EEME_Base.lib.php'); |
|
85 | 85 | $class_to_filepath_map = EEH_File::get_contents_of_folders($config['model_extension_paths']); |
86 | 86 | // remove all files that are not PHP |
87 | 87 | foreach ($class_to_filepath_map as $class => $path) { |
88 | 88 | if (substr($path, strlen($path) - 3) !== 'php') { |
89 | - unset($class_to_filepath_map[ $class ]); |
|
89 | + unset($class_to_filepath_map[$class]); |
|
90 | 90 | continue; |
91 | 91 | } |
92 | 92 | } |
93 | 93 | EEH_Autoloader::register_autoloader($class_to_filepath_map); |
94 | 94 | foreach (array_keys($class_to_filepath_map) as $classname) { |
95 | - self::$_extensions[ $model_id ]['models'][ $classname ] = new $classname; |
|
95 | + self::$_extensions[$model_id]['models'][$classname] = new $classname; |
|
96 | 96 | } |
97 | 97 | unset($config['model_extension_paths']); |
98 | 98 | } |
99 | 99 | if (isset($config['class_extension_paths'])) { |
100 | - require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php'); |
|
100 | + require_once(EE_LIBRARIES.'plugin_api/db/EEE_Base_Class.lib.php'); |
|
101 | 101 | $class_to_filepath_map = EEH_File::get_contents_of_folders($config['class_extension_paths']); |
102 | 102 | EEH_Autoloader::register_autoloader($class_to_filepath_map); |
103 | 103 | foreach (array_keys($class_to_filepath_map) as $classname) { |
104 | - self::$_extensions[ $model_id ]['classes'][ $classname ] = new $classname; |
|
104 | + self::$_extensions[$model_id]['classes'][$classname] = new $classname; |
|
105 | 105 | } |
106 | 106 | unset($config['class_extension_paths']); |
107 | 107 | } |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public static function deregister($model_id = null) |
122 | 122 | { |
123 | - if (isset(self::$_registry[ $model_id ])) { |
|
124 | - unset(self::$_registry[ $model_id ]); |
|
125 | - foreach (self::$_extensions[ $model_id ] as $extension_of_type) { |
|
123 | + if (isset(self::$_registry[$model_id])) { |
|
124 | + unset(self::$_registry[$model_id]); |
|
125 | + foreach (self::$_extensions[$model_id] as $extension_of_type) { |
|
126 | 126 | foreach ($extension_of_type as $extension) { |
127 | 127 | $extension->deregister(); |
128 | 128 | } |
@@ -17,189 +17,189 @@ |
||
17 | 17 | class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $_model_name |
|
22 | - */ |
|
23 | - protected $_model_name; |
|
20 | + /** |
|
21 | + * @var string $_model_name |
|
22 | + */ |
|
23 | + protected $_model_name; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var string $_display_field_name |
|
27 | - */ |
|
28 | - protected $_display_field_name; |
|
25 | + /** |
|
26 | + * @var string $_display_field_name |
|
27 | + */ |
|
28 | + protected $_display_field_name; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var string $_value_field_name |
|
32 | - */ |
|
33 | - protected $_value_field_name; |
|
30 | + /** |
|
31 | + * @var string $_value_field_name |
|
32 | + */ |
|
33 | + protected $_value_field_name; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var array $_extra_select_columns |
|
37 | - */ |
|
38 | - protected $_extra_select_columns = array(); |
|
35 | + /** |
|
36 | + * @var array $_extra_select_columns |
|
37 | + */ |
|
38 | + protected $_extra_select_columns = array(); |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param array $input_settings { |
|
43 | - * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
44 | - * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
45 | - * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
46 | - * the string "where") |
|
47 | - * @type string $value_field_name the name of the model field on this model to |
|
48 | - * be used for the HTML select's option's values |
|
49 | - * @type string $display_field_name the name of the model field on this model |
|
50 | - * to be used for the HTML select's option's display text |
|
51 | - * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
52 | - * } |
|
53 | - * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
54 | - * } |
|
55 | - * @throws EE_Error |
|
56 | - * @throws InvalidArgumentException |
|
57 | - * @throws InvalidDataTypeException |
|
58 | - * @throws InvalidInterfaceException |
|
59 | - */ |
|
60 | - public function __construct($input_settings = array()) |
|
61 | - { |
|
62 | - // needed input settings: |
|
63 | - // select2_args |
|
64 | - $this->_model_name = EEH_Array::is_set( |
|
65 | - $input_settings, |
|
66 | - 'model_name', |
|
67 | - null |
|
68 | - ); |
|
69 | - $model = $this->_get_model(); |
|
70 | - $query_params = EEH_Array::is_set( |
|
71 | - $input_settings, |
|
72 | - 'query_params', |
|
73 | - array() |
|
74 | - ); |
|
75 | - // make sure limit and caps are always set |
|
76 | - $query_params = array_merge( |
|
77 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
78 | - $query_params |
|
79 | - ); |
|
80 | - $this->_value_field_name = EEH_Array::is_set( |
|
81 | - $input_settings, |
|
82 | - 'value_field_name', |
|
83 | - $model->primary_key_name() |
|
84 | - ); |
|
85 | - $this->_display_field_name = EEH_Array::is_set( |
|
86 | - $input_settings, |
|
87 | - 'display_field_name', |
|
88 | - $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
89 | - ); |
|
90 | - $this->_extra_select_columns = EEH_Array::is_set( |
|
91 | - $input_settings, |
|
92 | - 'extra_select_columns', |
|
93 | - array() |
|
94 | - ); |
|
95 | - $this->_add_validation_strategy( |
|
96 | - new EE_Model_Matching_Query_Validation_Strategy( |
|
97 | - '', |
|
98 | - $this->_model_name, |
|
99 | - $query_params, |
|
100 | - $this->_value_field_name |
|
101 | - ) |
|
102 | - ); |
|
103 | - // get resource endpoint |
|
104 | - $rest_controller = LoaderFactory::getLoader()->getNew( |
|
105 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
106 | - ); |
|
107 | - $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
108 | - $default_select2_args = array( |
|
109 | - 'ajax' => array( |
|
110 | - 'url' => $rest_controller->getVersionedLinkTo( |
|
111 | - EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
112 | - ), |
|
113 | - 'dataType' => 'json', |
|
114 | - 'delay' => '250', |
|
115 | - 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
116 | - 'data_interface_args' => array( |
|
117 | - 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
118 | - $query_params, |
|
119 | - $model |
|
120 | - ), |
|
121 | - 'display_field' => $this->_display_field_name, |
|
122 | - 'value_field' => $this->_value_field_name, |
|
123 | - 'nonce' => wp_create_nonce('wp_rest'), |
|
124 | - 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
125 | - ), |
|
126 | - ), |
|
127 | - 'cache' => true, |
|
128 | - 'width' => 'resolve' |
|
129 | - ); |
|
130 | - $select2_args = array_replace_recursive( |
|
131 | - $default_select2_args, |
|
132 | - (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
133 | - ); |
|
134 | - $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
135 | - parent::__construct(array(), $input_settings); |
|
136 | - } |
|
41 | + /** |
|
42 | + * @param array $input_settings { |
|
43 | + * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
44 | + * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
45 | + * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
46 | + * the string "where") |
|
47 | + * @type string $value_field_name the name of the model field on this model to |
|
48 | + * be used for the HTML select's option's values |
|
49 | + * @type string $display_field_name the name of the model field on this model |
|
50 | + * to be used for the HTML select's option's display text |
|
51 | + * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
52 | + * } |
|
53 | + * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
54 | + * } |
|
55 | + * @throws EE_Error |
|
56 | + * @throws InvalidArgumentException |
|
57 | + * @throws InvalidDataTypeException |
|
58 | + * @throws InvalidInterfaceException |
|
59 | + */ |
|
60 | + public function __construct($input_settings = array()) |
|
61 | + { |
|
62 | + // needed input settings: |
|
63 | + // select2_args |
|
64 | + $this->_model_name = EEH_Array::is_set( |
|
65 | + $input_settings, |
|
66 | + 'model_name', |
|
67 | + null |
|
68 | + ); |
|
69 | + $model = $this->_get_model(); |
|
70 | + $query_params = EEH_Array::is_set( |
|
71 | + $input_settings, |
|
72 | + 'query_params', |
|
73 | + array() |
|
74 | + ); |
|
75 | + // make sure limit and caps are always set |
|
76 | + $query_params = array_merge( |
|
77 | + array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
78 | + $query_params |
|
79 | + ); |
|
80 | + $this->_value_field_name = EEH_Array::is_set( |
|
81 | + $input_settings, |
|
82 | + 'value_field_name', |
|
83 | + $model->primary_key_name() |
|
84 | + ); |
|
85 | + $this->_display_field_name = EEH_Array::is_set( |
|
86 | + $input_settings, |
|
87 | + 'display_field_name', |
|
88 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
89 | + ); |
|
90 | + $this->_extra_select_columns = EEH_Array::is_set( |
|
91 | + $input_settings, |
|
92 | + 'extra_select_columns', |
|
93 | + array() |
|
94 | + ); |
|
95 | + $this->_add_validation_strategy( |
|
96 | + new EE_Model_Matching_Query_Validation_Strategy( |
|
97 | + '', |
|
98 | + $this->_model_name, |
|
99 | + $query_params, |
|
100 | + $this->_value_field_name |
|
101 | + ) |
|
102 | + ); |
|
103 | + // get resource endpoint |
|
104 | + $rest_controller = LoaderFactory::getLoader()->getNew( |
|
105 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
106 | + ); |
|
107 | + $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
108 | + $default_select2_args = array( |
|
109 | + 'ajax' => array( |
|
110 | + 'url' => $rest_controller->getVersionedLinkTo( |
|
111 | + EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
112 | + ), |
|
113 | + 'dataType' => 'json', |
|
114 | + 'delay' => '250', |
|
115 | + 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
116 | + 'data_interface_args' => array( |
|
117 | + 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
118 | + $query_params, |
|
119 | + $model |
|
120 | + ), |
|
121 | + 'display_field' => $this->_display_field_name, |
|
122 | + 'value_field' => $this->_value_field_name, |
|
123 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
124 | + 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
125 | + ), |
|
126 | + ), |
|
127 | + 'cache' => true, |
|
128 | + 'width' => 'resolve' |
|
129 | + ); |
|
130 | + $select2_args = array_replace_recursive( |
|
131 | + $default_select2_args, |
|
132 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
133 | + ); |
|
134 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
135 | + parent::__construct(array(), $input_settings); |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | 139 | |
140 | - /** |
|
141 | - * Before setting the raw value (usually because we're setting the default, |
|
142 | - * or we've received a form submission and this might be re-displayed to the user), |
|
143 | - * sets the options so that the current selections appear on initial display. |
|
144 | - * |
|
145 | - * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
146 | - * for validation, this input's options only affect DISPLAY and NOT validation, |
|
147 | - * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
148 | - * |
|
149 | - * @param mixed $value |
|
150 | - * @return void |
|
151 | - * @throws \EE_Error |
|
152 | - */ |
|
153 | - public function _set_raw_value($value) |
|
154 | - { |
|
155 | - $values_for_options = (array) $value; |
|
156 | - $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
157 | - $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
158 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
160 | - $display_values = $this->_get_model()->get_all_wpdb_results( |
|
161 | - array( |
|
162 | - array( |
|
163 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
164 | - ) |
|
165 | - ), |
|
166 | - ARRAY_A, |
|
167 | - implode(',', $this->_extra_select_columns) |
|
168 | - ); |
|
169 | - $select_options = array(); |
|
170 | - if (is_array($select_options)) { |
|
171 | - foreach ($display_values as $db_rows) { |
|
172 | - $db_rows = (array) $db_rows; |
|
173 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
174 | - 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
175 | - $db_rows[ $this->_display_field_name ], |
|
176 | - $db_rows |
|
177 | - ); |
|
178 | - } |
|
179 | - } |
|
180 | - $this->set_select_options($select_options); |
|
181 | - parent::_set_raw_value($value); |
|
182 | - } |
|
140 | + /** |
|
141 | + * Before setting the raw value (usually because we're setting the default, |
|
142 | + * or we've received a form submission and this might be re-displayed to the user), |
|
143 | + * sets the options so that the current selections appear on initial display. |
|
144 | + * |
|
145 | + * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
146 | + * for validation, this input's options only affect DISPLAY and NOT validation, |
|
147 | + * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
148 | + * |
|
149 | + * @param mixed $value |
|
150 | + * @return void |
|
151 | + * @throws \EE_Error |
|
152 | + */ |
|
153 | + public function _set_raw_value($value) |
|
154 | + { |
|
155 | + $values_for_options = (array) $value; |
|
156 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
157 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
158 | + $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | + $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
160 | + $display_values = $this->_get_model()->get_all_wpdb_results( |
|
161 | + array( |
|
162 | + array( |
|
163 | + $this->_value_field_name => array( 'IN', $values_for_options ) |
|
164 | + ) |
|
165 | + ), |
|
166 | + ARRAY_A, |
|
167 | + implode(',', $this->_extra_select_columns) |
|
168 | + ); |
|
169 | + $select_options = array(); |
|
170 | + if (is_array($select_options)) { |
|
171 | + foreach ($display_values as $db_rows) { |
|
172 | + $db_rows = (array) $db_rows; |
|
173 | + $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
174 | + 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
175 | + $db_rows[ $this->_display_field_name ], |
|
176 | + $db_rows |
|
177 | + ); |
|
178 | + } |
|
179 | + } |
|
180 | + $this->set_select_options($select_options); |
|
181 | + parent::_set_raw_value($value); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
186 | - * @return EEM_Base |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - protected function _get_model() |
|
190 | - { |
|
191 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | - throw new EE_Error( |
|
193 | - sprintf( |
|
194 | - __( |
|
195 | - '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
196 | - 'event_espresso' |
|
197 | - ), |
|
198 | - $this->_model_name |
|
199 | - ) |
|
200 | - ); |
|
201 | - } else { |
|
202 | - return EE_Registry::instance()->load_model($this->_model_name); |
|
203 | - } |
|
204 | - } |
|
184 | + /** |
|
185 | + * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
186 | + * @return EEM_Base |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + protected function _get_model() |
|
190 | + { |
|
191 | + if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | + throw new EE_Error( |
|
193 | + sprintf( |
|
194 | + __( |
|
195 | + '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
196 | + 'event_espresso' |
|
197 | + ), |
|
198 | + $this->_model_name |
|
199 | + ) |
|
200 | + ); |
|
201 | + } else { |
|
202 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
203 | + } |
|
204 | + } |
|
205 | 205 | } |
@@ -14,78 +14,78 @@ |
||
14 | 14 | class EE_Select_Display_Strategy extends EE_Display_Strategy_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * |
|
19 | - * @throws EE_Error |
|
20 | - * @return string of html to display the field |
|
21 | - */ |
|
22 | - public function display() |
|
23 | - { |
|
24 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
25 | - throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
|
26 | - } |
|
17 | + /** |
|
18 | + * |
|
19 | + * @throws EE_Error |
|
20 | + * @return string of html to display the field |
|
21 | + */ |
|
22 | + public function display() |
|
23 | + { |
|
24 | + if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
25 | + throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
|
26 | + } |
|
27 | 27 | |
28 | - $html = EEH_HTML::nl(0, 'select'); |
|
29 | - $html .= '<select'; |
|
30 | - $html .= $this->_attributes_string( |
|
31 | - $this->_standard_attributes_array() |
|
32 | - ); |
|
33 | - $html .= '>'; |
|
28 | + $html = EEH_HTML::nl(0, 'select'); |
|
29 | + $html .= '<select'; |
|
30 | + $html .= $this->_attributes_string( |
|
31 | + $this->_standard_attributes_array() |
|
32 | + ); |
|
33 | + $html .= '>'; |
|
34 | 34 | |
35 | - if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
36 | - EEH_HTML::indent(1, 'optgroup'); |
|
37 | - foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
38 | - if (! empty($opt_group_label)) { |
|
39 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
40 | - } |
|
41 | - EEH_HTML::indent(1, 'option'); |
|
42 | - $html .= $this->_display_options($opt_group); |
|
43 | - EEH_HTML::indent(-1, 'option'); |
|
44 | - if (! empty($opt_group_label)) { |
|
45 | - $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; |
|
46 | - } |
|
47 | - } |
|
48 | - EEH_HTML::indent(-1, 'optgroup'); |
|
49 | - } else { |
|
50 | - $html.=$this->_display_options($this->_input->options()); |
|
51 | - } |
|
35 | + if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
36 | + EEH_HTML::indent(1, 'optgroup'); |
|
37 | + foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
38 | + if (! empty($opt_group_label)) { |
|
39 | + $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
40 | + } |
|
41 | + EEH_HTML::indent(1, 'option'); |
|
42 | + $html .= $this->_display_options($opt_group); |
|
43 | + EEH_HTML::indent(-1, 'option'); |
|
44 | + if (! empty($opt_group_label)) { |
|
45 | + $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; |
|
46 | + } |
|
47 | + } |
|
48 | + EEH_HTML::indent(-1, 'optgroup'); |
|
49 | + } else { |
|
50 | + $html.=$this->_display_options($this->_input->options()); |
|
51 | + } |
|
52 | 52 | |
53 | - $html.= EEH_HTML::nl(0, 'select') . '</select>'; |
|
54 | - return $html; |
|
55 | - } |
|
53 | + $html.= EEH_HTML::nl(0, 'select') . '</select>'; |
|
54 | + return $html; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Displays a flat list of options as option tags |
|
61 | - * @param array $options |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - protected function _display_options($options) |
|
65 | - { |
|
66 | - $html = ''; |
|
67 | - EEH_HTML::indent(1, 'option'); |
|
68 | - foreach ($options as $value => $display_text) { |
|
69 | - // even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
70 | - // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
71 | - $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
72 | - $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : ''; |
|
73 | - $html.= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>'; |
|
74 | - } |
|
75 | - EEH_HTML::indent(-1, 'option'); |
|
76 | - return $html; |
|
77 | - } |
|
59 | + /** |
|
60 | + * Displays a flat list of options as option tags |
|
61 | + * @param array $options |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + protected function _display_options($options) |
|
65 | + { |
|
66 | + $html = ''; |
|
67 | + EEH_HTML::indent(1, 'option'); |
|
68 | + foreach ($options as $value => $display_text) { |
|
69 | + // even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
70 | + // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
71 | + $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
72 | + $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : ''; |
|
73 | + $html.= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>'; |
|
74 | + } |
|
75 | + EEH_HTML::indent(-1, 'option'); |
|
76 | + return $html; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * Checks if that value is the one selected |
|
83 | - * |
|
84 | - * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - protected function _check_if_option_selected($option_value) |
|
88 | - { |
|
89 | - return $option_value === $this->_input->raw_value(); |
|
90 | - } |
|
81 | + /** |
|
82 | + * Checks if that value is the one selected |
|
83 | + * |
|
84 | + * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + protected function _check_if_option_selected($option_value) |
|
88 | + { |
|
89 | + return $option_value === $this->_input->raw_value(); |
|
90 | + } |
|
91 | 91 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function display() |
23 | 23 | { |
24 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
24 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
25 | 25 | throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
26 | 26 | } |
27 | 27 | |
@@ -35,22 +35,22 @@ discard block |
||
35 | 35 | if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
36 | 36 | EEH_HTML::indent(1, 'optgroup'); |
37 | 37 | foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
38 | - if (! empty($opt_group_label)) { |
|
39 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
38 | + if ( ! empty($opt_group_label)) { |
|
39 | + $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">'; |
|
40 | 40 | } |
41 | 41 | EEH_HTML::indent(1, 'option'); |
42 | 42 | $html .= $this->_display_options($opt_group); |
43 | 43 | EEH_HTML::indent(-1, 'option'); |
44 | - if (! empty($opt_group_label)) { |
|
45 | - $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; |
|
44 | + if ( ! empty($opt_group_label)) { |
|
45 | + $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>'; |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | EEH_HTML::indent(-1, 'optgroup'); |
49 | 49 | } else { |
50 | - $html.=$this->_display_options($this->_input->options()); |
|
50 | + $html .= $this->_display_options($this->_input->options()); |
|
51 | 51 | } |
52 | 52 | |
53 | - $html.= EEH_HTML::nl(0, 'select') . '</select>'; |
|
53 | + $html .= EEH_HTML::nl(0, 'select').'</select>'; |
|
54 | 54 | return $html; |
55 | 55 | } |
56 | 56 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
71 | 71 | $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
72 | 72 | $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : ''; |
73 | - $html.= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>'; |
|
73 | + $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>'; |
|
74 | 74 | } |
75 | 75 | EEH_HTML::indent(-1, 'option'); |
76 | 76 | return $html; |
@@ -15,80 +15,80 @@ |
||
15 | 15 | class EE_Select2_Display_Strategy extends EE_Select_Display_Strategy |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Arguments that will be passed into the select2 javascript constructor |
|
20 | - * @var array |
|
21 | - */ |
|
22 | - protected $_select2_js_args = array(); |
|
18 | + /** |
|
19 | + * Arguments that will be passed into the select2 javascript constructor |
|
20 | + * @var array |
|
21 | + */ |
|
22 | + protected $_select2_js_args = array(); |
|
23 | 23 | |
24 | - /** |
|
25 | - * |
|
26 | - * @param array $select2_js_args pass in the EXACT array of JS arguments you want |
|
27 | - * to pass into the select2 js/html input. See https://select2.github.io |
|
28 | - */ |
|
29 | - public function __construct($select2_js_args = array()) |
|
30 | - { |
|
31 | - $this->_select2_js_args = $select2_js_args; |
|
32 | - parent::__construct(); |
|
33 | - } |
|
24 | + /** |
|
25 | + * |
|
26 | + * @param array $select2_js_args pass in the EXACT array of JS arguments you want |
|
27 | + * to pass into the select2 js/html input. See https://select2.github.io |
|
28 | + */ |
|
29 | + public function __construct($select2_js_args = array()) |
|
30 | + { |
|
31 | + $this->_select2_js_args = $select2_js_args; |
|
32 | + parent::__construct(); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * enqueues the select2 initializing js (which depends on the select2 js) and |
|
37 | - * the select2 css |
|
38 | - */ |
|
39 | - public function enqueue_js() |
|
40 | - { |
|
41 | - // need to first deregister the select2 script in case some other plugin **cough cough Toolset Types cough** |
|
42 | - // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
|
43 | - wp_deregister_script('select2'); |
|
44 | - wp_deregister_style('select2'); |
|
45 | - wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true); |
|
46 | - wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
47 | - wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true); |
|
48 | - wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
49 | - } |
|
35 | + /** |
|
36 | + * enqueues the select2 initializing js (which depends on the select2 js) and |
|
37 | + * the select2 css |
|
38 | + */ |
|
39 | + public function enqueue_js() |
|
40 | + { |
|
41 | + // need to first deregister the select2 script in case some other plugin **cough cough Toolset Types cough** |
|
42 | + // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
|
43 | + wp_deregister_script('select2'); |
|
44 | + wp_deregister_style('select2'); |
|
45 | + wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true); |
|
46 | + wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
47 | + wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true); |
|
48 | + wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Gets the javascript args which will be localized and passed into the select2 js/html input |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function get_js_args() |
|
56 | - { |
|
57 | - return $this->_select2_js_args; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Gets the javascript args which will be localized and passed into the select2 js/html input |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function get_js_args() |
|
56 | + { |
|
57 | + return $this->_select2_js_args; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Sets the exact js args which will be passed into the select2 js/html input |
|
62 | - * @param array $js_args |
|
63 | - */ |
|
64 | - public function set_js_args($js_args) |
|
65 | - { |
|
66 | - $this->_select2_js_args = $js_args; |
|
67 | - } |
|
60 | + /** |
|
61 | + * Sets the exact js args which will be passed into the select2 js/html input |
|
62 | + * @param array $js_args |
|
63 | + */ |
|
64 | + public function set_js_args($js_args) |
|
65 | + { |
|
66 | + $this->_select2_js_args = $js_args; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Adds select2 data for localization |
|
71 | - * @param array $other_js_data |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - public function get_other_js_data($other_js_data = array()) |
|
75 | - { |
|
76 | - $other_js_data = parent::get_other_js_data($other_js_data); |
|
77 | - if (! isset($other_js_data['select2s'])) { |
|
78 | - $other_js_data['select2s'] = array(); |
|
79 | - } |
|
80 | - $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args(); |
|
81 | - return $other_js_data; |
|
82 | - } |
|
69 | + /** |
|
70 | + * Adds select2 data for localization |
|
71 | + * @param array $other_js_data |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + public function get_other_js_data($other_js_data = array()) |
|
75 | + { |
|
76 | + $other_js_data = parent::get_other_js_data($other_js_data); |
|
77 | + if (! isset($other_js_data['select2s'])) { |
|
78 | + $other_js_data['select2s'] = array(); |
|
79 | + } |
|
80 | + $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args(); |
|
81 | + return $other_js_data; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Overrides standard attributes array to add the CSS class "ee-select2" |
|
86 | - * @return array |
|
87 | - */ |
|
88 | - protected function _standard_attributes_array() |
|
89 | - { |
|
90 | - $standard_attributes = parent::_standard_attributes_array(); |
|
91 | - $standard_attributes['class'] .= ' ee-select2'; |
|
92 | - return $standard_attributes; |
|
93 | - } |
|
84 | + /** |
|
85 | + * Overrides standard attributes array to add the CSS class "ee-select2" |
|
86 | + * @return array |
|
87 | + */ |
|
88 | + protected function _standard_attributes_array() |
|
89 | + { |
|
90 | + $standard_attributes = parent::_standard_attributes_array(); |
|
91 | + $standard_attributes['class'] .= ' ee-select2'; |
|
92 | + return $standard_attributes; |
|
93 | + } |
|
94 | 94 | } |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
43 | 43 | wp_deregister_script('select2'); |
44 | 44 | wp_deregister_style('select2'); |
45 | - wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true); |
|
46 | - wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
47 | - wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true); |
|
48 | - wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all'); |
|
45 | + wp_register_script('select2', EE_GLOBAL_ASSETS_URL.'scripts/select2.min.js', array(), '4.0.2', true); |
|
46 | + wp_register_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
47 | + wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL.'scripts/form_section_select2_init.js', array('select2'), '1.0.0', true); |
|
48 | + wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | public function get_other_js_data($other_js_data = array()) |
75 | 75 | { |
76 | 76 | $other_js_data = parent::get_other_js_data($other_js_data); |
77 | - if (! isset($other_js_data['select2s'])) { |
|
77 | + if ( ! isset($other_js_data['select2s'])) { |
|
78 | 78 | $other_js_data['select2s'] = array(); |
79 | 79 | } |
80 | - $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args(); |
|
80 | + $other_js_data['select2s'][$this->_input->html_id()] = $this->get_js_args(); |
|
81 | 81 | return $other_js_data; |
82 | 82 | } |
83 | 83 |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.024'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.80.rc.024'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |