Completed
Branch BUG/192/php-72-specific-warnin... (26bd26)
by
unknown
26:27 queued 17:42
created
libraries/form_sections/inputs/EE_Select_Ajax_Model_Rest_Input.input.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -17,189 +17,189 @@
 block discarded – undo
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' => '100'
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' => '100'
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
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
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.68.rc.012');
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.68.rc.012');
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
 }
Please login to merge, or discard this patch.