Completed
Pull Request — develop (#1272)
by
unknown
03:03
created
src/wordlift/mappings/pages/class-edit-mappings-page.php 2 patches
Indentation   +351 added lines, -351 removed lines patch added patch discarded remove patch
@@ -24,188 +24,188 @@  discard block
 block discarded – undo
24 24
  */
25 25
 class Edit_Mappings_Page extends Wordlift_Admin_Page {
26 26
 
27
-	/** Instance to store the registry class.
28
-	 * @var Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance}
29
-	 */
30
-	public $transform_function_registry;
31
-
32
-	/**
33
-	 * Edit_Mappings_Page constructor.
34
-	 *
35
-	 * @param $transform_function_registry Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance }
36
-	 */
37
-	public function __construct( $transform_function_registry ) {
38
-		parent::__construct();
39
-		$this->transform_function_registry = $transform_function_registry;
40
-	}
41
-
42
-	public function render() {
43
-		// Render all the settings when this method is called, because the partial page is loaded after
44
-		// this method.
45
-		// Load the UI dependencies.
46
-		$edit_mapping_settings = $this->get_ui_settings_array();
47
-		// Supply the settings to js client.
48
-		wp_localize_script( 'wl-mappings-edit', 'wl_edit_mappings_config', $edit_mapping_settings );
49
-
50
-		parent::render();
51
-	}
52
-
53
-	/**
54
-	 * Load the text settings needed for the edit_mappings_page.
55
-	 * @param array $edit_mapping_settings Key value pair of settings used by edit mappings page.
56
-	 *
57
-	 * @return array Adding text settings to the main settings array.
58
-	 */
59
-	private function load_text_settings_for_edit_mapping_page( array $edit_mapping_settings ) {
60
-		$edit_mapping_settings['wl_add_mapping_text']     = __( 'Add Mapping', 'wordlift' );
61
-		$edit_mapping_settings['wl_edit_mapping_text']    = __( 'Edit Mapping', 'wordlift' );
62
-		$edit_mapping_settings['wl_edit_mapping_no_item'] = __( 'Unable to find the mapping item', 'wordlift' );
63
-		$edit_mapping_settings['page']                    = 'wl_edit_mapping';
64
-		return $edit_mapping_settings;
65
-	}
66
-
67
-	/**
68
-	 * The base class {@link Wordlift_Admin_Page} will add the admin page to the WordLift menu.
69
-	 *
70
-	 * We don't want this page to be in the menu though. Therefore we override the `parent_slug` so that WordPress won't
71
-	 * show it there.
72
-	 *
73
-	 * @return null return null to avoid this page to be displayed in WordLift's menu.
74
-	 */
75
-	protected function get_parent_slug() {
76
-		return null;
77
-	}
78
-
79
-	/**
80
-	 * {@inheritdoc}
81
-	 */
82
-	public function get_page_title() {
83
-
84
-		return __( 'Edit Mappings', 'wordlift' );
85
-	}
86
-
87
-	/**
88
-	 * {@inheritdoc}
89
-	 */
90
-	public function get_menu_title() {
91
-
92
-		return __( 'Edit Mappings', 'wordlift' );
93
-	}
94
-
95
-	/**
96
-	 * {@inheritdoc}
97
-	 */
98
-	public function get_menu_slug() {
99
-
100
-		return 'wl_edit_mapping';
101
-	}
102
-
103
-	/**
104
-	 * {@inheritdoc}
105
-	 */
106
-	public function get_partial_name() {
107
-		return 'wordlift-admin-mappings-edit.php';
108
-	}
109
-
110
-	/**
111
-	 * {@inheritdoc}
112
-	 */
113
-	public function enqueue_scripts() {
114
-
115
-		// Enqueue the script.
116
-		Scripts_Helper::enqueue_based_on_wordpress_version(
117
-			'wl-mappings-edit',
118
-			plugin_dir_url( dirname( dirname( dirname( __FILE__ ) ) ) ) . 'js/dist/mappings-edit',
119
-			array( 'react', 'react-dom', 'wp-polyfill' ),
120
-			true
121
-		);
122
-
123
-		// Enqueue the style.
124
-		wp_enqueue_style(
125
-			'wl-mappings-edit',
126
-			plugin_dir_url( dirname( dirname( dirname( __FILE__ ) ) ) ) . 'js/dist/mappings-edit.css',
127
-			Wordlift::get_instance()->get_version()
128
-		);
129
-	}
130
-
131
-	/**
132
-	 * Returns field name options based on the chosen field type.
133
-	 * if string is returned a text field would be shown to user, if an array of options is returned
134
-	 * then the select box would be shown to user.
135
-	 *
136
-	 * @return array Array of the options.
137
-	 */
138
-	public static function get_all_field_name_options() {
139
-
140
-		$options = array(
141
-			array(
142
-				'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_TEXT_FIELD,
143
-				'value'      => '',
144
-				'label'      => __( 'Fixed Text', 'wordlift' ),
145
-			),
146
-			// @@todo maybe it makes sense to move this one as well to Wordlift/Mappings/Custom_Fields_Mappings.
147
-			array(
148
-				'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD,
149
-				'value'      => '',
150
-				'label'      => __( 'Custom Field', 'wordlift' ),
151
-			),
152
-		);
153
-
154
-		/**
155
-		 * Allow 3rd parties to add field types.
156
-		 *
157
-		 * @param array An array of Field Types.
158
-		 *
159
-		 * @return array An array of Field Types.
160
-		 *
161
-		 * @since 3.25.0
162
-		 */
163
-		return apply_filters( 'wl_mappings_field_types', $options );
164
-	}
165
-
166
-	/**
167
-	 * @since 3.25.0
168
-	 * Load dependencies required for js client.
169
-	 * @return array An Array containing key value pairs of settings.
170
-	 */
171
-	public function get_ui_settings_array() {
172
-		// Create ui settings array to be used by js client.
173
-		$edit_mapping_settings                               = array();
174
-		$edit_mapping_settings                               = $this->load_rest_settings( $edit_mapping_settings );
175
-		$edit_mapping_settings = $this->load_text_settings_for_edit_mapping_page( $edit_mapping_settings );
176
-		$edit_mapping_settings['wl_transform_function_options'] = $this->transform_function_registry->get_options();
177
-		$edit_mapping_settings = $this->load_field_type_and_name_options( $edit_mapping_settings );
178
-		// Load logic field options.
179
-		$edit_mapping_settings = $this->load_logic_field_options( $edit_mapping_settings );
180
-		$edit_mapping_settings = $this->load_rule_field_options( $edit_mapping_settings );
181
-
182
-		return $edit_mapping_settings;
183
-	}
184
-
185
-	/**
186
-	 * Returns post type, post category, or any other post taxonomies
187
-	 * @return array An array of select options
188
-	 */
189
-	private static function get_post_taxonomies_and_terms() {
190
-		$taxonomy_options = array();
191
-		$term_options     = array();
192
-		$taxonomies       = get_object_taxonomies( 'post', 'objects' );
193
-
194
-		foreach ( $taxonomies as $taxonomy ) {
195
-			array_push(
196
-				$taxonomy_options,
197
-				array(
198
-					'label'      => $taxonomy->label,
199
-					'value'      => $taxonomy->name,
200
-					'api_source' => 'taxonomy'
201
-				)
202
-			);
203
-		}
204
-		// Post type is also included in the list of taxonomies, so get the post type and merge with options.
205
-		$post_type_array =  self::get_post_type_key_and_value();
206
-		$post_type_option = $post_type_array['post_type_option_name'];
207
-		// Get also the list of post types from the post_type_array.
208
-		$post_type_option_values = $post_type_array['post_type_option_values'];
27
+    /** Instance to store the registry class.
28
+     * @var Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance}
29
+     */
30
+    public $transform_function_registry;
31
+
32
+    /**
33
+     * Edit_Mappings_Page constructor.
34
+     *
35
+     * @param $transform_function_registry Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance }
36
+     */
37
+    public function __construct( $transform_function_registry ) {
38
+        parent::__construct();
39
+        $this->transform_function_registry = $transform_function_registry;
40
+    }
41
+
42
+    public function render() {
43
+        // Render all the settings when this method is called, because the partial page is loaded after
44
+        // this method.
45
+        // Load the UI dependencies.
46
+        $edit_mapping_settings = $this->get_ui_settings_array();
47
+        // Supply the settings to js client.
48
+        wp_localize_script( 'wl-mappings-edit', 'wl_edit_mappings_config', $edit_mapping_settings );
49
+
50
+        parent::render();
51
+    }
52
+
53
+    /**
54
+     * Load the text settings needed for the edit_mappings_page.
55
+     * @param array $edit_mapping_settings Key value pair of settings used by edit mappings page.
56
+     *
57
+     * @return array Adding text settings to the main settings array.
58
+     */
59
+    private function load_text_settings_for_edit_mapping_page( array $edit_mapping_settings ) {
60
+        $edit_mapping_settings['wl_add_mapping_text']     = __( 'Add Mapping', 'wordlift' );
61
+        $edit_mapping_settings['wl_edit_mapping_text']    = __( 'Edit Mapping', 'wordlift' );
62
+        $edit_mapping_settings['wl_edit_mapping_no_item'] = __( 'Unable to find the mapping item', 'wordlift' );
63
+        $edit_mapping_settings['page']                    = 'wl_edit_mapping';
64
+        return $edit_mapping_settings;
65
+    }
66
+
67
+    /**
68
+     * The base class {@link Wordlift_Admin_Page} will add the admin page to the WordLift menu.
69
+     *
70
+     * We don't want this page to be in the menu though. Therefore we override the `parent_slug` so that WordPress won't
71
+     * show it there.
72
+     *
73
+     * @return null return null to avoid this page to be displayed in WordLift's menu.
74
+     */
75
+    protected function get_parent_slug() {
76
+        return null;
77
+    }
78
+
79
+    /**
80
+     * {@inheritdoc}
81
+     */
82
+    public function get_page_title() {
83
+
84
+        return __( 'Edit Mappings', 'wordlift' );
85
+    }
86
+
87
+    /**
88
+     * {@inheritdoc}
89
+     */
90
+    public function get_menu_title() {
91
+
92
+        return __( 'Edit Mappings', 'wordlift' );
93
+    }
94
+
95
+    /**
96
+     * {@inheritdoc}
97
+     */
98
+    public function get_menu_slug() {
99
+
100
+        return 'wl_edit_mapping';
101
+    }
102
+
103
+    /**
104
+     * {@inheritdoc}
105
+     */
106
+    public function get_partial_name() {
107
+        return 'wordlift-admin-mappings-edit.php';
108
+    }
109
+
110
+    /**
111
+     * {@inheritdoc}
112
+     */
113
+    public function enqueue_scripts() {
114
+
115
+        // Enqueue the script.
116
+        Scripts_Helper::enqueue_based_on_wordpress_version(
117
+            'wl-mappings-edit',
118
+            plugin_dir_url( dirname( dirname( dirname( __FILE__ ) ) ) ) . 'js/dist/mappings-edit',
119
+            array( 'react', 'react-dom', 'wp-polyfill' ),
120
+            true
121
+        );
122
+
123
+        // Enqueue the style.
124
+        wp_enqueue_style(
125
+            'wl-mappings-edit',
126
+            plugin_dir_url( dirname( dirname( dirname( __FILE__ ) ) ) ) . 'js/dist/mappings-edit.css',
127
+            Wordlift::get_instance()->get_version()
128
+        );
129
+    }
130
+
131
+    /**
132
+     * Returns field name options based on the chosen field type.
133
+     * if string is returned a text field would be shown to user, if an array of options is returned
134
+     * then the select box would be shown to user.
135
+     *
136
+     * @return array Array of the options.
137
+     */
138
+    public static function get_all_field_name_options() {
139
+
140
+        $options = array(
141
+            array(
142
+                'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_TEXT_FIELD,
143
+                'value'      => '',
144
+                'label'      => __( 'Fixed Text', 'wordlift' ),
145
+            ),
146
+            // @@todo maybe it makes sense to move this one as well to Wordlift/Mappings/Custom_Fields_Mappings.
147
+            array(
148
+                'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD,
149
+                'value'      => '',
150
+                'label'      => __( 'Custom Field', 'wordlift' ),
151
+            ),
152
+        );
153
+
154
+        /**
155
+         * Allow 3rd parties to add field types.
156
+         *
157
+         * @param array An array of Field Types.
158
+         *
159
+         * @return array An array of Field Types.
160
+         *
161
+         * @since 3.25.0
162
+         */
163
+        return apply_filters( 'wl_mappings_field_types', $options );
164
+    }
165
+
166
+    /**
167
+     * @since 3.25.0
168
+     * Load dependencies required for js client.
169
+     * @return array An Array containing key value pairs of settings.
170
+     */
171
+    public function get_ui_settings_array() {
172
+        // Create ui settings array to be used by js client.
173
+        $edit_mapping_settings                               = array();
174
+        $edit_mapping_settings                               = $this->load_rest_settings( $edit_mapping_settings );
175
+        $edit_mapping_settings = $this->load_text_settings_for_edit_mapping_page( $edit_mapping_settings );
176
+        $edit_mapping_settings['wl_transform_function_options'] = $this->transform_function_registry->get_options();
177
+        $edit_mapping_settings = $this->load_field_type_and_name_options( $edit_mapping_settings );
178
+        // Load logic field options.
179
+        $edit_mapping_settings = $this->load_logic_field_options( $edit_mapping_settings );
180
+        $edit_mapping_settings = $this->load_rule_field_options( $edit_mapping_settings );
181
+
182
+        return $edit_mapping_settings;
183
+    }
184
+
185
+    /**
186
+     * Returns post type, post category, or any other post taxonomies
187
+     * @return array An array of select options
188
+     */
189
+    private static function get_post_taxonomies_and_terms() {
190
+        $taxonomy_options = array();
191
+        $term_options     = array();
192
+        $taxonomies       = get_object_taxonomies( 'post', 'objects' );
193
+
194
+        foreach ( $taxonomies as $taxonomy ) {
195
+            array_push(
196
+                $taxonomy_options,
197
+                array(
198
+                    'label'      => $taxonomy->label,
199
+                    'value'      => $taxonomy->name,
200
+                    'api_source' => 'taxonomy'
201
+                )
202
+            );
203
+        }
204
+        // Post type is also included in the list of taxonomies, so get the post type and merge with options.
205
+        $post_type_array =  self::get_post_type_key_and_value();
206
+        $post_type_option = $post_type_array['post_type_option_name'];
207
+        // Get also the list of post types from the post_type_array.
208
+        $post_type_option_values = $post_type_array['post_type_option_values'];
209 209
 
210 210
         $post_array =  self::get_post_taxonomy_key_and_value();
211 211
         $post_option = $post_array['post_taxonomy_option_name'];
@@ -213,49 +213,49 @@  discard block
 block discarded – undo
213 213
         $post_option_values = $post_array['post_taxonomy_option_values'];
214 214
 
215 215
 
216
-		// Merge the post type option and post types in the taxonomy options
217
-		array_push( $taxonomy_options, $post_type_option, $post_option );
218
-		$term_options = array_merge( $term_options, $post_type_option_values, $post_option_values );
219
-		return array(
220
-			'taxonomy_options' => $taxonomy_options,
221
-			'term_options' => $term_options
222
-		);
223
-	}
224
-
225
-	/**
226
-	 * Return post type option and post type option values.
227
-	 *
228
-	 * @return array Array of post_type_option and post_type_option_values.
229
-	 */
230
-	private static function get_post_type_key_and_value() {
231
-		$post_type_option_name   = array(
232
-			'label'      => __( 'Post type', 'wordlift' ),
233
-			'value'      => Wordlift\Mappings\Validators\Post_Type_Rule_Validator::POST_TYPE,
234
-			// Left empty since post types are provided locally.
235
-			'api_source' => '',
236
-		);
237
-		$post_type_option_values = array();
238
-		$post_types              = get_post_types(
239
-			array(),
240
-			'objects'
241
-		);
242
-
243
-		foreach ( $post_types as $post_type ) {
244
-			array_push(
245
-				$post_type_option_values,
246
-				array(
247
-					'label'        => $post_type->label,
248
-					'value'        => $post_type->name,
249
-					'parent_value' => 'post_type',
250
-				)
251
-			);
252
-		}
253
-
254
-		return array(
255
-			'post_type_option_name' =>  $post_type_option_name,
256
-			'post_type_option_values' => $post_type_option_values
257
-		);
258
-	}
216
+        // Merge the post type option and post types in the taxonomy options
217
+        array_push( $taxonomy_options, $post_type_option, $post_option );
218
+        $term_options = array_merge( $term_options, $post_type_option_values, $post_option_values );
219
+        return array(
220
+            'taxonomy_options' => $taxonomy_options,
221
+            'term_options' => $term_options
222
+        );
223
+    }
224
+
225
+    /**
226
+     * Return post type option and post type option values.
227
+     *
228
+     * @return array Array of post_type_option and post_type_option_values.
229
+     */
230
+    private static function get_post_type_key_and_value() {
231
+        $post_type_option_name   = array(
232
+            'label'      => __( 'Post type', 'wordlift' ),
233
+            'value'      => Wordlift\Mappings\Validators\Post_Type_Rule_Validator::POST_TYPE,
234
+            // Left empty since post types are provided locally.
235
+            'api_source' => '',
236
+        );
237
+        $post_type_option_values = array();
238
+        $post_types              = get_post_types(
239
+            array(),
240
+            'objects'
241
+        );
242
+
243
+        foreach ( $post_types as $post_type ) {
244
+            array_push(
245
+                $post_type_option_values,
246
+                array(
247
+                    'label'        => $post_type->label,
248
+                    'value'        => $post_type->name,
249
+                    'parent_value' => 'post_type',
250
+                )
251
+            );
252
+        }
253
+
254
+        return array(
255
+            'post_type_option_name' =>  $post_type_option_name,
256
+            'post_type_option_values' => $post_type_option_values
257
+        );
258
+    }
259 259
 
260 260
     /**
261 261
      * Return post type option and post type option values.
@@ -322,132 +322,132 @@  discard block
 block discarded – undo
322 322
         );
323 323
     }
324 324
 
325
-	/**
326
-	 * This function loads the equal to, not equal to operator to the edit mapping settings.
327
-	 *
328
-	 * @param array $edit_mapping_settings
329
-	 * @return array Loads the logic field options to the $edit_mapping_settings.
330
-	 */
331
-	private function load_logic_field_options( array $edit_mapping_settings ) {
332
-		$edit_mapping_settings['wl_logic_field_options'] = array(
333
-			array(
334
-				'label' => __( 'is equal to', 'wordlift' ),
335
-				'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_EQUAL_TO,
336
-			),
337
-			array(
338
-				'label' => __( 'is not equal to', 'wordlift' ),
339
-				'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_NOT_EQUAL_TO,
340
-			),
341
-		);
342
-
343
-		return $edit_mapping_settings;
344
-	}
345
-
346
-	/**
347
-	 * Validates the nonce posted by client and then assign the mapping id which should be edited.
348
-	 *
349
-	 * @param array $edit_mapping_settings
350
-	 * @return array Edit mapping settings array with the mapping id if the nonce is valid.
351
-	 */
352
-	private function validate_nonce_and_assign_mapping_id( array $edit_mapping_settings ) {
325
+    /**
326
+     * This function loads the equal to, not equal to operator to the edit mapping settings.
327
+     *
328
+     * @param array $edit_mapping_settings
329
+     * @return array Loads the logic field options to the $edit_mapping_settings.
330
+     */
331
+    private function load_logic_field_options( array $edit_mapping_settings ) {
332
+        $edit_mapping_settings['wl_logic_field_options'] = array(
333
+            array(
334
+                'label' => __( 'is equal to', 'wordlift' ),
335
+                'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_EQUAL_TO,
336
+            ),
337
+            array(
338
+                'label' => __( 'is not equal to', 'wordlift' ),
339
+                'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_NOT_EQUAL_TO,
340
+            ),
341
+        );
342
+
343
+        return $edit_mapping_settings;
344
+    }
345
+
346
+    /**
347
+     * Validates the nonce posted by client and then assign the mapping id which should be edited.
348
+     *
349
+     * @param array $edit_mapping_settings
350
+     * @return array Edit mapping settings array with the mapping id if the nonce is valid.
351
+     */
352
+    private function validate_nonce_and_assign_mapping_id( array $edit_mapping_settings ) {
353 353
         // We verify the nonce before making to load the edit mapping page for the wl_edit_mapping_id
354
-		if ( isset( $_REQUEST['_wl_edit_mapping_nonce'] )
355
-		     && wp_verify_nonce( $_REQUEST['_wl_edit_mapping_nonce'], 'wl-edit-mapping-nonce' ) ) {
356
-			// We're using `INPUT_GET` here because this is a link from the UI, i.e. no POST.
357
-			$edit_mapping_settings['wl_edit_mapping_id'] = (int) filter_var( $_REQUEST['wl_edit_mapping_id'], FILTER_VALIDATE_INT );
358
-		}
359
-
360
-		return $edit_mapping_settings;
361
-	}
362
-
363
-	/**
364
-	 * Load the rest settings required for the edit_mappings js client.
365
-	 *
366
-	 * @param array $edit_mapping_settings
367
-	 * @return array
368
-	 */
369
-	private function load_rest_settings( array $edit_mapping_settings ) {
370
-		$edit_mapping_settings['rest_url']                   = get_rest_url(
371
-			null,
372
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . Mappings_REST_Controller::MAPPINGS_NAMESPACE
373
-		);
374
-		$edit_mapping_settings['wl_edit_mapping_rest_nonce'] = wp_create_nonce( 'wp_rest' );
375
-		$edit_mapping_settings                               = $this->validate_nonce_and_assign_mapping_id( $edit_mapping_settings );
376
-
377
-		return $edit_mapping_settings;
378
-	}
379
-
380
-	/**
381
-	 * Load the rule field options in to the settings.
382
-	 *
383
-	 * @param array $edit_mapping_settings
384
-	 *
385
-	 * @return array Return the settings.
386
- 	 */
387
-	private function load_rule_field_options( array $edit_mapping_settings ) {
388
-		// Load the rule field options.
389
-		$rule_field_data                                    = self::get_post_taxonomies_and_terms();
390
-		$edit_mapping_settings['wl_rule_field_one_options'] = $rule_field_data['taxonomy_options'];
391
-		$edit_mapping_settings['wl_rule_field_two_options'] = $rule_field_data['term_options'];
392
-
393
-		/**
394
-		 * Allow 3rd parties to add ui options.
395
-		 *
396
-		 * @param array Array of Rule field one options where each item is in format
397
-		 *
398
-		 *  array ( 'label' => string, 'value' => string, 'api_source'=>string);
399
-		 *
400
-		 *  Leave api_source empty string to ensure didnt fetch rule field two options
401
-		 *  from api.
402
-		 *
403
-		 * @return array Array of Rule field one options
404
-		 *
405
-		 * @since 3.27.0
406
-		 */
407
-		$edit_mapping_settings['wl_rule_field_one_options'] = apply_filters(
408
-			'wl_mappings_rule_field_one_options',
409
-			$edit_mapping_settings['wl_rule_field_one_options']
410
-		);
411
-
412
-		/**
413
-		 * Allow 3rd parties to add rule field two options.
414
-		 *
415
-		 * @param array Array of Rule field two option where each item is in format
416
-		 *
417
-		 * array ( 'label' => string, 'value' => string, 'parent_value' => string );
418
-		 *
419
-		 * where parent_value is the value of the parent option in the rule_field_one_option.
420
-		 *
421
-		 * @since 3.27.0
422
-		 */
423
-		$edit_mapping_settings['wl_rule_field_two_options'] = apply_filters(
424
-			'wl_mappings_rule_field_two_options',
425
-			$edit_mapping_settings['wl_rule_field_two_options']
426
-		);
427
-
428
-		return $edit_mapping_settings;
429
-	}
430
-
431
-	/**
432
-	 * Load field type and field name options to the settings array.
433
-	 * @param array $edit_mapping_settings
434
-	 *
435
-	 * @return array
436
-	 */
437
-	private function load_field_type_and_name_options( array $edit_mapping_settings ) {
438
-		$all_field_name_options  = self::get_all_field_name_options();
439
-		$all_field_types_options = array_map( function ( $item ) {
440
-			return array(
441
-				'label' => $item['label'],
442
-				'value' => $item['field_type'],
443
-			);
444
-		}, $all_field_name_options );
445
-
446
-		$edit_mapping_settings['wl_field_type_options'] = $all_field_types_options;
447
-		// Add wl_edit_field_name_options.
448
-		$edit_mapping_settings['wl_field_name_options'] = $all_field_name_options;
449
-
450
-		return $edit_mapping_settings;
451
-	}
354
+        if ( isset( $_REQUEST['_wl_edit_mapping_nonce'] )
355
+             && wp_verify_nonce( $_REQUEST['_wl_edit_mapping_nonce'], 'wl-edit-mapping-nonce' ) ) {
356
+            // We're using `INPUT_GET` here because this is a link from the UI, i.e. no POST.
357
+            $edit_mapping_settings['wl_edit_mapping_id'] = (int) filter_var( $_REQUEST['wl_edit_mapping_id'], FILTER_VALIDATE_INT );
358
+        }
359
+
360
+        return $edit_mapping_settings;
361
+    }
362
+
363
+    /**
364
+     * Load the rest settings required for the edit_mappings js client.
365
+     *
366
+     * @param array $edit_mapping_settings
367
+     * @return array
368
+     */
369
+    private function load_rest_settings( array $edit_mapping_settings ) {
370
+        $edit_mapping_settings['rest_url']                   = get_rest_url(
371
+            null,
372
+            WL_REST_ROUTE_DEFAULT_NAMESPACE . Mappings_REST_Controller::MAPPINGS_NAMESPACE
373
+        );
374
+        $edit_mapping_settings['wl_edit_mapping_rest_nonce'] = wp_create_nonce( 'wp_rest' );
375
+        $edit_mapping_settings                               = $this->validate_nonce_and_assign_mapping_id( $edit_mapping_settings );
376
+
377
+        return $edit_mapping_settings;
378
+    }
379
+
380
+    /**
381
+     * Load the rule field options in to the settings.
382
+     *
383
+     * @param array $edit_mapping_settings
384
+     *
385
+     * @return array Return the settings.
386
+     */
387
+    private function load_rule_field_options( array $edit_mapping_settings ) {
388
+        // Load the rule field options.
389
+        $rule_field_data                                    = self::get_post_taxonomies_and_terms();
390
+        $edit_mapping_settings['wl_rule_field_one_options'] = $rule_field_data['taxonomy_options'];
391
+        $edit_mapping_settings['wl_rule_field_two_options'] = $rule_field_data['term_options'];
392
+
393
+        /**
394
+         * Allow 3rd parties to add ui options.
395
+         *
396
+         * @param array Array of Rule field one options where each item is in format
397
+         *
398
+         *  array ( 'label' => string, 'value' => string, 'api_source'=>string);
399
+         *
400
+         *  Leave api_source empty string to ensure didnt fetch rule field two options
401
+         *  from api.
402
+         *
403
+         * @return array Array of Rule field one options
404
+         *
405
+         * @since 3.27.0
406
+         */
407
+        $edit_mapping_settings['wl_rule_field_one_options'] = apply_filters(
408
+            'wl_mappings_rule_field_one_options',
409
+            $edit_mapping_settings['wl_rule_field_one_options']
410
+        );
411
+
412
+        /**
413
+         * Allow 3rd parties to add rule field two options.
414
+         *
415
+         * @param array Array of Rule field two option where each item is in format
416
+         *
417
+         * array ( 'label' => string, 'value' => string, 'parent_value' => string );
418
+         *
419
+         * where parent_value is the value of the parent option in the rule_field_one_option.
420
+         *
421
+         * @since 3.27.0
422
+         */
423
+        $edit_mapping_settings['wl_rule_field_two_options'] = apply_filters(
424
+            'wl_mappings_rule_field_two_options',
425
+            $edit_mapping_settings['wl_rule_field_two_options']
426
+        );
427
+
428
+        return $edit_mapping_settings;
429
+    }
430
+
431
+    /**
432
+     * Load field type and field name options to the settings array.
433
+     * @param array $edit_mapping_settings
434
+     *
435
+     * @return array
436
+     */
437
+    private function load_field_type_and_name_options( array $edit_mapping_settings ) {
438
+        $all_field_name_options  = self::get_all_field_name_options();
439
+        $all_field_types_options = array_map( function ( $item ) {
440
+            return array(
441
+                'label' => $item['label'],
442
+                'value' => $item['field_type'],
443
+            );
444
+        }, $all_field_name_options );
445
+
446
+        $edit_mapping_settings['wl_field_type_options'] = $all_field_types_options;
447
+        // Add wl_edit_field_name_options.
448
+        $edit_mapping_settings['wl_field_name_options'] = $all_field_name_options;
449
+
450
+        return $edit_mapping_settings;
451
+    }
452 452
 
453 453
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param $transform_function_registry Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance }
36 36
 	 */
37
-	public function __construct( $transform_function_registry ) {
37
+	public function __construct($transform_function_registry) {
38 38
 		parent::__construct();
39 39
 		$this->transform_function_registry = $transform_function_registry;
40 40
 	}
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 		// Load the UI dependencies.
46 46
 		$edit_mapping_settings = $this->get_ui_settings_array();
47 47
 		// Supply the settings to js client.
48
-		wp_localize_script( 'wl-mappings-edit', 'wl_edit_mappings_config', $edit_mapping_settings );
48
+		wp_localize_script('wl-mappings-edit', 'wl_edit_mappings_config', $edit_mapping_settings);
49 49
 
50 50
 		parent::render();
51 51
 	}
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 	 *
57 57
 	 * @return array Adding text settings to the main settings array.
58 58
 	 */
59
-	private function load_text_settings_for_edit_mapping_page( array $edit_mapping_settings ) {
60
-		$edit_mapping_settings['wl_add_mapping_text']     = __( 'Add Mapping', 'wordlift' );
61
-		$edit_mapping_settings['wl_edit_mapping_text']    = __( 'Edit Mapping', 'wordlift' );
62
-		$edit_mapping_settings['wl_edit_mapping_no_item'] = __( 'Unable to find the mapping item', 'wordlift' );
59
+	private function load_text_settings_for_edit_mapping_page(array $edit_mapping_settings) {
60
+		$edit_mapping_settings['wl_add_mapping_text']     = __('Add Mapping', 'wordlift');
61
+		$edit_mapping_settings['wl_edit_mapping_text']    = __('Edit Mapping', 'wordlift');
62
+		$edit_mapping_settings['wl_edit_mapping_no_item'] = __('Unable to find the mapping item', 'wordlift');
63 63
 		$edit_mapping_settings['page']                    = 'wl_edit_mapping';
64 64
 		return $edit_mapping_settings;
65 65
 	}
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 */
82 82
 	public function get_page_title() {
83 83
 
84
-		return __( 'Edit Mappings', 'wordlift' );
84
+		return __('Edit Mappings', 'wordlift');
85 85
 	}
86 86
 
87 87
 	/**
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 */
90 90
 	public function get_menu_title() {
91 91
 
92
-		return __( 'Edit Mappings', 'wordlift' );
92
+		return __('Edit Mappings', 'wordlift');
93 93
 	}
94 94
 
95 95
 	/**
@@ -115,15 +115,15 @@  discard block
 block discarded – undo
115 115
 		// Enqueue the script.
116 116
 		Scripts_Helper::enqueue_based_on_wordpress_version(
117 117
 			'wl-mappings-edit',
118
-			plugin_dir_url( dirname( dirname( dirname( __FILE__ ) ) ) ) . 'js/dist/mappings-edit',
119
-			array( 'react', 'react-dom', 'wp-polyfill' ),
118
+			plugin_dir_url(dirname(dirname(dirname(__FILE__)))).'js/dist/mappings-edit',
119
+			array('react', 'react-dom', 'wp-polyfill'),
120 120
 			true
121 121
 		);
122 122
 
123 123
 		// Enqueue the style.
124 124
 		wp_enqueue_style(
125 125
 			'wl-mappings-edit',
126
-			plugin_dir_url( dirname( dirname( dirname( __FILE__ ) ) ) ) . 'js/dist/mappings-edit.css',
126
+			plugin_dir_url(dirname(dirname(dirname(__FILE__)))).'js/dist/mappings-edit.css',
127 127
 			Wordlift::get_instance()->get_version()
128 128
 		);
129 129
 	}
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 			array(
142 142
 				'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_TEXT_FIELD,
143 143
 				'value'      => '',
144
-				'label'      => __( 'Fixed Text', 'wordlift' ),
144
+				'label'      => __('Fixed Text', 'wordlift'),
145 145
 			),
146 146
 			// @@todo maybe it makes sense to move this one as well to Wordlift/Mappings/Custom_Fields_Mappings.
147 147
 			array(
148 148
 				'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD,
149 149
 				'value'      => '',
150
-				'label'      => __( 'Custom Field', 'wordlift' ),
150
+				'label'      => __('Custom Field', 'wordlift'),
151 151
 			),
152 152
 		);
153 153
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		 *
161 161
 		 * @since 3.25.0
162 162
 		 */
163
-		return apply_filters( 'wl_mappings_field_types', $options );
163
+		return apply_filters('wl_mappings_field_types', $options);
164 164
 	}
165 165
 
166 166
 	/**
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 	public function get_ui_settings_array() {
172 172
 		// Create ui settings array to be used by js client.
173 173
 		$edit_mapping_settings                               = array();
174
-		$edit_mapping_settings                               = $this->load_rest_settings( $edit_mapping_settings );
175
-		$edit_mapping_settings = $this->load_text_settings_for_edit_mapping_page( $edit_mapping_settings );
174
+		$edit_mapping_settings                               = $this->load_rest_settings($edit_mapping_settings);
175
+		$edit_mapping_settings = $this->load_text_settings_for_edit_mapping_page($edit_mapping_settings);
176 176
 		$edit_mapping_settings['wl_transform_function_options'] = $this->transform_function_registry->get_options();
177
-		$edit_mapping_settings = $this->load_field_type_and_name_options( $edit_mapping_settings );
177
+		$edit_mapping_settings = $this->load_field_type_and_name_options($edit_mapping_settings);
178 178
 		// Load logic field options.
179
-		$edit_mapping_settings = $this->load_logic_field_options( $edit_mapping_settings );
180
-		$edit_mapping_settings = $this->load_rule_field_options( $edit_mapping_settings );
179
+		$edit_mapping_settings = $this->load_logic_field_options($edit_mapping_settings);
180
+		$edit_mapping_settings = $this->load_rule_field_options($edit_mapping_settings);
181 181
 
182 182
 		return $edit_mapping_settings;
183 183
 	}
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
 	private static function get_post_taxonomies_and_terms() {
190 190
 		$taxonomy_options = array();
191 191
 		$term_options     = array();
192
-		$taxonomies       = get_object_taxonomies( 'post', 'objects' );
192
+		$taxonomies       = get_object_taxonomies('post', 'objects');
193 193
 
194
-		foreach ( $taxonomies as $taxonomy ) {
194
+		foreach ($taxonomies as $taxonomy) {
195 195
 			array_push(
196 196
 				$taxonomy_options,
197 197
 				array(
@@ -202,20 +202,20 @@  discard block
 block discarded – undo
202 202
 			);
203 203
 		}
204 204
 		// Post type is also included in the list of taxonomies, so get the post type and merge with options.
205
-		$post_type_array =  self::get_post_type_key_and_value();
205
+		$post_type_array = self::get_post_type_key_and_value();
206 206
 		$post_type_option = $post_type_array['post_type_option_name'];
207 207
 		// Get also the list of post types from the post_type_array.
208 208
 		$post_type_option_values = $post_type_array['post_type_option_values'];
209 209
 
210
-        $post_array =  self::get_post_taxonomy_key_and_value();
210
+        $post_array = self::get_post_taxonomy_key_and_value();
211 211
         $post_option = $post_array['post_taxonomy_option_name'];
212 212
         // Get also the list of post types from the post_type_array.
213 213
         $post_option_values = $post_array['post_taxonomy_option_values'];
214 214
 
215 215
 
216 216
 		// Merge the post type option and post types in the taxonomy options
217
-		array_push( $taxonomy_options, $post_type_option, $post_option );
218
-		$term_options = array_merge( $term_options, $post_type_option_values, $post_option_values );
217
+		array_push($taxonomy_options, $post_type_option, $post_option);
218
+		$term_options = array_merge($term_options, $post_type_option_values, $post_option_values);
219 219
 		return array(
220 220
 			'taxonomy_options' => $taxonomy_options,
221 221
 			'term_options' => $term_options
@@ -228,8 +228,8 @@  discard block
 block discarded – undo
228 228
 	 * @return array Array of post_type_option and post_type_option_values.
229 229
 	 */
230 230
 	private static function get_post_type_key_and_value() {
231
-		$post_type_option_name   = array(
232
-			'label'      => __( 'Post type', 'wordlift' ),
231
+		$post_type_option_name = array(
232
+			'label'      => __('Post type', 'wordlift'),
233 233
 			'value'      => Wordlift\Mappings\Validators\Post_Type_Rule_Validator::POST_TYPE,
234 234
 			// Left empty since post types are provided locally.
235 235
 			'api_source' => '',
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 			'objects'
241 241
 		);
242 242
 
243
-		foreach ( $post_types as $post_type ) {
243
+		foreach ($post_types as $post_type) {
244 244
 			array_push(
245 245
 				$post_type_option_values,
246 246
 				array(
@@ -263,17 +263,17 @@  discard block
 block discarded – undo
263 263
      * @return array Array of post_type_option and post_type_option_values.
264 264
      */
265 265
     private static function get_post_taxonomy_key_and_value() {
266
-        $post_taxonomy_option_name   = array(
267
-            'label'      => __( 'Post Taxonomy', 'wordlift' ),
266
+        $post_taxonomy_option_name = array(
267
+            'label'      => __('Post Taxonomy', 'wordlift'),
268 268
             'value'      => Wordlift\Mappings\Validators\Post_Taxonomy_Term_Rule_Validator::POST_TAXONOMY,
269 269
             // Left empty since post types are provided locally.
270 270
             'api_source' => '',
271 271
         );
272 272
         $post_taxonomy_option_values = array();
273 273
 
274
-        $post_taxonomies = get_taxonomies( array(), 'objects' );
274
+        $post_taxonomies = get_taxonomies(array(), 'objects');
275 275
 
276
-        foreach ( $post_taxonomies as $post_taxonomy ) {
276
+        foreach ($post_taxonomies as $post_taxonomy) {
277 277
 
278 278
             array_push(
279 279
                 $post_taxonomy_option_values,
@@ -284,16 +284,16 @@  discard block
 block discarded – undo
284 284
                 )
285 285
             );
286 286
 
287
-            $post_taxonomy_terms = get_terms( array(
287
+            $post_taxonomy_terms = get_terms(array(
288 288
                 'taxonomy' => $post_taxonomy->name,
289 289
                 'hide_empty' => true
290
-            ) );
290
+            ));
291 291
 
292
-            foreach ( $post_taxonomy_terms as $post_taxonomy_term ) {
292
+            foreach ($post_taxonomy_terms as $post_taxonomy_term) {
293 293
                 array_push(
294 294
                     $post_taxonomy_option_values,
295 295
                     array(
296
-                        'label'        => ' - ' . $post_taxonomy_term->name,
296
+                        'label'        => ' - '.$post_taxonomy_term->name,
297 297
                         'value'        => $post_taxonomy_term->slug,
298 298
                         'parent_value' => 'post_taxonomy',
299 299
                     )
@@ -301,13 +301,13 @@  discard block
 block discarded – undo
301 301
 
302 302
                 $post_term_children = get_term_children($post_taxonomy_term->term_id, $post_taxonomy->name);
303 303
 
304
-                foreach ( $post_term_children as $post_term_child ) {
305
-                    $child_term =  get_term_by('id', $post_term_child, $post_taxonomy->name);
304
+                foreach ($post_term_children as $post_term_child) {
305
+                    $child_term = get_term_by('id', $post_term_child, $post_taxonomy->name);
306 306
 
307 307
                     array_push(
308 308
                         $post_taxonomy_option_values,
309 309
                         array(
310
-                            'label'        => ' -- ' . $child_term->name,
310
+                            'label'        => ' -- '.$child_term->name,
311 311
                             'value'        => $child_term->slug,
312 312
                             'parent_value' => 'post_taxonomy',
313 313
                         )
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
 	 * @param array $edit_mapping_settings
329 329
 	 * @return array Loads the logic field options to the $edit_mapping_settings.
330 330
 	 */
331
-	private function load_logic_field_options( array $edit_mapping_settings ) {
331
+	private function load_logic_field_options(array $edit_mapping_settings) {
332 332
 		$edit_mapping_settings['wl_logic_field_options'] = array(
333 333
 			array(
334
-				'label' => __( 'is equal to', 'wordlift' ),
334
+				'label' => __('is equal to', 'wordlift'),
335 335
 				'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_EQUAL_TO,
336 336
 			),
337 337
 			array(
338
-				'label' => __( 'is not equal to', 'wordlift' ),
338
+				'label' => __('is not equal to', 'wordlift'),
339 339
 				'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_NOT_EQUAL_TO,
340 340
 			),
341 341
 		);
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
 	 * @param array $edit_mapping_settings
350 350
 	 * @return array Edit mapping settings array with the mapping id if the nonce is valid.
351 351
 	 */
352
-	private function validate_nonce_and_assign_mapping_id( array $edit_mapping_settings ) {
352
+	private function validate_nonce_and_assign_mapping_id(array $edit_mapping_settings) {
353 353
         // We verify the nonce before making to load the edit mapping page for the wl_edit_mapping_id
354
-		if ( isset( $_REQUEST['_wl_edit_mapping_nonce'] )
355
-		     && wp_verify_nonce( $_REQUEST['_wl_edit_mapping_nonce'], 'wl-edit-mapping-nonce' ) ) {
354
+		if (isset($_REQUEST['_wl_edit_mapping_nonce'])
355
+		     && wp_verify_nonce($_REQUEST['_wl_edit_mapping_nonce'], 'wl-edit-mapping-nonce')) {
356 356
 			// We're using `INPUT_GET` here because this is a link from the UI, i.e. no POST.
357
-			$edit_mapping_settings['wl_edit_mapping_id'] = (int) filter_var( $_REQUEST['wl_edit_mapping_id'], FILTER_VALIDATE_INT );
357
+			$edit_mapping_settings['wl_edit_mapping_id'] = (int) filter_var($_REQUEST['wl_edit_mapping_id'], FILTER_VALIDATE_INT);
358 358
 		}
359 359
 
360 360
 		return $edit_mapping_settings;
@@ -366,13 +366,13 @@  discard block
 block discarded – undo
366 366
 	 * @param array $edit_mapping_settings
367 367
 	 * @return array
368 368
 	 */
369
-	private function load_rest_settings( array $edit_mapping_settings ) {
370
-		$edit_mapping_settings['rest_url']                   = get_rest_url(
369
+	private function load_rest_settings(array $edit_mapping_settings) {
370
+		$edit_mapping_settings['rest_url'] = get_rest_url(
371 371
 			null,
372
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . Mappings_REST_Controller::MAPPINGS_NAMESPACE
372
+			WL_REST_ROUTE_DEFAULT_NAMESPACE.Mappings_REST_Controller::MAPPINGS_NAMESPACE
373 373
 		);
374
-		$edit_mapping_settings['wl_edit_mapping_rest_nonce'] = wp_create_nonce( 'wp_rest' );
375
-		$edit_mapping_settings                               = $this->validate_nonce_and_assign_mapping_id( $edit_mapping_settings );
374
+		$edit_mapping_settings['wl_edit_mapping_rest_nonce'] = wp_create_nonce('wp_rest');
375
+		$edit_mapping_settings                               = $this->validate_nonce_and_assign_mapping_id($edit_mapping_settings);
376 376
 
377 377
 		return $edit_mapping_settings;
378 378
 	}
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 	 *
385 385
 	 * @return array Return the settings.
386 386
  	 */
387
-	private function load_rule_field_options( array $edit_mapping_settings ) {
387
+	private function load_rule_field_options(array $edit_mapping_settings) {
388 388
 		// Load the rule field options.
389 389
 		$rule_field_data                                    = self::get_post_taxonomies_and_terms();
390 390
 		$edit_mapping_settings['wl_rule_field_one_options'] = $rule_field_data['taxonomy_options'];
@@ -434,14 +434,14 @@  discard block
 block discarded – undo
434 434
 	 *
435 435
 	 * @return array
436 436
 	 */
437
-	private function load_field_type_and_name_options( array $edit_mapping_settings ) {
437
+	private function load_field_type_and_name_options(array $edit_mapping_settings) {
438 438
 		$all_field_name_options  = self::get_all_field_name_options();
439
-		$all_field_types_options = array_map( function ( $item ) {
439
+		$all_field_types_options = array_map(function($item) {
440 440
 			return array(
441 441
 				'label' => $item['label'],
442 442
 				'value' => $item['field_type'],
443 443
 			);
444
-		}, $all_field_name_options );
444
+		}, $all_field_name_options);
445 445
 
446 446
 		$edit_mapping_settings['wl_field_type_options'] = $all_field_types_options;
447 447
 		// Add wl_edit_field_name_options.
Please login to merge, or discard this patch.
wordlift/mappings/validators/class-post-taxonomy-term-rule-validator.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -17,49 +17,49 @@  discard block
 block discarded – undo
17 17
  * @package Wordlift\Mappings\Validators
18 18
  */
19 19
 class Post_Taxonomy_Term_Rule_Validator implements Rule_Validator {
20
-	/**
21
-	 * @since 3.25.0
22
-	 * Enum for the post type rule validator.
23
-	 */
24
-	const POST_TAXONOMY = 'post_taxonomy';
25
-
26
-	/**
27
-	 * Post_Type_Rule_Validator constructor.
28
-	 *
29
-	 * When initializing the class hooks to `wl_mappings_rule_validators`.
30
-	 */
31
-	public function __construct() {
32
-
33
-		add_filter( 'wl_mappings_rule_validators', array( $this, 'wl_mappings_rule_validators' ) );
34
-
35
-
36
-	}
37
-
38
-	/**
39
-	 * Hook to `wl_mappings_rule_validators` to register ourselves.
40
-	 *
41
-	 * @param array $value An array with validators.
42
-	 *
43
-	 * @return array An array with validators plus ours.
44
-	 */
45
-	public function wl_mappings_rule_validators( $value ) {
46
-
47
-		$value[ self::POST ] = $this;
48
-
49
-		return $value;
50
-	}
51
-
52
-	/**
53
-	 * {@inheritdoc}
54
-	 */
55
-	public function get_label() {
56
-		return __( 'Post Taxonomy', 'wordlift' );
57
-	}
58
-
59
-	/**
60
-	 * {@inheritdoc}
61
-	 */
62
-	public function is_valid ( $identifier, $operator, $operand_1, $operand_2, $type ) {
20
+    /**
21
+     * @since 3.25.0
22
+     * Enum for the post type rule validator.
23
+     */
24
+    const POST_TAXONOMY = 'post_taxonomy';
25
+
26
+    /**
27
+     * Post_Type_Rule_Validator constructor.
28
+     *
29
+     * When initializing the class hooks to `wl_mappings_rule_validators`.
30
+     */
31
+    public function __construct() {
32
+
33
+        add_filter( 'wl_mappings_rule_validators', array( $this, 'wl_mappings_rule_validators' ) );
34
+
35
+
36
+    }
37
+
38
+    /**
39
+     * Hook to `wl_mappings_rule_validators` to register ourselves.
40
+     *
41
+     * @param array $value An array with validators.
42
+     *
43
+     * @return array An array with validators plus ours.
44
+     */
45
+    public function wl_mappings_rule_validators( $value ) {
46
+
47
+        $value[ self::POST ] = $this;
48
+
49
+        return $value;
50
+    }
51
+
52
+    /**
53
+     * {@inheritdoc}
54
+     */
55
+    public function get_label() {
56
+        return __( 'Post Taxonomy', 'wordlift' );
57
+    }
58
+
59
+    /**
60
+     * {@inheritdoc}
61
+     */
62
+    public function is_valid ( $identifier, $operator, $operand_1, $operand_2, $type ) {
63 63
         $taxonomy  = $operand_1;
64 64
         $term_slug = $operand_2;
65 65
 
@@ -76,5 +76,5 @@  discard block
 block discarded – undo
76 76
         }
77 77
 
78 78
         return true;
79
-	}
79
+    }
80 80
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 */
31 31
 	public function __construct() {
32 32
 
33
-		add_filter( 'wl_mappings_rule_validators', array( $this, 'wl_mappings_rule_validators' ) );
33
+		add_filter('wl_mappings_rule_validators', array($this, 'wl_mappings_rule_validators'));
34 34
 
35 35
 
36 36
 	}
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return array An array with validators plus ours.
44 44
 	 */
45
-	public function wl_mappings_rule_validators( $value ) {
45
+	public function wl_mappings_rule_validators($value) {
46 46
 
47
-		$value[ self::POST ] = $this;
47
+		$value[self::POST] = $this;
48 48
 
49 49
 		return $value;
50 50
 	}
@@ -53,25 +53,25 @@  discard block
 block discarded – undo
53 53
 	 * {@inheritdoc}
54 54
 	 */
55 55
 	public function get_label() {
56
-		return __( 'Post Taxonomy', 'wordlift' );
56
+		return __('Post Taxonomy', 'wordlift');
57 57
 	}
58 58
 
59 59
 	/**
60 60
 	 * {@inheritdoc}
61 61
 	 */
62
-	public function is_valid ( $identifier, $operator, $operand_1, $operand_2, $type ) {
62
+	public function is_valid($identifier, $operator, $operand_1, $operand_2, $type) {
63 63
         $taxonomy  = $operand_1;
64 64
         $term_slug = $operand_2;
65 65
 
66
-        $is_object_in_term = is_object_in_term( $identifier, $taxonomy, $term_slug );
66
+        $is_object_in_term = is_object_in_term($identifier, $taxonomy, $term_slug);
67 67
 
68
-        $taxonomy = get_taxonomy( $term_slug );
68
+        $taxonomy = get_taxonomy($term_slug);
69 69
 
70
-        if (!in_array('post', $taxonomy->object_type )) {
70
+        if ( ! in_array('post', $taxonomy->object_type)) {
71 71
             return false;
72 72
         }
73 73
 
74
-        if ( is_wp_error( $is_object_in_term ) ) {
74
+        if (is_wp_error($is_object_in_term)) {
75 75
             return false;
76 76
         }
77 77
 
Please login to merge, or discard this patch.