Completed
Push — master ( 878879...f163dd )
by David
02:25 queued 11s
created
src/wordlift/cache/class-ttl-cache-cleaner.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -124,6 +124,9 @@  discard block
 block discarded – undo
124 124
 		) );
125 125
 	}
126 126
 
127
+	/**
128
+	 * @param string $path
129
+	 */
127 130
 	private function reduce( $accumulator, $path ) {
128 131
 
129 132
 		/**
@@ -157,7 +160,7 @@  discard block
 block discarded – undo
157 160
 	/**
158 161
 	 * @param $accumulator
159 162
 	 * @param $path
160
-	 * @param $handle
163
+	 * @param resource $handle
161 164
 	 *
162 165
 	 * @return array
163 166
 	 */
Please login to merge, or discard this patch.
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -21,174 +21,174 @@
 block discarded – undo
21 21
 
22 22
 class Ttl_Cache_Cleaner {
23 23
 
24
-	const PATH = 0;
25
-	const MTIME = 1;
26
-	const SIZE = 2;
27
-
28
-	/**
29
-	 * The max TTL in seconds.
30
-	 *
31
-	 * @access private
32
-	 * @var int $ttl The max TTL in seconds.
33
-	 */
34
-	private $ttl;
35
-
36
-	/**
37
-	 * The max size in bytes.
38
-	 *
39
-	 * @access private
40
-	 * @var int $ttl The max size in bytes.
41
-	 */
42
-	private $max_size;
43
-
44
-	/**
45
-	 * Ttl_Cache_Cleaner constructor.
46
-	 *
47
-	 * @param int $ttl The max TTL in seconds.
48
-	 * @param int $max_size The max size in bytes.
49
-	 */
50
-	public function __construct( $ttl = WORDLIFT_CACHE_DEFAULT_TTL, $max_size = WORDLIFT_CACHE_DEFAULT_MAX_SIZE ) {
51
-
52
-		$this->ttl      = $ttl;
53
-		$this->max_size = $max_size;
54
-
55
-		add_action( 'wp_ajax_wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) );
56
-		add_action( 'wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) );
57
-
58
-		// Do not bother to configure scheduled tasks while running on the front-end.
59
-		if ( is_admin() && ! wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' ) ) {
60
-			wp_schedule_event( time(), 'hourly', 'wl_ttl_cache_cleaner__cleanup' );
61
-		}
62
-
63
-	}
64
-
65
-	public static function deactivate() {
66
-
67
-		$timestamp = wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' );
68
-		wp_unschedule_event( $timestamp, 'wl_ttl_cache_cleaner__cleanup' );
69
-
70
-	}
71
-
72
-	public function cleanup() {
73
-
74
-		// Get all the files, recursive.
75
-		$files = $this->reduce( array(), Ttl_Cache::get_cache_folder() );
76
-
77
-
78
-		// Get the max mtime.
79
-		$max_mtime = time() - WORDLIFT_CACHE_DEFAULT_TTL;
80
-
81
-		// Keep the original count for statistics that we're going to send the client.
82
-		$original_count = count( $files );
83
-
84
-		// Sort by size ascending.
85
-		usort( $files, function ( $f1, $f2 ) {
86
-			if ( $f1[ Ttl_Cache_Cleaner::MTIME ] === $f2[ Ttl_Cache_Cleaner::MTIME ] ) {
87
-				return 0;
88
-			}
89
-
90
-			return ( $f1[ Ttl_Cache_Cleaner::MTIME ] < $f2[ Ttl_Cache_Cleaner::MTIME ] ) ? - 1 : 1;
91
-		} );
92
-
93
-		// Start removing stale files.
94
-		for ( $i = 0; $i < count( $files ); $i ++ ) {
95
-			$file = $files[ $i ];
96
-			// Break if the mtime is within the range.
97
-			if ( $file[ Ttl_Cache_Cleaner::MTIME ] > $max_mtime ) {
98
-				break;
99
-			}
100
-
101
-			unset( $files[ $i ] );
102
-			@unlink( $file[ Ttl_Cache_Cleaner::PATH ] );
103
-		}
104
-
105
-		// Calculate the size.
106
-		$total_size = array_reduce( $files, function ( $carry, $item ) {
107
-
108
-			return $carry + $item[ Ttl_Cache_Cleaner::SIZE ];
109
-		}, 0 );
110
-
111
-
112
-		// Remove files until we're within the max size.
113
-		while ( $total_size > $this->max_size ) {
114
-			$file       = array_shift( $files );
115
-			$total_size -= $file[ Ttl_Cache_Cleaner::SIZE ];
116
-			@unlink( $file[ Ttl_Cache_Cleaner::PATH ] );
117
-		}
118
-
119
-		// Send back some stats.
120
-		wp_send_json_success( array(
121
-			'initial_count' => $original_count,
122
-			'current_count' => count( $files ),
123
-			'current_size'  => $total_size,
124
-		) );
125
-	}
126
-
127
-	private function reduce( $accumulator, $path ) {
128
-
129
-		/**
130
-		 * Bail out if the path doesn't exist.
131
-		 *
132
-		 * Avoid warnings when trying to open a path which doesn't exist.
133
-		 *
134
-		 * @since 3.23.0
135
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/966
136
-		 */
137
-		if ( ! file_exists( $path ) ) {
138
-			return $accumulator;
139
-		}
140
-
141
-		// Open the dir handle.
142
-		$handle = opendir( $path );
143
-
144
-		// Catch exceptions to be sure to close the dir handle.
145
-		try {
146
-			$accumulator = @$this->_reduce( $accumulator, $path, $handle );
147
-		} catch ( Exception $e ) {
148
-			// Do nothing.
149
-		}
24
+    const PATH = 0;
25
+    const MTIME = 1;
26
+    const SIZE = 2;
27
+
28
+    /**
29
+     * The max TTL in seconds.
30
+     *
31
+     * @access private
32
+     * @var int $ttl The max TTL in seconds.
33
+     */
34
+    private $ttl;
35
+
36
+    /**
37
+     * The max size in bytes.
38
+     *
39
+     * @access private
40
+     * @var int $ttl The max size in bytes.
41
+     */
42
+    private $max_size;
43
+
44
+    /**
45
+     * Ttl_Cache_Cleaner constructor.
46
+     *
47
+     * @param int $ttl The max TTL in seconds.
48
+     * @param int $max_size The max size in bytes.
49
+     */
50
+    public function __construct( $ttl = WORDLIFT_CACHE_DEFAULT_TTL, $max_size = WORDLIFT_CACHE_DEFAULT_MAX_SIZE ) {
51
+
52
+        $this->ttl      = $ttl;
53
+        $this->max_size = $max_size;
54
+
55
+        add_action( 'wp_ajax_wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) );
56
+        add_action( 'wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) );
57
+
58
+        // Do not bother to configure scheduled tasks while running on the front-end.
59
+        if ( is_admin() && ! wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' ) ) {
60
+            wp_schedule_event( time(), 'hourly', 'wl_ttl_cache_cleaner__cleanup' );
61
+        }
62
+
63
+    }
64
+
65
+    public static function deactivate() {
66
+
67
+        $timestamp = wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' );
68
+        wp_unschedule_event( $timestamp, 'wl_ttl_cache_cleaner__cleanup' );
69
+
70
+    }
71
+
72
+    public function cleanup() {
73
+
74
+        // Get all the files, recursive.
75
+        $files = $this->reduce( array(), Ttl_Cache::get_cache_folder() );
76
+
77
+
78
+        // Get the max mtime.
79
+        $max_mtime = time() - WORDLIFT_CACHE_DEFAULT_TTL;
80
+
81
+        // Keep the original count for statistics that we're going to send the client.
82
+        $original_count = count( $files );
83
+
84
+        // Sort by size ascending.
85
+        usort( $files, function ( $f1, $f2 ) {
86
+            if ( $f1[ Ttl_Cache_Cleaner::MTIME ] === $f2[ Ttl_Cache_Cleaner::MTIME ] ) {
87
+                return 0;
88
+            }
89
+
90
+            return ( $f1[ Ttl_Cache_Cleaner::MTIME ] < $f2[ Ttl_Cache_Cleaner::MTIME ] ) ? - 1 : 1;
91
+        } );
92
+
93
+        // Start removing stale files.
94
+        for ( $i = 0; $i < count( $files ); $i ++ ) {
95
+            $file = $files[ $i ];
96
+            // Break if the mtime is within the range.
97
+            if ( $file[ Ttl_Cache_Cleaner::MTIME ] > $max_mtime ) {
98
+                break;
99
+            }
100
+
101
+            unset( $files[ $i ] );
102
+            @unlink( $file[ Ttl_Cache_Cleaner::PATH ] );
103
+        }
104
+
105
+        // Calculate the size.
106
+        $total_size = array_reduce( $files, function ( $carry, $item ) {
107
+
108
+            return $carry + $item[ Ttl_Cache_Cleaner::SIZE ];
109
+        }, 0 );
110
+
111
+
112
+        // Remove files until we're within the max size.
113
+        while ( $total_size > $this->max_size ) {
114
+            $file       = array_shift( $files );
115
+            $total_size -= $file[ Ttl_Cache_Cleaner::SIZE ];
116
+            @unlink( $file[ Ttl_Cache_Cleaner::PATH ] );
117
+        }
118
+
119
+        // Send back some stats.
120
+        wp_send_json_success( array(
121
+            'initial_count' => $original_count,
122
+            'current_count' => count( $files ),
123
+            'current_size'  => $total_size,
124
+        ) );
125
+    }
126
+
127
+    private function reduce( $accumulator, $path ) {
128
+
129
+        /**
130
+         * Bail out if the path doesn't exist.
131
+         *
132
+         * Avoid warnings when trying to open a path which doesn't exist.
133
+         *
134
+         * @since 3.23.0
135
+         * @see https://github.com/insideout10/wordlift-plugin/issues/966
136
+         */
137
+        if ( ! file_exists( $path ) ) {
138
+            return $accumulator;
139
+        }
140
+
141
+        // Open the dir handle.
142
+        $handle = opendir( $path );
143
+
144
+        // Catch exceptions to be sure to close the dir handle.
145
+        try {
146
+            $accumulator = @$this->_reduce( $accumulator, $path, $handle );
147
+        } catch ( Exception $e ) {
148
+            // Do nothing.
149
+        }
150 150
 
151
-		// Finally close the directory handle.
152
-		closedir( $handle );
153
-
154
-		return $accumulator;
155
-	}
156
-
157
-	/**
158
-	 * @param $accumulator
159
-	 * @param $path
160
-	 * @param $handle
161
-	 *
162
-	 * @return array
163
-	 */
164
-	private function _reduce( $accumulator, $path, $handle ) {
165
-
166
-		while ( false !== ( $entry = readdir( $handle ) ) ) {
167
-
168
-			// Skip to the next one.
169
-			if ( 0 === strpos( $entry, '.' ) ) {
170
-				continue;
171
-			}
172
-
173
-			// Set the full path to the entry.
174
-			$entry_path = $path . DIRECTORY_SEPARATOR . $entry;
175
-
176
-			// Handle directories.
177
-			if ( is_dir( $entry_path ) ) {
178
-				$accumulator = $this->reduce( $accumulator, $entry_path );
179
-
180
-				continue;
181
-			}
182
-
183
-			// Store the file data.
184
-			$accumulator[] = array(
185
-				$entry_path,
186
-				filemtime( $entry_path ),
187
-				filesize( $entry_path ),
188
-			);
189
-		}
190
-
191
-		return $accumulator;
192
-	}
151
+        // Finally close the directory handle.
152
+        closedir( $handle );
153
+
154
+        return $accumulator;
155
+    }
156
+
157
+    /**
158
+     * @param $accumulator
159
+     * @param $path
160
+     * @param $handle
161
+     *
162
+     * @return array
163
+     */
164
+    private function _reduce( $accumulator, $path, $handle ) {
165
+
166
+        while ( false !== ( $entry = readdir( $handle ) ) ) {
167
+
168
+            // Skip to the next one.
169
+            if ( 0 === strpos( $entry, '.' ) ) {
170
+                continue;
171
+            }
172
+
173
+            // Set the full path to the entry.
174
+            $entry_path = $path . DIRECTORY_SEPARATOR . $entry;
175
+
176
+            // Handle directories.
177
+            if ( is_dir( $entry_path ) ) {
178
+                $accumulator = $this->reduce( $accumulator, $entry_path );
179
+
180
+                continue;
181
+            }
182
+
183
+            // Store the file data.
184
+            $accumulator[] = array(
185
+                $entry_path,
186
+                filemtime( $entry_path ),
187
+                filesize( $entry_path ),
188
+            );
189
+        }
190
+
191
+        return $accumulator;
192
+    }
193 193
 
194 194
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
16 16
 
17 17
 use Exception;
18 18
 
19
-defined( 'WORDLIFT_CACHE_DEFAULT_TTL' ) || define( 'WORDLIFT_CACHE_DEFAULT_TTL', 86400 );  // 24 hours
20
-defined( 'WORDLIFT_CACHE_DEFAULT_MAX_SIZE' ) || define( 'WORDLIFT_CACHE_DEFAULT_MAX_SIZE', 104857600 ); // 100 M
19
+defined('WORDLIFT_CACHE_DEFAULT_TTL') || define('WORDLIFT_CACHE_DEFAULT_TTL', 86400); // 24 hours
20
+defined('WORDLIFT_CACHE_DEFAULT_MAX_SIZE') || define('WORDLIFT_CACHE_DEFAULT_MAX_SIZE', 104857600); // 100 M
21 21
 
22 22
 class Ttl_Cache_Cleaner {
23 23
 
@@ -47,84 +47,84 @@  discard block
 block discarded – undo
47 47
 	 * @param int $ttl The max TTL in seconds.
48 48
 	 * @param int $max_size The max size in bytes.
49 49
 	 */
50
-	public function __construct( $ttl = WORDLIFT_CACHE_DEFAULT_TTL, $max_size = WORDLIFT_CACHE_DEFAULT_MAX_SIZE ) {
50
+	public function __construct($ttl = WORDLIFT_CACHE_DEFAULT_TTL, $max_size = WORDLIFT_CACHE_DEFAULT_MAX_SIZE) {
51 51
 
52 52
 		$this->ttl      = $ttl;
53 53
 		$this->max_size = $max_size;
54 54
 
55
-		add_action( 'wp_ajax_wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) );
56
-		add_action( 'wl_ttl_cache_cleaner__cleanup', array( $this, 'cleanup' ) );
55
+		add_action('wp_ajax_wl_ttl_cache_cleaner__cleanup', array($this, 'cleanup'));
56
+		add_action('wl_ttl_cache_cleaner__cleanup', array($this, 'cleanup'));
57 57
 
58 58
 		// Do not bother to configure scheduled tasks while running on the front-end.
59
-		if ( is_admin() && ! wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' ) ) {
60
-			wp_schedule_event( time(), 'hourly', 'wl_ttl_cache_cleaner__cleanup' );
59
+		if (is_admin() && ! wp_next_scheduled('wl_ttl_cache_cleaner__cleanup')) {
60
+			wp_schedule_event(time(), 'hourly', 'wl_ttl_cache_cleaner__cleanup');
61 61
 		}
62 62
 
63 63
 	}
64 64
 
65 65
 	public static function deactivate() {
66 66
 
67
-		$timestamp = wp_next_scheduled( 'wl_ttl_cache_cleaner__cleanup' );
68
-		wp_unschedule_event( $timestamp, 'wl_ttl_cache_cleaner__cleanup' );
67
+		$timestamp = wp_next_scheduled('wl_ttl_cache_cleaner__cleanup');
68
+		wp_unschedule_event($timestamp, 'wl_ttl_cache_cleaner__cleanup');
69 69
 
70 70
 	}
71 71
 
72 72
 	public function cleanup() {
73 73
 
74 74
 		// Get all the files, recursive.
75
-		$files = $this->reduce( array(), Ttl_Cache::get_cache_folder() );
75
+		$files = $this->reduce(array(), Ttl_Cache::get_cache_folder());
76 76
 
77 77
 
78 78
 		// Get the max mtime.
79 79
 		$max_mtime = time() - WORDLIFT_CACHE_DEFAULT_TTL;
80 80
 
81 81
 		// Keep the original count for statistics that we're going to send the client.
82
-		$original_count = count( $files );
82
+		$original_count = count($files);
83 83
 
84 84
 		// Sort by size ascending.
85
-		usort( $files, function ( $f1, $f2 ) {
86
-			if ( $f1[ Ttl_Cache_Cleaner::MTIME ] === $f2[ Ttl_Cache_Cleaner::MTIME ] ) {
85
+		usort($files, function($f1, $f2) {
86
+			if ($f1[Ttl_Cache_Cleaner::MTIME] === $f2[Ttl_Cache_Cleaner::MTIME]) {
87 87
 				return 0;
88 88
 			}
89 89
 
90
-			return ( $f1[ Ttl_Cache_Cleaner::MTIME ] < $f2[ Ttl_Cache_Cleaner::MTIME ] ) ? - 1 : 1;
90
+			return ($f1[Ttl_Cache_Cleaner::MTIME] < $f2[Ttl_Cache_Cleaner::MTIME]) ? -1 : 1;
91 91
 		} );
92 92
 
93 93
 		// Start removing stale files.
94
-		for ( $i = 0; $i < count( $files ); $i ++ ) {
95
-			$file = $files[ $i ];
94
+		for ($i = 0; $i < count($files); $i++) {
95
+			$file = $files[$i];
96 96
 			// Break if the mtime is within the range.
97
-			if ( $file[ Ttl_Cache_Cleaner::MTIME ] > $max_mtime ) {
97
+			if ($file[Ttl_Cache_Cleaner::MTIME] > $max_mtime) {
98 98
 				break;
99 99
 			}
100 100
 
101
-			unset( $files[ $i ] );
102
-			@unlink( $file[ Ttl_Cache_Cleaner::PATH ] );
101
+			unset($files[$i]);
102
+			@unlink($file[Ttl_Cache_Cleaner::PATH]);
103 103
 		}
104 104
 
105 105
 		// Calculate the size.
106
-		$total_size = array_reduce( $files, function ( $carry, $item ) {
106
+		$total_size = array_reduce($files, function($carry, $item) {
107 107
 
108
-			return $carry + $item[ Ttl_Cache_Cleaner::SIZE ];
109
-		}, 0 );
108
+			return $carry + $item[Ttl_Cache_Cleaner::SIZE];
109
+		}, 0);
110 110
 
111 111
 
112 112
 		// Remove files until we're within the max size.
113
-		while ( $total_size > $this->max_size ) {
114
-			$file       = array_shift( $files );
115
-			$total_size -= $file[ Ttl_Cache_Cleaner::SIZE ];
116
-			@unlink( $file[ Ttl_Cache_Cleaner::PATH ] );
113
+		while ($total_size > $this->max_size) {
114
+			$file = array_shift($files);
115
+			$total_size -= $file[Ttl_Cache_Cleaner::SIZE];
116
+			@unlink($file[Ttl_Cache_Cleaner::PATH]);
117 117
 		}
118 118
 
119 119
 		// Send back some stats.
120
-		wp_send_json_success( array(
120
+		wp_send_json_success(array(
121 121
 			'initial_count' => $original_count,
122
-			'current_count' => count( $files ),
122
+			'current_count' => count($files),
123 123
 			'current_size'  => $total_size,
124
-		) );
124
+		));
125 125
 	}
126 126
 
127
-	private function reduce( $accumulator, $path ) {
127
+	private function reduce($accumulator, $path) {
128 128
 
129 129
 		/**
130 130
 		 * Bail out if the path doesn't exist.
@@ -134,22 +134,22 @@  discard block
 block discarded – undo
134 134
 		 * @since 3.23.0
135 135
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/966
136 136
 		 */
137
-		if ( ! file_exists( $path ) ) {
137
+		if ( ! file_exists($path)) {
138 138
 			return $accumulator;
139 139
 		}
140 140
 
141 141
 		// Open the dir handle.
142
-		$handle = opendir( $path );
142
+		$handle = opendir($path);
143 143
 
144 144
 		// Catch exceptions to be sure to close the dir handle.
145 145
 		try {
146
-			$accumulator = @$this->_reduce( $accumulator, $path, $handle );
147
-		} catch ( Exception $e ) {
146
+			$accumulator = @$this->_reduce($accumulator, $path, $handle);
147
+		} catch (Exception $e) {
148 148
 			// Do nothing.
149 149
 		}
150 150
 
151 151
 		// Finally close the directory handle.
152
-		closedir( $handle );
152
+		closedir($handle);
153 153
 
154 154
 		return $accumulator;
155 155
 	}
@@ -161,21 +161,21 @@  discard block
 block discarded – undo
161 161
 	 *
162 162
 	 * @return array
163 163
 	 */
164
-	private function _reduce( $accumulator, $path, $handle ) {
164
+	private function _reduce($accumulator, $path, $handle) {
165 165
 
166
-		while ( false !== ( $entry = readdir( $handle ) ) ) {
166
+		while (false !== ($entry = readdir($handle))) {
167 167
 
168 168
 			// Skip to the next one.
169
-			if ( 0 === strpos( $entry, '.' ) ) {
169
+			if (0 === strpos($entry, '.')) {
170 170
 				continue;
171 171
 			}
172 172
 
173 173
 			// Set the full path to the entry.
174
-			$entry_path = $path . DIRECTORY_SEPARATOR . $entry;
174
+			$entry_path = $path.DIRECTORY_SEPARATOR.$entry;
175 175
 
176 176
 			// Handle directories.
177
-			if ( is_dir( $entry_path ) ) {
178
-				$accumulator = $this->reduce( $accumulator, $entry_path );
177
+			if (is_dir($entry_path)) {
178
+				$accumulator = $this->reduce($accumulator, $entry_path);
179 179
 
180 180
 				continue;
181 181
 			}
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
 			// Store the file data.
184 184
 			$accumulator[] = array(
185 185
 				$entry_path,
186
-				filemtime( $entry_path ),
187
-				filesize( $entry_path ),
186
+				filemtime($entry_path),
187
+				filesize($entry_path),
188 188
 			);
189 189
 		}
190 190
 
Please login to merge, or discard this patch.
src/install/class-wordlift-install-service.php 2 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -18,141 +18,141 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Install_Service {
20 20
 
21
-	/**
22
-	 * A {@link Wordlift_Log_Service} instance.
23
-	 *
24
-	 * @since  3.18.0
25
-	 * @access private
26
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
27
-	 */
28
-	private $log;
29
-
30
-	/**
31
-	 * The singleton instance.
32
-	 *
33
-	 * @since  3.18.0
34
-	 * @access private
35
-	 * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance.
36
-	 */
37
-	private static $instance;
38
-
39
-	/**
40
-	 * Wordlift_Install_Service constructor.
41
-	 *
42
-	 * @since 3.18.0
43
-	 */
44
-	public function __construct() {
45
-
46
-		/** Installs. */
47
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install.php';
48
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-1-0-0.php';
49
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-10-0.php';
50
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-12-0.php';
51
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-14-0.php';
52
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-15-0.php';
53
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-0.php';
54
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-3.php';
55
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-19-5.php';
56
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-20-0.php';
57
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-all-entity-types.php';
58
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-package-type.php';
59
-
60
-		self::$instance = $this;
61
-
62
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
63
-
64
-	}
65
-
66
-	/**
67
-	 * Get the singleton instance.
68
-	 *
69
-	 * @since 3.18.0
70
-	 */
71
-	public static function get_instance() {
72
-
73
-		return self::$instance;
74
-	}
75
-
76
-	/**
77
-	 * Loop thought all versions and install the updates.
78
-	 *
79
-	 * @return void
80
-	 * @since 3.18.0
81
-	 *
82
-	 * @since 3.20.0 use a transient to avoid concurrent installation calls.
83
-	 */
84
-	public function install() {
85
-
86
-		if ( false === get_transient( '_wl_installing' ) ) {
87
-			set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS );
88
-
89
-			$this->do_install();
90
-
91
-			@delete_transient( '_wl_installing' );
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Perform the actual installation.
98
-	 *
99
-	 * @since 3.20.0
100
-	 */
101
-	private function do_install() {
102
-
103
-		// Get the install services.
104
-		$installs = array(
105
-			new Wordlift_Install_1_0_0(),
106
-			new Wordlift_Install_3_10_0(),
107
-			new Wordlift_Install_3_12_0(),
108
-			new Wordlift_Install_3_14_0(),
109
-			new Wordlift_Install_3_15_0(),
110
-			new Wordlift_Install_3_18_0(),
111
-			new Wordlift_Install_3_18_3(),
112
-			new Wordlift_Install_3_19_5(),
113
-			new Wordlift_Install_3_20_0(),
114
-			/*
21
+    /**
22
+     * A {@link Wordlift_Log_Service} instance.
23
+     *
24
+     * @since  3.18.0
25
+     * @access private
26
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
27
+     */
28
+    private $log;
29
+
30
+    /**
31
+     * The singleton instance.
32
+     *
33
+     * @since  3.18.0
34
+     * @access private
35
+     * @var \Wordlift_Install_Service $instance A {@link Wordlift_Install_Service} instance.
36
+     */
37
+    private static $instance;
38
+
39
+    /**
40
+     * Wordlift_Install_Service constructor.
41
+     *
42
+     * @since 3.18.0
43
+     */
44
+    public function __construct() {
45
+
46
+        /** Installs. */
47
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install.php';
48
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-1-0-0.php';
49
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-10-0.php';
50
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-12-0.php';
51
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-14-0.php';
52
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-15-0.php';
53
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-0.php';
54
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-3.php';
55
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-19-5.php';
56
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-20-0.php';
57
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-all-entity-types.php';
58
+        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-package-type.php';
59
+
60
+        self::$instance = $this;
61
+
62
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
63
+
64
+    }
65
+
66
+    /**
67
+     * Get the singleton instance.
68
+     *
69
+     * @since 3.18.0
70
+     */
71
+    public static function get_instance() {
72
+
73
+        return self::$instance;
74
+    }
75
+
76
+    /**
77
+     * Loop thought all versions and install the updates.
78
+     *
79
+     * @return void
80
+     * @since 3.18.0
81
+     *
82
+     * @since 3.20.0 use a transient to avoid concurrent installation calls.
83
+     */
84
+    public function install() {
85
+
86
+        if ( false === get_transient( '_wl_installing' ) ) {
87
+            set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS );
88
+
89
+            $this->do_install();
90
+
91
+            @delete_transient( '_wl_installing' );
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Perform the actual installation.
98
+     *
99
+     * @since 3.20.0
100
+     */
101
+    private function do_install() {
102
+
103
+        // Get the install services.
104
+        $installs = array(
105
+            new Wordlift_Install_1_0_0(),
106
+            new Wordlift_Install_3_10_0(),
107
+            new Wordlift_Install_3_12_0(),
108
+            new Wordlift_Install_3_14_0(),
109
+            new Wordlift_Install_3_15_0(),
110
+            new Wordlift_Install_3_18_0(),
111
+            new Wordlift_Install_3_18_3(),
112
+            new Wordlift_Install_3_19_5(),
113
+            new Wordlift_Install_3_20_0(),
114
+            /*
115 115
 			 * This should be enabled with #852.
116 116
 			 */
117
-			// new Wordlift_Install_All_Entity_Types(),
118
-			new Wordlift_Install_Package_Type(),
119
-		);
117
+            // new Wordlift_Install_All_Entity_Types(),
118
+            new Wordlift_Install_Package_Type(),
119
+        );
120 120
 
121
-		$version = null;
121
+        $version = null;
122 122
 
123
-		/** @var Wordlift_Install $install */
124
-		foreach ( $installs as $install ) {
125
-			// Get the install version.
126
-			$version = $install->get_version();
123
+        /** @var Wordlift_Install $install */
124
+        foreach ( $installs as $install ) {
125
+            // Get the install version.
126
+            $version = $install->get_version();
127 127
 
128
-			if ( version_compare( $version, $this->get_current_version(), '>' )
129
-			     || $install->must_install() ) {
128
+            if ( version_compare( $version, $this->get_current_version(), '>' )
129
+                 || $install->must_install() ) {
130 130
 
131
-				$class_name = get_class( $install );
131
+                $class_name = get_class( $install );
132 132
 
133
-				$this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." );
133
+                $this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." );
134 134
 
135
-				// Install version.
136
-				$install->install();
135
+                // Install version.
136
+                $install->install();
137 137
 
138
-				$this->log->info( "$class_name installed." );
138
+                $this->log->info( "$class_name installed." );
139 139
 
140
-				// Bump the version.
141
-				update_option( 'wl_db_version', $version );
140
+                // Bump the version.
141
+                update_option( 'wl_db_version', $version );
142 142
 
143
-			}
143
+            }
144 144
 
145
-		}
145
+        }
146 146
 
147
-	}
147
+    }
148 148
 
149
-	/**
150
-	 * Retrieve the current db version.
151
-	 *
152
-	 * @return type
153
-	 */
154
-	private function get_current_version() {
155
-		return get_option( 'wl_db_version', '0.0.0' );
156
-	}
149
+    /**
150
+     * Retrieve the current db version.
151
+     *
152
+     * @return type
153
+     */
154
+    private function get_current_version() {
155
+        return get_option( 'wl_db_version', '0.0.0' );
156
+    }
157 157
 
158 158
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -44,22 +44,22 @@  discard block
 block discarded – undo
44 44
 	public function __construct() {
45 45
 
46 46
 		/** Installs. */
47
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install.php';
48
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-1-0-0.php';
49
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-10-0.php';
50
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-12-0.php';
51
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-14-0.php';
52
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-15-0.php';
53
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-0.php';
54
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-18-3.php';
55
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-19-5.php';
56
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-3-20-0.php';
57
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-all-entity-types.php';
58
-		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'install/class-wordlift-install-package-type.php';
47
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install.php';
48
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-1-0-0.php';
49
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-10-0.php';
50
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-12-0.php';
51
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-14-0.php';
52
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-15-0.php';
53
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-18-0.php';
54
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-18-3.php';
55
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-19-5.php';
56
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-3-20-0.php';
57
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-all-entity-types.php';
58
+		require_once plugin_dir_path(dirname(__FILE__)).'install/class-wordlift-install-package-type.php';
59 59
 
60 60
 		self::$instance = $this;
61 61
 
62
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
62
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
63 63
 
64 64
 	}
65 65
 
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	public function install() {
85 85
 
86
-		if ( false === get_transient( '_wl_installing' ) ) {
87
-			set_transient( '_wl_installing', true, 5 * MINUTE_IN_SECONDS );
86
+		if (false === get_transient('_wl_installing')) {
87
+			set_transient('_wl_installing', true, 5 * MINUTE_IN_SECONDS);
88 88
 
89 89
 			$this->do_install();
90 90
 
91
-			@delete_transient( '_wl_installing' );
91
+			@delete_transient('_wl_installing');
92 92
 		}
93 93
 
94 94
 	}
@@ -121,24 +121,24 @@  discard block
 block discarded – undo
121 121
 		$version = null;
122 122
 
123 123
 		/** @var Wordlift_Install $install */
124
-		foreach ( $installs as $install ) {
124
+		foreach ($installs as $install) {
125 125
 			// Get the install version.
126 126
 			$version = $install->get_version();
127 127
 
128
-			if ( version_compare( $version, $this->get_current_version(), '>' )
129
-			     || $install->must_install() ) {
128
+			if (version_compare($version, $this->get_current_version(), '>')
129
+			     || $install->must_install()) {
130 130
 
131
-				$class_name = get_class( $install );
131
+				$class_name = get_class($install);
132 132
 
133
-				$this->log->info( "Current version is {$this->get_current_version()}, installing $class_name..." );
133
+				$this->log->info("Current version is {$this->get_current_version()}, installing $class_name...");
134 134
 
135 135
 				// Install version.
136 136
 				$install->install();
137 137
 
138
-				$this->log->info( "$class_name installed." );
138
+				$this->log->info("$class_name installed.");
139 139
 
140 140
 				// Bump the version.
141
-				update_option( 'wl_db_version', $version );
141
+				update_option('wl_db_version', $version);
142 142
 
143 143
 			}
144 144
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 * @return type
153 153
 	 */
154 154
 	private function get_current_version() {
155
-		return get_option( 'wl_db_version', '0.0.0' );
155
+		return get_option('wl_db_version', '0.0.0');
156 156
 	}
157 157
 
158 158
 }
Please login to merge, or discard this patch.
src/public/class-wordlift-public.php 2 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -22,107 +22,107 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class Wordlift_Public {
24 24
 
25
-	/**
26
-	 * The ID of this plugin.
27
-	 *
28
-	 * @since    1.0.0
29
-	 * @access   private
30
-	 * @var      string $plugin_name The ID of this plugin.
31
-	 */
32
-	private $plugin_name;
33
-
34
-	/**
35
-	 * The version of this plugin.
36
-	 *
37
-	 * @since    1.0.0
38
-	 * @access   private
39
-	 * @var      string $version The current version of this plugin.
40
-	 */
41
-	private $version;
42
-
43
-	/**
44
-	 * Initialize the class and set its properties.
45
-	 *
46
-	 * @since    1.0.0
47
-	 *
48
-	 * @param      string $plugin_name The name of the plugin.
49
-	 * @param      string $version The version of this plugin.
50
-	 */
51
-	public function __construct( $plugin_name, $version ) {
52
-
53
-		$this->plugin_name = $plugin_name;
54
-		$this->version     = $version;
55
-
56
-	}
57
-
58
-	/**
59
-	 * Register the stylesheets for the public-facing side of the site.
60
-	 *
61
-	 * @since 3.19.3 Register the `wordlift-ui` css.
62
-	 * @since 3.19.2 The call to this function is commented out in `class-wordlift.php` because `wordlift-public.css`
63
-	 *               is empty.
64
-	 * @since 1.0.0
65
-	 */
66
-	public function enqueue_styles() {
67
-
68
-		/**
69
-		 * An instance of this class should be passed to the run() function
70
-		 * defined in Wordlift_Loader as all of the hooks are defined
71
-		 * in that particular class.
72
-		 *
73
-		 * The Wordlift_Loader will then create the relationship
74
-		 * between the defined hooks and the functions defined in this
75
-		 * class.
76
-		 */
77
-
78
-		/**
79
-		 * Add the `wordlift-font-awesome` unless some 3rd party sets the flag to false.
80
-		 *
81
-		 * @since 3.19.3
82
-		 *
83
-		 * @param bool $include Whether to include or not font-awesome (default true).
84
-		 */
85
-		$deps = apply_filters( 'wl_include_font_awesome', true )
86
-			? array( 'wordlift-font-awesome' )
87
-			: array();
88
-		wp_register_style( 'wordlift-font-awesome', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' );
89
-		wp_register_style( 'wordlift-ui', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' );
90
-
91
-		// You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective.
92
-		//
93
-		// @see https://github.com/insideout10/wordlift-plugin/issues/821
94
-		//
95
-		// wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-public.css', array(), $this->version, 'all' );
96
-
97
-	}
98
-
99
-	/**
100
-	 * Register the stylesheets for the public-facing side of the site.
101
-	 *
102
-	 * @since    1.0.0
103
-	 */
104
-	public function enqueue_scripts() {
105
-
106
-		/**
107
-		 * This function is provided for demonstration purposes only.
108
-		 *
109
-		 * An instance of this class should be passed to the run() function
110
-		 * defined in Wordlift_Loader as all of the hooks are defined
111
-		 * in that particular class.
112
-		 *
113
-		 * The Wordlift_Loader will then create the relationship
114
-		 * between the defined hooks and the functions defined in this
115
-		 * class.
116
-		 */
117
-
118
-		$settings = self::get_settings();
119
-
120
-		// Note that we switched the js to be loaded in footer, since it is loading
121
-		// the json-ld representation.
122
-		wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true );
123
-		wp_localize_script( $this->plugin_name, 'wlSettings', $settings );
124
-
125
-		/*
25
+    /**
26
+     * The ID of this plugin.
27
+     *
28
+     * @since    1.0.0
29
+     * @access   private
30
+     * @var      string $plugin_name The ID of this plugin.
31
+     */
32
+    private $plugin_name;
33
+
34
+    /**
35
+     * The version of this plugin.
36
+     *
37
+     * @since    1.0.0
38
+     * @access   private
39
+     * @var      string $version The current version of this plugin.
40
+     */
41
+    private $version;
42
+
43
+    /**
44
+     * Initialize the class and set its properties.
45
+     *
46
+     * @since    1.0.0
47
+     *
48
+     * @param      string $plugin_name The name of the plugin.
49
+     * @param      string $version The version of this plugin.
50
+     */
51
+    public function __construct( $plugin_name, $version ) {
52
+
53
+        $this->plugin_name = $plugin_name;
54
+        $this->version     = $version;
55
+
56
+    }
57
+
58
+    /**
59
+     * Register the stylesheets for the public-facing side of the site.
60
+     *
61
+     * @since 3.19.3 Register the `wordlift-ui` css.
62
+     * @since 3.19.2 The call to this function is commented out in `class-wordlift.php` because `wordlift-public.css`
63
+     *               is empty.
64
+     * @since 1.0.0
65
+     */
66
+    public function enqueue_styles() {
67
+
68
+        /**
69
+         * An instance of this class should be passed to the run() function
70
+         * defined in Wordlift_Loader as all of the hooks are defined
71
+         * in that particular class.
72
+         *
73
+         * The Wordlift_Loader will then create the relationship
74
+         * between the defined hooks and the functions defined in this
75
+         * class.
76
+         */
77
+
78
+        /**
79
+         * Add the `wordlift-font-awesome` unless some 3rd party sets the flag to false.
80
+         *
81
+         * @since 3.19.3
82
+         *
83
+         * @param bool $include Whether to include or not font-awesome (default true).
84
+         */
85
+        $deps = apply_filters( 'wl_include_font_awesome', true )
86
+            ? array( 'wordlift-font-awesome' )
87
+            : array();
88
+        wp_register_style( 'wordlift-font-awesome', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' );
89
+        wp_register_style( 'wordlift-ui', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' );
90
+
91
+        // You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective.
92
+        //
93
+        // @see https://github.com/insideout10/wordlift-plugin/issues/821
94
+        //
95
+        // wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-public.css', array(), $this->version, 'all' );
96
+
97
+    }
98
+
99
+    /**
100
+     * Register the stylesheets for the public-facing side of the site.
101
+     *
102
+     * @since    1.0.0
103
+     */
104
+    public function enqueue_scripts() {
105
+
106
+        /**
107
+         * This function is provided for demonstration purposes only.
108
+         *
109
+         * An instance of this class should be passed to the run() function
110
+         * defined in Wordlift_Loader as all of the hooks are defined
111
+         * in that particular class.
112
+         *
113
+         * The Wordlift_Loader will then create the relationship
114
+         * between the defined hooks and the functions defined in this
115
+         * class.
116
+         */
117
+
118
+        $settings = self::get_settings();
119
+
120
+        // Note that we switched the js to be loaded in footer, since it is loading
121
+        // the json-ld representation.
122
+        wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true );
123
+        wp_localize_script( $this->plugin_name, 'wlSettings', $settings );
124
+
125
+        /*
126 126
 		 * Add WordLift's version.
127 127
 		 * Can be disabled via filter 'wl_disable_version_js' since 3.21.1
128 128
 		 *
@@ -131,81 +131,81 @@  discard block
 block discarded – undo
131 131
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/843.
132 132
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/926.
133 133
 		 */
134
-		$show_version_default = false;
135
-		$show_version = apply_filters( 'wl_disable_version_js', $show_version_default );
134
+        $show_version_default = false;
135
+        $show_version = apply_filters( 'wl_disable_version_js', $show_version_default );
136 136
 
137
-		if($show_version) {
138
-			wp_localize_script( $this->plugin_name, 'wordlift', array(
139
-				'version' => $this->version,
140
-			) );
141
-		}
137
+        if($show_version) {
138
+            wp_localize_script( $this->plugin_name, 'wordlift', array(
139
+                'version' => $this->version,
140
+            ) );
141
+        }
142 142
 
143
-		/*
143
+        /*
144 144
 		 * Register wordlift-cloud script which is shared by
145 145
 		 * Context Cards and Navigator
146 146
 		 *
147 147
 		 * @since 3.22.0
148 148
 		 *
149 149
 		 */
150
-		wp_register_script( 'wordlift-cloud', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/wordlift-cloud.js', array(), false, true );
151
-
152
-	}
153
-
154
-	/**
155
-	 * Get the settings array.
156
-	 *
157
-	 * @since 3.19.1
158
-	 *
159
-	 * @return array An array with the settings.
160
-	 */
161
-	public static function get_settings() {
162
-
163
-		// Prepare a settings array for client-side functions.
164
-		$settings = array(
165
-			'ajaxUrl' => admin_url( 'admin-ajax.php' ),
166
-			'apiUrl'  => get_home_url( null, 'wl-api/' ),
167
-		);
168
-
169
-		// If we're in a single page, then print out the post id.
170
-		if ( is_singular() ) {
171
-			$settings['postId'] = get_the_ID();
172
-		}
173
-
174
-		// Add flag that we are on home/blog page.
175
-		if ( is_home() || is_front_page() ) {
176
-			$settings['isHome'] = true;
177
-		}
178
-
179
-		// By default only enable JSON-LD on supported entity pages (includes
180
-		// `page`, `post` and `entity` by default) and on the home page.
181
-		//
182
-		// @see https://github.com/insideout10/wordlift-plugin/issues/733
183
-		$jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type( get_post_type() );
184
-
185
-		// Add the JSON-LD enabled flag, when set to false, the JSON-lD won't
186
-		// be loaded.
187
-		//
188
-		// @see https://github.com/insideout10/wordlift-plugin/issues/642.
189
-		$settings['jsonld_enabled'] = apply_filters( 'wl_jsonld_enabled', $jsonld_enabled );
190
-
191
-		return $settings;
192
-	}
193
-
194
-	/**
195
-	 * Get the public JavaScript URL.
196
-	 *
197
-	 * Using this function is encouraged, since the public JavaScript is also used by the {@link Wordlift_WpRocket_Adapter}
198
-	 * in order to avoid breaking optimizations.
199
-	 *
200
-	 * @since 3.19.4
201
-	 *
202
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/842.
203
-	 *
204
-	 * @return string The URL to the public JavaScript.
205
-	 */
206
-	public static function get_public_js_url() {
207
-
208
-		return plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/bundle.js';
209
-	}
150
+        wp_register_script( 'wordlift-cloud', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/wordlift-cloud.js', array(), false, true );
151
+
152
+    }
153
+
154
+    /**
155
+     * Get the settings array.
156
+     *
157
+     * @since 3.19.1
158
+     *
159
+     * @return array An array with the settings.
160
+     */
161
+    public static function get_settings() {
162
+
163
+        // Prepare a settings array for client-side functions.
164
+        $settings = array(
165
+            'ajaxUrl' => admin_url( 'admin-ajax.php' ),
166
+            'apiUrl'  => get_home_url( null, 'wl-api/' ),
167
+        );
168
+
169
+        // If we're in a single page, then print out the post id.
170
+        if ( is_singular() ) {
171
+            $settings['postId'] = get_the_ID();
172
+        }
173
+
174
+        // Add flag that we are on home/blog page.
175
+        if ( is_home() || is_front_page() ) {
176
+            $settings['isHome'] = true;
177
+        }
178
+
179
+        // By default only enable JSON-LD on supported entity pages (includes
180
+        // `page`, `post` and `entity` by default) and on the home page.
181
+        //
182
+        // @see https://github.com/insideout10/wordlift-plugin/issues/733
183
+        $jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type( get_post_type() );
184
+
185
+        // Add the JSON-LD enabled flag, when set to false, the JSON-lD won't
186
+        // be loaded.
187
+        //
188
+        // @see https://github.com/insideout10/wordlift-plugin/issues/642.
189
+        $settings['jsonld_enabled'] = apply_filters( 'wl_jsonld_enabled', $jsonld_enabled );
190
+
191
+        return $settings;
192
+    }
193
+
194
+    /**
195
+     * Get the public JavaScript URL.
196
+     *
197
+     * Using this function is encouraged, since the public JavaScript is also used by the {@link Wordlift_WpRocket_Adapter}
198
+     * in order to avoid breaking optimizations.
199
+     *
200
+     * @since 3.19.4
201
+     *
202
+     * @see https://github.com/insideout10/wordlift-plugin/issues/842.
203
+     *
204
+     * @return string The URL to the public JavaScript.
205
+     */
206
+    public static function get_public_js_url() {
207
+
208
+        return plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/bundle.js';
209
+    }
210 210
 
211 211
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @param      string $plugin_name The name of the plugin.
49 49
 	 * @param      string $version The version of this plugin.
50 50
 	 */
51
-	public function __construct( $plugin_name, $version ) {
51
+	public function __construct($plugin_name, $version) {
52 52
 
53 53
 		$this->plugin_name = $plugin_name;
54 54
 		$this->version     = $version;
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 		 *
83 83
 		 * @param bool $include Whether to include or not font-awesome (default true).
84 84
 		 */
85
-		$deps = apply_filters( 'wl_include_font_awesome', true )
86
-			? array( 'wordlift-font-awesome' )
85
+		$deps = apply_filters('wl_include_font_awesome', true)
86
+			? array('wordlift-font-awesome')
87 87
 			: array();
88
-		wp_register_style( 'wordlift-font-awesome', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-font-awesome' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), $this->version, 'all' );
89
-		wp_register_style( 'wordlift-ui', plugin_dir_url( dirname( __FILE__ ) ) . 'css/wordlift-ui' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', $deps, $this->version, 'all' );
88
+		wp_register_style('wordlift-font-awesome', plugin_dir_url(dirname(__FILE__)).'css/wordlift-font-awesome'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', array(), $this->version, 'all');
89
+		wp_register_style('wordlift-ui', plugin_dir_url(dirname(__FILE__)).'css/wordlift-ui'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', $deps, $this->version, 'all');
90 90
 
91 91
 		// You need to re-enable the enqueue_styles in `class-wordlift.php` to make this effective.
92 92
 		//
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 
120 120
 		// Note that we switched the js to be loaded in footer, since it is loading
121 121
 		// the json-ld representation.
122
-		wp_enqueue_script( $this->plugin_name, self::get_public_js_url(), array(), $this->version, true );
123
-		wp_localize_script( $this->plugin_name, 'wlSettings', $settings );
122
+		wp_enqueue_script($this->plugin_name, self::get_public_js_url(), array(), $this->version, true);
123
+		wp_localize_script($this->plugin_name, 'wlSettings', $settings);
124 124
 
125 125
 		/*
126 126
 		 * Add WordLift's version.
@@ -132,12 +132,12 @@  discard block
 block discarded – undo
132 132
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/926.
133 133
 		 */
134 134
 		$show_version_default = false;
135
-		$show_version = apply_filters( 'wl_disable_version_js', $show_version_default );
135
+		$show_version = apply_filters('wl_disable_version_js', $show_version_default);
136 136
 
137
-		if($show_version) {
138
-			wp_localize_script( $this->plugin_name, 'wordlift', array(
137
+		if ($show_version) {
138
+			wp_localize_script($this->plugin_name, 'wordlift', array(
139 139
 				'version' => $this->version,
140
-			) );
140
+			));
141 141
 		}
142 142
 
143 143
 		/*
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 		 * @since 3.22.0
148 148
 		 *
149 149
 		 */
150
-		wp_register_script( 'wordlift-cloud', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/wordlift-cloud.js', array(), false, true );
150
+		wp_register_script('wordlift-cloud', plugin_dir_url(dirname(__FILE__)).'js/dist/wordlift-cloud.js', array(), false, true);
151 151
 
152 152
 	}
153 153
 
@@ -162,17 +162,17 @@  discard block
 block discarded – undo
162 162
 
163 163
 		// Prepare a settings array for client-side functions.
164 164
 		$settings = array(
165
-			'ajaxUrl' => admin_url( 'admin-ajax.php' ),
166
-			'apiUrl'  => get_home_url( null, 'wl-api/' ),
165
+			'ajaxUrl' => admin_url('admin-ajax.php'),
166
+			'apiUrl'  => get_home_url(null, 'wl-api/'),
167 167
 		);
168 168
 
169 169
 		// If we're in a single page, then print out the post id.
170
-		if ( is_singular() ) {
170
+		if (is_singular()) {
171 171
 			$settings['postId'] = get_the_ID();
172 172
 		}
173 173
 
174 174
 		// Add flag that we are on home/blog page.
175
-		if ( is_home() || is_front_page() ) {
175
+		if (is_home() || is_front_page()) {
176 176
 			$settings['isHome'] = true;
177 177
 		}
178 178
 
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
 		// `page`, `post` and `entity` by default) and on the home page.
181 181
 		//
182 182
 		// @see https://github.com/insideout10/wordlift-plugin/issues/733
183
-		$jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type( get_post_type() );
183
+		$jsonld_enabled = is_home() || is_front_page() || Wordlift_Entity_Type_Service::is_valid_entity_post_type(get_post_type());
184 184
 
185 185
 		// Add the JSON-LD enabled flag, when set to false, the JSON-lD won't
186 186
 		// be loaded.
187 187
 		//
188 188
 		// @see https://github.com/insideout10/wordlift-plugin/issues/642.
189
-		$settings['jsonld_enabled'] = apply_filters( 'wl_jsonld_enabled', $jsonld_enabled );
189
+		$settings['jsonld_enabled'] = apply_filters('wl_jsonld_enabled', $jsonld_enabled);
190 190
 
191 191
 		return $settings;
192 192
 	}
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 */
206 206
 	public static function get_public_js_url() {
207 207
 
208
-		return plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/bundle.js';
208
+		return plugin_dir_url(dirname(__FILE__)).'js/dist/bundle.js';
209 209
 	}
210 210
 
211 211
 }
Please login to merge, or discard this patch.
src/public/class-wordlift-navigator-shortcode.php 2 patches
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -17,140 +17,140 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Navigator_Shortcode extends Wordlift_Shortcode {
19 19
 
20
-	/**
21
-	 * {@inheritdoc}
22
-	 */
23
-	const SHORTCODE = 'wl_navigator';
24
-
25
-	/**
26
-	 * {@inheritdoc}
27
-	 */
28
-	public function render( $atts ) {
29
-
30
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
31
-			: $this->web_shortcode( $atts );
32
-	}
33
-
34
-	/**
35
-	 * Shared function used by web_shortcode and amp_shortcode
36
-	 * Bootstrap logic for attributes extraction and boolean filtering
37
-	 *
38
-	 * @param array $atts Shortcode attributes.
39
-	 *
40
-	 * @return array $shortcode_atts
41
-	 * @since      3.20.0
42
-	 *
43
-	 */
44
-	private function make_shortcode_atts( $atts ) {
45
-
46
-		// Extract attributes and set default values.
47
-		$shortcode_atts = shortcode_atts( array(
48
-			'title'       => __( 'Related articles', 'wordlift' ),
49
-			'limit'       => 4,
50
-			'offset'      => 0,
51
-			'template_id' => '',
52
-			'post_id'     => '',
53
-			'uniqid'      => uniqid( 'wl-navigator-widget-' ),
54
-			'order_by'    => 'ID ASC'
55
-		), $atts );
56
-
57
-		return $shortcode_atts;
58
-	}
59
-
60
-	/**
61
-	 * Function in charge of diplaying the [wl-navigator] in web mode.
62
-	 *
63
-	 * @param array $atts Shortcode attributes.
64
-	 *
65
-	 * @return string Shortcode HTML for web
66
-	 * @since 3.20.0
67
-	 *
68
-	 */
69
-	private function web_shortcode( $atts ) {
70
-
71
-		// attributes extraction and boolean filtering
72
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
73
-
74
-		// avoid building the widget when no post_id is specified and there is a list of posts.
75
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
76
-			return;
77
-		}
78
-
79
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
80
-		$navigator_id = $shortcode_atts['uniqid'];
81
-		$rest_url     = $post ? admin_url( sprintf( 'admin-ajax.php?action=wl_navigator&uniqid=%s&post_id=%s&limit=%s&offset=%s&order_by=%s', $navigator_id, $post->ID, $shortcode_atts['limit'], $shortcode_atts['offset'], $shortcode_atts['order_by'] ) ) : false;
82
-
83
-		// avoid building the widget when no valid $rest_url
84
-		if ( ! $rest_url ) {
85
-			return;
86
-		}
87
-
88
-		wp_enqueue_script( 'wordlift-cloud' );
89
-		$json_navigator_id = json_encode( $navigator_id );
90
-		wp_add_inline_script( 'wordlift-cloud', "window.wlNavigators = window.wlNavigators || []; wlNavigators.push( $json_navigator_id );" );
91
-
92
-		return sprintf(
93
-			'<div id="%s" class="%s" data-rest-url="%s" data-title="%s" data-template-id="%s" data-limit="%s"></div>',
94
-			$navigator_id,
95
-			'wl-navigator',
96
-			$rest_url,
97
-			$shortcode_atts['title'],
98
-			$shortcode_atts['template_id'],
99
-			$shortcode_atts['limit']
100
-		);
101
-	}
102
-
103
-	/**
104
-	 * Function in charge of diplaying the [wl-faceted-search] in amp mode.
105
-	 *
106
-	 * @param array $atts Shortcode attributes.
107
-	 *
108
-	 * @return string Shortcode HTML for amp
109
-	 * @since 3.20.0
110
-	 *
111
-	 */
112
-	private function amp_shortcode( $atts ) {
113
-
114
-		// attributes extraction and boolean filtering
115
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
116
-
117
-		// avoid building the widget when there is a list of posts.
118
-		if ( ! is_singular() ) {
119
-			return '';
120
-		}
121
-
122
-		$current_post = get_post();
123
-
124
-		// Enqueue amp specific styles
125
-		wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
126
-
127
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
128
-		$navigator_id = $shortcode_atts['uniqid'];
129
-
130
-		$wp_json_base = get_rest_url() . WL_REST_ROUTE_DEFAULT_NAMESPACE;
131
-
132
-		$navigator_query = array(
133
-			'uniqid'  => $navigator_id,
134
-			'post_id' => $post->ID,
135
-			'limit'   => $shortcode_atts['limit'],
136
-			'offset'  => $shortcode_atts['offset'],
137
-			'order_by'=> 'ID ASC'
138
-		);
139
-
140
-		if ( strpos( $wp_json_base, 'wp-json/' . WL_REST_ROUTE_DEFAULT_NAMESPACE ) ) {
141
-			$delimiter = '?';
142
-		} else {
143
-			$delimiter = '&';
144
-		}
145
-
146
-		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
147
-		// This is a hackish way, but this works for http and https URLs
148
-		$wp_json_url_posts = str_replace( array(
149
-				'http:',
150
-				'https:',
151
-			), '', $wp_json_base ) . '/navigator' . $delimiter . http_build_query( $navigator_query );
152
-
153
-		return <<<HTML
20
+    /**
21
+     * {@inheritdoc}
22
+     */
23
+    const SHORTCODE = 'wl_navigator';
24
+
25
+    /**
26
+     * {@inheritdoc}
27
+     */
28
+    public function render( $atts ) {
29
+
30
+        return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
31
+            : $this->web_shortcode( $atts );
32
+    }
33
+
34
+    /**
35
+     * Shared function used by web_shortcode and amp_shortcode
36
+     * Bootstrap logic for attributes extraction and boolean filtering
37
+     *
38
+     * @param array $atts Shortcode attributes.
39
+     *
40
+     * @return array $shortcode_atts
41
+     * @since      3.20.0
42
+     *
43
+     */
44
+    private function make_shortcode_atts( $atts ) {
45
+
46
+        // Extract attributes and set default values.
47
+        $shortcode_atts = shortcode_atts( array(
48
+            'title'       => __( 'Related articles', 'wordlift' ),
49
+            'limit'       => 4,
50
+            'offset'      => 0,
51
+            'template_id' => '',
52
+            'post_id'     => '',
53
+            'uniqid'      => uniqid( 'wl-navigator-widget-' ),
54
+            'order_by'    => 'ID ASC'
55
+        ), $atts );
56
+
57
+        return $shortcode_atts;
58
+    }
59
+
60
+    /**
61
+     * Function in charge of diplaying the [wl-navigator] in web mode.
62
+     *
63
+     * @param array $atts Shortcode attributes.
64
+     *
65
+     * @return string Shortcode HTML for web
66
+     * @since 3.20.0
67
+     *
68
+     */
69
+    private function web_shortcode( $atts ) {
70
+
71
+        // attributes extraction and boolean filtering
72
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
73
+
74
+        // avoid building the widget when no post_id is specified and there is a list of posts.
75
+        if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
76
+            return;
77
+        }
78
+
79
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
80
+        $navigator_id = $shortcode_atts['uniqid'];
81
+        $rest_url     = $post ? admin_url( sprintf( 'admin-ajax.php?action=wl_navigator&uniqid=%s&post_id=%s&limit=%s&offset=%s&order_by=%s', $navigator_id, $post->ID, $shortcode_atts['limit'], $shortcode_atts['offset'], $shortcode_atts['order_by'] ) ) : false;
82
+
83
+        // avoid building the widget when no valid $rest_url
84
+        if ( ! $rest_url ) {
85
+            return;
86
+        }
87
+
88
+        wp_enqueue_script( 'wordlift-cloud' );
89
+        $json_navigator_id = json_encode( $navigator_id );
90
+        wp_add_inline_script( 'wordlift-cloud', "window.wlNavigators = window.wlNavigators || []; wlNavigators.push( $json_navigator_id );" );
91
+
92
+        return sprintf(
93
+            '<div id="%s" class="%s" data-rest-url="%s" data-title="%s" data-template-id="%s" data-limit="%s"></div>',
94
+            $navigator_id,
95
+            'wl-navigator',
96
+            $rest_url,
97
+            $shortcode_atts['title'],
98
+            $shortcode_atts['template_id'],
99
+            $shortcode_atts['limit']
100
+        );
101
+    }
102
+
103
+    /**
104
+     * Function in charge of diplaying the [wl-faceted-search] in amp mode.
105
+     *
106
+     * @param array $atts Shortcode attributes.
107
+     *
108
+     * @return string Shortcode HTML for amp
109
+     * @since 3.20.0
110
+     *
111
+     */
112
+    private function amp_shortcode( $atts ) {
113
+
114
+        // attributes extraction and boolean filtering
115
+        $shortcode_atts = $this->make_shortcode_atts( $atts );
116
+
117
+        // avoid building the widget when there is a list of posts.
118
+        if ( ! is_singular() ) {
119
+            return '';
120
+        }
121
+
122
+        $current_post = get_post();
123
+
124
+        // Enqueue amp specific styles
125
+        wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
126
+
127
+        $post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
128
+        $navigator_id = $shortcode_atts['uniqid'];
129
+
130
+        $wp_json_base = get_rest_url() . WL_REST_ROUTE_DEFAULT_NAMESPACE;
131
+
132
+        $navigator_query = array(
133
+            'uniqid'  => $navigator_id,
134
+            'post_id' => $post->ID,
135
+            'limit'   => $shortcode_atts['limit'],
136
+            'offset'  => $shortcode_atts['offset'],
137
+            'order_by'=> 'ID ASC'
138
+        );
139
+
140
+        if ( strpos( $wp_json_base, 'wp-json/' . WL_REST_ROUTE_DEFAULT_NAMESPACE ) ) {
141
+            $delimiter = '?';
142
+        } else {
143
+            $delimiter = '&';
144
+        }
145
+
146
+        // Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
147
+        // This is a hackish way, but this works for http and https URLs
148
+        $wp_json_url_posts = str_replace( array(
149
+                'http:',
150
+                'https:',
151
+            ), '', $wp_json_base ) . '/navigator' . $delimiter . http_build_query( $navigator_query );
152
+
153
+        return <<<HTML
154 154
 		<div id="{$navigator_id}" class="wl-navigator-widget" style="width: 100%">
155 155
 			<h3 class="wl-headline">{$shortcode_atts['title']}</h3>
156 156
 			<amp-list 
@@ -207,6 +207,6 @@  discard block
 block discarded – undo
207 207
 			</amp-list>	
208 208
 		</div>
209 209
 HTML;
210
-	}
210
+    }
211 211
 
212 212
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
 	/**
26 26
 	 * {@inheritdoc}
27 27
 	 */
28
-	public function render( $atts ) {
28
+	public function render($atts) {
29 29
 
30
-		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode( $atts )
31
-			: $this->web_shortcode( $atts );
30
+		return Wordlift_AMP_Service::is_amp_endpoint() ? $this->amp_shortcode($atts)
31
+			: $this->web_shortcode($atts);
32 32
 	}
33 33
 
34 34
 	/**
@@ -41,18 +41,18 @@  discard block
 block discarded – undo
41 41
 	 * @since      3.20.0
42 42
 	 *
43 43
 	 */
44
-	private function make_shortcode_atts( $atts ) {
44
+	private function make_shortcode_atts($atts) {
45 45
 
46 46
 		// Extract attributes and set default values.
47
-		$shortcode_atts = shortcode_atts( array(
48
-			'title'       => __( 'Related articles', 'wordlift' ),
47
+		$shortcode_atts = shortcode_atts(array(
48
+			'title'       => __('Related articles', 'wordlift'),
49 49
 			'limit'       => 4,
50 50
 			'offset'      => 0,
51 51
 			'template_id' => '',
52 52
 			'post_id'     => '',
53
-			'uniqid'      => uniqid( 'wl-navigator-widget-' ),
53
+			'uniqid'      => uniqid('wl-navigator-widget-'),
54 54
 			'order_by'    => 'ID ASC'
55
-		), $atts );
55
+		), $atts);
56 56
 
57 57
 		return $shortcode_atts;
58 58
 	}
@@ -66,28 +66,28 @@  discard block
 block discarded – undo
66 66
 	 * @since 3.20.0
67 67
 	 *
68 68
 	 */
69
-	private function web_shortcode( $atts ) {
69
+	private function web_shortcode($atts) {
70 70
 
71 71
 		// attributes extraction and boolean filtering
72
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
72
+		$shortcode_atts = $this->make_shortcode_atts($atts);
73 73
 
74 74
 		// avoid building the widget when no post_id is specified and there is a list of posts.
75
-		if ( empty( $shortcode_atts['post_id'] ) && ! is_singular() ) {
75
+		if (empty($shortcode_atts['post_id']) && ! is_singular()) {
76 76
 			return;
77 77
 		}
78 78
 
79
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
79
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval($shortcode_atts['post_id'])) : get_post();
80 80
 		$navigator_id = $shortcode_atts['uniqid'];
81
-		$rest_url     = $post ? admin_url( sprintf( 'admin-ajax.php?action=wl_navigator&uniqid=%s&post_id=%s&limit=%s&offset=%s&order_by=%s', $navigator_id, $post->ID, $shortcode_atts['limit'], $shortcode_atts['offset'], $shortcode_atts['order_by'] ) ) : false;
81
+		$rest_url     = $post ? admin_url(sprintf('admin-ajax.php?action=wl_navigator&uniqid=%s&post_id=%s&limit=%s&offset=%s&order_by=%s', $navigator_id, $post->ID, $shortcode_atts['limit'], $shortcode_atts['offset'], $shortcode_atts['order_by'])) : false;
82 82
 
83 83
 		// avoid building the widget when no valid $rest_url
84
-		if ( ! $rest_url ) {
84
+		if ( ! $rest_url) {
85 85
 			return;
86 86
 		}
87 87
 
88
-		wp_enqueue_script( 'wordlift-cloud' );
89
-		$json_navigator_id = json_encode( $navigator_id );
90
-		wp_add_inline_script( 'wordlift-cloud', "window.wlNavigators = window.wlNavigators || []; wlNavigators.push( $json_navigator_id );" );
88
+		wp_enqueue_script('wordlift-cloud');
89
+		$json_navigator_id = json_encode($navigator_id);
90
+		wp_add_inline_script('wordlift-cloud', "window.wlNavigators = window.wlNavigators || []; wlNavigators.push( $json_navigator_id );");
91 91
 
92 92
 		return sprintf(
93 93
 			'<div id="%s" class="%s" data-rest-url="%s" data-title="%s" data-template-id="%s" data-limit="%s"></div>',
@@ -109,25 +109,25 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.20.0
110 110
 	 *
111 111
 	 */
112
-	private function amp_shortcode( $atts ) {
112
+	private function amp_shortcode($atts) {
113 113
 
114 114
 		// attributes extraction and boolean filtering
115
-		$shortcode_atts = $this->make_shortcode_atts( $atts );
115
+		$shortcode_atts = $this->make_shortcode_atts($atts);
116 116
 
117 117
 		// avoid building the widget when there is a list of posts.
118
-		if ( ! is_singular() ) {
118
+		if ( ! is_singular()) {
119 119
 			return '';
120 120
 		}
121 121
 
122 122
 		$current_post = get_post();
123 123
 
124 124
 		// Enqueue amp specific styles
125
-		wp_enqueue_style( 'wordlift-amp-custom', plugin_dir_url( dirname( __FILE__ ) ) . '/css/wordlift-amp-custom.min.css' );
125
+		wp_enqueue_style('wordlift-amp-custom', plugin_dir_url(dirname(__FILE__)).'/css/wordlift-amp-custom.min.css');
126 126
 
127
-		$post         = ! empty( $shortcode_atts['post_id'] ) ? get_post( intval( $shortcode_atts['post_id'] ) ) : get_post();
127
+		$post         = ! empty($shortcode_atts['post_id']) ? get_post(intval($shortcode_atts['post_id'])) : get_post();
128 128
 		$navigator_id = $shortcode_atts['uniqid'];
129 129
 
130
-		$wp_json_base = get_rest_url() . WL_REST_ROUTE_DEFAULT_NAMESPACE;
130
+		$wp_json_base = get_rest_url().WL_REST_ROUTE_DEFAULT_NAMESPACE;
131 131
 
132 132
 		$navigator_query = array(
133 133
 			'uniqid'  => $navigator_id,
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			'order_by'=> 'ID ASC'
138 138
 		);
139 139
 
140
-		if ( strpos( $wp_json_base, 'wp-json/' . WL_REST_ROUTE_DEFAULT_NAMESPACE ) ) {
140
+		if (strpos($wp_json_base, 'wp-json/'.WL_REST_ROUTE_DEFAULT_NAMESPACE)) {
141 141
 			$delimiter = '?';
142 142
 		} else {
143 143
 			$delimiter = '&';
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 
146 146
 		// Use a protocol-relative URL as amp-list spec says that URL's protocol must be HTTPS.
147 147
 		// This is a hackish way, but this works for http and https URLs
148
-		$wp_json_url_posts = str_replace( array(
148
+		$wp_json_url_posts = str_replace(array(
149 149
 				'http:',
150 150
 				'https:',
151
-			), '', $wp_json_base ) . '/navigator' . $delimiter . http_build_query( $navigator_query );
151
+			), '', $wp_json_base).'/navigator'.$delimiter.http_build_query($navigator_query);
152 152
 
153 153
 		return <<<HTML
154 154
 		<div id="{$navigator_id}" class="wl-navigator-widget" style="width: 100%">
Please login to merge, or discard this patch.
src/shortcodes/wordlift_shortcode_navigator.php 3 patches
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -16,29 +16,29 @@  discard block
 block discarded – undo
16 16
  */
17 17
 function wl_shortcode_navigator_data() {
18 18
 
19
-	// Create the cache key.
20
-	$cache_key_params = $_REQUEST;
21
-	unset( $cache_key_params['uniqid'] );
22
-	$cache_key = array( 'request_params' => $cache_key_params );
19
+    // Create the cache key.
20
+    $cache_key_params = $_REQUEST;
21
+    unset( $cache_key_params['uniqid'] );
22
+    $cache_key = array( 'request_params' => $cache_key_params );
23 23
 
24
-	// Create the TTL cache and try to get the results.
25
-	$cache         = new Ttl_Cache( "navigator", 24 * 60 * 60 ); // 24 hours.
26
-	$cache_results = $cache->get( $cache_key );
24
+    // Create the TTL cache and try to get the results.
25
+    $cache         = new Ttl_Cache( "navigator", 24 * 60 * 60 ); // 24 hours.
26
+    $cache_results = $cache->get( $cache_key );
27 27
 
28
-	if ( isset( $cache_results ) ) {
29
-		header( 'X-WordLift-Cache: HIT' );
28
+    if ( isset( $cache_results ) ) {
29
+        header( 'X-WordLift-Cache: HIT' );
30 30
 
31
-		return $cache_results;
32
-	}
31
+        return $cache_results;
32
+    }
33 33
 
34
-	header( 'X-WordLift-Cache: MISS' );
34
+    header( 'X-WordLift-Cache: MISS' );
35 35
 
36
-	$results = _wl_navigator_get_data();
36
+    $results = _wl_navigator_get_data();
37 37
 
38
-	// Put the result before sending the json to the client, since sending the json will terminate us.
39
-	$cache->put( $cache_key, $results );
38
+    // Put the result before sending the json to the client, since sending the json will terminate us.
39
+    $cache->put( $cache_key, $results );
40 40
 
41
-	return $results;
41
+    return $results;
42 42
 }
43 43
 
44 44
 /**
@@ -53,187 +53,187 @@  discard block
 block discarded – undo
53 53
  */
54 54
 function wl_network_navigator_wp_json($request) {
55 55
 
56
-	// Create the cache key.
57
-	$cache_key_params = $_REQUEST;
58
-	unset( $cache_key_params['uniqid'] );
59
-	$cache_key = array( 'request_params' => $cache_key_params );
56
+    // Create the cache key.
57
+    $cache_key_params = $_REQUEST;
58
+    unset( $cache_key_params['uniqid'] );
59
+    $cache_key = array( 'request_params' => $cache_key_params );
60 60
 
61
-	// Create the TTL cache and try to get the results.
62
-	$cache         = new Ttl_Cache( "network-navigator", 24 * 60 * 60 ); // 24 hours.
63
-	$cache_results = $cache->get( $cache_key );
61
+    // Create the TTL cache and try to get the results.
62
+    $cache         = new Ttl_Cache( "network-navigator", 24 * 60 * 60 ); // 24 hours.
63
+    $cache_results = $cache->get( $cache_key );
64 64
 
65
-	if ( isset( $cache_results ) ) {
66
-		header( 'X-WordLift-Cache: HIT' );
65
+    if ( isset( $cache_results ) ) {
66
+        header( 'X-WordLift-Cache: HIT' );
67 67
 
68
-		return $cache_results;
69
-	}
68
+        return $cache_results;
69
+    }
70 70
 
71
-	header( 'X-WordLift-Cache: MISS' );
71
+    header( 'X-WordLift-Cache: MISS' );
72 72
 
73
-	$results = _wl_network_navigator_get_data($request);
73
+    $results = _wl_network_navigator_get_data($request);
74 74
 
75
-	// Put the result before sending the json to the client, since sending the json will terminate us.
76
-	$cache->put( $cache_key, $results );
75
+    // Put the result before sending the json to the client, since sending the json will terminate us.
76
+    $cache->put( $cache_key, $results );
77 77
 
78
-	return $results;
78
+    return $results;
79 79
 
80 80
 }
81 81
 
82 82
 function _wl_navigator_get_data() {
83 83
 
84
-	// Post ID must be defined
85
-	if ( ! isset( $_GET['post_id'] ) ) {
86
-		wp_send_json_error( 'No post_id given' );
87
-
88
-		return array();
89
-	}
90
-
91
-	// Limit the results (defaults to 4)
92
-	$navigator_length = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
93
-	$navigator_offset = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
94
-	$order_by         = isset( $_GET['order_by'] ) ? sanitize_sql_orderby($_GET['order_by']) : 'ID ASC';
95
-
96
-	$current_post_id = $_GET['post_id'];
97
-	$current_post    = get_post( $current_post_id );
98
-
99
-	$navigator_id = $_GET['uniqid'];
100
-
101
-	// Post ID has to match an existing item
102
-	if ( null === $current_post ) {
103
-		wp_send_json_error( 'No valid post_id given' );
104
-
105
-		return array();
106
-	}
107
-
108
-	$referencing_posts = _wl_navigator_get_results( $current_post_id, array(
109
-		'ID',
110
-		'post_title',
111
-	), $order_by, $navigator_length, $navigator_offset );
112
-
113
-	// loop over them and take the first one which is not already in the $related_posts
114
-	$results = array();
115
-	foreach ( $referencing_posts as $referencing_post ) {
116
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
117
-
118
-		/**
119
-		 * Use the thumbnail.
120
-		 *
121
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
122
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/837
123
-		 *
124
-		 * @since 3.19.3 We're using the medium size image.
125
-		 */
126
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
127
-
128
-		$result = array(
129
-			'post'   => array(
130
-				'permalink' => get_permalink( $referencing_post->ID ),
131
-				'title'     => $referencing_post->post_title,
132
-				'thumbnail' => $thumbnail,
133
-			),
134
-			'entity' => array(
135
-				'label'     => $serialized_entity['label'],
136
-				'mainType'  => $serialized_entity['mainType'],
137
-				'permalink' => get_permalink( $referencing_post->entity_id ),
138
-			),
139
-		);
140
-
141
-		$result['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
142
-		$result['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
143
-
144
-		$results[] = $result;
145
-	}
146
-
147
-	if ( count( $results ) < $navigator_length ) {
148
-		$results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
149
-	}
150
-
151
-	return $results;
84
+    // Post ID must be defined
85
+    if ( ! isset( $_GET['post_id'] ) ) {
86
+        wp_send_json_error( 'No post_id given' );
87
+
88
+        return array();
89
+    }
90
+
91
+    // Limit the results (defaults to 4)
92
+    $navigator_length = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
93
+    $navigator_offset = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
94
+    $order_by         = isset( $_GET['order_by'] ) ? sanitize_sql_orderby($_GET['order_by']) : 'ID ASC';
95
+
96
+    $current_post_id = $_GET['post_id'];
97
+    $current_post    = get_post( $current_post_id );
98
+
99
+    $navigator_id = $_GET['uniqid'];
100
+
101
+    // Post ID has to match an existing item
102
+    if ( null === $current_post ) {
103
+        wp_send_json_error( 'No valid post_id given' );
104
+
105
+        return array();
106
+    }
107
+
108
+    $referencing_posts = _wl_navigator_get_results( $current_post_id, array(
109
+        'ID',
110
+        'post_title',
111
+    ), $order_by, $navigator_length, $navigator_offset );
112
+
113
+    // loop over them and take the first one which is not already in the $related_posts
114
+    $results = array();
115
+    foreach ( $referencing_posts as $referencing_post ) {
116
+        $serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
117
+
118
+        /**
119
+         * Use the thumbnail.
120
+         *
121
+         * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
122
+         * @see https://github.com/insideout10/wordlift-plugin/issues/837
123
+         *
124
+         * @since 3.19.3 We're using the medium size image.
125
+         */
126
+        $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
127
+
128
+        $result = array(
129
+            'post'   => array(
130
+                'permalink' => get_permalink( $referencing_post->ID ),
131
+                'title'     => $referencing_post->post_title,
132
+                'thumbnail' => $thumbnail,
133
+            ),
134
+            'entity' => array(
135
+                'label'     => $serialized_entity['label'],
136
+                'mainType'  => $serialized_entity['mainType'],
137
+                'permalink' => get_permalink( $referencing_post->entity_id ),
138
+            ),
139
+        );
140
+
141
+        $result['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
142
+        $result['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
143
+
144
+        $results[] = $result;
145
+    }
146
+
147
+    if ( count( $results ) < $navigator_length ) {
148
+        $results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
149
+    }
150
+
151
+    return $results;
152 152
 }
153 153
 
154 154
 function _wl_network_navigator_get_data($request) {
155 155
 
156
-	// Limit the results (defaults to 4)
157
-	$navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
158
-	$navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
159
-	$navigator_id     = $request['uniqid'];
160
-	$order_by         = isset( $_GET['order_by'] ) ? sanitize_sql_orderby($_GET['order_by']) : 'ID ASC';
161
-
162
-	$entities = $request['entities'];
163
-
164
-	// Post ID has to match an existing item
165
-	if ( !isset($entities) || empty($entities) ) {
166
-		wp_send_json_error( 'No valid entities provided' );
167
-	}
168
-
169
-	$referencing_posts = _wl_network_navigator_get_results( $entities, array(
170
-		'ID',
171
-		'post_title',
172
-	), $order_by, $navigator_length, $navigator_offset );
173
-
174
-	// loop over them and take the first one which is not already in the $related_posts
175
-	$results = array();
176
-	foreach ( $referencing_posts as $referencing_post ) {
177
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
178
-
179
-		/**
180
-		 * Use the thumbnail.
181
-		 *
182
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
183
-		 * @see https://github.com/insideout10/wordlift-plugin/issues/837
184
-		 *
185
-		 * @since 3.19.3 We're using the medium size image.
186
-		 */
187
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
188
-
189
-		$result = array(
190
-			'post'   => array(
191
-				'permalink' => get_permalink( $referencing_post->ID ),
192
-				'title'     => $referencing_post->post_title,
193
-				'thumbnail' => $thumbnail,
194
-			),
195
-			'entity' => array(
196
-				'label'     => $serialized_entity['label'],
197
-				'mainType'  => $serialized_entity['mainType'],
198
-				'permalink' => get_permalink( $referencing_post->entity_id ),
199
-			),
200
-		);
201
-
202
-		$result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
203
-		$result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
204
-
205
-		$results[] = $result;
206
-
207
-	}
208
-
209
-	if ( count( $results ) < $navigator_length ) {
210
-		$results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
211
-	}
212
-
213
-	return $results;
156
+    // Limit the results (defaults to 4)
157
+    $navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
158
+    $navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
159
+    $navigator_id     = $request['uniqid'];
160
+    $order_by         = isset( $_GET['order_by'] ) ? sanitize_sql_orderby($_GET['order_by']) : 'ID ASC';
161
+
162
+    $entities = $request['entities'];
163
+
164
+    // Post ID has to match an existing item
165
+    if ( !isset($entities) || empty($entities) ) {
166
+        wp_send_json_error( 'No valid entities provided' );
167
+    }
168
+
169
+    $referencing_posts = _wl_network_navigator_get_results( $entities, array(
170
+        'ID',
171
+        'post_title',
172
+    ), $order_by, $navigator_length, $navigator_offset );
173
+
174
+    // loop over them and take the first one which is not already in the $related_posts
175
+    $results = array();
176
+    foreach ( $referencing_posts as $referencing_post ) {
177
+        $serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
178
+
179
+        /**
180
+         * Use the thumbnail.
181
+         *
182
+         * @see https://github.com/insideout10/wordlift-plugin/issues/825 related issue.
183
+         * @see https://github.com/insideout10/wordlift-plugin/issues/837
184
+         *
185
+         * @since 3.19.3 We're using the medium size image.
186
+         */
187
+        $thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
188
+
189
+        $result = array(
190
+            'post'   => array(
191
+                'permalink' => get_permalink( $referencing_post->ID ),
192
+                'title'     => $referencing_post->post_title,
193
+                'thumbnail' => $thumbnail,
194
+            ),
195
+            'entity' => array(
196
+                'label'     => $serialized_entity['label'],
197
+                'mainType'  => $serialized_entity['mainType'],
198
+                'permalink' => get_permalink( $referencing_post->entity_id ),
199
+            ),
200
+        );
201
+
202
+        $result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
203
+        $result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
204
+
205
+        $results[] = $result;
206
+
207
+    }
208
+
209
+    if ( count( $results ) < $navigator_length ) {
210
+        $results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
211
+    }
212
+
213
+    return $results;
214 214
 
215 215
 }
216 216
 
217 217
 
218 218
 function _wl_navigator_get_results(
219
-	$post_id, $fields = array(
220
-	'ID',
221
-	'post_title',
219
+    $post_id, $fields = array(
220
+    'ID',
221
+    'post_title',
222 222
 ), $order_by = 'ID DESC', $limit = 10, $offset = 0
223 223
 ) {
224
-	global $wpdb;
224
+    global $wpdb;
225 225
 
226
-	$select = implode( ', ', array_map( function ( $item ) {
227
-		return "p.$item AS $item";
228
-	}, (array) $fields ) );
226
+    $select = implode( ', ', array_map( function ( $item ) {
227
+        return "p.$item AS $item";
228
+    }, (array) $fields ) );
229 229
 
230
-	$order_by = implode( ', ', array_map( function ( $item ) {
231
-		return "p.$item";
232
-	}, (array) $order_by ) );
230
+    $order_by = implode( ', ', array_map( function ( $item ) {
231
+        return "p.$item";
232
+    }, (array) $order_by ) );
233 233
 
234
-	/** @noinspection SqlNoDataSourceInspection */
235
-	return $wpdb->get_results(
236
-		$wpdb->prepare( <<<EOF
234
+    /** @noinspection SqlNoDataSourceInspection */
235
+    return $wpdb->get_results(
236
+        $wpdb->prepare( <<<EOF
237 237
 SELECT %4\$s, p2.ID as entity_id
238 238
  FROM {$wpdb->prefix}wl_relation_instances r1
239 239
     INNER JOIN {$wpdb->prefix}wl_relation_instances r2
@@ -265,35 +265,35 @@  discard block
 block discarded – undo
265 265
  LIMIT %2\$d
266 266
  OFFSET %3\$d
267 267
 EOF
268
-			, $post_id, $limit, $offset, $select, $order_by )
269
-	);
268
+            , $post_id, $limit, $offset, $select, $order_by )
269
+    );
270 270
 
271 271
 }
272 272
 
273 273
 function _wl_network_navigator_get_results(
274
-	$entities, $fields = array(
275
-	'ID',
276
-	'post_title',
274
+    $entities, $fields = array(
275
+    'ID',
276
+    'post_title',
277 277
 ), $order_by = 'ID DESC', $limit = 10, $offset = 0
278 278
 ) {
279
-	global $wpdb;
279
+    global $wpdb;
280 280
 
281
-	$select = implode( ', ', array_map( function ( $item ) {
282
-		return "p.$item AS $item";
283
-	}, (array) $fields ) );
281
+    $select = implode( ', ', array_map( function ( $item ) {
282
+        return "p.$item AS $item";
283
+    }, (array) $fields ) );
284 284
 
285
-	$order_by = implode( ', ', array_map( function ( $item ) {
286
-		return "p.$item";
287
-	}, (array) $order_by ) );
285
+    $order_by = implode( ', ', array_map( function ( $item ) {
286
+        return "p.$item";
287
+    }, (array) $order_by ) );
288 288
 
289
-	$entities_in = implode( ',', array_map( function ( $item ) {
290
-		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri(urldecode($item));
291
-		if(isset($entity)) return $entity->ID;
292
-	}, $entities ) );
289
+    $entities_in = implode( ',', array_map( function ( $item ) {
290
+        $entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri(urldecode($item));
291
+        if(isset($entity)) return $entity->ID;
292
+    }, $entities ) );
293 293
 
294
-	/** @noinspection SqlNoDataSourceInspection */
295
-	return $wpdb->get_results(
296
-		$wpdb->prepare( <<<EOF
294
+    /** @noinspection SqlNoDataSourceInspection */
295
+    return $wpdb->get_results(
296
+        $wpdb->prepare( <<<EOF
297 297
 SELECT %3\$s, p2.ID as entity_id
298 298
  FROM {$wpdb->prefix}wl_relation_instances r1
299 299
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
  LIMIT %1\$d
320 320
  OFFSET %2\$d
321 321
 EOF
322
-			, $limit, $offset, $select, $order_by )
323
-	);
322
+            , $limit, $offset, $select, $order_by )
323
+    );
324 324
 
325 325
 }
326 326
 
@@ -331,9 +331,9 @@  discard block
 block discarded – undo
331 331
  */
332 332
 function wl_shortcode_navigator_ajax() {
333 333
 
334
-	// Temporary blocking the Navigator.
335
-	$results = wl_shortcode_navigator_data();
336
-	wl_core_send_json( $results );
334
+    // Temporary blocking the Navigator.
335
+    $results = wl_shortcode_navigator_data();
336
+    wl_core_send_json( $results );
337 337
 
338 338
 }
339 339
 
@@ -345,16 +345,16 @@  discard block
 block discarded – undo
345 345
  */
346 346
 function wl_shortcode_navigator_wp_json() {
347 347
 
348
-	$results = wl_shortcode_navigator_data();
349
-	if ( ob_get_contents() ) {
350
-		ob_clean();
351
-	}
348
+    $results = wl_shortcode_navigator_data();
349
+    if ( ob_get_contents() ) {
350
+        ob_clean();
351
+    }
352 352
 
353
-	return array(
354
-		'items' => array(
355
-			array( 'values' => $results ),
356
-		),
357
-	);
353
+    return array(
354
+        'items' => array(
355
+            array( 'values' => $results ),
356
+        ),
357
+    );
358 358
 
359 359
 }
360 360
 
@@ -362,66 +362,66 @@  discard block
 block discarded – undo
362 362
  * Adding `rest_api_init` action for amp backend of navigator
363 363
  */
364 364
 add_action( 'rest_api_init', function () {
365
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
366
-		'methods'  => 'GET',
367
-		'callback' => 'wl_shortcode_navigator_wp_json',
368
-	) );
365
+    register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
366
+        'methods'  => 'GET',
367
+        'callback' => 'wl_shortcode_navigator_wp_json',
368
+    ) );
369 369
 } );
370 370
 
371 371
 /**
372 372
  * Adding `rest_api_init` action for backend of network navigator
373 373
  */
374 374
 add_action( 'rest_api_init', function () {
375
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
376
-		'methods'  => 'GET',
377
-		'callback' => 'wl_network_navigator_wp_json',
378
-	) );
375
+    register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
376
+        'methods'  => 'GET',
377
+        'callback' => 'wl_network_navigator_wp_json',
378
+    ) );
379 379
 } );
380 380
 
381 381
 /**
382 382
  * register_block_type for Gutenberg blocks
383 383
  */
384 384
 add_action( 'init', function () {
385
-	// Bail out if the `register_block_type` function isn't available.
386
-	if ( ! function_exists( 'register_block_type' ) ) {
387
-		return;
388
-	}
389
-
390
-	register_block_type( 'wordlift/navigator', array(
391
-		'editor_script'   => 'wordlift-admin-edit-gutenberg',
392
-		'render_callback' => function ( $attributes ) {
393
-			$attr_code = '';
394
-			foreach ( $attributes as $key => $value ) {
395
-				$attr_code .= $key . '="' . $value . '" ';
396
-			}
397
-
398
-			return '[wl_navigator ' . $attr_code . ']';
399
-		},
400
-		'attributes'      => array(
401
-			'title'       => array(
402
-				'type'    => 'string',
403
-				'default' => __( 'Related articles', 'wordlift' ),
404
-			),
405
-			'limit'       => array(
406
-				'type'    => 'number',
407
-				'default' => 4,
408
-			),
409
-			'template_id' => array(
410
-				'type' => 'string',
411
-			),
412
-			'post_id'     => array(
413
-				'type' => 'number',
414
-			),
415
-			'offset'      => array(
416
-				'type'    => 'number',
417
-				'default' => 0,
418
-			),
419
-			'uniqid'      => array(
420
-				'type'    => 'string',
421
-				'default' => uniqid( 'wl-navigator-widget-' ),
422
-			),
423
-		),
424
-	) );
385
+    // Bail out if the `register_block_type` function isn't available.
386
+    if ( ! function_exists( 'register_block_type' ) ) {
387
+        return;
388
+    }
389
+
390
+    register_block_type( 'wordlift/navigator', array(
391
+        'editor_script'   => 'wordlift-admin-edit-gutenberg',
392
+        'render_callback' => function ( $attributes ) {
393
+            $attr_code = '';
394
+            foreach ( $attributes as $key => $value ) {
395
+                $attr_code .= $key . '="' . $value . '" ';
396
+            }
397
+
398
+            return '[wl_navigator ' . $attr_code . ']';
399
+        },
400
+        'attributes'      => array(
401
+            'title'       => array(
402
+                'type'    => 'string',
403
+                'default' => __( 'Related articles', 'wordlift' ),
404
+            ),
405
+            'limit'       => array(
406
+                'type'    => 'number',
407
+                'default' => 4,
408
+            ),
409
+            'template_id' => array(
410
+                'type' => 'string',
411
+            ),
412
+            'post_id'     => array(
413
+                'type' => 'number',
414
+            ),
415
+            'offset'      => array(
416
+                'type'    => 'number',
417
+                'default' => 0,
418
+            ),
419
+            'uniqid'      => array(
420
+                'type'    => 'string',
421
+                'default' => uniqid( 'wl-navigator-widget-' ),
422
+            ),
423
+        ),
424
+    ) );
425 425
 } );
426 426
 
427 427
 /**
@@ -431,22 +431,22 @@  discard block
 block discarded – undo
431 431
  */
432 432
 add_action( 'plugins_loaded', function () {
433 433
 
434
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
435
-		return;
436
-	}
434
+    if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
435
+        return;
436
+    }
437 437
 
438
-	remove_action( 'plugins_loaded', 'rocket_init' );
439
-	remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
440
-	remove_action( 'plugins_loaded', 'wpseo_init', 14 );
438
+    remove_action( 'plugins_loaded', 'rocket_init' );
439
+    remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
440
+    remove_action( 'plugins_loaded', 'wpseo_init', 14 );
441 441
 }, 0 );
442 442
 
443 443
 add_action( 'init', function () {
444 444
 
445
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
446
-		return;
447
-	}
445
+    if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
446
+        return;
447
+    }
448 448
 
449
-	remove_action( 'init', 'wp_widgets_init', 1 );
450
-	remove_action( 'init', 'gglcptch_init' );
449
+    remove_action( 'init', 'wp_widgets_init', 1 );
450
+    remove_action( 'init', 'gglcptch_init' );
451 451
 }, 0 );
452 452
 
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -18,25 +18,25 @@  discard block
 block discarded – undo
18 18
 
19 19
 	// Create the cache key.
20 20
 	$cache_key_params = $_REQUEST;
21
-	unset( $cache_key_params['uniqid'] );
22
-	$cache_key = array( 'request_params' => $cache_key_params );
21
+	unset($cache_key_params['uniqid']);
22
+	$cache_key = array('request_params' => $cache_key_params);
23 23
 
24 24
 	// Create the TTL cache and try to get the results.
25
-	$cache         = new Ttl_Cache( "navigator", 24 * 60 * 60 ); // 24 hours.
26
-	$cache_results = $cache->get( $cache_key );
25
+	$cache         = new Ttl_Cache("navigator", 24 * 60 * 60); // 24 hours.
26
+	$cache_results = $cache->get($cache_key);
27 27
 
28
-	if ( isset( $cache_results ) ) {
29
-		header( 'X-WordLift-Cache: HIT' );
28
+	if (isset($cache_results)) {
29
+		header('X-WordLift-Cache: HIT');
30 30
 
31 31
 		return $cache_results;
32 32
 	}
33 33
 
34
-	header( 'X-WordLift-Cache: MISS' );
34
+	header('X-WordLift-Cache: MISS');
35 35
 
36 36
 	$results = _wl_navigator_get_data();
37 37
 
38 38
 	// Put the result before sending the json to the client, since sending the json will terminate us.
39
-	$cache->put( $cache_key, $results );
39
+	$cache->put($cache_key, $results);
40 40
 
41 41
 	return $results;
42 42
 }
@@ -55,25 +55,25 @@  discard block
 block discarded – undo
55 55
 
56 56
 	// Create the cache key.
57 57
 	$cache_key_params = $_REQUEST;
58
-	unset( $cache_key_params['uniqid'] );
59
-	$cache_key = array( 'request_params' => $cache_key_params );
58
+	unset($cache_key_params['uniqid']);
59
+	$cache_key = array('request_params' => $cache_key_params);
60 60
 
61 61
 	// Create the TTL cache and try to get the results.
62
-	$cache         = new Ttl_Cache( "network-navigator", 24 * 60 * 60 ); // 24 hours.
63
-	$cache_results = $cache->get( $cache_key );
62
+	$cache         = new Ttl_Cache("network-navigator", 24 * 60 * 60); // 24 hours.
63
+	$cache_results = $cache->get($cache_key);
64 64
 
65
-	if ( isset( $cache_results ) ) {
66
-		header( 'X-WordLift-Cache: HIT' );
65
+	if (isset($cache_results)) {
66
+		header('X-WordLift-Cache: HIT');
67 67
 
68 68
 		return $cache_results;
69 69
 	}
70 70
 
71
-	header( 'X-WordLift-Cache: MISS' );
71
+	header('X-WordLift-Cache: MISS');
72 72
 
73 73
 	$results = _wl_network_navigator_get_data($request);
74 74
 
75 75
 	// Put the result before sending the json to the client, since sending the json will terminate us.
76
-	$cache->put( $cache_key, $results );
76
+	$cache->put($cache_key, $results);
77 77
 
78 78
 	return $results;
79 79
 
@@ -82,38 +82,38 @@  discard block
 block discarded – undo
82 82
 function _wl_navigator_get_data() {
83 83
 
84 84
 	// Post ID must be defined
85
-	if ( ! isset( $_GET['post_id'] ) ) {
86
-		wp_send_json_error( 'No post_id given' );
85
+	if ( ! isset($_GET['post_id'])) {
86
+		wp_send_json_error('No post_id given');
87 87
 
88 88
 		return array();
89 89
 	}
90 90
 
91 91
 	// Limit the results (defaults to 4)
92
-	$navigator_length = isset( $_GET['limit'] ) ? intval( $_GET['limit'] ) : 4;
93
-	$navigator_offset = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0;
94
-	$order_by         = isset( $_GET['order_by'] ) ? sanitize_sql_orderby($_GET['order_by']) : 'ID ASC';
92
+	$navigator_length = isset($_GET['limit']) ? intval($_GET['limit']) : 4;
93
+	$navigator_offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
94
+	$order_by         = isset($_GET['order_by']) ? sanitize_sql_orderby($_GET['order_by']) : 'ID ASC';
95 95
 
96 96
 	$current_post_id = $_GET['post_id'];
97
-	$current_post    = get_post( $current_post_id );
97
+	$current_post    = get_post($current_post_id);
98 98
 
99 99
 	$navigator_id = $_GET['uniqid'];
100 100
 
101 101
 	// Post ID has to match an existing item
102
-	if ( null === $current_post ) {
103
-		wp_send_json_error( 'No valid post_id given' );
102
+	if (null === $current_post) {
103
+		wp_send_json_error('No valid post_id given');
104 104
 
105 105
 		return array();
106 106
 	}
107 107
 
108
-	$referencing_posts = _wl_navigator_get_results( $current_post_id, array(
108
+	$referencing_posts = _wl_navigator_get_results($current_post_id, array(
109 109
 		'ID',
110 110
 		'post_title',
111
-	), $order_by, $navigator_length, $navigator_offset );
111
+	), $order_by, $navigator_length, $navigator_offset);
112 112
 
113 113
 	// loop over them and take the first one which is not already in the $related_posts
114 114
 	$results = array();
115
-	foreach ( $referencing_posts as $referencing_post ) {
116
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
115
+	foreach ($referencing_posts as $referencing_post) {
116
+		$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
117 117
 
118 118
 		/**
119 119
 		 * Use the thumbnail.
@@ -123,29 +123,29 @@  discard block
 block discarded – undo
123 123
 		 *
124 124
 		 * @since 3.19.3 We're using the medium size image.
125 125
 		 */
126
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
126
+		$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
127 127
 
128 128
 		$result = array(
129 129
 			'post'   => array(
130
-				'permalink' => get_permalink( $referencing_post->ID ),
130
+				'permalink' => get_permalink($referencing_post->ID),
131 131
 				'title'     => $referencing_post->post_title,
132 132
 				'thumbnail' => $thumbnail,
133 133
 			),
134 134
 			'entity' => array(
135 135
 				'label'     => $serialized_entity['label'],
136 136
 				'mainType'  => $serialized_entity['mainType'],
137
-				'permalink' => get_permalink( $referencing_post->entity_id ),
137
+				'permalink' => get_permalink($referencing_post->entity_id),
138 138
 			),
139 139
 		);
140 140
 
141
-		$result['post']   = apply_filters( 'wl_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
142
-		$result['entity'] = apply_filters( 'wl_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
141
+		$result['post']   = apply_filters('wl_navigator_data_post', $result['post'], intval($referencing_post->ID), $navigator_id);
142
+		$result['entity'] = apply_filters('wl_navigator_data_entity', $result['entity'], intval($referencing_post->entity_id), $navigator_id);
143 143
 
144 144
 		$results[] = $result;
145 145
 	}
146 146
 
147
-	if ( count( $results ) < $navigator_length ) {
148
-		$results = apply_filters( 'wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
147
+	if (count($results) < $navigator_length) {
148
+		$results = apply_filters('wl_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
149 149
 	}
150 150
 
151 151
 	return $results;
@@ -154,27 +154,27 @@  discard block
 block discarded – undo
154 154
 function _wl_network_navigator_get_data($request) {
155 155
 
156 156
 	// Limit the results (defaults to 4)
157
-	$navigator_length = isset( $request['limit'] ) ? intval( $request['limit'] ) : 4;
158
-	$navigator_offset = isset( $request['offset'] ) ? intval( $request['offset'] ) : 0;
157
+	$navigator_length = isset($request['limit']) ? intval($request['limit']) : 4;
158
+	$navigator_offset = isset($request['offset']) ? intval($request['offset']) : 0;
159 159
 	$navigator_id     = $request['uniqid'];
160
-	$order_by         = isset( $_GET['order_by'] ) ? sanitize_sql_orderby($_GET['order_by']) : 'ID ASC';
160
+	$order_by         = isset($_GET['order_by']) ? sanitize_sql_orderby($_GET['order_by']) : 'ID ASC';
161 161
 
162 162
 	$entities = $request['entities'];
163 163
 
164 164
 	// Post ID has to match an existing item
165
-	if ( !isset($entities) || empty($entities) ) {
166
-		wp_send_json_error( 'No valid entities provided' );
165
+	if ( ! isset($entities) || empty($entities)) {
166
+		wp_send_json_error('No valid entities provided');
167 167
 	}
168 168
 
169
-	$referencing_posts = _wl_network_navigator_get_results( $entities, array(
169
+	$referencing_posts = _wl_network_navigator_get_results($entities, array(
170 170
 		'ID',
171 171
 		'post_title',
172
-	), $order_by, $navigator_length, $navigator_offset );
172
+	), $order_by, $navigator_length, $navigator_offset);
173 173
 
174 174
 	// loop over them and take the first one which is not already in the $related_posts
175 175
 	$results = array();
176
-	foreach ( $referencing_posts as $referencing_post ) {
177
-		$serialized_entity = wl_serialize_entity( $referencing_post->entity_id );
176
+	foreach ($referencing_posts as $referencing_post) {
177
+		$serialized_entity = wl_serialize_entity($referencing_post->entity_id);
178 178
 
179 179
 		/**
180 180
 		 * Use the thumbnail.
@@ -184,30 +184,30 @@  discard block
 block discarded – undo
184 184
 		 *
185 185
 		 * @since 3.19.3 We're using the medium size image.
186 186
 		 */
187
-		$thumbnail = get_the_post_thumbnail_url( $referencing_post, 'medium' );
187
+		$thumbnail = get_the_post_thumbnail_url($referencing_post, 'medium');
188 188
 
189 189
 		$result = array(
190 190
 			'post'   => array(
191
-				'permalink' => get_permalink( $referencing_post->ID ),
191
+				'permalink' => get_permalink($referencing_post->ID),
192 192
 				'title'     => $referencing_post->post_title,
193 193
 				'thumbnail' => $thumbnail,
194 194
 			),
195 195
 			'entity' => array(
196 196
 				'label'     => $serialized_entity['label'],
197 197
 				'mainType'  => $serialized_entity['mainType'],
198
-				'permalink' => get_permalink( $referencing_post->entity_id ),
198
+				'permalink' => get_permalink($referencing_post->entity_id),
199 199
 			),
200 200
 		);
201 201
 
202
-		$result['post']   = apply_filters( 'wl_network_navigator_data_post', $result['post'], intval( $referencing_post->ID ), $navigator_id );
203
-		$result['entity'] = apply_filters( 'wl_network_navigator_data_entity', $result['entity'], intval( $referencing_post->entity_id ), $navigator_id );
202
+		$result['post']   = apply_filters('wl_network_navigator_data_post', $result['post'], intval($referencing_post->ID), $navigator_id);
203
+		$result['entity'] = apply_filters('wl_network_navigator_data_entity', $result['entity'], intval($referencing_post->entity_id), $navigator_id);
204 204
 
205 205
 		$results[] = $result;
206 206
 
207 207
 	}
208 208
 
209
-	if ( count( $results ) < $navigator_length ) {
210
-		$results = apply_filters( 'wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length );
209
+	if (count($results) < $navigator_length) {
210
+		$results = apply_filters('wl_network_navigator_data_placeholder', $results, $navigator_id, $navigator_offset, $navigator_length);
211 211
 	}
212 212
 
213 213
 	return $results;
@@ -223,17 +223,17 @@  discard block
 block discarded – undo
223 223
 ) {
224 224
 	global $wpdb;
225 225
 
226
-	$select = implode( ', ', array_map( function ( $item ) {
226
+	$select = implode(', ', array_map(function($item) {
227 227
 		return "p.$item AS $item";
228
-	}, (array) $fields ) );
228
+	}, (array) $fields));
229 229
 
230
-	$order_by = implode( ', ', array_map( function ( $item ) {
230
+	$order_by = implode(', ', array_map(function($item) {
231 231
 		return "p.$item";
232
-	}, (array) $order_by ) );
232
+	}, (array) $order_by));
233 233
 
234 234
 	/** @noinspection SqlNoDataSourceInspection */
235 235
 	return $wpdb->get_results(
236
-		$wpdb->prepare( <<<EOF
236
+		$wpdb->prepare(<<<EOF
237 237
 SELECT %4\$s, p2.ID as entity_id
238 238
  FROM {$wpdb->prefix}wl_relation_instances r1
239 239
     INNER JOIN {$wpdb->prefix}wl_relation_instances r2
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
  LIMIT %2\$d
266 266
  OFFSET %3\$d
267 267
 EOF
268
-			, $post_id, $limit, $offset, $select, $order_by )
268
+			, $post_id, $limit, $offset, $select, $order_by)
269 269
 	);
270 270
 
271 271
 }
@@ -278,22 +278,22 @@  discard block
 block discarded – undo
278 278
 ) {
279 279
 	global $wpdb;
280 280
 
281
-	$select = implode( ', ', array_map( function ( $item ) {
281
+	$select = implode(', ', array_map(function($item) {
282 282
 		return "p.$item AS $item";
283
-	}, (array) $fields ) );
283
+	}, (array) $fields));
284 284
 
285
-	$order_by = implode( ', ', array_map( function ( $item ) {
285
+	$order_by = implode(', ', array_map(function($item) {
286 286
 		return "p.$item";
287
-	}, (array) $order_by ) );
287
+	}, (array) $order_by));
288 288
 
289
-	$entities_in = implode( ',', array_map( function ( $item ) {
289
+	$entities_in = implode(',', array_map(function($item) {
290 290
 		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri(urldecode($item));
291
-		if(isset($entity)) return $entity->ID;
292
-	}, $entities ) );
291
+		if (isset($entity)) return $entity->ID;
292
+	}, $entities));
293 293
 
294 294
 	/** @noinspection SqlNoDataSourceInspection */
295 295
 	return $wpdb->get_results(
296
-		$wpdb->prepare( <<<EOF
296
+		$wpdb->prepare(<<<EOF
297 297
 SELECT %3\$s, p2.ID as entity_id
298 298
  FROM {$wpdb->prefix}wl_relation_instances r1
299 299
 	-- get the ID of the post entity in common between the object and the subject 2. 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
  LIMIT %1\$d
320 320
  OFFSET %2\$d
321 321
 EOF
322
-			, $limit, $offset, $select, $order_by )
322
+			, $limit, $offset, $select, $order_by)
323 323
 	);
324 324
 
325 325
 }
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
 
334 334
 	// Temporary blocking the Navigator.
335 335
 	$results = wl_shortcode_navigator_data();
336
-	wl_core_send_json( $results );
336
+	wl_core_send_json($results);
337 337
 
338 338
 }
339 339
 
340
-add_action( 'wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax' );
341
-add_action( 'wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax' );
340
+add_action('wp_ajax_wl_navigator', 'wl_shortcode_navigator_ajax');
341
+add_action('wp_ajax_nopriv_wl_navigator', 'wl_shortcode_navigator_ajax');
342 342
 
343 343
 /**
344 344
  * wp-json call for the navigator widget
@@ -346,13 +346,13 @@  discard block
 block discarded – undo
346 346
 function wl_shortcode_navigator_wp_json() {
347 347
 
348 348
 	$results = wl_shortcode_navigator_data();
349
-	if ( ob_get_contents() ) {
349
+	if (ob_get_contents()) {
350 350
 		ob_clean();
351 351
 	}
352 352
 
353 353
 	return array(
354 354
 		'items' => array(
355
-			array( 'values' => $results ),
355
+			array('values' => $results),
356 356
 		),
357 357
 	);
358 358
 
@@ -361,46 +361,46 @@  discard block
 block discarded – undo
361 361
 /**
362 362
  * Adding `rest_api_init` action for amp backend of navigator
363 363
  */
364
-add_action( 'rest_api_init', function () {
365
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
364
+add_action('rest_api_init', function() {
365
+	register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/navigator', array(
366 366
 		'methods'  => 'GET',
367 367
 		'callback' => 'wl_shortcode_navigator_wp_json',
368
-	) );
368
+	));
369 369
 } );
370 370
 
371 371
 /**
372 372
  * Adding `rest_api_init` action for backend of network navigator
373 373
  */
374
-add_action( 'rest_api_init', function () {
375
-	register_rest_route( WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
374
+add_action('rest_api_init', function() {
375
+	register_rest_route(WL_REST_ROUTE_DEFAULT_NAMESPACE, '/network-navigator', array(
376 376
 		'methods'  => 'GET',
377 377
 		'callback' => 'wl_network_navigator_wp_json',
378
-	) );
378
+	));
379 379
 } );
380 380
 
381 381
 /**
382 382
  * register_block_type for Gutenberg blocks
383 383
  */
384
-add_action( 'init', function () {
384
+add_action('init', function() {
385 385
 	// Bail out if the `register_block_type` function isn't available.
386
-	if ( ! function_exists( 'register_block_type' ) ) {
386
+	if ( ! function_exists('register_block_type')) {
387 387
 		return;
388 388
 	}
389 389
 
390
-	register_block_type( 'wordlift/navigator', array(
390
+	register_block_type('wordlift/navigator', array(
391 391
 		'editor_script'   => 'wordlift-admin-edit-gutenberg',
392
-		'render_callback' => function ( $attributes ) {
392
+		'render_callback' => function($attributes) {
393 393
 			$attr_code = '';
394
-			foreach ( $attributes as $key => $value ) {
395
-				$attr_code .= $key . '="' . $value . '" ';
394
+			foreach ($attributes as $key => $value) {
395
+				$attr_code .= $key.'="'.$value.'" ';
396 396
 			}
397 397
 
398
-			return '[wl_navigator ' . $attr_code . ']';
398
+			return '[wl_navigator '.$attr_code.']';
399 399
 		},
400 400
 		'attributes'      => array(
401 401
 			'title'       => array(
402 402
 				'type'    => 'string',
403
-				'default' => __( 'Related articles', 'wordlift' ),
403
+				'default' => __('Related articles', 'wordlift'),
404 404
 			),
405 405
 			'limit'       => array(
406 406
 				'type'    => 'number',
@@ -418,10 +418,10 @@  discard block
 block discarded – undo
418 418
 			),
419 419
 			'uniqid'      => array(
420 420
 				'type'    => 'string',
421
-				'default' => uniqid( 'wl-navigator-widget-' ),
421
+				'default' => uniqid('wl-navigator-widget-'),
422 422
 			),
423 423
 		),
424
-	) );
424
+	));
425 425
 } );
426 426
 
427 427
 /**
@@ -429,24 +429,24 @@  discard block
 block discarded – undo
429 429
  *
430 430
  * @since 2.2.0
431 431
  */
432
-add_action( 'plugins_loaded', function () {
432
+add_action('plugins_loaded', function() {
433 433
 
434
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
434
+	if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action']) {
435 435
 		return;
436 436
 	}
437 437
 
438
-	remove_action( 'plugins_loaded', 'rocket_init' );
439
-	remove_action( 'plugins_loaded', 'wpseo_premium_init', 14 );
440
-	remove_action( 'plugins_loaded', 'wpseo_init', 14 );
441
-}, 0 );
438
+	remove_action('plugins_loaded', 'rocket_init');
439
+	remove_action('plugins_loaded', 'wpseo_premium_init', 14);
440
+	remove_action('plugins_loaded', 'wpseo_init', 14);
441
+}, 0);
442 442
 
443
-add_action( 'init', function () {
443
+add_action('init', function() {
444 444
 
445
-	if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action'] ) {
445
+	if ( ! defined('DOING_AJAX') || ! DOING_AJAX || 'wl_navigator' !== $_REQUEST['action']) {
446 446
 		return;
447 447
 	}
448 448
 
449
-	remove_action( 'init', 'wp_widgets_init', 1 );
450
-	remove_action( 'init', 'gglcptch_init' );
451
-}, 0 );
449
+	remove_action('init', 'wp_widgets_init', 1);
450
+	remove_action('init', 'gglcptch_init');
451
+}, 0);
452 452
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -288,7 +288,9 @@
 block discarded – undo
288 288
 
289 289
 	$entities_in = implode( ',', array_map( function ( $item ) {
290 290
 		$entity = Wordlift_Entity_Service::get_instance()->get_entity_post_by_uri(urldecode($item));
291
-		if(isset($entity)) return $entity->ID;
291
+		if(isset($entity)) {
292
+		    return $entity->ID;
293
+		}
292 294
 	}, $entities ) );
293 295
 
294 296
 	/** @noinspection SqlNoDataSourceInspection */
Please login to merge, or discard this patch.