Completed
Pull Request — develop (#1082)
by Naveen
03:05 queued 14s
created
src/wordlift/autocomplete/class-all-autocomplete-service.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -12,55 +12,55 @@
 block discarded – undo
12 12
 
13 13
 class All_Autocomplete_Service implements Autocomplete_Service {
14 14
 
15
-	/**
16
-	 * One ore more {@link Autocomplete_Service} instances.
17
-	 *
18
-	 * @var Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
19
-	 */
20
-	private $autocomplete_services;
15
+    /**
16
+     * One ore more {@link Autocomplete_Service} instances.
17
+     *
18
+     * @var Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
19
+     */
20
+    private $autocomplete_services;
21 21
 
22
-	/**
23
-	 * All_Autocomplete_Service constructor.
24
-	 *
25
-	 * @param Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
26
-	 */
27
-	public function __construct( $autocomplete_services ) {
22
+    /**
23
+     * All_Autocomplete_Service constructor.
24
+     *
25
+     * @param Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
26
+     */
27
+    public function __construct( $autocomplete_services ) {
28 28
 
29
-		$this->autocomplete_services = (array) $autocomplete_services;
30
-	}
29
+        $this->autocomplete_services = (array) $autocomplete_services;
30
+    }
31 31
 
32
-	/**
33
-	 * {@inheritDoc}
34
-	 */
35
-	public function query( $query, $scope, $excludes ) {
32
+    /**
33
+     * {@inheritDoc}
34
+     */
35
+    public function query( $query, $scope, $excludes ) {
36 36
 
37
-		/**
38
-		 * Filter to show local entities on the entity autocompletion field.
39
-		 *
40
-		 * @param $state bool
41
-		 *
42
-		 * @return bool Whether to show local entities in the page or not.
43
-		 * @since 3.26.1
44
-		 */
45
-		$show_local_entities = apply_filters( 'wl_show_local_entities', false );
37
+        /**
38
+         * Filter to show local entities on the entity autocompletion field.
39
+         *
40
+         * @param $state bool
41
+         *
42
+         * @return bool Whether to show local entities in the page or not.
43
+         * @since 3.26.1
44
+         */
45
+        $show_local_entities = apply_filters( 'wl_show_local_entities', false );
46 46
 
47
-		$autocomplete_services = $this->autocomplete_services;
47
+        $autocomplete_services = $this->autocomplete_services;
48 48
 
49
-		// Remove the local autocomplete services.
50
-		if ( ! $show_local_entities ) {
51
-			$autocomplete_services = array_filter( $autocomplete_services, function ( $service ) {
52
-				return ! $service instanceof Local_Autocomplete_Service;
53
-			} );
54
-		}
49
+        // Remove the local autocomplete services.
50
+        if ( ! $show_local_entities ) {
51
+            $autocomplete_services = array_filter( $autocomplete_services, function ( $service ) {
52
+                return ! $service instanceof Local_Autocomplete_Service;
53
+            } );
54
+        }
55 55
 
56
-		// Query each Autocomplete service and merge the results.
57
-		return array_reduce( $autocomplete_services, function ( $carry, $item ) use ( $query, $scope, $excludes ) {
56
+        // Query each Autocomplete service and merge the results.
57
+        return array_reduce( $autocomplete_services, function ( $carry, $item ) use ( $query, $scope, $excludes ) {
58 58
 
59
-			$results = $item->query( $query, $scope, $excludes );
59
+            $results = $item->query( $query, $scope, $excludes );
60 60
 
61
-			return array_merge( $carry, $results );
62
-		}, array() );
61
+            return array_merge( $carry, $results );
62
+        }, array() );
63 63
 
64
-	}
64
+    }
65 65
 
66 66
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @param Autocomplete_Service|Autocomplete_Service[] $autocomplete_services
26 26
 	 */
27
-	public function __construct( $autocomplete_services ) {
27
+	public function __construct($autocomplete_services) {
28 28
 
29 29
 		$this->autocomplete_services = (array) $autocomplete_services;
30 30
 	}
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	/**
33 33
 	 * {@inheritDoc}
34 34
 	 */
35
-	public function query( $query, $scope, $excludes ) {
35
+	public function query($query, $scope, $excludes) {
36 36
 
37 37
 		/**
38 38
 		 * Filter to show local entities on the entity autocompletion field.
@@ -42,24 +42,24 @@  discard block
 block discarded – undo
42 42
 		 * @return bool Whether to show local entities in the page or not.
43 43
 		 * @since 3.26.1
44 44
 		 */
45
-		$show_local_entities = apply_filters( 'wl_show_local_entities', false );
45
+		$show_local_entities = apply_filters('wl_show_local_entities', false);
46 46
 
47 47
 		$autocomplete_services = $this->autocomplete_services;
48 48
 
49 49
 		// Remove the local autocomplete services.
50
-		if ( ! $show_local_entities ) {
51
-			$autocomplete_services = array_filter( $autocomplete_services, function ( $service ) {
50
+		if ( ! $show_local_entities) {
51
+			$autocomplete_services = array_filter($autocomplete_services, function($service) {
52 52
 				return ! $service instanceof Local_Autocomplete_Service;
53 53
 			} );
54 54
 		}
55 55
 
56 56
 		// Query each Autocomplete service and merge the results.
57
-		return array_reduce( $autocomplete_services, function ( $carry, $item ) use ( $query, $scope, $excludes ) {
57
+		return array_reduce($autocomplete_services, function($carry, $item) use ($query, $scope, $excludes) {
58 58
 
59
-			$results = $item->query( $query, $scope, $excludes );
59
+			$results = $item->query($query, $scope, $excludes);
60 60
 
61
-			return array_merge( $carry, $results );
62
-		}, array() );
61
+			return array_merge($carry, $results);
62
+		}, array());
63 63
 
64 64
 	}
65 65
 
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-term-adapter.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -16,64 +16,64 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Admin_Term_Adapter {
18 18
 
19
-	/**
20
-	 * The meta key holding the entity id.
21
-	 *
22
-	 * @since 3.20.0
23
-	 */
24
-	const META_KEY = '_wl_entity_id';
25
-
26
-	/**
27
-	 * Create a Wordlift_Admin_Term_Adapter instance.
28
-	 *
29
-	 * @since 3.20.0
30
-	 */
31
-	public function __construct() {
32
-
33
-		add_action( 'registered_taxonomy', array( $this, 'add_action', ) );
34
-		add_action( 'edit_term', array( $this, 'edit_term', ), 10, 3 );
35
-		$this->add_settings();
36
-
37
-	}
38
-
39
-	/**
40
-	 * Hook in to WordLift admin settings and add the term page specific
41
-	 * settings.
42
-	 * @since 3.26.1
43
-	 */
44
-	public function add_settings() {
45
-		add_filter( 'wl_admin_settings', function ( $params ) {
46
-			$params['show_local_entities'] = true;
47
-			return $params;
48
-		} );
49
-	}
50
-
51
-	/**
52
-	 * Add the form fields to the entity edit screen.
53
-	 *
54
-	 * @param object $tag Current taxonomy term object.
55
-	 * @param string $taxonomy Current taxonomy slug.
56
-	 *
57
-	 * @since 3.20.0
58
-	 *
59
-	 */
60
-	public function edit_form_fields( $tag, $taxonomy ) {
61
-
62
-		global $wp_version;
63
-
64
-		// Enqueue the JavaScript app.
65
-		if ( version_compare( $wp_version, '5.0', '>=' ) ) {
66
-			$term_asset = include plugin_dir_path( dirname( __FILE__ ) ) . 'js/dist/term.asset.php';
67
-			wp_enqueue_script( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.js', array_merge( array( 'wp-util' ), $term_asset['dependencies'] ), Wordlift::get_instance()->get_version(), true );
68
-		} else {
69
-			wp_enqueue_script( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.full.js', array( 'wp-util' ), Wordlift::get_instance()->get_version(), true );
70
-		}
71
-
72
-		wp_enqueue_style( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.css', array(), Wordlift::get_instance()->get_version() );
73
-
74
-		$values = get_term_meta( $tag->term_id, self::META_KEY );
75
-
76
-		?>
19
+    /**
20
+     * The meta key holding the entity id.
21
+     *
22
+     * @since 3.20.0
23
+     */
24
+    const META_KEY = '_wl_entity_id';
25
+
26
+    /**
27
+     * Create a Wordlift_Admin_Term_Adapter instance.
28
+     *
29
+     * @since 3.20.0
30
+     */
31
+    public function __construct() {
32
+
33
+        add_action( 'registered_taxonomy', array( $this, 'add_action', ) );
34
+        add_action( 'edit_term', array( $this, 'edit_term', ), 10, 3 );
35
+        $this->add_settings();
36
+
37
+    }
38
+
39
+    /**
40
+     * Hook in to WordLift admin settings and add the term page specific
41
+     * settings.
42
+     * @since 3.26.1
43
+     */
44
+    public function add_settings() {
45
+        add_filter( 'wl_admin_settings', function ( $params ) {
46
+            $params['show_local_entities'] = true;
47
+            return $params;
48
+        } );
49
+    }
50
+
51
+    /**
52
+     * Add the form fields to the entity edit screen.
53
+     *
54
+     * @param object $tag Current taxonomy term object.
55
+     * @param string $taxonomy Current taxonomy slug.
56
+     *
57
+     * @since 3.20.0
58
+     *
59
+     */
60
+    public function edit_form_fields( $tag, $taxonomy ) {
61
+
62
+        global $wp_version;
63
+
64
+        // Enqueue the JavaScript app.
65
+        if ( version_compare( $wp_version, '5.0', '>=' ) ) {
66
+            $term_asset = include plugin_dir_path( dirname( __FILE__ ) ) . 'js/dist/term.asset.php';
67
+            wp_enqueue_script( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.js', array_merge( array( 'wp-util' ), $term_asset['dependencies'] ), Wordlift::get_instance()->get_version(), true );
68
+        } else {
69
+            wp_enqueue_script( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.full.js', array( 'wp-util' ), Wordlift::get_instance()->get_version(), true );
70
+        }
71
+
72
+        wp_enqueue_style( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.css', array(), Wordlift::get_instance()->get_version() );
73
+
74
+        $values = get_term_meta( $tag->term_id, self::META_KEY );
75
+
76
+        ?>
77 77
         <tr class="form-field term-name-wrap">
78 78
             <th scope="row"><label for="wl-entity-id"><?php _ex( 'Entity', 'term entity', 'wordlift' ); ?></label></th>
79 79
             <td>
@@ -85,65 +85,65 @@  discard block
 block discarded – undo
85 85
             </td>
86 86
         </tr>
87 87
 		<?php
88
-	}
89
-
90
-	/**
91
-	 * Bind the new fields to the edit term screen.
92
-	 *
93
-	 * @since 3.20.0
94
-	 *
95
-	 * @param string $taxonomy The taxonomy name.
96
-	 */
97
-	public function add_action( $taxonomy ) {
98
-
99
-		add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10, 2 );
100
-	}
101
-
102
-	/**
103
-	 * Hook to the edit term to handle our own custom fields.
104
-	 *
105
-	 * @since 3.20.0
106
-	 *
107
-	 * @param int    $term_id The term id.
108
-	 * @param int    $tt_id The term taxonomy id.
109
-	 * @param string $taxonomy The taxonomy.
110
-	 */
111
-	public function edit_term( $term_id, $tt_id, $taxonomy ) {
112
-
113
-		// Bail if the action isn't related to the term currently being edited.
114
-		if ( ! isset( $_POST['tag_ID'] ) || $term_id !== (int) (int) $_POST['tag_ID'] ) {
115
-			return;
116
-		}
117
-
118
-		// Delete.
119
-		if ( ! isset( $_POST['wl_entity_id'] ) || ! is_array( $_POST['wl_entity_id'] ) || empty( $_POST['wl_entity_id'] ) ) {
120
-			delete_term_meta( $term_id, self::META_KEY );
121
-
122
-			return;
123
-		}
124
-
125
-		// Update.
126
-		//
127
-		// Only use mb_* functions when mbstring is available.
128
-		//
129
-		// See https://github.com/insideout10/wordlift-plugin/issues/693.
130
-		if ( extension_loaded( 'mbstring' ) ) {
131
-			mb_regex_encoding( 'UTF-8' );
132
-
133
-			$merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) {
134
-				return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
135
-			}, array() );
136
-		} else {
137
-			$merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) {
138
-				return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
139
-			}, array() );
140
-		}
141
-
142
-		delete_term_meta( $term_id, self::META_KEY );
143
-		foreach ( array_unique( array_filter( $merged ) ) as $single ) {
144
-			add_term_meta( $term_id, self::META_KEY, $single );
145
-		}
146
-
147
-	}
88
+    }
89
+
90
+    /**
91
+     * Bind the new fields to the edit term screen.
92
+     *
93
+     * @since 3.20.0
94
+     *
95
+     * @param string $taxonomy The taxonomy name.
96
+     */
97
+    public function add_action( $taxonomy ) {
98
+
99
+        add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10, 2 );
100
+    }
101
+
102
+    /**
103
+     * Hook to the edit term to handle our own custom fields.
104
+     *
105
+     * @since 3.20.0
106
+     *
107
+     * @param int    $term_id The term id.
108
+     * @param int    $tt_id The term taxonomy id.
109
+     * @param string $taxonomy The taxonomy.
110
+     */
111
+    public function edit_term( $term_id, $tt_id, $taxonomy ) {
112
+
113
+        // Bail if the action isn't related to the term currently being edited.
114
+        if ( ! isset( $_POST['tag_ID'] ) || $term_id !== (int) (int) $_POST['tag_ID'] ) {
115
+            return;
116
+        }
117
+
118
+        // Delete.
119
+        if ( ! isset( $_POST['wl_entity_id'] ) || ! is_array( $_POST['wl_entity_id'] ) || empty( $_POST['wl_entity_id'] ) ) {
120
+            delete_term_meta( $term_id, self::META_KEY );
121
+
122
+            return;
123
+        }
124
+
125
+        // Update.
126
+        //
127
+        // Only use mb_* functions when mbstring is available.
128
+        //
129
+        // See https://github.com/insideout10/wordlift-plugin/issues/693.
130
+        if ( extension_loaded( 'mbstring' ) ) {
131
+            mb_regex_encoding( 'UTF-8' );
132
+
133
+            $merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) {
134
+                return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
135
+            }, array() );
136
+        } else {
137
+            $merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) {
138
+                return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
139
+            }, array() );
140
+        }
141
+
142
+        delete_term_meta( $term_id, self::META_KEY );
143
+        foreach ( array_unique( array_filter( $merged ) ) as $single ) {
144
+            add_term_meta( $term_id, self::META_KEY, $single );
145
+        }
146
+
147
+    }
148 148
 
149 149
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 	 */
31 31
 	public function __construct() {
32 32
 
33
-		add_action( 'registered_taxonomy', array( $this, 'add_action', ) );
34
-		add_action( 'edit_term', array( $this, 'edit_term', ), 10, 3 );
33
+		add_action('registered_taxonomy', array($this, 'add_action',));
34
+		add_action('edit_term', array($this, 'edit_term',), 10, 3);
35 35
 		$this->add_settings();
36 36
 
37 37
 	}
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @since 3.26.1
43 43
 	 */
44 44
 	public function add_settings() {
45
-		add_filter( 'wl_admin_settings', function ( $params ) {
45
+		add_filter('wl_admin_settings', function($params) {
46 46
 			$params['show_local_entities'] = true;
47 47
 			return $params;
48 48
 		} );
@@ -57,31 +57,31 @@  discard block
 block discarded – undo
57 57
 	 * @since 3.20.0
58 58
 	 *
59 59
 	 */
60
-	public function edit_form_fields( $tag, $taxonomy ) {
60
+	public function edit_form_fields($tag, $taxonomy) {
61 61
 
62 62
 		global $wp_version;
63 63
 
64 64
 		// Enqueue the JavaScript app.
65
-		if ( version_compare( $wp_version, '5.0', '>=' ) ) {
66
-			$term_asset = include plugin_dir_path( dirname( __FILE__ ) ) . 'js/dist/term.asset.php';
67
-			wp_enqueue_script( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.js', array_merge( array( 'wp-util' ), $term_asset['dependencies'] ), Wordlift::get_instance()->get_version(), true );
65
+		if (version_compare($wp_version, '5.0', '>=')) {
66
+			$term_asset = include plugin_dir_path(dirname(__FILE__)).'js/dist/term.asset.php';
67
+			wp_enqueue_script('wl-term', plugin_dir_url(dirname(__FILE__)).'js/dist/term.js', array_merge(array('wp-util'), $term_asset['dependencies']), Wordlift::get_instance()->get_version(), true);
68 68
 		} else {
69
-			wp_enqueue_script( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.full.js', array( 'wp-util' ), Wordlift::get_instance()->get_version(), true );
69
+			wp_enqueue_script('wl-term', plugin_dir_url(dirname(__FILE__)).'js/dist/term.full.js', array('wp-util'), Wordlift::get_instance()->get_version(), true);
70 70
 		}
71 71
 
72
-		wp_enqueue_style( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.css', array(), Wordlift::get_instance()->get_version() );
72
+		wp_enqueue_style('wl-term', plugin_dir_url(dirname(__FILE__)).'js/dist/term.css', array(), Wordlift::get_instance()->get_version());
73 73
 
74
-		$values = get_term_meta( $tag->term_id, self::META_KEY );
74
+		$values = get_term_meta($tag->term_id, self::META_KEY);
75 75
 
76 76
 		?>
77 77
         <tr class="form-field term-name-wrap">
78
-            <th scope="row"><label for="wl-entity-id"><?php _ex( 'Entity', 'term entity', 'wordlift' ); ?></label></th>
78
+            <th scope="row"><label for="wl-entity-id"><?php _ex('Entity', 'term entity', 'wordlift'); ?></label></th>
79 79
             <td>
80
-				<?php foreach ( $values as $value ) { ?>
81
-                    <input type="text" name="wl_entity_id[]" value="<?php echo esc_attr( $value ); ?>"/>
80
+				<?php foreach ($values as $value) { ?>
81
+                    <input type="text" name="wl_entity_id[]" value="<?php echo esc_attr($value); ?>"/>
82 82
 				<?php } ?>
83 83
                 <div id="wl-term-entity-id"></div>
84
-                <p class="description"><?php _e( 'The entity bound to the term.', 'wordlift' ); ?></p>
84
+                <p class="description"><?php _e('The entity bound to the term.', 'wordlift'); ?></p>
85 85
             </td>
86 86
         </tr>
87 87
 		<?php
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @param string $taxonomy The taxonomy name.
96 96
 	 */
97
-	public function add_action( $taxonomy ) {
97
+	public function add_action($taxonomy) {
98 98
 
99
-		add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10, 2 );
99
+		add_action("{$taxonomy}_edit_form_fields", array($this, 'edit_form_fields'), 10, 2);
100 100
 	}
101 101
 
102 102
 	/**
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
 	 * @param int    $tt_id The term taxonomy id.
109 109
 	 * @param string $taxonomy The taxonomy.
110 110
 	 */
111
-	public function edit_term( $term_id, $tt_id, $taxonomy ) {
111
+	public function edit_term($term_id, $tt_id, $taxonomy) {
112 112
 
113 113
 		// Bail if the action isn't related to the term currently being edited.
114
-		if ( ! isset( $_POST['tag_ID'] ) || $term_id !== (int) (int) $_POST['tag_ID'] ) {
114
+		if ( ! isset($_POST['tag_ID']) || $term_id !== (int) (int) $_POST['tag_ID']) {
115 115
 			return;
116 116
 		}
117 117
 
118 118
 		// Delete.
119
-		if ( ! isset( $_POST['wl_entity_id'] ) || ! is_array( $_POST['wl_entity_id'] ) || empty( $_POST['wl_entity_id'] ) ) {
120
-			delete_term_meta( $term_id, self::META_KEY );
119
+		if ( ! isset($_POST['wl_entity_id']) || ! is_array($_POST['wl_entity_id']) || empty($_POST['wl_entity_id'])) {
120
+			delete_term_meta($term_id, self::META_KEY);
121 121
 
122 122
 			return;
123 123
 		}
@@ -127,21 +127,21 @@  discard block
 block discarded – undo
127 127
 		// Only use mb_* functions when mbstring is available.
128 128
 		//
129 129
 		// See https://github.com/insideout10/wordlift-plugin/issues/693.
130
-		if ( extension_loaded( 'mbstring' ) ) {
131
-			mb_regex_encoding( 'UTF-8' );
130
+		if (extension_loaded('mbstring')) {
131
+			mb_regex_encoding('UTF-8');
132 132
 
133
-			$merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) {
134
-				return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) );
135
-			}, array() );
133
+			$merged = array_reduce((array) $_POST['wl_entity_id'], function($carry, $item) {
134
+				return array_merge($carry, mb_split("\x{2063}", wp_unslash($item)));
135
+			}, array());
136 136
 		} else {
137
-			$merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) {
138
-				return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) );
139
-			}, array() );
137
+			$merged = array_reduce((array) $_POST['wl_entity_id'], function($carry, $item) {
138
+				return array_merge($carry, preg_split("/\x{2063}/u", wp_unslash($item)));
139
+			}, array());
140 140
 		}
141 141
 
142
-		delete_term_meta( $term_id, self::META_KEY );
143
-		foreach ( array_unique( array_filter( $merged ) ) as $single ) {
144
-			add_term_meta( $term_id, self::META_KEY, $single );
142
+		delete_term_meta($term_id, self::META_KEY);
143
+		foreach (array_unique(array_filter($merged)) as $single) {
144
+			add_term_meta($term_id, self::META_KEY, $single);
145 145
 		}
146 146
 
147 147
 	}
Please login to merge, or discard this patch.
src/wordlift/autocomplete/class-local-autocomplete-service.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -15,61 +15,61 @@
 block discarded – undo
15 15
 
16 16
 class Local_Autocomplete_Service extends Abstract_Autocomplete_Service {
17 17
 
18
-	/**
19
-	 * @inheritDoc
20
-	 */
21
-	public function query( $query, $scope, $excludes ) {
22
-		global $wpdb;
18
+    /**
19
+     * @inheritDoc
20
+     */
21
+    public function query( $query, $scope, $excludes ) {
22
+        global $wpdb;
23 23
 
24
-		$posts = $wpdb->get_results( $wpdb->prepare(
25
-			"SELECT * FROM {$wpdb->posts} p"
26
-			. " INNER JOIN {$wpdb->term_relationships} tr"
27
-			. "  ON tr.object_id = p.ID"
28
-			. " INNER JOIN {$wpdb->term_taxonomy} tt"
29
-			. "  ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id"
30
-			. " INNER JOIN {$wpdb->terms} t"
31
-			. "  ON t.term_id = tt.term_id AND t.name != %s"
32
-			. " LEFT OUTER JOIN {$wpdb->postmeta} pm"
33
-			. "  ON pm.meta_key = %s AND pm.post_id = p.ID"
34
-			. " WHERE p.post_type IN ( '" . implode( "', '", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) ) . "' )"
35
-			. "  AND ( p.post_title LIKE %s OR pm.meta_value LIKE %s )"
36
-			. " LIMIT %d",
37
-			Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
38
-			'article',
39
-			Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
40
-			// `prepare` doesn't support argument number, hence we must repeat the query.
41
-			'%' . $wpdb->esc_like( $query ) . '%',
42
-			'%' . $wpdb->esc_like( $query ) . '%',
43
-			50
44
-		) );
24
+        $posts = $wpdb->get_results( $wpdb->prepare(
25
+            "SELECT * FROM {$wpdb->posts} p"
26
+            . " INNER JOIN {$wpdb->term_relationships} tr"
27
+            . "  ON tr.object_id = p.ID"
28
+            . " INNER JOIN {$wpdb->term_taxonomy} tt"
29
+            . "  ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id"
30
+            . " INNER JOIN {$wpdb->terms} t"
31
+            . "  ON t.term_id = tt.term_id AND t.name != %s"
32
+            . " LEFT OUTER JOIN {$wpdb->postmeta} pm"
33
+            . "  ON pm.meta_key = %s AND pm.post_id = p.ID"
34
+            . " WHERE p.post_type IN ( '" . implode( "', '", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) ) . "' )"
35
+            . "  AND ( p.post_title LIKE %s OR pm.meta_value LIKE %s )"
36
+            . " LIMIT %d",
37
+            Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
38
+            'article',
39
+            Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
40
+            // `prepare` doesn't support argument number, hence we must repeat the query.
41
+            '%' . $wpdb->esc_like( $query ) . '%',
42
+            '%' . $wpdb->esc_like( $query ) . '%',
43
+            50
44
+        ) );
45 45
 
46
-		$results = array_map( function ( $item ) {
46
+        $results = array_map( function ( $item ) {
47 47
 
48
-			$entity_service = Wordlift_Entity_Service::get_instance();
49
-			$uri            = $entity_service->get_uri( $item->ID );
48
+            $entity_service = Wordlift_Entity_Service::get_instance();
49
+            $uri            = $entity_service->get_uri( $item->ID );
50 50
 
51
-			return array(
52
-				// see #1074: The value property is needed for autocomplete in category page
53
-				// to function correctly, if value is not provided, then the entity
54
-				// wont be correctly saved.
55
-				'value'        => $uri,
56
-				'id'           => $uri,
57
-				'label'        => array( $item->post_title ),
58
-				'labels'       => $entity_service->get_alternative_labels( $item->ID ),
59
-				'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ),
60
-				'scope'        => 'local',
61
-				'sameAss'      => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ),
62
-				// The following properties are less relevant because we're linking entities that exist already in the
63
-				// vocabulary. That's why we don't make an effort to load the real data.
64
-				'types'        => array( 'http://schema.org/Thing' ),
65
-				'urls'         => array(),
66
-				'images'       => array(),
67
-			);
68
-		}, $posts );
51
+            return array(
52
+                // see #1074: The value property is needed for autocomplete in category page
53
+                // to function correctly, if value is not provided, then the entity
54
+                // wont be correctly saved.
55
+                'value'        => $uri,
56
+                'id'           => $uri,
57
+                'label'        => array( $item->post_title ),
58
+                'labels'       => $entity_service->get_alternative_labels( $item->ID ),
59
+                'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ),
60
+                'scope'        => 'local',
61
+                'sameAss'      => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ),
62
+                // The following properties are less relevant because we're linking entities that exist already in the
63
+                // vocabulary. That's why we don't make an effort to load the real data.
64
+                'types'        => array( 'http://schema.org/Thing' ),
65
+                'urls'         => array(),
66
+                'images'       => array(),
67
+            );
68
+        }, $posts );
69 69
 
70
-		$results = array_unique( $results );
70
+        $results = array_unique( $results );
71 71
 
72
-		return $this->filter( $results, $excludes );
73
-	}
72
+        return $this->filter( $results, $excludes );
73
+    }
74 74
 
75 75
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
 	/**
19 19
 	 * @inheritDoc
20 20
 	 */
21
-	public function query( $query, $scope, $excludes ) {
21
+	public function query($query, $scope, $excludes) {
22 22
 		global $wpdb;
23 23
 
24
-		$posts = $wpdb->get_results( $wpdb->prepare(
24
+		$posts = $wpdb->get_results($wpdb->prepare(
25 25
 			"SELECT * FROM {$wpdb->posts} p"
26 26
 			. " INNER JOIN {$wpdb->term_relationships} tr"
27 27
 			. "  ON tr.object_id = p.ID"
@@ -31,22 +31,22 @@  discard block
 block discarded – undo
31 31
 			. "  ON t.term_id = tt.term_id AND t.name != %s"
32 32
 			. " LEFT OUTER JOIN {$wpdb->postmeta} pm"
33 33
 			. "  ON pm.meta_key = %s AND pm.post_id = p.ID"
34
-			. " WHERE p.post_type IN ( '" . implode( "', '", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) ) . "' )"
34
+			. " WHERE p.post_type IN ( '".implode("', '", array_map('esc_sql', Wordlift_Entity_Service::valid_entity_post_types()))."' )"
35 35
 			. "  AND ( p.post_title LIKE %s OR pm.meta_value LIKE %s )"
36 36
 			. " LIMIT %d",
37 37
 			Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
38 38
 			'article',
39 39
 			Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
40 40
 			// `prepare` doesn't support argument number, hence we must repeat the query.
41
-			'%' . $wpdb->esc_like( $query ) . '%',
42
-			'%' . $wpdb->esc_like( $query ) . '%',
41
+			'%'.$wpdb->esc_like($query).'%',
42
+			'%'.$wpdb->esc_like($query).'%',
43 43
 			50
44
-		) );
44
+		));
45 45
 
46
-		$results = array_map( function ( $item ) {
46
+		$results = array_map(function($item) {
47 47
 
48 48
 			$entity_service = Wordlift_Entity_Service::get_instance();
49
-			$uri            = $entity_service->get_uri( $item->ID );
49
+			$uri            = $entity_service->get_uri($item->ID);
50 50
 
51 51
 			return array(
52 52
 				// see #1074: The value property is needed for autocomplete in category page
@@ -54,22 +54,22 @@  discard block
 block discarded – undo
54 54
 				// wont be correctly saved.
55 55
 				'value'        => $uri,
56 56
 				'id'           => $uri,
57
-				'label'        => array( $item->post_title ),
58
-				'labels'       => $entity_service->get_alternative_labels( $item->ID ),
59
-				'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ),
57
+				'label'        => array($item->post_title),
58
+				'labels'       => $entity_service->get_alternative_labels($item->ID),
59
+				'descriptions' => array(Wordlift_Post_Excerpt_Helper::get_text_excerpt($item)),
60 60
 				'scope'        => 'local',
61
-				'sameAss'      => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ),
61
+				'sameAss'      => get_post_meta($item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS),
62 62
 				// The following properties are less relevant because we're linking entities that exist already in the
63 63
 				// vocabulary. That's why we don't make an effort to load the real data.
64
-				'types'        => array( 'http://schema.org/Thing' ),
64
+				'types'        => array('http://schema.org/Thing'),
65 65
 				'urls'         => array(),
66 66
 				'images'       => array(),
67 67
 			);
68
-		}, $posts );
68
+		}, $posts);
69 69
 
70
-		$results = array_unique( $results );
70
+		$results = array_unique($results);
71 71
 
72
-		return $this->filter( $results, $excludes );
72
+		return $this->filter($results, $excludes);
73 73
 	}
74 74
 
75 75
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-autocomplete-adapter.php 3 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use Wordlift\Autocomplete\Autocomplete_Service;
14 14
 
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -23,76 +23,76 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class Wordlift_Autocomplete_Adapter {
25 25
 
26
-	/**
27
-	 * The {@link Autocomplete_Service} instance.
28
-	 *
29
-	 * @since  3.15.0
30
-	 * @access private
31
-	 * @var Autocomplete_Service $configuration_service The {@link Autocomplete_Service} instance.
32
-	 */
33
-	private $autocomplete_service;
34
-
35
-
36
-	/**
37
-	 * Wordlift_Autocomplete_Adapter constructor.
38
-	 *
39
-	 * @param Autocomplete_Service $autocomplete_service The {@link Autocomplete_Service} instance.
40
-	 *
41
-	 * @since 3.14.2
42
-	 *
43
-	 */
44
-	public function __construct( $autocomplete_service ) {
45
-		$this->autocomplete_service = $autocomplete_service;
46
-	}
47
-
48
-	/**
49
-	 * Handle the autocomplete ajax request.
50
-	 *
51
-	 * @since 3.15.0
52
-	 */
53
-	public function wl_autocomplete() {
54
-
55
-		check_ajax_referer( 'wl_autocomplete' );
56
-
57
-		// Return error if the query param is empty.
58
-		if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay.
59
-			$query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay.
60
-		} else {
61
-			wp_send_json_error( array(
62
-				'message' => __( 'The query param is empty.', 'wordlift' ),
63
-			) );
64
-		}
65
-
66
-		// Get the exclude parameter.
67
-		$exclude = ! empty( $_REQUEST['exclude'] )
68
-			? sanitize_text_field( wp_unslash( $_REQUEST['exclude'] ) ) : '';
69
-
70
-		$scope = ! empty( $_REQUEST['scope'] )
71
-			? sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ) : WL_AUTOCOMPLETE_SCOPE;
72
-
73
-		/**
74
-		 * @since 3.26.1
75
-		 * Providing a way for term pages to show and save local entities.
76
-		 */
77
-		$show_local_entities = false;
78
-
79
-		if ( isset( $_REQUEST['show_local_entities'] )
80
-		     && ! empty( $_REQUEST['show_local_entities'] ) ) // Make request.
81
-		{
82
-			$show_local_entities = filter_var( $_REQUEST['show_local_entities'], FILTER_VALIDATE_BOOLEAN );
83
-		}
84
-
85
-		// Add the filter to check if we need to show local entities or not.
86
-		add_filter( 'wl_show_local_entities', function ( $state ) use ( $show_local_entities ) {
87
-			return $show_local_entities;
88
-		} );
89
-
90
-		$results = $this->autocomplete_service->query( $query, $scope, $exclude );
91
-
92
-		// Clear any buffer.
93
-		ob_clean();
94
-
95
-		wp_send_json_success( $results );
96
-
97
-	}
26
+    /**
27
+     * The {@link Autocomplete_Service} instance.
28
+     *
29
+     * @since  3.15.0
30
+     * @access private
31
+     * @var Autocomplete_Service $configuration_service The {@link Autocomplete_Service} instance.
32
+     */
33
+    private $autocomplete_service;
34
+
35
+
36
+    /**
37
+     * Wordlift_Autocomplete_Adapter constructor.
38
+     *
39
+     * @param Autocomplete_Service $autocomplete_service The {@link Autocomplete_Service} instance.
40
+     *
41
+     * @since 3.14.2
42
+     *
43
+     */
44
+    public function __construct( $autocomplete_service ) {
45
+        $this->autocomplete_service = $autocomplete_service;
46
+    }
47
+
48
+    /**
49
+     * Handle the autocomplete ajax request.
50
+     *
51
+     * @since 3.15.0
52
+     */
53
+    public function wl_autocomplete() {
54
+
55
+        check_ajax_referer( 'wl_autocomplete' );
56
+
57
+        // Return error if the query param is empty.
58
+        if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay.
59
+            $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay.
60
+        } else {
61
+            wp_send_json_error( array(
62
+                'message' => __( 'The query param is empty.', 'wordlift' ),
63
+            ) );
64
+        }
65
+
66
+        // Get the exclude parameter.
67
+        $exclude = ! empty( $_REQUEST['exclude'] )
68
+            ? sanitize_text_field( wp_unslash( $_REQUEST['exclude'] ) ) : '';
69
+
70
+        $scope = ! empty( $_REQUEST['scope'] )
71
+            ? sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ) : WL_AUTOCOMPLETE_SCOPE;
72
+
73
+        /**
74
+         * @since 3.26.1
75
+         * Providing a way for term pages to show and save local entities.
76
+         */
77
+        $show_local_entities = false;
78
+
79
+        if ( isset( $_REQUEST['show_local_entities'] )
80
+             && ! empty( $_REQUEST['show_local_entities'] ) ) // Make request.
81
+        {
82
+            $show_local_entities = filter_var( $_REQUEST['show_local_entities'], FILTER_VALIDATE_BOOLEAN );
83
+        }
84
+
85
+        // Add the filter to check if we need to show local entities or not.
86
+        add_filter( 'wl_show_local_entities', function ( $state ) use ( $show_local_entities ) {
87
+            return $show_local_entities;
88
+        } );
89
+
90
+        $results = $this->autocomplete_service->query( $query, $scope, $exclude );
91
+
92
+        // Clear any buffer.
93
+        ob_clean();
94
+
95
+        wp_send_json_success( $results );
96
+
97
+    }
98 98
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 use Wordlift\Autocomplete\Autocomplete_Service;
14 14
 
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 * @since 3.14.2
42 42
 	 *
43 43
 	 */
44
-	public function __construct( $autocomplete_service ) {
44
+	public function __construct($autocomplete_service) {
45 45
 		$this->autocomplete_service = $autocomplete_service;
46 46
 	}
47 47
 
@@ -52,23 +52,23 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	public function wl_autocomplete() {
54 54
 
55
-		check_ajax_referer( 'wl_autocomplete' );
55
+		check_ajax_referer('wl_autocomplete');
56 56
 
57 57
 		// Return error if the query param is empty.
58
-		if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay.
59
-			$query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay.
58
+		if ( ! empty($_REQUEST['query'])) { // Input var okay.
59
+			$query = sanitize_text_field(wp_unslash($_REQUEST['query'])); // Input var okay.
60 60
 		} else {
61
-			wp_send_json_error( array(
62
-				'message' => __( 'The query param is empty.', 'wordlift' ),
63
-			) );
61
+			wp_send_json_error(array(
62
+				'message' => __('The query param is empty.', 'wordlift'),
63
+			));
64 64
 		}
65 65
 
66 66
 		// Get the exclude parameter.
67
-		$exclude = ! empty( $_REQUEST['exclude'] )
68
-			? sanitize_text_field( wp_unslash( $_REQUEST['exclude'] ) ) : '';
67
+		$exclude = ! empty($_REQUEST['exclude'])
68
+			? sanitize_text_field(wp_unslash($_REQUEST['exclude'])) : '';
69 69
 
70
-		$scope = ! empty( $_REQUEST['scope'] )
71
-			? sanitize_text_field( wp_unslash( $_REQUEST['scope'] ) ) : WL_AUTOCOMPLETE_SCOPE;
70
+		$scope = ! empty($_REQUEST['scope'])
71
+			? sanitize_text_field(wp_unslash($_REQUEST['scope'])) : WL_AUTOCOMPLETE_SCOPE;
72 72
 
73 73
 		/**
74 74
 		 * @since 3.26.1
@@ -76,23 +76,23 @@  discard block
 block discarded – undo
76 76
 		 */
77 77
 		$show_local_entities = false;
78 78
 
79
-		if ( isset( $_REQUEST['show_local_entities'] )
80
-		     && ! empty( $_REQUEST['show_local_entities'] ) ) // Make request.
79
+		if (isset($_REQUEST['show_local_entities'])
80
+		     && ! empty($_REQUEST['show_local_entities'])) // Make request.
81 81
 		{
82
-			$show_local_entities = filter_var( $_REQUEST['show_local_entities'], FILTER_VALIDATE_BOOLEAN );
82
+			$show_local_entities = filter_var($_REQUEST['show_local_entities'], FILTER_VALIDATE_BOOLEAN);
83 83
 		}
84 84
 
85 85
 		// Add the filter to check if we need to show local entities or not.
86
-		add_filter( 'wl_show_local_entities', function ( $state ) use ( $show_local_entities ) {
86
+		add_filter('wl_show_local_entities', function($state) use ($show_local_entities) {
87 87
 			return $show_local_entities;
88 88
 		} );
89 89
 
90
-		$results = $this->autocomplete_service->query( $query, $scope, $exclude );
90
+		$results = $this->autocomplete_service->query($query, $scope, $exclude);
91 91
 
92 92
 		// Clear any buffer.
93 93
 		ob_clean();
94 94
 
95
-		wp_send_json_success( $results );
95
+		wp_send_json_success($results);
96 96
 
97 97
 	}
98 98
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,10 +77,12 @@
 block discarded – undo
77 77
 		$show_local_entities = false;
78 78
 
79 79
 		if ( isset( $_REQUEST['show_local_entities'] )
80
-		     && ! empty( $_REQUEST['show_local_entities'] ) ) // Make request.
80
+		     && ! empty( $_REQUEST['show_local_entities'] ) ) {
81
+		    // Make request.
81 82
 		{
82 83
 			$show_local_entities = filter_var( $_REQUEST['show_local_entities'], FILTER_VALIDATE_BOOLEAN );
83 84
 		}
85
+		}
84 86
 
85 87
 		// Add the filter to check if we need to show local entities or not.
86 88
 		add_filter( 'wl_show_local_entities', function ( $state ) use ( $show_local_entities ) {
Please login to merge, or discard this patch.