Completed
Pull Request — master (#1641)
by Naveen
01:35
created
src/wordlift/templates/class-templates-ajax-endpoint.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -17,33 +17,33 @@
 block discarded – undo
17 17
  */
18 18
 class Templates_Ajax_Endpoint {
19 19
 
20
-	/**
21
-	 * Templates_Ajax_Endpoint constructor.
22
-	 *
23
-	 * Hook to `wl_templates` Ajax action.
24
-	 */
25
-	public function __construct() {
20
+    /**
21
+     * Templates_Ajax_Endpoint constructor.
22
+     *
23
+     * Hook to `wl_templates` Ajax action.
24
+     */
25
+    public function __construct() {
26 26
 
27
-		add_action( 'wp_ajax_wl_templates', array( $this, 'template' ) );
27
+        add_action( 'wp_ajax_wl_templates', array( $this, 'template' ) );
28 28
 
29
-	}
29
+    }
30 30
 
31
-	/**
32
-	 * Display the requested template. The template is searched in wp-content/wordlift/templates/wordlift-widget-be/
33
-	 *
34
-	 * Non alphanumeric names (including `-`) are considered invalid.
35
-	 */
36
-	public function template() {
31
+    /**
32
+     * Display the requested template. The template is searched in wp-content/wordlift/templates/wordlift-widget-be/
33
+     *
34
+     * Non alphanumeric names (including `-`) are considered invalid.
35
+     */
36
+    public function template() {
37 37
 
38
-		$name = filter_input( INPUT_GET, 'name' );
38
+        $name = filter_input( INPUT_GET, 'name' );
39 39
 
40
-		if ( 1 !== preg_match( '|^[a-z0-9\-]+$|', $name ) ) {
41
-			return wp_send_json_error( 'Invalid name.' );
42
-		}
40
+        if ( 1 !== preg_match( '|^[a-z0-9\-]+$|', $name ) ) {
41
+            return wp_send_json_error( 'Invalid name.' );
42
+        }
43 43
 
44
-		require dirname( dirname( __DIR__ ) ) . "/templates/wordlift-widget-be/$name.html";
44
+        require dirname( dirname( __DIR__ ) ) . "/templates/wordlift-widget-be/$name.html";
45 45
 
46
-		die();
47
-	}
46
+        die();
47
+    }
48 48
 
49 49
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	public function __construct() {
26 26
 
27
-		add_action( 'wp_ajax_wl_templates', array( $this, 'template' ) );
27
+		add_action('wp_ajax_wl_templates', array($this, 'template'));
28 28
 
29 29
 	}
30 30
 
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
 	 */
36 36
 	public function template() {
37 37
 
38
-		$name = filter_input( INPUT_GET, 'name' );
38
+		$name = filter_input(INPUT_GET, 'name');
39 39
 
40
-		if ( 1 !== preg_match( '|^[a-z0-9\-]+$|', $name ) ) {
41
-			return wp_send_json_error( 'Invalid name.' );
40
+		if (1 !== preg_match('|^[a-z0-9\-]+$|', $name)) {
41
+			return wp_send_json_error('Invalid name.');
42 42
 		}
43 43
 
44
-		require dirname( dirname( __DIR__ ) ) . "/templates/wordlift-widget-be/$name.html";
44
+		require dirname(dirname(__DIR__))."/templates/wordlift-widget-be/$name.html";
45 45
 
46 46
 		die();
47 47
 	}
Please login to merge, or discard this patch.
src/wordlift/admin/class-key-validation-notice.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -11,138 +11,138 @@
 block discarded – undo
11 11
  */
12 12
 class Key_Validation_Notice {
13 13
 
14
-	const CACHE_KEY = 'is_key_valid';
14
+    const CACHE_KEY = 'is_key_valid';
15 15
 
16
-	const KEY_VALIDATION_NONCE_ACTION = 'wl_key_validation_notice_nonce';
16
+    const KEY_VALIDATION_NONCE_ACTION = 'wl_key_validation_notice_nonce';
17 17
 
18
-	const KEY_VALIDATION_NONCE_PARAM = '_wl_key_validation_notice_nonce';
18
+    const KEY_VALIDATION_NONCE_PARAM = '_wl_key_validation_notice_nonce';
19 19
 
20
-	const KEY_VALIDATION_NOTICE_PARAM = 'wl_key_validation_notice';
20
+    const KEY_VALIDATION_NOTICE_PARAM = 'wl_key_validation_notice';
21 21
 
22
-	const NOTIFICATION_OPTION_KEY = 'wordlift_key_validation_notification_shown';
22
+    const NOTIFICATION_OPTION_KEY = 'wordlift_key_validation_notification_shown';
23 23
 
24
-	/**
25
-	 * @var \Wordlift_Key_Validation_Service
26
-	 */
27
-	private $key_validation_service;
24
+    /**
25
+     * @var \Wordlift_Key_Validation_Service
26
+     */
27
+    private $key_validation_service;
28 28
 
29
-	/**
30
-	 * @var Ttl_Cache
31
-	 */
32
-	private $ttl_cache_service;
29
+    /**
30
+     * @var Ttl_Cache
31
+     */
32
+    private $ttl_cache_service;
33 33
 
34
-	/**
35
-	 * @var Wordlift_Configuration_Service
36
-	 */
37
-	private $configuration_service;
34
+    /**
35
+     * @var Wordlift_Configuration_Service
36
+     */
37
+    private $configuration_service;
38 38
 
39
-	/**
40
-	 * Key_Validation_Notice constructor.
41
-	 *
42
-	 * @param \Wordlift_Key_Validation_Service $key_validation_service
43
-	 * @param Wordlift_Configuration_Service   $configuration_service
44
-	 */
45
-	public function __construct( $key_validation_service, $configuration_service ) {
39
+    /**
40
+     * Key_Validation_Notice constructor.
41
+     *
42
+     * @param \Wordlift_Key_Validation_Service $key_validation_service
43
+     * @param Wordlift_Configuration_Service   $configuration_service
44
+     */
45
+    public function __construct( $key_validation_service, $configuration_service ) {
46 46
 
47
-		$this->key_validation_service = $key_validation_service;
48
-		$this->configuration_service  = $configuration_service;
47
+        $this->key_validation_service = $key_validation_service;
48
+        $this->configuration_service  = $configuration_service;
49 49
 
50
-		$this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification', 60 * 60 * 8 );
50
+        $this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification', 60 * 60 * 8 );
51 51
 
52
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
53
-			$this->display_key_validation_notice();
54
-		}
52
+        if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
53
+            $this->display_key_validation_notice();
54
+        }
55 55
 
56
-		$that = $this;
57
-		add_action(
58
-			'plugins_loaded',
59
-			function () use ( $that ) {
60
-				$that->notification_close_handler();
61
-			}
62
-		);
63
-	}
56
+        $that = $this;
57
+        add_action(
58
+            'plugins_loaded',
59
+            function () use ( $that ) {
60
+                $that->notification_close_handler();
61
+            }
62
+        );
63
+    }
64 64
 
65
-	public function show_notification() {
66
-		$settings_url = admin_url( 'admin.php?page=wl_configuration_admin_menu' );
67
-		?>
65
+    public function show_notification() {
66
+        $settings_url = admin_url( 'admin.php?page=wl_configuration_admin_menu' );
67
+        ?>
68 68
 		<div class="wl-notice notice is-dismissible error">
69 69
 			<p>
70 70
 				<?php
71
-				/* translators: %s: the link to the WordLift configuration screen. */
72
-				echo wp_kses( sprintf( __( "Your WordLift key is not valid, please update the key in <a href='%s'>WordLift Settings</a> or contact our support at [email protected].", 'wordlift' ), esc_attr( $settings_url ) ), array( 'a' => array( 'href' ) ) );
73
-				?>
71
+                /* translators: %s: the link to the WordLift configuration screen. */
72
+                echo wp_kses( sprintf( __( "Your WordLift key is not valid, please update the key in <a href='%s'>WordLift Settings</a> or contact our support at [email protected].", 'wordlift' ), esc_attr( $settings_url ) ), array( 'a' => array( 'href' ) ) );
73
+                ?>
74 74
 			</p>
75 75
 			<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span>
76 76
 			</button>
77 77
 		</div>
78 78
 		<?php
79
-	}
79
+    }
80 80
 
81
-	private function is_key_valid() {
81
+    private function is_key_valid() {
82 82
 
83
-		$key = $this->configuration_service->get_key();
83
+        $key = $this->configuration_service->get_key();
84 84
 
85
-		// Check cache if the result is present, if not get the results
86
-		// save it and return the data.
87
-		if ( $this->ttl_cache_service->get( self::CACHE_KEY ) !== null ) {
88
-			return $this->ttl_cache_service->get( self::CACHE_KEY );
89
-		}
85
+        // Check cache if the result is present, if not get the results
86
+        // save it and return the data.
87
+        if ( $this->ttl_cache_service->get( self::CACHE_KEY ) !== null ) {
88
+            return $this->ttl_cache_service->get( self::CACHE_KEY );
89
+        }
90 90
 
91
-		$is_valid = $this->key_validation_service->is_key_valid( $key );
91
+        $is_valid = $this->key_validation_service->is_key_valid( $key );
92 92
 
93
-		// when the cache is set, clear the notification flag.
94
-		delete_option( self::NOTIFICATION_OPTION_KEY );
93
+        // when the cache is set, clear the notification flag.
94
+        delete_option( self::NOTIFICATION_OPTION_KEY );
95 95
 
96
-		$this->ttl_cache_service->put( self::CACHE_KEY, $is_valid );
96
+        $this->ttl_cache_service->put( self::CACHE_KEY, $is_valid );
97 97
 
98
-		return $is_valid;
99
-	}
98
+        return $is_valid;
99
+    }
100 100
 
101
-	private function display_key_validation_notice() {
102
-		$that = $this;
103
-		add_action(
104
-			'admin_notices',
105
-			function () use ( $that ) {
101
+    private function display_key_validation_notice() {
102
+        $that = $this;
103
+        add_action(
104
+            'admin_notices',
105
+            function () use ( $that ) {
106 106
 
107
-				$is_notification_shown = get_option( Key_Validation_Notice::NOTIFICATION_OPTION_KEY, false );
107
+                $is_notification_shown = get_option( Key_Validation_Notice::NOTIFICATION_OPTION_KEY, false );
108 108
 
109
-				$key = $that->configuration_service->get_key();
109
+                $key = $that->configuration_service->get_key();
110 110
 
111
-				if ( ! $key ) {
112
-					// Dont show warning or make API call, return early.
113
-					return;
114
-				}
111
+                if ( ! $key ) {
112
+                    // Dont show warning or make API call, return early.
113
+                    return;
114
+                }
115 115
 
116
-				if ( $that->is_key_valid() ) {
117
-					return;
118
-				}
116
+                if ( $that->is_key_valid() ) {
117
+                    return;
118
+                }
119 119
 
120
-				if ( $is_notification_shown ) {
121
-					return;
122
-				}
120
+                if ( $is_notification_shown ) {
121
+                    return;
122
+                }
123 123
 
124
-				$that->show_notification();
124
+                $that->show_notification();
125 125
 
126
-			}
127
-		);
128
-	}
126
+            }
127
+        );
128
+    }
129 129
 
130
-	public function notification_close_handler() {
131
-		if ( ! isset( $_GET['wl_key_validation_notice'] )
132
-			 || ! isset( $_GET['_wl_key_validation_notice_nonce'] ) ) {
133
-			return false;
134
-		}
135
-		$nonce = sanitize_text_field( wp_unslash( (string) $_GET['_wl_key_validation_notice_nonce'] ) );
136
-		if ( wp_verify_nonce( $nonce, self::KEY_VALIDATION_NONCE_ACTION )
137
-			 && current_user_can( 'manage_options' ) ) {
138
-			// close the notification.
139
-			update_option( self::NOTIFICATION_OPTION_KEY, true );
140
-		}
141
-	}
130
+    public function notification_close_handler() {
131
+        if ( ! isset( $_GET['wl_key_validation_notice'] )
132
+             || ! isset( $_GET['_wl_key_validation_notice_nonce'] ) ) {
133
+            return false;
134
+        }
135
+        $nonce = sanitize_text_field( wp_unslash( (string) $_GET['_wl_key_validation_notice_nonce'] ) );
136
+        if ( wp_verify_nonce( $nonce, self::KEY_VALIDATION_NONCE_ACTION )
137
+             && current_user_can( 'manage_options' ) ) {
138
+            // close the notification.
139
+            update_option( self::NOTIFICATION_OPTION_KEY, true );
140
+        }
141
+    }
142 142
 
143
-	public static function remove_notification_flag() {
144
-		delete_option( self::NOTIFICATION_OPTION_KEY );
145
-	}
143
+    public static function remove_notification_flag() {
144
+        delete_option( self::NOTIFICATION_OPTION_KEY );
145
+    }
146 146
 
147 147
 }
148 148
 
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -42,34 +42,34 @@  discard block
 block discarded – undo
42 42
 	 * @param \Wordlift_Key_Validation_Service $key_validation_service
43 43
 	 * @param Wordlift_Configuration_Service   $configuration_service
44 44
 	 */
45
-	public function __construct( $key_validation_service, $configuration_service ) {
45
+	public function __construct($key_validation_service, $configuration_service) {
46 46
 
47 47
 		$this->key_validation_service = $key_validation_service;
48 48
 		$this->configuration_service  = $configuration_service;
49 49
 
50
-		$this->ttl_cache_service = new Ttl_Cache( 'key-validation-notification', 60 * 60 * 8 );
50
+		$this->ttl_cache_service = new Ttl_Cache('key-validation-notification', 60 * 60 * 8);
51 51
 
52
-		if ( apply_filters( 'wl_feature__enable__notices', true ) ) {
52
+		if (apply_filters('wl_feature__enable__notices', true)) {
53 53
 			$this->display_key_validation_notice();
54 54
 		}
55 55
 
56 56
 		$that = $this;
57 57
 		add_action(
58 58
 			'plugins_loaded',
59
-			function () use ( $that ) {
59
+			function() use ($that) {
60 60
 				$that->notification_close_handler();
61 61
 			}
62 62
 		);
63 63
 	}
64 64
 
65 65
 	public function show_notification() {
66
-		$settings_url = admin_url( 'admin.php?page=wl_configuration_admin_menu' );
66
+		$settings_url = admin_url('admin.php?page=wl_configuration_admin_menu');
67 67
 		?>
68 68
 		<div class="wl-notice notice is-dismissible error">
69 69
 			<p>
70 70
 				<?php
71 71
 				/* translators: %s: the link to the WordLift configuration screen. */
72
-				echo wp_kses( sprintf( __( "Your WordLift key is not valid, please update the key in <a href='%s'>WordLift Settings</a> or contact our support at [email protected].", 'wordlift' ), esc_attr( $settings_url ) ), array( 'a' => array( 'href' ) ) );
72
+				echo wp_kses(sprintf(__("Your WordLift key is not valid, please update the key in <a href='%s'>WordLift Settings</a> or contact our support at [email protected].", 'wordlift'), esc_attr($settings_url)), array('a' => array('href')));
73 73
 				?>
74 74
 			</p>
75 75
 			<button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span>
@@ -84,16 +84,16 @@  discard block
 block discarded – undo
84 84
 
85 85
 		// Check cache if the result is present, if not get the results
86 86
 		// save it and return the data.
87
-		if ( $this->ttl_cache_service->get( self::CACHE_KEY ) !== null ) {
88
-			return $this->ttl_cache_service->get( self::CACHE_KEY );
87
+		if ($this->ttl_cache_service->get(self::CACHE_KEY) !== null) {
88
+			return $this->ttl_cache_service->get(self::CACHE_KEY);
89 89
 		}
90 90
 
91
-		$is_valid = $this->key_validation_service->is_key_valid( $key );
91
+		$is_valid = $this->key_validation_service->is_key_valid($key);
92 92
 
93 93
 		// when the cache is set, clear the notification flag.
94
-		delete_option( self::NOTIFICATION_OPTION_KEY );
94
+		delete_option(self::NOTIFICATION_OPTION_KEY);
95 95
 
96
-		$this->ttl_cache_service->put( self::CACHE_KEY, $is_valid );
96
+		$this->ttl_cache_service->put(self::CACHE_KEY, $is_valid);
97 97
 
98 98
 		return $is_valid;
99 99
 	}
@@ -102,22 +102,22 @@  discard block
 block discarded – undo
102 102
 		$that = $this;
103 103
 		add_action(
104 104
 			'admin_notices',
105
-			function () use ( $that ) {
105
+			function() use ($that) {
106 106
 
107
-				$is_notification_shown = get_option( Key_Validation_Notice::NOTIFICATION_OPTION_KEY, false );
107
+				$is_notification_shown = get_option(Key_Validation_Notice::NOTIFICATION_OPTION_KEY, false);
108 108
 
109 109
 				$key = $that->configuration_service->get_key();
110 110
 
111
-				if ( ! $key ) {
111
+				if ( ! $key) {
112 112
 					// Dont show warning or make API call, return early.
113 113
 					return;
114 114
 				}
115 115
 
116
-				if ( $that->is_key_valid() ) {
116
+				if ($that->is_key_valid()) {
117 117
 					return;
118 118
 				}
119 119
 
120
-				if ( $is_notification_shown ) {
120
+				if ($is_notification_shown) {
121 121
 					return;
122 122
 				}
123 123
 
@@ -128,20 +128,20 @@  discard block
 block discarded – undo
128 128
 	}
129 129
 
130 130
 	public function notification_close_handler() {
131
-		if ( ! isset( $_GET['wl_key_validation_notice'] )
132
-			 || ! isset( $_GET['_wl_key_validation_notice_nonce'] ) ) {
131
+		if ( ! isset($_GET['wl_key_validation_notice'])
132
+			 || ! isset($_GET['_wl_key_validation_notice_nonce'])) {
133 133
 			return false;
134 134
 		}
135
-		$nonce = sanitize_text_field( wp_unslash( (string) $_GET['_wl_key_validation_notice_nonce'] ) );
136
-		if ( wp_verify_nonce( $nonce, self::KEY_VALIDATION_NONCE_ACTION )
137
-			 && current_user_can( 'manage_options' ) ) {
135
+		$nonce = sanitize_text_field(wp_unslash((string) $_GET['_wl_key_validation_notice_nonce']));
136
+		if (wp_verify_nonce($nonce, self::KEY_VALIDATION_NONCE_ACTION)
137
+			 && current_user_can('manage_options')) {
138 138
 			// close the notification.
139
-			update_option( self::NOTIFICATION_OPTION_KEY, true );
139
+			update_option(self::NOTIFICATION_OPTION_KEY, true);
140 140
 		}
141 141
 	}
142 142
 
143 143
 	public static function remove_notification_flag() {
144
-		delete_option( self::NOTIFICATION_OPTION_KEY );
144
+		delete_option(self::NOTIFICATION_OPTION_KEY);
145 145
 	}
146 146
 
147 147
 }
Please login to merge, or discard this patch.
src/wordlift/admin/class-top-entities.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -8,23 +8,23 @@  discard block
 block discarded – undo
8 8
  */
9 9
 class Top_Entities {
10 10
 
11
-	const CRON_ACTION = 'wl_admin_dashboard_top_entities';
11
+    const CRON_ACTION = 'wl_admin_dashboard_top_entities';
12 12
 
13
-	/**
14
-	 * Option key where the top entities data is stored.
15
-	 */
16
-	const OPTION_KEY = 'wl_admin_dashboard_top_entities_option';
13
+    /**
14
+     * Option key where the top entities data is stored.
15
+     */
16
+    const OPTION_KEY = 'wl_admin_dashboard_top_entities_option';
17 17
 
18
-	public function __construct() {
19
-		add_action( self::CRON_ACTION, array( $this, 'save_top_entities' ) );
20
-	}
18
+    public function __construct() {
19
+        add_action( self::CRON_ACTION, array( $this, 'save_top_entities' ) );
20
+    }
21 21
 
22
-	public function save_top_entities() {
22
+    public function save_top_entities() {
23 23
 
24
-		global $wpdb;
24
+        global $wpdb;
25 25
 
26
-		$results = $wpdb->get_results(
27
-			"
26
+        $results = $wpdb->get_results(
27
+            "
28 28
 			SELECT p_as_object.ID
29 29
 			    , p_as_object.post_title
30 30
 			    , COALESCE(SUM(CASE WHEN t_as_subject.slug IS NULL THEN 1 END), 0)     entities
@@ -49,20 +49,20 @@  discard block
 block discarded – undo
49 49
 			ORDER BY total DESC
50 50
 			LIMIT 20
51 51
 		"
52
-		);
52
+        );
53 53
 
54
-		update_option( self::OPTION_KEY, $results );
55
-	}
54
+        update_option( self::OPTION_KEY, $results );
55
+    }
56 56
 
57
-	public static function activate() {
58
-		if ( ! wp_next_scheduled( self::CRON_ACTION ) ) {
59
-			wp_schedule_event( time(), 'daily', self::CRON_ACTION );
60
-		}
61
-	}
57
+    public static function activate() {
58
+        if ( ! wp_next_scheduled( self::CRON_ACTION ) ) {
59
+            wp_schedule_event( time(), 'daily', self::CRON_ACTION );
60
+        }
61
+    }
62 62
 
63
-	public static function deactivate() {
64
-		$timestamp = wp_next_scheduled( self::CRON_ACTION );
65
-		wp_unschedule_event( $timestamp, self::CRON_ACTION );
66
-	}
63
+    public static function deactivate() {
64
+        $timestamp = wp_next_scheduled( self::CRON_ACTION );
65
+        wp_unschedule_event( $timestamp, self::CRON_ACTION );
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 	const OPTION_KEY = 'wl_admin_dashboard_top_entities_option';
17 17
 
18 18
 	public function __construct() {
19
-		add_action( self::CRON_ACTION, array( $this, 'save_top_entities' ) );
19
+		add_action(self::CRON_ACTION, array($this, 'save_top_entities'));
20 20
 	}
21 21
 
22 22
 	public function save_top_entities() {
@@ -51,18 +51,18 @@  discard block
 block discarded – undo
51 51
 		"
52 52
 		);
53 53
 
54
-		update_option( self::OPTION_KEY, $results );
54
+		update_option(self::OPTION_KEY, $results);
55 55
 	}
56 56
 
57 57
 	public static function activate() {
58
-		if ( ! wp_next_scheduled( self::CRON_ACTION ) ) {
59
-			wp_schedule_event( time(), 'daily', self::CRON_ACTION );
58
+		if ( ! wp_next_scheduled(self::CRON_ACTION)) {
59
+			wp_schedule_event(time(), 'daily', self::CRON_ACTION);
60 60
 		}
61 61
 	}
62 62
 
63 63
 	public static function deactivate() {
64
-		$timestamp = wp_next_scheduled( self::CRON_ACTION );
65
-		wp_unschedule_event( $timestamp, self::CRON_ACTION );
64
+		$timestamp = wp_next_scheduled(self::CRON_ACTION);
65
+		wp_unschedule_event($timestamp, self::CRON_ACTION);
66 66
 	}
67 67
 
68 68
 }
Please login to merge, or discard this patch.
src/wordlift/admin/class-admin-user-option.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -8,55 +8,55 @@
 block discarded – undo
8 8
  */
9 9
 class Admin_User_Option {
10 10
 
11
-	const WORDLIFT_ADMIN = 'wl_is_wordlift_admin';
12
-
13
-	public static function is_wordlift_admin() {
14
-		return intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
15
-	}
16
-
17
-	public function connect_hook() {
18
-		add_action( 'wordlift_user_settings_page', array( $this, 'render_checkbox' ) );
19
-		add_action( 'edit_user_profile_update', array( $this, 'save_checkbox' ) );
20
-		add_action( 'personal_options_update', array( $this, 'save_checkbox' ) );
21
-	}
22
-
23
-	public function save_checkbox() {
24
-
25
-		if ( ! current_user_can( 'manage_options' ) ) {
26
-			return;
27
-		}
28
-
29
-		if ( ! isset( $_POST[ self::WORDLIFT_ADMIN ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
30
-			delete_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN );
31
-
32
-			return;
33
-		}
34
-		update_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, 1 );
35
-	}
36
-
37
-	public function render_checkbox() {
38
-		if ( ! current_user_can( 'manage_options' ) ) {
39
-			return;
40
-		}
41
-		$is_checked   = intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
42
-		$allowed_html = array(
43
-			'tr'    => array(),
44
-			'th'    => array(),
45
-			'td'    => array(),
46
-			'input' => array(
47
-				'type'    => array(),
48
-				'name'    => array(),
49
-				'checked' => array(),
50
-			),
51
-		);
52
-		echo wp_kses( $this->get_checkbox( $is_checked ), $allowed_html );
53
-	}
54
-
55
-	public static function get_checkbox( $is_checked ) {
56
-		$checked    = $is_checked ? "checked='checked'" : '';
57
-		$admin_text = __( 'Wordlift Admin', 'wordlift' );
58
-
59
-		return "<tr><th>$admin_text</th><td><input type='checkbox' name='wl_is_wordlift_admin' $checked></td></tr>";
60
-	}
11
+    const WORDLIFT_ADMIN = 'wl_is_wordlift_admin';
12
+
13
+    public static function is_wordlift_admin() {
14
+        return intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
15
+    }
16
+
17
+    public function connect_hook() {
18
+        add_action( 'wordlift_user_settings_page', array( $this, 'render_checkbox' ) );
19
+        add_action( 'edit_user_profile_update', array( $this, 'save_checkbox' ) );
20
+        add_action( 'personal_options_update', array( $this, 'save_checkbox' ) );
21
+    }
22
+
23
+    public function save_checkbox() {
24
+
25
+        if ( ! current_user_can( 'manage_options' ) ) {
26
+            return;
27
+        }
28
+
29
+        if ( ! isset( $_POST[ self::WORDLIFT_ADMIN ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
30
+            delete_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN );
31
+
32
+            return;
33
+        }
34
+        update_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, 1 );
35
+    }
36
+
37
+    public function render_checkbox() {
38
+        if ( ! current_user_can( 'manage_options' ) ) {
39
+            return;
40
+        }
41
+        $is_checked   = intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
42
+        $allowed_html = array(
43
+            'tr'    => array(),
44
+            'th'    => array(),
45
+            'td'    => array(),
46
+            'input' => array(
47
+                'type'    => array(),
48
+                'name'    => array(),
49
+                'checked' => array(),
50
+            ),
51
+        );
52
+        echo wp_kses( $this->get_checkbox( $is_checked ), $allowed_html );
53
+    }
54
+
55
+    public static function get_checkbox( $is_checked ) {
56
+        $checked    = $is_checked ? "checked='checked'" : '';
57
+        $admin_text = __( 'Wordlift Admin', 'wordlift' );
58
+
59
+        return "<tr><th>$admin_text</th><td><input type='checkbox' name='wl_is_wordlift_admin' $checked></td></tr>";
60
+    }
61 61
 
62 62
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,34 +11,34 @@  discard block
 block discarded – undo
11 11
 	const WORDLIFT_ADMIN = 'wl_is_wordlift_admin';
12 12
 
13 13
 	public static function is_wordlift_admin() {
14
-		return intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
14
+		return intval(get_user_meta(get_current_user_id(), self::WORDLIFT_ADMIN, true)) === 1;
15 15
 	}
16 16
 
17 17
 	public function connect_hook() {
18
-		add_action( 'wordlift_user_settings_page', array( $this, 'render_checkbox' ) );
19
-		add_action( 'edit_user_profile_update', array( $this, 'save_checkbox' ) );
20
-		add_action( 'personal_options_update', array( $this, 'save_checkbox' ) );
18
+		add_action('wordlift_user_settings_page', array($this, 'render_checkbox'));
19
+		add_action('edit_user_profile_update', array($this, 'save_checkbox'));
20
+		add_action('personal_options_update', array($this, 'save_checkbox'));
21 21
 	}
22 22
 
23 23
 	public function save_checkbox() {
24 24
 
25
-		if ( ! current_user_can( 'manage_options' ) ) {
25
+		if ( ! current_user_can('manage_options')) {
26 26
 			return;
27 27
 		}
28 28
 
29
-		if ( ! isset( $_POST[ self::WORDLIFT_ADMIN ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
30
-			delete_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN );
29
+		if ( ! isset($_POST[self::WORDLIFT_ADMIN])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
30
+			delete_user_meta(get_current_user_id(), self::WORDLIFT_ADMIN);
31 31
 
32 32
 			return;
33 33
 		}
34
-		update_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, 1 );
34
+		update_user_meta(get_current_user_id(), self::WORDLIFT_ADMIN, 1);
35 35
 	}
36 36
 
37 37
 	public function render_checkbox() {
38
-		if ( ! current_user_can( 'manage_options' ) ) {
38
+		if ( ! current_user_can('manage_options')) {
39 39
 			return;
40 40
 		}
41
-		$is_checked   = intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
41
+		$is_checked   = intval(get_user_meta(get_current_user_id(), self::WORDLIFT_ADMIN, true)) === 1;
42 42
 		$allowed_html = array(
43 43
 			'tr'    => array(),
44 44
 			'th'    => array(),
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
 				'checked' => array(),
50 50
 			),
51 51
 		);
52
-		echo wp_kses( $this->get_checkbox( $is_checked ), $allowed_html );
52
+		echo wp_kses($this->get_checkbox($is_checked), $allowed_html);
53 53
 	}
54 54
 
55
-	public static function get_checkbox( $is_checked ) {
55
+	public static function get_checkbox($is_checked) {
56 56
 		$checked    = $is_checked ? "checked='checked'" : '';
57
-		$admin_text = __( 'Wordlift Admin', 'wordlift' );
57
+		$admin_text = __('Wordlift Admin', 'wordlift');
58 58
 
59 59
 		return "<tr><th>$admin_text</th><td><input type='checkbox' name='wl_is_wordlift_admin' $checked></td></tr>";
60 60
 	}
Please login to merge, or discard this patch.
src/wordlift/class-assertions.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -15,84 +15,84 @@
 block discarded – undo
15 15
 
16 16
 class Assertions {
17 17
 
18
-	/**
19
-	 * Asserts that the provided value is of the specified type.
20
-	 *
21
-	 * @param mixed  $value The value to test.
22
-	 * @param string $type The expected type.
23
-	 *
24
-	 * @throws Exception when an error occurs.
25
-	 */
26
-	public static function assert_of_type( $value, $type ) {
27
-
28
-		// Check for nulls.
29
-		if ( null === $value ) {
30
-			throw new Exception( 'Value can`t be null.' );
31
-		}
32
-
33
-		// Check for type.
34
-		if ( get_class( $value ) !== $type ) {
35
-			throw new Exception( "Value must be a $type." );
36
-		}
37
-
38
-	}
39
-
40
-	/**
41
-	 * @throws Exception when the argument is not a string.
42
-	 */
43
-	public static function is_string( $arg, $message = 'Value must be a string' ) {
44
-		if ( ! is_string( $arg ) ) {
45
-			throw new Exception( $message );
46
-		}
47
-	}
48
-
49
-	/**
50
-	 * @throws Exception when actual doesn't match expected.
51
-	 */
52
-	public static function equals( $actual, $expected, $message = 'Values do not match' ) {
53
-		if ( $actual !== $expected ) {
54
-			throw new Exception( $message );
55
-		}
56
-	}
57
-
58
-	/**
59
-	 * @throws Exception when the value doesn't match the pattern.
60
-	 */
61
-	public static function matches( $value, $pattern, $message = "Value doesn't match" ) {
62
-		if ( 1 !== preg_match( $pattern, $value ) ) {
63
-			throw new Exception( $message );
64
-		}
65
-
66
-	}
67
-
68
-	/**
69
-	 * @throws Exception when the value doesn't start with the provided scope.
70
-	 */
71
-	public static function starts_with( $value, $scope, $message = "Value doesn't start with provided scope" ) {
72
-		if ( 0 !== strpos( $value, $scope ) ) {
73
-			throw new Exception( $message );
74
-		}
75
-	}
76
-
77
-	/**
78
-	 * @throws Exception when the value is not of the specified type.
79
-	 */
80
-	public static function is_a( $value, $type, $message = 'Value is not of the required type' ) {
81
-		if ( ! is_a( $value, $type ) ) {
82
-			throw new Exception( $message );
83
-		}
84
-	}
85
-
86
-	public static function is_set( $value, $message = 'Value is not set' ) {
87
-		if ( ! isset( $value ) ) {
88
-			throw new Exception( $message );
89
-		}
90
-	}
91
-
92
-	public static function not_empty( $value, $message = "Value can't be empty" ) {
93
-		if ( empty( $value ) ) {
94
-			throw new Exception( $message );
95
-		}
96
-	}
18
+    /**
19
+     * Asserts that the provided value is of the specified type.
20
+     *
21
+     * @param mixed  $value The value to test.
22
+     * @param string $type The expected type.
23
+     *
24
+     * @throws Exception when an error occurs.
25
+     */
26
+    public static function assert_of_type( $value, $type ) {
27
+
28
+        // Check for nulls.
29
+        if ( null === $value ) {
30
+            throw new Exception( 'Value can`t be null.' );
31
+        }
32
+
33
+        // Check for type.
34
+        if ( get_class( $value ) !== $type ) {
35
+            throw new Exception( "Value must be a $type." );
36
+        }
37
+
38
+    }
39
+
40
+    /**
41
+     * @throws Exception when the argument is not a string.
42
+     */
43
+    public static function is_string( $arg, $message = 'Value must be a string' ) {
44
+        if ( ! is_string( $arg ) ) {
45
+            throw new Exception( $message );
46
+        }
47
+    }
48
+
49
+    /**
50
+     * @throws Exception when actual doesn't match expected.
51
+     */
52
+    public static function equals( $actual, $expected, $message = 'Values do not match' ) {
53
+        if ( $actual !== $expected ) {
54
+            throw new Exception( $message );
55
+        }
56
+    }
57
+
58
+    /**
59
+     * @throws Exception when the value doesn't match the pattern.
60
+     */
61
+    public static function matches( $value, $pattern, $message = "Value doesn't match" ) {
62
+        if ( 1 !== preg_match( $pattern, $value ) ) {
63
+            throw new Exception( $message );
64
+        }
65
+
66
+    }
67
+
68
+    /**
69
+     * @throws Exception when the value doesn't start with the provided scope.
70
+     */
71
+    public static function starts_with( $value, $scope, $message = "Value doesn't start with provided scope" ) {
72
+        if ( 0 !== strpos( $value, $scope ) ) {
73
+            throw new Exception( $message );
74
+        }
75
+    }
76
+
77
+    /**
78
+     * @throws Exception when the value is not of the specified type.
79
+     */
80
+    public static function is_a( $value, $type, $message = 'Value is not of the required type' ) {
81
+        if ( ! is_a( $value, $type ) ) {
82
+            throw new Exception( $message );
83
+        }
84
+    }
85
+
86
+    public static function is_set( $value, $message = 'Value is not set' ) {
87
+        if ( ! isset( $value ) ) {
88
+            throw new Exception( $message );
89
+        }
90
+    }
91
+
92
+    public static function not_empty( $value, $message = "Value can't be empty" ) {
93
+        if ( empty( $value ) ) {
94
+            throw new Exception( $message );
95
+        }
96
+    }
97 97
 
98 98
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @throws Exception when an error occurs.
25 25
 	 */
26
-	public static function assert_of_type( $value, $type ) {
26
+	public static function assert_of_type($value, $type) {
27 27
 
28 28
 		// Check for nulls.
29
-		if ( null === $value ) {
30
-			throw new Exception( 'Value can`t be null.' );
29
+		if (null === $value) {
30
+			throw new Exception('Value can`t be null.');
31 31
 		}
32 32
 
33 33
 		// Check for type.
34
-		if ( get_class( $value ) !== $type ) {
35
-			throw new Exception( "Value must be a $type." );
34
+		if (get_class($value) !== $type) {
35
+			throw new Exception("Value must be a $type.");
36 36
 		}
37 37
 
38 38
 	}
@@ -40,27 +40,27 @@  discard block
 block discarded – undo
40 40
 	/**
41 41
 	 * @throws Exception when the argument is not a string.
42 42
 	 */
43
-	public static function is_string( $arg, $message = 'Value must be a string' ) {
44
-		if ( ! is_string( $arg ) ) {
45
-			throw new Exception( $message );
43
+	public static function is_string($arg, $message = 'Value must be a string') {
44
+		if ( ! is_string($arg)) {
45
+			throw new Exception($message);
46 46
 		}
47 47
 	}
48 48
 
49 49
 	/**
50 50
 	 * @throws Exception when actual doesn't match expected.
51 51
 	 */
52
-	public static function equals( $actual, $expected, $message = 'Values do not match' ) {
53
-		if ( $actual !== $expected ) {
54
-			throw new Exception( $message );
52
+	public static function equals($actual, $expected, $message = 'Values do not match') {
53
+		if ($actual !== $expected) {
54
+			throw new Exception($message);
55 55
 		}
56 56
 	}
57 57
 
58 58
 	/**
59 59
 	 * @throws Exception when the value doesn't match the pattern.
60 60
 	 */
61
-	public static function matches( $value, $pattern, $message = "Value doesn't match" ) {
62
-		if ( 1 !== preg_match( $pattern, $value ) ) {
63
-			throw new Exception( $message );
61
+	public static function matches($value, $pattern, $message = "Value doesn't match") {
62
+		if (1 !== preg_match($pattern, $value)) {
63
+			throw new Exception($message);
64 64
 		}
65 65
 
66 66
 	}
@@ -68,30 +68,30 @@  discard block
 block discarded – undo
68 68
 	/**
69 69
 	 * @throws Exception when the value doesn't start with the provided scope.
70 70
 	 */
71
-	public static function starts_with( $value, $scope, $message = "Value doesn't start with provided scope" ) {
72
-		if ( 0 !== strpos( $value, $scope ) ) {
73
-			throw new Exception( $message );
71
+	public static function starts_with($value, $scope, $message = "Value doesn't start with provided scope") {
72
+		if (0 !== strpos($value, $scope)) {
73
+			throw new Exception($message);
74 74
 		}
75 75
 	}
76 76
 
77 77
 	/**
78 78
 	 * @throws Exception when the value is not of the specified type.
79 79
 	 */
80
-	public static function is_a( $value, $type, $message = 'Value is not of the required type' ) {
81
-		if ( ! is_a( $value, $type ) ) {
82
-			throw new Exception( $message );
80
+	public static function is_a($value, $type, $message = 'Value is not of the required type') {
81
+		if ( ! is_a($value, $type)) {
82
+			throw new Exception($message);
83 83
 		}
84 84
 	}
85 85
 
86
-	public static function is_set( $value, $message = 'Value is not set' ) {
87
-		if ( ! isset( $value ) ) {
88
-			throw new Exception( $message );
86
+	public static function is_set($value, $message = 'Value is not set') {
87
+		if ( ! isset($value)) {
88
+			throw new Exception($message);
89 89
 		}
90 90
 	}
91 91
 
92
-	public static function not_empty( $value, $message = "Value can't be empty" ) {
93
-		if ( empty( $value ) ) {
94
-			throw new Exception( $message );
92
+	public static function not_empty($value, $message = "Value can't be empty") {
93
+		if (empty($value)) {
94
+			throw new Exception($message);
95 95
 		}
96 96
 	}
97 97
 
Please login to merge, or discard this patch.
src/wordlift/mappings/pages/class-admin-mappings-page.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -22,69 +22,69 @@
 block discarded – undo
22 22
  */
23 23
 class Admin_Mappings_Page extends Wordlift_Admin_Page {
24 24
 
25
-	/**
26
-	 * Provides script and js global values used by react component.
27
-	 */
28
-	public static function provide_ui_dependencies() {
29
-		// Create ui settings array to be used by js client.
30
-		$mapping_settings                          = array();
31
-		$mapping_settings['rest_url']              = get_rest_url(
32
-			null,
33
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . Mappings_REST_Controller::MAPPINGS_NAMESPACE
34
-		);
35
-		$mapping_settings['wl_mapping_nonce']      = wp_create_nonce( 'wp_rest' );
36
-		$mapping_settings['wl_edit_mapping_nonce'] = wp_create_nonce( 'wl-edit-mapping-nonce' );
37
-		wp_localize_script( 'wl-mappings-admin', 'wlMappingsConfig', $mapping_settings );
38
-	}
39
-
40
-	/**
41
-	 * {@inheritdoc}
42
-	 */
43
-	public function get_page_title() {
44
-
45
-		return __( 'Mappings', 'wordlift' );
46
-	}
47
-
48
-	/**
49
-	 * {@inheritdoc}
50
-	 */
51
-	public function get_menu_title() {
52
-
53
-		return __( 'Mappings', 'wordlift' );
54
-	}
55
-
56
-	/**
57
-	 * {@inheritdoc}
58
-	 */
59
-	public function get_menu_slug() {
60
-
61
-		return 'wl_mappings_admin';
62
-	}
63
-
64
-	/**
65
-	 * {@inheritdoc}
66
-	 */
67
-	public function get_partial_name() {
68
-
69
-		return 'wordlift-admin-mappings-admin.php';
70
-	}
71
-
72
-	public function enqueue_scripts() {
73
-
74
-		Scripts_Helper::enqueue_based_on_wordpress_version(
75
-			'wl-mappings-admin',
76
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings',
77
-			array( 'react', 'react-dom', 'wp-polyfill' ),
78
-			true
79
-		);
80
-
81
-		wp_enqueue_style(
82
-			'wl-mappings-admin',
83
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings.css',
84
-			array(),
85
-			WORDLIFT_VERSION
86
-		);
87
-		self::provide_ui_dependencies();
88
-	}
25
+    /**
26
+     * Provides script and js global values used by react component.
27
+     */
28
+    public static function provide_ui_dependencies() {
29
+        // Create ui settings array to be used by js client.
30
+        $mapping_settings                          = array();
31
+        $mapping_settings['rest_url']              = get_rest_url(
32
+            null,
33
+            WL_REST_ROUTE_DEFAULT_NAMESPACE . Mappings_REST_Controller::MAPPINGS_NAMESPACE
34
+        );
35
+        $mapping_settings['wl_mapping_nonce']      = wp_create_nonce( 'wp_rest' );
36
+        $mapping_settings['wl_edit_mapping_nonce'] = wp_create_nonce( 'wl-edit-mapping-nonce' );
37
+        wp_localize_script( 'wl-mappings-admin', 'wlMappingsConfig', $mapping_settings );
38
+    }
39
+
40
+    /**
41
+     * {@inheritdoc}
42
+     */
43
+    public function get_page_title() {
44
+
45
+        return __( 'Mappings', 'wordlift' );
46
+    }
47
+
48
+    /**
49
+     * {@inheritdoc}
50
+     */
51
+    public function get_menu_title() {
52
+
53
+        return __( 'Mappings', 'wordlift' );
54
+    }
55
+
56
+    /**
57
+     * {@inheritdoc}
58
+     */
59
+    public function get_menu_slug() {
60
+
61
+        return 'wl_mappings_admin';
62
+    }
63
+
64
+    /**
65
+     * {@inheritdoc}
66
+     */
67
+    public function get_partial_name() {
68
+
69
+        return 'wordlift-admin-mappings-admin.php';
70
+    }
71
+
72
+    public function enqueue_scripts() {
73
+
74
+        Scripts_Helper::enqueue_based_on_wordpress_version(
75
+            'wl-mappings-admin',
76
+            plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings',
77
+            array( 'react', 'react-dom', 'wp-polyfill' ),
78
+            true
79
+        );
80
+
81
+        wp_enqueue_style(
82
+            'wl-mappings-admin',
83
+            plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings.css',
84
+            array(),
85
+            WORDLIFT_VERSION
86
+        );
87
+        self::provide_ui_dependencies();
88
+    }
89 89
 
90 90
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,11 +30,11 @@  discard block
 block discarded – undo
30 30
 		$mapping_settings                          = array();
31 31
 		$mapping_settings['rest_url']              = get_rest_url(
32 32
 			null,
33
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . Mappings_REST_Controller::MAPPINGS_NAMESPACE
33
+			WL_REST_ROUTE_DEFAULT_NAMESPACE.Mappings_REST_Controller::MAPPINGS_NAMESPACE
34 34
 		);
35
-		$mapping_settings['wl_mapping_nonce']      = wp_create_nonce( 'wp_rest' );
36
-		$mapping_settings['wl_edit_mapping_nonce'] = wp_create_nonce( 'wl-edit-mapping-nonce' );
37
-		wp_localize_script( 'wl-mappings-admin', 'wlMappingsConfig', $mapping_settings );
35
+		$mapping_settings['wl_mapping_nonce']      = wp_create_nonce('wp_rest');
36
+		$mapping_settings['wl_edit_mapping_nonce'] = wp_create_nonce('wl-edit-mapping-nonce');
37
+		wp_localize_script('wl-mappings-admin', 'wlMappingsConfig', $mapping_settings);
38 38
 	}
39 39
 
40 40
 	/**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public function get_page_title() {
44 44
 
45
-		return __( 'Mappings', 'wordlift' );
45
+		return __('Mappings', 'wordlift');
46 46
 	}
47 47
 
48 48
 	/**
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function get_menu_title() {
52 52
 
53
-		return __( 'Mappings', 'wordlift' );
53
+		return __('Mappings', 'wordlift');
54 54
 	}
55 55
 
56 56
 	/**
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
73 73
 
74 74
 		Scripts_Helper::enqueue_based_on_wordpress_version(
75 75
 			'wl-mappings-admin',
76
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings',
77
-			array( 'react', 'react-dom', 'wp-polyfill' ),
76
+			plugin_dir_url(dirname(dirname(__DIR__))).'js/dist/mappings',
77
+			array('react', 'react-dom', 'wp-polyfill'),
78 78
 			true
79 79
 		);
80 80
 
81 81
 		wp_enqueue_style(
82 82
 			'wl-mappings-admin',
83
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings.css',
83
+			plugin_dir_url(dirname(dirname(__DIR__))).'js/dist/mappings.css',
84 84
 			array(),
85 85
 			WORDLIFT_VERSION
86 86
 		);
Please login to merge, or discard this patch.
src/wordlift/mappings/pages/class-edit-mappings-page.php 2 patches
Indentation   +392 added lines, -392 removed lines patch added patch discarded remove patch
@@ -24,397 +24,397 @@
 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
-	 *
29
-	 * @var Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance}
30
-	 */
31
-	public $transform_function_registry;
32
-
33
-	/**
34
-	 * Edit_Mappings_Page constructor.
35
-	 *
36
-	 * @param $transform_function_registry Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance }
37
-	 */
38
-	public function __construct( $transform_function_registry ) {
39
-		parent::__construct();
40
-		$this->transform_function_registry = $transform_function_registry;
41
-	}
42
-
43
-	public function render() {
44
-		// Render all the settings when this method is called, because the partial page is loaded after
45
-		// this method.
46
-		// Load the UI dependencies.
47
-		$edit_mapping_settings = $this->get_ui_settings_array();
48
-		// Supply the settings to js client.
49
-		wp_localize_script( 'wl-mappings-edit', 'wl_edit_mappings_config', $edit_mapping_settings );
50
-
51
-		parent::render();
52
-	}
53
-
54
-	/**
55
-	 * Load the text settings needed for the edit_mappings_page.
56
-	 *
57
-	 * @param array $edit_mapping_settings Key value pair of settings used by edit mappings page.
58
-	 *
59
-	 * @return array Adding text settings to the main settings array.
60
-	 */
61
-	private function load_text_settings_for_edit_mapping_page( array $edit_mapping_settings ) {
62
-		$edit_mapping_settings['wl_add_mapping_text']     = __( 'Add Mapping', 'wordlift' );
63
-		$edit_mapping_settings['wl_edit_mapping_text']    = __( 'Edit Mapping', 'wordlift' );
64
-		$edit_mapping_settings['wl_edit_mapping_no_item'] = __( 'Unable to find the mapping item', 'wordlift' );
65
-		$edit_mapping_settings['page']                    = 'wl_edit_mapping';
66
-
67
-		return $edit_mapping_settings;
68
-	}
69
-
70
-	/**
71
-	 * The base class {@link Wordlift_Admin_Page} will add the admin page to the WordLift menu.
72
-	 *
73
-	 * We don't want this page to be in the menu though. Therefore we override the `parent_slug` so that WordPress won't
74
-	 * show it there.
75
-	 *
76
-	 * @return null return null to avoid this page to be displayed in WordLift's menu.
77
-	 */
78
-	protected function get_parent_slug() {
79
-		return null;
80
-	}
81
-
82
-	/**
83
-	 * {@inheritdoc}
84
-	 */
85
-	public function get_page_title() {
86
-
87
-		return __( 'Edit Mappings', 'wordlift' );
88
-	}
89
-
90
-	/**
91
-	 * {@inheritdoc}
92
-	 */
93
-	public function get_menu_title() {
94
-
95
-		return __( 'Edit Mappings', 'wordlift' );
96
-	}
97
-
98
-	/**
99
-	 * {@inheritdoc}
100
-	 */
101
-	public function get_menu_slug() {
102
-
103
-		return 'wl_edit_mapping';
104
-	}
105
-
106
-	/**
107
-	 * {@inheritdoc}
108
-	 */
109
-	public function get_partial_name() {
110
-		return 'wordlift-admin-mappings-edit.php';
111
-	}
112
-
113
-	/**
114
-	 * {@inheritdoc}
115
-	 */
116
-	public function enqueue_scripts() {
117
-
118
-		// Enqueue the script.
119
-		Scripts_Helper::enqueue_based_on_wordpress_version(
120
-			'wl-mappings-edit',
121
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings-edit',
122
-			array( 'react', 'react-dom', 'wp-polyfill' ),
123
-			true
124
-		);
125
-
126
-		// Enqueue the style.
127
-		wp_enqueue_style(
128
-			'wl-mappings-edit',
129
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings-edit.css',
130
-			array(),
131
-			WORDLIFT_VERSION
132
-		);
133
-	}
134
-
135
-	/**
136
-	 * Returns field name options based on the chosen field type.
137
-	 * if string is returned a text field would be shown to user, if an array of options is returned
138
-	 * then the select box would be shown to user.
139
-	 *
140
-	 * @return array Array of the options.
141
-	 */
142
-	public static function get_all_field_name_options() {
143
-
144
-		$options = array(
145
-			array(
146
-				'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_TEXT_FIELD,
147
-				'value'      => '',
148
-				'label'      => __( 'Fixed Text', 'wordlift' ),
149
-			),
150
-			// @@todo maybe it makes sense to move this one as well to Wordlift/Mappings/Custom_Fields_Mappings.
151
-			array(
152
-				'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD,
153
-				'value'      => '',
154
-				'label'      => __( 'Custom Field', 'wordlift' ),
155
-			),
156
-		);
157
-
158
-		/**
159
-		 * Allow 3rd parties to add field types.
160
-		 *
161
-		 * @param array An array of Field Types.
162
-		 *
163
-		 * @return array An array of Field Types.
164
-		 *
165
-		 * @since 3.25.0
166
-		 */
167
-		return apply_filters( 'wl_mappings_field_types', $options );
168
-	}
169
-
170
-	/**
171
-	 * @return array An Array containing key value pairs of settings.
172
-	 * @since 3.25.0
173
-	 * Load dependencies required for js client.
174
-	 */
175
-	public function get_ui_settings_array() {
176
-		// Create ui settings array to be used by js client.
177
-		$edit_mapping_settings                                  = array();
178
-		$edit_mapping_settings                                  = $this->load_rest_settings( $edit_mapping_settings );
179
-		$edit_mapping_settings                                  = $this->load_text_settings_for_edit_mapping_page( $edit_mapping_settings );
180
-		$edit_mapping_settings['wl_transform_function_options'] = $this->transform_function_registry->get_options();
181
-		$edit_mapping_settings                                  = $this->load_field_type_and_name_options( $edit_mapping_settings );
182
-		// Load logic field options.
183
-		$edit_mapping_settings = $this->load_logic_field_options( $edit_mapping_settings );
184
-		$edit_mapping_settings = $this->load_rule_field_options( $edit_mapping_settings );
185
-
186
-		return $edit_mapping_settings;
187
-	}
188
-
189
-	/**
190
-	 * Returns post type, post category, or any other post taxonomies
191
-	 *
192
-	 * @return array An array of select options
193
-	 */
194
-	private static function get_post_taxonomies_and_terms() {
195
-		$taxonomy_options = array();
196
-		$term_options     = array();
197
-		$taxonomies       = get_object_taxonomies( 'post', 'objects' );
198
-
199
-		foreach ( $taxonomies as $taxonomy ) {
200
-			array_push(
201
-				$taxonomy_options,
202
-				array(
203
-					'label'      => $taxonomy->label,
204
-					'value'      => $taxonomy->name,
205
-					'api_source' => 'taxonomy',
206
-				)
207
-			);
208
-		}
209
-		// Post type is also included in the list of taxonomies, so get the post type and merge with options.
210
-		$post_type_array  = self::get_post_type_key_and_value();
211
-		$post_type_option = $post_type_array['post_type_option_name'];
212
-		// Get also the list of post types from the post_type_array.
213
-		$post_type_option_values = $post_type_array['post_type_option_values'];
214
-
215
-		$post_taxonomy_array  = self::get_post_taxonomy_key_and_value();
216
-		$post_taxonomy_option = $post_taxonomy_array['post_taxonomy_option_name'];
217
-
218
-		// Merge the post type option and post types in the taxonomy options
219
-		array_push( $taxonomy_options, $post_type_option, $post_taxonomy_option );
220
-		$term_options = array_merge( $term_options, $post_type_option_values );
221
-
222
-		return array(
223
-			'taxonomy_options' => $taxonomy_options,
224
-			'term_options'     => $term_options,
225
-		);
226
-	}
227
-
228
-	/**
229
-	 * Return post type option and post type option values.
230
-	 *
231
-	 * @return array Array of post_type_option and post_type_option_values.
232
-	 */
233
-	private static function get_post_type_key_and_value() {
234
-		$post_type_option_name   = array(
235
-			'label'      => __( 'Post type', 'wordlift' ),
236
-			'value'      => Wordlift\Mappings\Validators\Post_Type_Rule_Validator::POST_TYPE,
237
-			// Left empty since post types are provided locally.
238
-			'api_source' => '',
239
-		);
240
-		$post_type_option_values = array();
241
-		$post_types              = get_post_types(
242
-			array(),
243
-			'objects'
244
-		);
245
-
246
-		foreach ( $post_types as $post_type ) {
247
-			array_push(
248
-				$post_type_option_values,
249
-				array(
250
-					'label'        => $post_type->label,
251
-					'value'        => $post_type->name,
252
-					'parent_value' => 'post_type',
253
-				)
254
-			);
255
-		}
256
-
257
-		return array(
258
-			'post_type_option_name'   => $post_type_option_name,
259
-			'post_type_option_values' => $post_type_option_values,
260
-		);
261
-	}
262
-
263
-	/**
264
-	 * Return post type option and post type option values.
265
-	 *
266
-	 * @return array Array of post_type_option and post_type_option_values.
267
-	 */
268
-	private static function get_post_taxonomy_key_and_value() {
269
-
270
-		$post_taxonomy_option_name   = array(
271
-			'label'      => __( 'Post Taxonomy', 'wordlift' ),
272
-			'value'      => Wordlift\Mappings\Validators\Post_Taxonomy_Term_Rule_Validator::POST_TAXONOMY,
273
-			'api_source' => 'post_taxonomy',
274
-		);
275
-		$post_taxonomy_option_values = array();
276
-
277
-		return array(
278
-			'post_taxonomy_option_name'   => $post_taxonomy_option_name,
279
-			'post_taxonomy_option_values' => $post_taxonomy_option_values,
280
-		);
281
-	}
282
-
283
-	/**
284
-	 * This function loads the equal to, not equal to operator to the edit mapping settings.
285
-	 *
286
-	 * @param array $edit_mapping_settings
287
-	 *
288
-	 * @return array Loads the logic field options to the $edit_mapping_settings.
289
-	 */
290
-	private function load_logic_field_options( array $edit_mapping_settings ) {
291
-		$edit_mapping_settings['wl_logic_field_options'] = array(
292
-			array(
293
-				'label' => __( 'is equal to', 'wordlift' ),
294
-				'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_EQUAL_TO,
295
-			),
296
-			array(
297
-				'label' => __( 'is not equal to', 'wordlift' ),
298
-				'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_NOT_EQUAL_TO,
299
-			),
300
-		);
301
-
302
-		return $edit_mapping_settings;
303
-	}
304
-
305
-	/**
306
-	 * Validates the nonce posted by client and then assign the mapping id which should be edited.
307
-	 *
308
-	 * @param array $edit_mapping_settings
309
-	 *
310
-	 * @return array Edit mapping settings array with the mapping id if the nonce is valid.
311
-	 */
312
-	private function validate_nonce_and_assign_mapping_id( array $edit_mapping_settings ) {
313
-		// We verify the nonce before making to load the edit mapping page for the wl_edit_mapping_id
314
-		if ( isset( $_REQUEST['_wl_edit_mapping_nonce'] )
315
-			 && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wl_edit_mapping_nonce'] ) ), 'wl-edit-mapping-nonce' ) ) {
316
-			// We're using `INPUT_GET` here because this is a link from the UI, i.e. no POST.
317
-			$mapping_id                                  = isset( $_REQUEST['wl_edit_mapping_id'] ) ?
318
-				(int) filter_var( sanitize_text_field( wp_unslash( $_REQUEST['wl_edit_mapping_id'] ) ), FILTER_VALIDATE_INT ) : 0;
319
-			$edit_mapping_settings['wl_edit_mapping_id'] = $mapping_id;
320
-		}
321
-
322
-		return $edit_mapping_settings;
323
-	}
324
-
325
-	/**
326
-	 * Load the rest settings required for the edit_mappings js client.
327
-	 *
328
-	 * @param array $edit_mapping_settings
329
-	 *
330
-	 * @return array
331
-	 */
332
-	private function load_rest_settings( array $edit_mapping_settings ) {
333
-		$edit_mapping_settings['rest_url']                   = get_rest_url(
334
-			null,
335
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . Mappings_REST_Controller::MAPPINGS_NAMESPACE
336
-		);
337
-		$edit_mapping_settings['wl_edit_mapping_rest_nonce'] = wp_create_nonce( 'wp_rest' );
338
-		$edit_mapping_settings                               = $this->validate_nonce_and_assign_mapping_id( $edit_mapping_settings );
339
-
340
-		return $edit_mapping_settings;
341
-	}
342
-
343
-	/**
344
-	 * Load the rule field options in to the settings.
345
-	 *
346
-	 * @param array $edit_mapping_settings
347
-	 *
348
-	 * @return array Return the settings.
349
-	 */
350
-	private function load_rule_field_options( array $edit_mapping_settings ) {
351
-		// Load the rule field options.
352
-		$rule_field_data                                    = self::get_post_taxonomies_and_terms();
353
-		$edit_mapping_settings['wl_rule_field_one_options'] = $rule_field_data['taxonomy_options'];
354
-		$edit_mapping_settings['wl_rule_field_two_options'] = $rule_field_data['term_options'];
355
-
356
-		/**
357
-		 * Allow 3rd parties to add ui options.
358
-		 *
359
-		 * @param array Array of Rule field one options where each item is in format
360
-		 *
361
-		 *  array ( 'label' => string, 'value' => string, 'api_source'=>string);
362
-		 *
363
-		 *  Leave api_source empty string to ensure didnt fetch rule field two options
364
-		 *  from api.
365
-		 *
366
-		 * @return array Array of Rule field one options
367
-		 *
368
-		 * @since 3.27.0
369
-		 */
370
-		$edit_mapping_settings['wl_rule_field_one_options'] = apply_filters(
371
-			'wl_mappings_rule_field_one_options',
372
-			$edit_mapping_settings['wl_rule_field_one_options']
373
-		);
374
-
375
-		/**
376
-		 * Allow 3rd parties to add rule field two options.
377
-		 *
378
-		 * @param array Array of Rule field two option where each item is in format
379
-		 *
380
-		 * array ( 'label' => string, 'value' => string, 'parent_value' => string );
381
-		 *
382
-		 * where parent_value is the value of the parent option in the rule_field_one_option.
383
-		 *
384
-		 * @since 3.27.0
385
-		 */
386
-		$edit_mapping_settings['wl_rule_field_two_options'] = apply_filters(
387
-			'wl_mappings_rule_field_two_options',
388
-			$edit_mapping_settings['wl_rule_field_two_options']
389
-		);
390
-
391
-		return $edit_mapping_settings;
392
-	}
393
-
394
-	/**
395
-	 * Load field type and field name options to the settings array.
396
-	 *
397
-	 * @param array $edit_mapping_settings
398
-	 *
399
-	 * @return array
400
-	 */
401
-	private function load_field_type_and_name_options( array $edit_mapping_settings ) {
402
-		$all_field_name_options  = self::get_all_field_name_options();
403
-		$all_field_types_options = array_map(
404
-			function ( $item ) {
405
-				return array(
406
-					'label' => $item['label'],
407
-					'value' => $item['field_type'],
408
-				);
409
-			},
410
-			$all_field_name_options
411
-		);
412
-
413
-		$edit_mapping_settings['wl_field_type_options'] = $all_field_types_options;
414
-		// Add wl_edit_field_name_options.
415
-		$edit_mapping_settings['wl_field_name_options'] = $all_field_name_options;
416
-
417
-		return $edit_mapping_settings;
418
-	}
27
+    /** Instance to store the registry class.
28
+     *
29
+     * @var Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance}
30
+     */
31
+    public $transform_function_registry;
32
+
33
+    /**
34
+     * Edit_Mappings_Page constructor.
35
+     *
36
+     * @param $transform_function_registry Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance }
37
+     */
38
+    public function __construct( $transform_function_registry ) {
39
+        parent::__construct();
40
+        $this->transform_function_registry = $transform_function_registry;
41
+    }
42
+
43
+    public function render() {
44
+        // Render all the settings when this method is called, because the partial page is loaded after
45
+        // this method.
46
+        // Load the UI dependencies.
47
+        $edit_mapping_settings = $this->get_ui_settings_array();
48
+        // Supply the settings to js client.
49
+        wp_localize_script( 'wl-mappings-edit', 'wl_edit_mappings_config', $edit_mapping_settings );
50
+
51
+        parent::render();
52
+    }
53
+
54
+    /**
55
+     * Load the text settings needed for the edit_mappings_page.
56
+     *
57
+     * @param array $edit_mapping_settings Key value pair of settings used by edit mappings page.
58
+     *
59
+     * @return array Adding text settings to the main settings array.
60
+     */
61
+    private function load_text_settings_for_edit_mapping_page( array $edit_mapping_settings ) {
62
+        $edit_mapping_settings['wl_add_mapping_text']     = __( 'Add Mapping', 'wordlift' );
63
+        $edit_mapping_settings['wl_edit_mapping_text']    = __( 'Edit Mapping', 'wordlift' );
64
+        $edit_mapping_settings['wl_edit_mapping_no_item'] = __( 'Unable to find the mapping item', 'wordlift' );
65
+        $edit_mapping_settings['page']                    = 'wl_edit_mapping';
66
+
67
+        return $edit_mapping_settings;
68
+    }
69
+
70
+    /**
71
+     * The base class {@link Wordlift_Admin_Page} will add the admin page to the WordLift menu.
72
+     *
73
+     * We don't want this page to be in the menu though. Therefore we override the `parent_slug` so that WordPress won't
74
+     * show it there.
75
+     *
76
+     * @return null return null to avoid this page to be displayed in WordLift's menu.
77
+     */
78
+    protected function get_parent_slug() {
79
+        return null;
80
+    }
81
+
82
+    /**
83
+     * {@inheritdoc}
84
+     */
85
+    public function get_page_title() {
86
+
87
+        return __( 'Edit Mappings', 'wordlift' );
88
+    }
89
+
90
+    /**
91
+     * {@inheritdoc}
92
+     */
93
+    public function get_menu_title() {
94
+
95
+        return __( 'Edit Mappings', 'wordlift' );
96
+    }
97
+
98
+    /**
99
+     * {@inheritdoc}
100
+     */
101
+    public function get_menu_slug() {
102
+
103
+        return 'wl_edit_mapping';
104
+    }
105
+
106
+    /**
107
+     * {@inheritdoc}
108
+     */
109
+    public function get_partial_name() {
110
+        return 'wordlift-admin-mappings-edit.php';
111
+    }
112
+
113
+    /**
114
+     * {@inheritdoc}
115
+     */
116
+    public function enqueue_scripts() {
117
+
118
+        // Enqueue the script.
119
+        Scripts_Helper::enqueue_based_on_wordpress_version(
120
+            'wl-mappings-edit',
121
+            plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings-edit',
122
+            array( 'react', 'react-dom', 'wp-polyfill' ),
123
+            true
124
+        );
125
+
126
+        // Enqueue the style.
127
+        wp_enqueue_style(
128
+            'wl-mappings-edit',
129
+            plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings-edit.css',
130
+            array(),
131
+            WORDLIFT_VERSION
132
+        );
133
+    }
134
+
135
+    /**
136
+     * Returns field name options based on the chosen field type.
137
+     * if string is returned a text field would be shown to user, if an array of options is returned
138
+     * then the select box would be shown to user.
139
+     *
140
+     * @return array Array of the options.
141
+     */
142
+    public static function get_all_field_name_options() {
143
+
144
+        $options = array(
145
+            array(
146
+                'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_TEXT_FIELD,
147
+                'value'      => '',
148
+                'label'      => __( 'Fixed Text', 'wordlift' ),
149
+            ),
150
+            // @@todo maybe it makes sense to move this one as well to Wordlift/Mappings/Custom_Fields_Mappings.
151
+            array(
152
+                'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD,
153
+                'value'      => '',
154
+                'label'      => __( 'Custom Field', 'wordlift' ),
155
+            ),
156
+        );
157
+
158
+        /**
159
+         * Allow 3rd parties to add field types.
160
+         *
161
+         * @param array An array of Field Types.
162
+         *
163
+         * @return array An array of Field Types.
164
+         *
165
+         * @since 3.25.0
166
+         */
167
+        return apply_filters( 'wl_mappings_field_types', $options );
168
+    }
169
+
170
+    /**
171
+     * @return array An Array containing key value pairs of settings.
172
+     * @since 3.25.0
173
+     * Load dependencies required for js client.
174
+     */
175
+    public function get_ui_settings_array() {
176
+        // Create ui settings array to be used by js client.
177
+        $edit_mapping_settings                                  = array();
178
+        $edit_mapping_settings                                  = $this->load_rest_settings( $edit_mapping_settings );
179
+        $edit_mapping_settings                                  = $this->load_text_settings_for_edit_mapping_page( $edit_mapping_settings );
180
+        $edit_mapping_settings['wl_transform_function_options'] = $this->transform_function_registry->get_options();
181
+        $edit_mapping_settings                                  = $this->load_field_type_and_name_options( $edit_mapping_settings );
182
+        // Load logic field options.
183
+        $edit_mapping_settings = $this->load_logic_field_options( $edit_mapping_settings );
184
+        $edit_mapping_settings = $this->load_rule_field_options( $edit_mapping_settings );
185
+
186
+        return $edit_mapping_settings;
187
+    }
188
+
189
+    /**
190
+     * Returns post type, post category, or any other post taxonomies
191
+     *
192
+     * @return array An array of select options
193
+     */
194
+    private static function get_post_taxonomies_and_terms() {
195
+        $taxonomy_options = array();
196
+        $term_options     = array();
197
+        $taxonomies       = get_object_taxonomies( 'post', 'objects' );
198
+
199
+        foreach ( $taxonomies as $taxonomy ) {
200
+            array_push(
201
+                $taxonomy_options,
202
+                array(
203
+                    'label'      => $taxonomy->label,
204
+                    'value'      => $taxonomy->name,
205
+                    'api_source' => 'taxonomy',
206
+                )
207
+            );
208
+        }
209
+        // Post type is also included in the list of taxonomies, so get the post type and merge with options.
210
+        $post_type_array  = self::get_post_type_key_and_value();
211
+        $post_type_option = $post_type_array['post_type_option_name'];
212
+        // Get also the list of post types from the post_type_array.
213
+        $post_type_option_values = $post_type_array['post_type_option_values'];
214
+
215
+        $post_taxonomy_array  = self::get_post_taxonomy_key_and_value();
216
+        $post_taxonomy_option = $post_taxonomy_array['post_taxonomy_option_name'];
217
+
218
+        // Merge the post type option and post types in the taxonomy options
219
+        array_push( $taxonomy_options, $post_type_option, $post_taxonomy_option );
220
+        $term_options = array_merge( $term_options, $post_type_option_values );
221
+
222
+        return array(
223
+            'taxonomy_options' => $taxonomy_options,
224
+            'term_options'     => $term_options,
225
+        );
226
+    }
227
+
228
+    /**
229
+     * Return post type option and post type option values.
230
+     *
231
+     * @return array Array of post_type_option and post_type_option_values.
232
+     */
233
+    private static function get_post_type_key_and_value() {
234
+        $post_type_option_name   = array(
235
+            'label'      => __( 'Post type', 'wordlift' ),
236
+            'value'      => Wordlift\Mappings\Validators\Post_Type_Rule_Validator::POST_TYPE,
237
+            // Left empty since post types are provided locally.
238
+            'api_source' => '',
239
+        );
240
+        $post_type_option_values = array();
241
+        $post_types              = get_post_types(
242
+            array(),
243
+            'objects'
244
+        );
245
+
246
+        foreach ( $post_types as $post_type ) {
247
+            array_push(
248
+                $post_type_option_values,
249
+                array(
250
+                    'label'        => $post_type->label,
251
+                    'value'        => $post_type->name,
252
+                    'parent_value' => 'post_type',
253
+                )
254
+            );
255
+        }
256
+
257
+        return array(
258
+            'post_type_option_name'   => $post_type_option_name,
259
+            'post_type_option_values' => $post_type_option_values,
260
+        );
261
+    }
262
+
263
+    /**
264
+     * Return post type option and post type option values.
265
+     *
266
+     * @return array Array of post_type_option and post_type_option_values.
267
+     */
268
+    private static function get_post_taxonomy_key_and_value() {
269
+
270
+        $post_taxonomy_option_name   = array(
271
+            'label'      => __( 'Post Taxonomy', 'wordlift' ),
272
+            'value'      => Wordlift\Mappings\Validators\Post_Taxonomy_Term_Rule_Validator::POST_TAXONOMY,
273
+            'api_source' => 'post_taxonomy',
274
+        );
275
+        $post_taxonomy_option_values = array();
276
+
277
+        return array(
278
+            'post_taxonomy_option_name'   => $post_taxonomy_option_name,
279
+            'post_taxonomy_option_values' => $post_taxonomy_option_values,
280
+        );
281
+    }
282
+
283
+    /**
284
+     * This function loads the equal to, not equal to operator to the edit mapping settings.
285
+     *
286
+     * @param array $edit_mapping_settings
287
+     *
288
+     * @return array Loads the logic field options to the $edit_mapping_settings.
289
+     */
290
+    private function load_logic_field_options( array $edit_mapping_settings ) {
291
+        $edit_mapping_settings['wl_logic_field_options'] = array(
292
+            array(
293
+                'label' => __( 'is equal to', 'wordlift' ),
294
+                'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_EQUAL_TO,
295
+            ),
296
+            array(
297
+                'label' => __( 'is not equal to', 'wordlift' ),
298
+                'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_NOT_EQUAL_TO,
299
+            ),
300
+        );
301
+
302
+        return $edit_mapping_settings;
303
+    }
304
+
305
+    /**
306
+     * Validates the nonce posted by client and then assign the mapping id which should be edited.
307
+     *
308
+     * @param array $edit_mapping_settings
309
+     *
310
+     * @return array Edit mapping settings array with the mapping id if the nonce is valid.
311
+     */
312
+    private function validate_nonce_and_assign_mapping_id( array $edit_mapping_settings ) {
313
+        // We verify the nonce before making to load the edit mapping page for the wl_edit_mapping_id
314
+        if ( isset( $_REQUEST['_wl_edit_mapping_nonce'] )
315
+             && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wl_edit_mapping_nonce'] ) ), 'wl-edit-mapping-nonce' ) ) {
316
+            // We're using `INPUT_GET` here because this is a link from the UI, i.e. no POST.
317
+            $mapping_id                                  = isset( $_REQUEST['wl_edit_mapping_id'] ) ?
318
+                (int) filter_var( sanitize_text_field( wp_unslash( $_REQUEST['wl_edit_mapping_id'] ) ), FILTER_VALIDATE_INT ) : 0;
319
+            $edit_mapping_settings['wl_edit_mapping_id'] = $mapping_id;
320
+        }
321
+
322
+        return $edit_mapping_settings;
323
+    }
324
+
325
+    /**
326
+     * Load the rest settings required for the edit_mappings js client.
327
+     *
328
+     * @param array $edit_mapping_settings
329
+     *
330
+     * @return array
331
+     */
332
+    private function load_rest_settings( array $edit_mapping_settings ) {
333
+        $edit_mapping_settings['rest_url']                   = get_rest_url(
334
+            null,
335
+            WL_REST_ROUTE_DEFAULT_NAMESPACE . Mappings_REST_Controller::MAPPINGS_NAMESPACE
336
+        );
337
+        $edit_mapping_settings['wl_edit_mapping_rest_nonce'] = wp_create_nonce( 'wp_rest' );
338
+        $edit_mapping_settings                               = $this->validate_nonce_and_assign_mapping_id( $edit_mapping_settings );
339
+
340
+        return $edit_mapping_settings;
341
+    }
342
+
343
+    /**
344
+     * Load the rule field options in to the settings.
345
+     *
346
+     * @param array $edit_mapping_settings
347
+     *
348
+     * @return array Return the settings.
349
+     */
350
+    private function load_rule_field_options( array $edit_mapping_settings ) {
351
+        // Load the rule field options.
352
+        $rule_field_data                                    = self::get_post_taxonomies_and_terms();
353
+        $edit_mapping_settings['wl_rule_field_one_options'] = $rule_field_data['taxonomy_options'];
354
+        $edit_mapping_settings['wl_rule_field_two_options'] = $rule_field_data['term_options'];
355
+
356
+        /**
357
+         * Allow 3rd parties to add ui options.
358
+         *
359
+         * @param array Array of Rule field one options where each item is in format
360
+         *
361
+         *  array ( 'label' => string, 'value' => string, 'api_source'=>string);
362
+         *
363
+         *  Leave api_source empty string to ensure didnt fetch rule field two options
364
+         *  from api.
365
+         *
366
+         * @return array Array of Rule field one options
367
+         *
368
+         * @since 3.27.0
369
+         */
370
+        $edit_mapping_settings['wl_rule_field_one_options'] = apply_filters(
371
+            'wl_mappings_rule_field_one_options',
372
+            $edit_mapping_settings['wl_rule_field_one_options']
373
+        );
374
+
375
+        /**
376
+         * Allow 3rd parties to add rule field two options.
377
+         *
378
+         * @param array Array of Rule field two option where each item is in format
379
+         *
380
+         * array ( 'label' => string, 'value' => string, 'parent_value' => string );
381
+         *
382
+         * where parent_value is the value of the parent option in the rule_field_one_option.
383
+         *
384
+         * @since 3.27.0
385
+         */
386
+        $edit_mapping_settings['wl_rule_field_two_options'] = apply_filters(
387
+            'wl_mappings_rule_field_two_options',
388
+            $edit_mapping_settings['wl_rule_field_two_options']
389
+        );
390
+
391
+        return $edit_mapping_settings;
392
+    }
393
+
394
+    /**
395
+     * Load field type and field name options to the settings array.
396
+     *
397
+     * @param array $edit_mapping_settings
398
+     *
399
+     * @return array
400
+     */
401
+    private function load_field_type_and_name_options( array $edit_mapping_settings ) {
402
+        $all_field_name_options  = self::get_all_field_name_options();
403
+        $all_field_types_options = array_map(
404
+            function ( $item ) {
405
+                return array(
406
+                    'label' => $item['label'],
407
+                    'value' => $item['field_type'],
408
+                );
409
+            },
410
+            $all_field_name_options
411
+        );
412
+
413
+        $edit_mapping_settings['wl_field_type_options'] = $all_field_types_options;
414
+        // Add wl_edit_field_name_options.
415
+        $edit_mapping_settings['wl_field_name_options'] = $all_field_name_options;
416
+
417
+        return $edit_mapping_settings;
418
+    }
419 419
 
420 420
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param $transform_function_registry Mappings_Transform_Functions_Registry { @link Mappings_Transform_Functions_Registry instance }
37 37
 	 */
38
-	public function __construct( $transform_function_registry ) {
38
+	public function __construct($transform_function_registry) {
39 39
 		parent::__construct();
40 40
 		$this->transform_function_registry = $transform_function_registry;
41 41
 	}
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		// Load the UI dependencies.
47 47
 		$edit_mapping_settings = $this->get_ui_settings_array();
48 48
 		// Supply the settings to js client.
49
-		wp_localize_script( 'wl-mappings-edit', 'wl_edit_mappings_config', $edit_mapping_settings );
49
+		wp_localize_script('wl-mappings-edit', 'wl_edit_mappings_config', $edit_mapping_settings);
50 50
 
51 51
 		parent::render();
52 52
 	}
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @return array Adding text settings to the main settings array.
60 60
 	 */
61
-	private function load_text_settings_for_edit_mapping_page( array $edit_mapping_settings ) {
62
-		$edit_mapping_settings['wl_add_mapping_text']     = __( 'Add Mapping', 'wordlift' );
63
-		$edit_mapping_settings['wl_edit_mapping_text']    = __( 'Edit Mapping', 'wordlift' );
64
-		$edit_mapping_settings['wl_edit_mapping_no_item'] = __( 'Unable to find the mapping item', 'wordlift' );
61
+	private function load_text_settings_for_edit_mapping_page(array $edit_mapping_settings) {
62
+		$edit_mapping_settings['wl_add_mapping_text']     = __('Add Mapping', 'wordlift');
63
+		$edit_mapping_settings['wl_edit_mapping_text']    = __('Edit Mapping', 'wordlift');
64
+		$edit_mapping_settings['wl_edit_mapping_no_item'] = __('Unable to find the mapping item', 'wordlift');
65 65
 		$edit_mapping_settings['page']                    = 'wl_edit_mapping';
66 66
 
67 67
 		return $edit_mapping_settings;
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	public function get_page_title() {
86 86
 
87
-		return __( 'Edit Mappings', 'wordlift' );
87
+		return __('Edit Mappings', 'wordlift');
88 88
 	}
89 89
 
90 90
 	/**
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	public function get_menu_title() {
94 94
 
95
-		return __( 'Edit Mappings', 'wordlift' );
95
+		return __('Edit Mappings', 'wordlift');
96 96
 	}
97 97
 
98 98
 	/**
@@ -118,15 +118,15 @@  discard block
 block discarded – undo
118 118
 		// Enqueue the script.
119 119
 		Scripts_Helper::enqueue_based_on_wordpress_version(
120 120
 			'wl-mappings-edit',
121
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings-edit',
122
-			array( 'react', 'react-dom', 'wp-polyfill' ),
121
+			plugin_dir_url(dirname(dirname(__DIR__))).'js/dist/mappings-edit',
122
+			array('react', 'react-dom', 'wp-polyfill'),
123 123
 			true
124 124
 		);
125 125
 
126 126
 		// Enqueue the style.
127 127
 		wp_enqueue_style(
128 128
 			'wl-mappings-edit',
129
-			plugin_dir_url( dirname( dirname( __DIR__ ) ) ) . 'js/dist/mappings-edit.css',
129
+			plugin_dir_url(dirname(dirname(__DIR__))).'js/dist/mappings-edit.css',
130 130
 			array(),
131 131
 			WORDLIFT_VERSION
132 132
 		);
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 			array(
146 146
 				'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_TEXT_FIELD,
147 147
 				'value'      => '',
148
-				'label'      => __( 'Fixed Text', 'wordlift' ),
148
+				'label'      => __('Fixed Text', 'wordlift'),
149 149
 			),
150 150
 			// @@todo maybe it makes sense to move this one as well to Wordlift/Mappings/Custom_Fields_Mappings.
151 151
 			array(
152 152
 				'field_type' => Wordlift\Mappings\Jsonld_Converter::FIELD_TYPE_CUSTOM_FIELD,
153 153
 				'value'      => '',
154
-				'label'      => __( 'Custom Field', 'wordlift' ),
154
+				'label'      => __('Custom Field', 'wordlift'),
155 155
 			),
156 156
 		);
157 157
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 		 *
165 165
 		 * @since 3.25.0
166 166
 		 */
167
-		return apply_filters( 'wl_mappings_field_types', $options );
167
+		return apply_filters('wl_mappings_field_types', $options);
168 168
 	}
169 169
 
170 170
 	/**
@@ -175,13 +175,13 @@  discard block
 block discarded – undo
175 175
 	public function get_ui_settings_array() {
176 176
 		// Create ui settings array to be used by js client.
177 177
 		$edit_mapping_settings                                  = array();
178
-		$edit_mapping_settings                                  = $this->load_rest_settings( $edit_mapping_settings );
179
-		$edit_mapping_settings                                  = $this->load_text_settings_for_edit_mapping_page( $edit_mapping_settings );
178
+		$edit_mapping_settings                                  = $this->load_rest_settings($edit_mapping_settings);
179
+		$edit_mapping_settings                                  = $this->load_text_settings_for_edit_mapping_page($edit_mapping_settings);
180 180
 		$edit_mapping_settings['wl_transform_function_options'] = $this->transform_function_registry->get_options();
181
-		$edit_mapping_settings                                  = $this->load_field_type_and_name_options( $edit_mapping_settings );
181
+		$edit_mapping_settings                                  = $this->load_field_type_and_name_options($edit_mapping_settings);
182 182
 		// Load logic field options.
183
-		$edit_mapping_settings = $this->load_logic_field_options( $edit_mapping_settings );
184
-		$edit_mapping_settings = $this->load_rule_field_options( $edit_mapping_settings );
183
+		$edit_mapping_settings = $this->load_logic_field_options($edit_mapping_settings);
184
+		$edit_mapping_settings = $this->load_rule_field_options($edit_mapping_settings);
185 185
 
186 186
 		return $edit_mapping_settings;
187 187
 	}
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
 	private static function get_post_taxonomies_and_terms() {
195 195
 		$taxonomy_options = array();
196 196
 		$term_options     = array();
197
-		$taxonomies       = get_object_taxonomies( 'post', 'objects' );
197
+		$taxonomies       = get_object_taxonomies('post', 'objects');
198 198
 
199
-		foreach ( $taxonomies as $taxonomy ) {
199
+		foreach ($taxonomies as $taxonomy) {
200 200
 			array_push(
201 201
 				$taxonomy_options,
202 202
 				array(
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
 		$post_taxonomy_option = $post_taxonomy_array['post_taxonomy_option_name'];
217 217
 
218 218
 		// Merge the post type option and post types in the taxonomy options
219
-		array_push( $taxonomy_options, $post_type_option, $post_taxonomy_option );
220
-		$term_options = array_merge( $term_options, $post_type_option_values );
219
+		array_push($taxonomy_options, $post_type_option, $post_taxonomy_option);
220
+		$term_options = array_merge($term_options, $post_type_option_values);
221 221
 
222 222
 		return array(
223 223
 			'taxonomy_options' => $taxonomy_options,
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
 	 * @return array Array of post_type_option and post_type_option_values.
232 232
 	 */
233 233
 	private static function get_post_type_key_and_value() {
234
-		$post_type_option_name   = array(
235
-			'label'      => __( 'Post type', 'wordlift' ),
234
+		$post_type_option_name = array(
235
+			'label'      => __('Post type', 'wordlift'),
236 236
 			'value'      => Wordlift\Mappings\Validators\Post_Type_Rule_Validator::POST_TYPE,
237 237
 			// Left empty since post types are provided locally.
238 238
 			'api_source' => '',
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 			'objects'
244 244
 		);
245 245
 
246
-		foreach ( $post_types as $post_type ) {
246
+		foreach ($post_types as $post_type) {
247 247
 			array_push(
248 248
 				$post_type_option_values,
249 249
 				array(
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 	 */
268 268
 	private static function get_post_taxonomy_key_and_value() {
269 269
 
270
-		$post_taxonomy_option_name   = array(
271
-			'label'      => __( 'Post Taxonomy', 'wordlift' ),
270
+		$post_taxonomy_option_name = array(
271
+			'label'      => __('Post Taxonomy', 'wordlift'),
272 272
 			'value'      => Wordlift\Mappings\Validators\Post_Taxonomy_Term_Rule_Validator::POST_TAXONOMY,
273 273
 			'api_source' => 'post_taxonomy',
274 274
 		);
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
 	 *
288 288
 	 * @return array Loads the logic field options to the $edit_mapping_settings.
289 289
 	 */
290
-	private function load_logic_field_options( array $edit_mapping_settings ) {
290
+	private function load_logic_field_options(array $edit_mapping_settings) {
291 291
 		$edit_mapping_settings['wl_logic_field_options'] = array(
292 292
 			array(
293
-				'label' => __( 'is equal to', 'wordlift' ),
293
+				'label' => __('is equal to', 'wordlift'),
294 294
 				'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_EQUAL_TO,
295 295
 			),
296 296
 			array(
297
-				'label' => __( 'is not equal to', 'wordlift' ),
297
+				'label' => __('is not equal to', 'wordlift'),
298 298
 				'value' => Wordlift\Mappings\Validators\Rule_Validator::IS_NOT_EQUAL_TO,
299 299
 			),
300 300
 		);
@@ -309,13 +309,13 @@  discard block
 block discarded – undo
309 309
 	 *
310 310
 	 * @return array Edit mapping settings array with the mapping id if the nonce is valid.
311 311
 	 */
312
-	private function validate_nonce_and_assign_mapping_id( array $edit_mapping_settings ) {
312
+	private function validate_nonce_and_assign_mapping_id(array $edit_mapping_settings) {
313 313
 		// We verify the nonce before making to load the edit mapping page for the wl_edit_mapping_id
314
-		if ( isset( $_REQUEST['_wl_edit_mapping_nonce'] )
315
-			 && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wl_edit_mapping_nonce'] ) ), 'wl-edit-mapping-nonce' ) ) {
314
+		if (isset($_REQUEST['_wl_edit_mapping_nonce'])
315
+			 && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_wl_edit_mapping_nonce'])), 'wl-edit-mapping-nonce')) {
316 316
 			// We're using `INPUT_GET` here because this is a link from the UI, i.e. no POST.
317
-			$mapping_id                                  = isset( $_REQUEST['wl_edit_mapping_id'] ) ?
318
-				(int) filter_var( sanitize_text_field( wp_unslash( $_REQUEST['wl_edit_mapping_id'] ) ), FILTER_VALIDATE_INT ) : 0;
317
+			$mapping_id                                  = isset($_REQUEST['wl_edit_mapping_id']) ?
318
+				(int) filter_var(sanitize_text_field(wp_unslash($_REQUEST['wl_edit_mapping_id'])), FILTER_VALIDATE_INT) : 0;
319 319
 			$edit_mapping_settings['wl_edit_mapping_id'] = $mapping_id;
320 320
 		}
321 321
 
@@ -329,13 +329,13 @@  discard block
 block discarded – undo
329 329
 	 *
330 330
 	 * @return array
331 331
 	 */
332
-	private function load_rest_settings( array $edit_mapping_settings ) {
333
-		$edit_mapping_settings['rest_url']                   = get_rest_url(
332
+	private function load_rest_settings(array $edit_mapping_settings) {
333
+		$edit_mapping_settings['rest_url'] = get_rest_url(
334 334
 			null,
335
-			WL_REST_ROUTE_DEFAULT_NAMESPACE . Mappings_REST_Controller::MAPPINGS_NAMESPACE
335
+			WL_REST_ROUTE_DEFAULT_NAMESPACE.Mappings_REST_Controller::MAPPINGS_NAMESPACE
336 336
 		);
337
-		$edit_mapping_settings['wl_edit_mapping_rest_nonce'] = wp_create_nonce( 'wp_rest' );
338
-		$edit_mapping_settings                               = $this->validate_nonce_and_assign_mapping_id( $edit_mapping_settings );
337
+		$edit_mapping_settings['wl_edit_mapping_rest_nonce'] = wp_create_nonce('wp_rest');
338
+		$edit_mapping_settings                               = $this->validate_nonce_and_assign_mapping_id($edit_mapping_settings);
339 339
 
340 340
 		return $edit_mapping_settings;
341 341
 	}
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 	 *
348 348
 	 * @return array Return the settings.
349 349
 	 */
350
-	private function load_rule_field_options( array $edit_mapping_settings ) {
350
+	private function load_rule_field_options(array $edit_mapping_settings) {
351 351
 		// Load the rule field options.
352 352
 		$rule_field_data                                    = self::get_post_taxonomies_and_terms();
353 353
 		$edit_mapping_settings['wl_rule_field_one_options'] = $rule_field_data['taxonomy_options'];
@@ -398,10 +398,10 @@  discard block
 block discarded – undo
398 398
 	 *
399 399
 	 * @return array
400 400
 	 */
401
-	private function load_field_type_and_name_options( array $edit_mapping_settings ) {
401
+	private function load_field_type_and_name_options(array $edit_mapping_settings) {
402 402
 		$all_field_name_options  = self::get_all_field_name_options();
403 403
 		$all_field_types_options = array_map(
404
-			function ( $item ) {
404
+			function($item) {
405 405
 				return array(
406 406
 					'label' => $item['label'],
407 407
 					'value' => $item['field_type'],
Please login to merge, or discard this patch.
src/wordlift/mappings/validators/class-post-type-rule-validator.php 2 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -17,70 +17,70 @@
 block discarded – undo
17 17
  * @package Wordlift\Mappings\Validators
18 18
  */
19 19
 class Post_Type_Rule_Validator implements Rule_Validator {
20
-	/**
21
-	 * @since 3.25.0
22
-	 * Enum for the post type rule validator.
23
-	 */
24
-	const POST_TYPE = 'post_type';
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
-	 * Hook to `wl_mappings_rule_validators` to register ourselves.
39
-	 *
40
-	 * @param array $value An array with validators.
41
-	 *
42
-	 * @return array An array with validators plus ours.
43
-	 */
44
-	public function wl_mappings_rule_validators( $value ) {
45
-
46
-		$value[ self::POST_TYPE ] = $this;
47
-
48
-		return $value;
49
-	}
50
-
51
-	/**
52
-	 * {@inheritdoc}
53
-	 */
54
-	public function get_label() {
55
-		return __( 'Post Type', 'wordlift' );
56
-	}
57
-
58
-	/**
59
-	 * {@inheritdoc}
60
-	 */
61
-	public function is_valid( $identifier, $operator, $operand_1, $operand_2, $type ) {
62
-		/**
63
-		 * If this is not done then this will validate for term
64
-		 * which causes a bug, so this rule validator would return false
65
-		 * when the current thing is not a post.
66
-		 */
67
-		if ( Jsonld_Converter::POST !== $type ) {
68
-			return false;
69
-		}
70
-		// Get the post type and then check whether it matches or not according to the operator.
71
-		$post_type = get_post_type( $identifier );
72
-
73
-		switch ( $operator ) {
74
-			case Rule_Validator::IS_NOT_EQUAL_TO:
75
-				return $post_type !== $operand_2;
76
-
77
-			case Rule_Validator::IS_EQUAL_TO:
78
-				return $post_type === $operand_2;
79
-
80
-			default:
81
-		}
82
-
83
-		return false;
84
-	}
20
+    /**
21
+     * @since 3.25.0
22
+     * Enum for the post type rule validator.
23
+     */
24
+    const POST_TYPE = 'post_type';
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
+     * Hook to `wl_mappings_rule_validators` to register ourselves.
39
+     *
40
+     * @param array $value An array with validators.
41
+     *
42
+     * @return array An array with validators plus ours.
43
+     */
44
+    public function wl_mappings_rule_validators( $value ) {
45
+
46
+        $value[ self::POST_TYPE ] = $this;
47
+
48
+        return $value;
49
+    }
50
+
51
+    /**
52
+     * {@inheritdoc}
53
+     */
54
+    public function get_label() {
55
+        return __( 'Post Type', 'wordlift' );
56
+    }
57
+
58
+    /**
59
+     * {@inheritdoc}
60
+     */
61
+    public function is_valid( $identifier, $operator, $operand_1, $operand_2, $type ) {
62
+        /**
63
+         * If this is not done then this will validate for term
64
+         * which causes a bug, so this rule validator would return false
65
+         * when the current thing is not a post.
66
+         */
67
+        if ( Jsonld_Converter::POST !== $type ) {
68
+            return false;
69
+        }
70
+        // Get the post type and then check whether it matches or not according to the operator.
71
+        $post_type = get_post_type( $identifier );
72
+
73
+        switch ( $operator ) {
74
+            case Rule_Validator::IS_NOT_EQUAL_TO:
75
+                return $post_type !== $operand_2;
76
+
77
+            case Rule_Validator::IS_EQUAL_TO:
78
+                return $post_type === $operand_2;
79
+
80
+            default:
81
+        }
82
+
83
+        return false;
84
+    }
85 85
 
86 86
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 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
 
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @return array An array with validators plus ours.
43 43
 	 */
44
-	public function wl_mappings_rule_validators( $value ) {
44
+	public function wl_mappings_rule_validators($value) {
45 45
 
46
-		$value[ self::POST_TYPE ] = $this;
46
+		$value[self::POST_TYPE] = $this;
47 47
 
48 48
 		return $value;
49 49
 	}
@@ -52,25 +52,25 @@  discard block
 block discarded – undo
52 52
 	 * {@inheritdoc}
53 53
 	 */
54 54
 	public function get_label() {
55
-		return __( 'Post Type', 'wordlift' );
55
+		return __('Post Type', 'wordlift');
56 56
 	}
57 57
 
58 58
 	/**
59 59
 	 * {@inheritdoc}
60 60
 	 */
61
-	public function is_valid( $identifier, $operator, $operand_1, $operand_2, $type ) {
61
+	public function is_valid($identifier, $operator, $operand_1, $operand_2, $type) {
62 62
 		/**
63 63
 		 * If this is not done then this will validate for term
64 64
 		 * which causes a bug, so this rule validator would return false
65 65
 		 * when the current thing is not a post.
66 66
 		 */
67
-		if ( Jsonld_Converter::POST !== $type ) {
67
+		if (Jsonld_Converter::POST !== $type) {
68 68
 			return false;
69 69
 		}
70 70
 		// Get the post type and then check whether it matches or not according to the operator.
71
-		$post_type = get_post_type( $identifier );
71
+		$post_type = get_post_type($identifier);
72 72
 
73
-		switch ( $operator ) {
73
+		switch ($operator) {
74 74
 			case Rule_Validator::IS_NOT_EQUAL_TO:
75 75
 				return $post_type !== $operand_2;
76 76
 
Please login to merge, or discard this patch.
src/wordlift/mappings/validators/class-rule-validators-registry.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -18,43 +18,43 @@
 block discarded – undo
18 18
  */
19 19
 class Rule_Validators_Registry {
20 20
 
21
-	/**
22
-	 * An array of {@link Rule_Validator}s.
23
-	 *
24
-	 * @var array An array of {@link Rule_Validator}s.
25
-	 */
26
-	private $rule_validators;
27
-
28
-	/**
29
-	 * Rule_Validators_Registry constructor.
30
-	 *
31
-	 * @param Rule_Validator $default The default rule validator.
32
-	 *
33
-	 * @throws Exception throws an exception if an invalid validator has been provided.
34
-	 */
35
-	public function __construct( $default ) {
36
-
37
-		// Check that a valid validator has been provided.
38
-		if ( ! ( $default instanceof Rule_Validator ) ) {
39
-			throw new Exception( 'An invalid Rule_Validator was provided as default validator.' );
40
-		}
41
-
42
-		// Allow 3rd parties to register other validators.
43
-		$this->rule_validators = apply_filters( 'wl_mappings_rule_validators', array( '__default__' => $default ) );
44
-
45
-	}
46
-
47
-	/**
48
-	 * Get a rule validator by its key.
49
-	 *
50
-	 * @param string $key A key uniquely identifying a validator.
51
-	 *
52
-	 * @return Rule_Validator A {@link Rule_Validator} instance or the default one when not found.
53
-	 */
54
-	public function get_rule_validator( $key ) {
55
-
56
-		return isset( $this->rule_validators[ $key ] )
57
-			? $this->rule_validators[ $key ] : $this->rule_validators['__default__'];
58
-	}
21
+    /**
22
+     * An array of {@link Rule_Validator}s.
23
+     *
24
+     * @var array An array of {@link Rule_Validator}s.
25
+     */
26
+    private $rule_validators;
27
+
28
+    /**
29
+     * Rule_Validators_Registry constructor.
30
+     *
31
+     * @param Rule_Validator $default The default rule validator.
32
+     *
33
+     * @throws Exception throws an exception if an invalid validator has been provided.
34
+     */
35
+    public function __construct( $default ) {
36
+
37
+        // Check that a valid validator has been provided.
38
+        if ( ! ( $default instanceof Rule_Validator ) ) {
39
+            throw new Exception( 'An invalid Rule_Validator was provided as default validator.' );
40
+        }
41
+
42
+        // Allow 3rd parties to register other validators.
43
+        $this->rule_validators = apply_filters( 'wl_mappings_rule_validators', array( '__default__' => $default ) );
44
+
45
+    }
46
+
47
+    /**
48
+     * Get a rule validator by its key.
49
+     *
50
+     * @param string $key A key uniquely identifying a validator.
51
+     *
52
+     * @return Rule_Validator A {@link Rule_Validator} instance or the default one when not found.
53
+     */
54
+    public function get_rule_validator( $key ) {
55
+
56
+        return isset( $this->rule_validators[ $key ] )
57
+            ? $this->rule_validators[ $key ] : $this->rule_validators['__default__'];
58
+    }
59 59
 
60 60
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,15 +32,15 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @throws Exception throws an exception if an invalid validator has been provided.
34 34
 	 */
35
-	public function __construct( $default ) {
35
+	public function __construct($default) {
36 36
 
37 37
 		// Check that a valid validator has been provided.
38
-		if ( ! ( $default instanceof Rule_Validator ) ) {
39
-			throw new Exception( 'An invalid Rule_Validator was provided as default validator.' );
38
+		if ( ! ($default instanceof Rule_Validator)) {
39
+			throw new Exception('An invalid Rule_Validator was provided as default validator.');
40 40
 		}
41 41
 
42 42
 		// Allow 3rd parties to register other validators.
43
-		$this->rule_validators = apply_filters( 'wl_mappings_rule_validators', array( '__default__' => $default ) );
43
+		$this->rule_validators = apply_filters('wl_mappings_rule_validators', array('__default__' => $default));
44 44
 
45 45
 	}
46 46
 
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @return Rule_Validator A {@link Rule_Validator} instance or the default one when not found.
53 53
 	 */
54
-	public function get_rule_validator( $key ) {
54
+	public function get_rule_validator($key) {
55 55
 
56
-		return isset( $this->rule_validators[ $key ] )
57
-			? $this->rule_validators[ $key ] : $this->rule_validators['__default__'];
56
+		return isset($this->rule_validators[$key])
57
+			? $this->rule_validators[$key] : $this->rule_validators['__default__'];
58 58
 	}
59 59
 
60 60
 }
Please login to merge, or discard this patch.