Completed
Pull Request — develop (#1652)
by Naveen
01:13
created
src/wordlift.php 2 patches
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
 use Wordlift\Post\Post_Adapter;
33 33
 // If this file is called directly, abort.
34 34
 if ( ! defined( 'WPINC' ) ) {
35
-	die;
35
+    die;
36 36
 }
37 37
 define(
38
-	'WORDLIFT_PLUGIN_FILE',
39
-	__FILE__
38
+    'WORDLIFT_PLUGIN_FILE',
39
+    __FILE__
40 40
 );
41 41
 define( 'WORDLIFT_VERSION', '3.40.5' );
42 42
 
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
  * @since 3.33.6
51 51
  */
52 52
 if ( ! apply_filters( 'wl_is_enabled', true ) ) {
53
-	return;
53
+    return;
54 54
 }
55 55
 
56 56
 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
@@ -79,33 +79,33 @@  discard block
 block discarded – undo
79 79
  */
80 80
 function activate_wordlift() {
81 81
 
82
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
82
+    $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
83 83
 
84
-	$log->info( 'Activating WordLift...' );
84
+    $log->info( 'Activating WordLift...' );
85 85
 
86
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
87
-	Wordlift_Activator::activate();
86
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
87
+    Wordlift_Activator::activate();
88 88
 
89
-	/**
90
-	 * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
91
-	 *
92
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
93
-	 * @since 3.19.2
94
-	 */
95
-	Wordlift_Http_Api::activate();
96
-
97
-	// Ensure the post type is registered before flushing the rewrite rules.
98
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
99
-	flush_rewrite_rules();
100
-	/**
101
-	 * @since 3.27.7
102
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
103
-	 */
104
-	Top_Entities::activate();
89
+    /**
90
+     * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
91
+     *
92
+     * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
93
+     * @since 3.19.2
94
+     */
95
+    Wordlift_Http_Api::activate();
96
+
97
+    // Ensure the post type is registered before flushing the rewrite rules.
98
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
99
+    flush_rewrite_rules();
100
+    /**
101
+     * @since 3.27.7
102
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
103
+     */
104
+    Top_Entities::activate();
105 105
 
106
-	if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
107
-		wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
108
-	}
106
+    if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
107
+        wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
108
+    }
109 109
 
110 110
 }
111 111
 
@@ -115,23 +115,23 @@  discard block
 block discarded – undo
115 115
  */
116 116
 function deactivate_wordlift() {
117 117
 
118
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
119
-	Wordlift_Deactivator::deactivate();
120
-	Wordlift_Http_Api::deactivate();
121
-	Ttl_Cache_Cleaner::deactivate();
122
-	/**
123
-	 * @since 3.27.7
124
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
125
-	 */
126
-	Top_Entities::deactivate();
127
-	/**
128
-	 * @since 3.27.8
129
-	 * Remove notification flag on deactivation.
130
-	 */
131
-	Key_Validation_Notice::remove_notification_flag();
132
-	flush_rewrite_rules();
133
-
134
-	wp_clear_scheduled_hook( 'wl_daily_cron' );
118
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
119
+    Wordlift_Deactivator::deactivate();
120
+    Wordlift_Http_Api::deactivate();
121
+    Ttl_Cache_Cleaner::deactivate();
122
+    /**
123
+     * @since 3.27.7
124
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
125
+     */
126
+    Top_Entities::deactivate();
127
+    /**
128
+     * @since 3.27.8
129
+     * Remove notification flag on deactivation.
130
+     */
131
+    Key_Validation_Notice::remove_notification_flag();
132
+    flush_rewrite_rules();
133
+
134
+    wp_clear_scheduled_hook( 'wl_daily_cron' );
135 135
 
136 136
 }
137 137
 
@@ -154,84 +154,84 @@  discard block
 block discarded – undo
154 154
  * @since    1.0.0
155 155
  */
156 156
 function run_wordlift() {
157
-	/**
158
-	 * Filter: wl_feature__enable__widgets.
159
-	 *
160
-	 * @param bool whether the widgets needed to be registered, defaults to true.
161
-	 *
162
-	 * @return bool
163
-	 * @since 3.27.6
164
-	 */
165
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
166
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
167
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
168
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
169
-	}
170
-	add_filter( 'widget_text', 'do_shortcode' );
171
-
172
-	/**
173
-	 * Filter: wl_feature__enable__analysis
174
-	 *
175
-	 * @param bool Whether to send api request to analysis or not
176
-	 *
177
-	 * @return bool
178
-	 * @since 3.27.6
179
-	 */
180
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
181
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
182
-	} else {
183
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
184
-	}
185
-
186
-	$plugin = new Wordlift();
187
-	$plugin->run();
188
-
189
-	// Initialize the TTL Cache Cleaner.
190
-	new Ttl_Cache_Cleaner();
191
-
192
-	// Load the new Post Adapter.
193
-	new Post_Adapter();
194
-
195
-	// Load the API Data Hooks.
196
-	new Api_Data_Hooks();
197
-
198
-	add_action(
199
-		'plugins_loaded',
200
-		function () {
201
-			// All features from registry should be initialized here.
202
-			$features_registry = Features_Registry::get_instance();
203
-			$features_registry->initialize_all_features();
204
-		},
205
-		5
206
-	);
207
-
208
-	add_action(
209
-		'plugins_loaded',
210
-		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
211
-		function () use ( $plugin ) {
212
-
213
-			new Wordlift_Products_Navigator_Shortcode_REST();
214
-
215
-			// Register the Dataset module, requires `$api_service`.
216
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
217
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
218
-
219
-			/*
157
+    /**
158
+     * Filter: wl_feature__enable__widgets.
159
+     *
160
+     * @param bool whether the widgets needed to be registered, defaults to true.
161
+     *
162
+     * @return bool
163
+     * @since 3.27.6
164
+     */
165
+    if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
166
+        add_action( 'widgets_init', 'wl_register_chord_widget' );
167
+        add_action( 'widgets_init', 'wl_register_geo_widget' );
168
+        add_action( 'widgets_init', 'wl_register_timeline_widget' );
169
+    }
170
+    add_filter( 'widget_text', 'do_shortcode' );
171
+
172
+    /**
173
+     * Filter: wl_feature__enable__analysis
174
+     *
175
+     * @param bool Whether to send api request to analysis or not
176
+     *
177
+     * @return bool
178
+     * @since 3.27.6
179
+     */
180
+    if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
181
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
182
+    } else {
183
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
184
+    }
185
+
186
+    $plugin = new Wordlift();
187
+    $plugin->run();
188
+
189
+    // Initialize the TTL Cache Cleaner.
190
+    new Ttl_Cache_Cleaner();
191
+
192
+    // Load the new Post Adapter.
193
+    new Post_Adapter();
194
+
195
+    // Load the API Data Hooks.
196
+    new Api_Data_Hooks();
197
+
198
+    add_action(
199
+        'plugins_loaded',
200
+        function () {
201
+            // All features from registry should be initialized here.
202
+            $features_registry = Features_Registry::get_instance();
203
+            $features_registry->initialize_all_features();
204
+        },
205
+        5
206
+    );
207
+
208
+    add_action(
209
+        'plugins_loaded',
210
+        // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
211
+        function () use ( $plugin ) {
212
+
213
+            new Wordlift_Products_Navigator_Shortcode_REST();
214
+
215
+            // Register the Dataset module, requires `$api_service`.
216
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
217
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
218
+
219
+            /*
220 220
 			* Require the Entity annotation cleanup module.
221 221
 			*
222 222
 			* @since 3.34.6
223 223
 			*/
224
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
224
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
225 225
 
226
-			/*
226
+            /*
227 227
 			* Import LOD entities.
228 228
 			*
229 229
 			* @since 3.35.0
230 230
 			*/
231
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
231
+            require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
232 232
 
233
-		}
234
-	);
233
+        }
234
+    );
235 235
 
236 236
 }
237 237
 
@@ -245,45 +245,45 @@  discard block
 block discarded – undo
245 245
  */
246 246
 function wordlift_plugin_autoload_register() {
247 247
 
248
-	spl_autoload_register(
249
-		function ( $class_name ) {
248
+    spl_autoload_register(
249
+        function ( $class_name ) {
250 250
 
251
-			// Bail out if these are not our classes.
252
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
253
-				return false;
254
-			}
251
+            // Bail out if these are not our classes.
252
+            if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
253
+                return false;
254
+            }
255 255
 
256
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
256
+            $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
257 257
 
258
-			preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
258
+            preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
259 259
 
260
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
261
-			$file = 'class-' . $matches[2] . '.php';
260
+            $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
261
+            $file = 'class-' . $matches[2] . '.php';
262 262
 
263
-			$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
263
+            $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
264 264
 
265
-			if ( ! file_exists( $full_path ) ) {
266
-				return false;
267
-			}
265
+            if ( ! file_exists( $full_path ) ) {
266
+                return false;
267
+            }
268 268
 
269
-			require_once $full_path;
269
+            require_once $full_path;
270 270
 
271
-			return true;
272
-		}
273
-	);
271
+            return true;
272
+        }
273
+    );
274 274
 
275 275
 }
276 276
 
277 277
 function wl_block_categories( $categories ) {
278
-	return array_merge(
279
-		$categories,
280
-		array(
281
-			array(
282
-				'slug'  => 'wordlift',
283
-				'title' => __( 'WordLift', 'wordlift' ),
284
-			),
285
-		)
286
-	);
278
+    return array_merge(
279
+        $categories,
280
+        array(
281
+            array(
282
+                'slug'  => 'wordlift',
283
+                'title' => __( 'WordLift', 'wordlift' ),
284
+            ),
285
+        )
286
+    );
287 287
 }
288 288
 
289 289
 /**
@@ -291,19 +291,19 @@  discard block
 block discarded – undo
291 291
  * this has to be removed when removing the legacy fields from the ui.
292 292
  */
293 293
 function wl_enqueue_leaflet( $in_footer = false ) {
294
-	// Leaflet.
295
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
296
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
294
+    // Leaflet.
295
+    wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
296
+    wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
297 297
 }
298 298
 
299 299
 add_filter( 'block_categories', 'wl_block_categories', 10 );
300 300
 
301 301
 // Temporary fix for a typo in WooCommerce Extension.
302 302
 add_filter(
303
-	'wl_feature__enable__dataset',
304
-	function ( $value ) {
305
-		return apply_filters( 'wl_features__enable__dataset', $value );
306
-	}
303
+    'wl_feature__enable__dataset',
304
+    function ( $value ) {
305
+        return apply_filters( 'wl_features__enable__dataset', $value );
306
+    }
307 307
 );
308 308
 
309 309
 require_once __DIR__ . '/modules/food-kg/load.php';
@@ -312,26 +312,26 @@  discard block
 block discarded – undo
312 312
 require_once __DIR__ . '/modules/include-exclude-push-config/load.php';
313 313
 
314 314
 add_action(
315
-	'update_plugins_adthrive.wordlift.io',
316
-	function ( $update, $plugin_data, $plugin_file ) {
317
-		// Bail out if it's not our plugin.
318
-		$update_uri = $plugin_data['UpdateURI'];
319
-		if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
320
-			return $update;
321
-		}
322
-
323
-		$response = wp_remote_get( "$update_uri?nocache=" . time() );
324
-
325
-		if ( is_wp_error( $response ) ) {
326
-			return $update;
327
-		}
328
-
329
-		try {
330
-			return json_decode( wp_remote_retrieve_body( $response ) );
331
-		} catch ( Exception $e ) {
332
-			return $update;
333
-		}
334
-	},
335
-	10,
336
-	3
315
+    'update_plugins_adthrive.wordlift.io',
316
+    function ( $update, $plugin_data, $plugin_file ) {
317
+        // Bail out if it's not our plugin.
318
+        $update_uri = $plugin_data['UpdateURI'];
319
+        if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
320
+            return $update;
321
+        }
322
+
323
+        $response = wp_remote_get( "$update_uri?nocache=" . time() );
324
+
325
+        if ( is_wp_error( $response ) ) {
326
+            return $update;
327
+        }
328
+
329
+        try {
330
+            return json_decode( wp_remote_retrieve_body( $response ) );
331
+        } catch ( Exception $e ) {
332
+            return $update;
333
+        }
334
+    },
335
+    10,
336
+    3
337 337
 );
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -31,29 +31,29 @@  discard block
 block discarded – undo
31 31
 use Wordlift\Features\Features_Registry;
32 32
 use Wordlift\Post\Post_Adapter;
33 33
 // If this file is called directly, abort.
34
-if ( ! defined( 'WPINC' ) ) {
34
+if ( ! defined('WPINC')) {
35 35
 	die;
36 36
 }
37 37
 define(
38 38
 	'WORDLIFT_PLUGIN_FILE',
39 39
 	__FILE__
40 40
 );
41
-define( 'WORDLIFT_VERSION', '3.40.5' );
41
+define('WORDLIFT_VERSION', '3.40.5');
42 42
 
43
-require_once plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php';
44
-require_once __DIR__ . '/modules/common/load.php';
45
-require_once __DIR__ . '/modules/include-exclude/load.php';
43
+require_once plugin_dir_path(__FILE__).'/libraries/action-scheduler/action-scheduler.php';
44
+require_once __DIR__.'/modules/common/load.php';
45
+require_once __DIR__.'/modules/include-exclude/load.php';
46 46
 
47 47
 /**
48 48
  * Filter to disable WLP on any request, defaults to true.
49 49
  *
50 50
  * @since 3.33.6
51 51
  */
52
-if ( ! apply_filters( 'wl_is_enabled', true ) ) {
52
+if ( ! apply_filters('wl_is_enabled', true)) {
53 53
 	return;
54 54
 }
55 55
 
56
-require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
56
+require_once plugin_dir_path(__FILE__).'vendor/autoload.php';
57 57
 
58 58
 /*
59 59
 	 * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
@@ -63,15 +63,15 @@  discard block
 block discarded – undo
63 63
 wordlift_plugin_autoload_register();
64 64
 
65 65
 // Include WordLift constants.
66
-require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php';
66
+require_once plugin_dir_path(__FILE__).'wordlift-constants.php';
67 67
 
68 68
 // Load modules.
69
-require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php';
69
+require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php';
70 70
 
71
-require_once plugin_dir_path( __FILE__ ) . 'deprecations.php';
71
+require_once plugin_dir_path(__FILE__).'deprecations.php';
72 72
 
73 73
 // Load early to enable/disable features.
74
-require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php';
74
+require_once plugin_dir_path(__FILE__).'wordlift/features/index.php';
75 75
 
76 76
 /**
77 77
  * The code that runs during plugin activation.
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
  */
80 80
 function activate_wordlift() {
81 81
 
82
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
82
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
83 83
 
84
-	$log->info( 'Activating WordLift...' );
84
+	$log->info('Activating WordLift...');
85 85
 
86
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
86
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
87 87
 	Wordlift_Activator::activate();
88 88
 
89 89
 	/**
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 	 */
104 104
 	Top_Entities::activate();
105 105
 
106
-	if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
107
-		wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
106
+	if ( ! wp_next_scheduled('wl_daily_cron')) {
107
+		wp_schedule_event(time(), 'daily', 'wl_daily_cron');
108 108
 	}
109 109
 
110 110
 }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
  */
116 116
 function deactivate_wordlift() {
117 117
 
118
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
118
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
119 119
 	Wordlift_Deactivator::deactivate();
120 120
 	Wordlift_Http_Api::deactivate();
121 121
 	Ttl_Cache_Cleaner::deactivate();
@@ -131,18 +131,18 @@  discard block
 block discarded – undo
131 131
 	Key_Validation_Notice::remove_notification_flag();
132 132
 	flush_rewrite_rules();
133 133
 
134
-	wp_clear_scheduled_hook( 'wl_daily_cron' );
134
+	wp_clear_scheduled_hook('wl_daily_cron');
135 135
 
136 136
 }
137 137
 
138
-register_activation_hook( __FILE__, 'activate_wordlift' );
139
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
138
+register_activation_hook(__FILE__, 'activate_wordlift');
139
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
140 140
 
141 141
 /**
142 142
  * The core plugin class that is used to define internationalization,
143 143
  * admin-specific hooks, and public-facing site hooks.
144 144
  */
145
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
145
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
146 146
 
147 147
 /**
148 148
  * Begins execution of the plugin.
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
 	 * @return bool
163 163
 	 * @since 3.27.6
164 164
 	 */
165
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
166
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
167
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
168
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
165
+	if (apply_filters('wl_feature__enable__widgets', true)) {
166
+		add_action('widgets_init', 'wl_register_chord_widget');
167
+		add_action('widgets_init', 'wl_register_geo_widget');
168
+		add_action('widgets_init', 'wl_register_timeline_widget');
169 169
 	}
170
-	add_filter( 'widget_text', 'do_shortcode' );
170
+	add_filter('widget_text', 'do_shortcode');
171 171
 
172 172
 	/**
173 173
 	 * Filter: wl_feature__enable__analysis
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
 	 * @return bool
178 178
 	 * @since 3.27.6
179 179
 	 */
180
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
181
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
180
+	if (apply_filters('wl_feature__enable__analysis', true)) {
181
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
182 182
 	} else {
183
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
183
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action');
184 184
 	}
185 185
 
186 186
 	$plugin = new Wordlift();
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 
198 198
 	add_action(
199 199
 		'plugins_loaded',
200
-		function () {
200
+		function() {
201 201
 			// All features from registry should be initialized here.
202 202
 			$features_registry = Features_Registry::get_instance();
203 203
 			$features_registry->initialize_all_features();
@@ -208,27 +208,27 @@  discard block
 block discarded – undo
208 208
 	add_action(
209 209
 		'plugins_loaded',
210 210
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
211
-		function () use ( $plugin ) {
211
+		function() use ($plugin) {
212 212
 
213 213
 			new Wordlift_Products_Navigator_Shortcode_REST();
214 214
 
215 215
 			// Register the Dataset module, requires `$api_service`.
216
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
217
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
216
+			require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php';
217
+			require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php';
218 218
 
219 219
 			/*
220 220
 			* Require the Entity annotation cleanup module.
221 221
 			*
222 222
 			* @since 3.34.6
223 223
 			*/
224
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
224
+			require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php';
225 225
 
226 226
 			/*
227 227
 			* Import LOD entities.
228 228
 			*
229 229
 			* @since 3.35.0
230 230
 			*/
231
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
231
+			require_once plugin_dir_path(__FILE__).'wordlift/lod-import/index.php';
232 232
 
233 233
 		}
234 234
 	);
@@ -246,23 +246,23 @@  discard block
 block discarded – undo
246 246
 function wordlift_plugin_autoload_register() {
247 247
 
248 248
 	spl_autoload_register(
249
-		function ( $class_name ) {
249
+		function($class_name) {
250 250
 
251 251
 			// Bail out if these are not our classes.
252
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
252
+			if (0 !== strpos($class_name, 'Wordlift\\')) {
253 253
 				return false;
254 254
 			}
255 255
 
256
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
256
+			$class_name_lc = strtolower(str_replace('_', '-', $class_name));
257 257
 
258
-			preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
258
+			preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches);
259 259
 
260
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
261
-			$file = 'class-' . $matches[2] . '.php';
260
+			$path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]);
261
+			$file = 'class-'.$matches[2].'.php';
262 262
 
263
-			$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
263
+			$full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file;
264 264
 
265
-			if ( ! file_exists( $full_path ) ) {
265
+			if ( ! file_exists($full_path)) {
266 266
 				return false;
267 267
 			}
268 268
 
@@ -274,13 +274,13 @@  discard block
 block discarded – undo
274 274
 
275 275
 }
276 276
 
277
-function wl_block_categories( $categories ) {
277
+function wl_block_categories($categories) {
278 278
 	return array_merge(
279 279
 		$categories,
280 280
 		array(
281 281
 			array(
282 282
 				'slug'  => 'wordlift',
283
-				'title' => __( 'WordLift', 'wordlift' ),
283
+				'title' => __('WordLift', 'wordlift'),
284 284
 			),
285 285
 		)
286 286
 	);
@@ -290,45 +290,45 @@  discard block
 block discarded – undo
290 290
  * This function is created temporarily to handle the legacy library,
291 291
  * this has to be removed when removing the legacy fields from the ui.
292 292
  */
293
-function wl_enqueue_leaflet( $in_footer = false ) {
293
+function wl_enqueue_leaflet($in_footer = false) {
294 294
 	// Leaflet.
295
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
296
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
295
+	wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0');
296
+	wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer);
297 297
 }
298 298
 
299
-add_filter( 'block_categories', 'wl_block_categories', 10 );
299
+add_filter('block_categories', 'wl_block_categories', 10);
300 300
 
301 301
 // Temporary fix for a typo in WooCommerce Extension.
302 302
 add_filter(
303 303
 	'wl_feature__enable__dataset',
304
-	function ( $value ) {
305
-		return apply_filters( 'wl_features__enable__dataset', $value );
304
+	function($value) {
305
+		return apply_filters('wl_features__enable__dataset', $value);
306 306
 	}
307 307
 );
308 308
 
309
-require_once __DIR__ . '/modules/food-kg/load.php';
310
-require_once __DIR__ . '/modules/acf4so/load.php';
311
-require_once __DIR__ . '/modules/pods/load.php';
312
-require_once __DIR__ . '/modules/include-exclude-push-config/load.php';
309
+require_once __DIR__.'/modules/food-kg/load.php';
310
+require_once __DIR__.'/modules/acf4so/load.php';
311
+require_once __DIR__.'/modules/pods/load.php';
312
+require_once __DIR__.'/modules/include-exclude-push-config/load.php';
313 313
 
314 314
 add_action(
315 315
 	'update_plugins_adthrive.wordlift.io',
316
-	function ( $update, $plugin_data, $plugin_file ) {
316
+	function($update, $plugin_data, $plugin_file) {
317 317
 		// Bail out if it's not our plugin.
318 318
 		$update_uri = $plugin_data['UpdateURI'];
319
-		if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) {
319
+		if ('wordlift/wordlift.php' !== $plugin_file || ! isset($update_uri)) {
320 320
 			return $update;
321 321
 		}
322 322
 
323
-		$response = wp_remote_get( "$update_uri?nocache=" . time() );
323
+		$response = wp_remote_get("$update_uri?nocache=".time());
324 324
 
325
-		if ( is_wp_error( $response ) ) {
325
+		if (is_wp_error($response)) {
326 326
 			return $update;
327 327
 		}
328 328
 
329 329
 		try {
330
-			return json_decode( wp_remote_retrieve_body( $response ) );
331
-		} catch ( Exception $e ) {
330
+			return json_decode(wp_remote_retrieve_body($response));
331
+		} catch (Exception $e) {
332 332
 			return $update;
333 333
 		}
334 334
 	},
Please login to merge, or discard this patch.
src/modules/food-kg/includes/Jsonld.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -7,43 +7,43 @@
 block discarded – undo
7 7
 
8 8
 class Jsonld {
9 9
 
10
-	public function register_hooks() {
11
-		add_action( 'wprm_recipe_metadata', array( $this, '__recipe_metadata' ), 10, 2 );
12
-	}
13
-
14
-	/**
15
-	 * @param array       $metadata
16
-	 * @param WPRM_Recipe $recipe
17
-	 *
18
-	 * @return array
19
-	 */
20
-	public function __recipe_metadata( $metadata, $recipe ) {
21
-
22
-		$ingredients = get_the_terms( $recipe->id(), 'wprm_ingredient' );
23
-		if ( ! $ingredients ) {
24
-			return $metadata;
25
-		}
26
-		$jsonlds = array_filter( array_map( array( $this, '__term_id_to_jsonld' ), $ingredients ) );
27
-
28
-		if ( empty( $jsonlds ) ) {
29
-			return $metadata;
30
-		}
31
-
32
-		// We're embedding the full json-ld here because WL doesn't output its own markup, so it makes no sense
33
-		// to hook to wl_after_json_ld.
34
-		$metadata['mentions'] = isset( $metadata['mentions'] ) ? $metadata['mentions'] : array();
35
-		$metadata['mentions'] = array_merge( $metadata['mentions'], $jsonlds );
36
-
37
-		return $metadata;
38
-	}
39
-
40
-	/**
41
-	 * @param WP_Term $ingredient
42
-	 *
43
-	 * @return array void
44
-	 */
45
-	private function __term_id_to_jsonld( $ingredient ) {
46
-		return json_decode( get_term_meta( $ingredient->term_id, '_wl_jsonld', true ), true );
47
-	}
10
+    public function register_hooks() {
11
+        add_action( 'wprm_recipe_metadata', array( $this, '__recipe_metadata' ), 10, 2 );
12
+    }
13
+
14
+    /**
15
+     * @param array       $metadata
16
+     * @param WPRM_Recipe $recipe
17
+     *
18
+     * @return array
19
+     */
20
+    public function __recipe_metadata( $metadata, $recipe ) {
21
+
22
+        $ingredients = get_the_terms( $recipe->id(), 'wprm_ingredient' );
23
+        if ( ! $ingredients ) {
24
+            return $metadata;
25
+        }
26
+        $jsonlds = array_filter( array_map( array( $this, '__term_id_to_jsonld' ), $ingredients ) );
27
+
28
+        if ( empty( $jsonlds ) ) {
29
+            return $metadata;
30
+        }
31
+
32
+        // We're embedding the full json-ld here because WL doesn't output its own markup, so it makes no sense
33
+        // to hook to wl_after_json_ld.
34
+        $metadata['mentions'] = isset( $metadata['mentions'] ) ? $metadata['mentions'] : array();
35
+        $metadata['mentions'] = array_merge( $metadata['mentions'], $jsonlds );
36
+
37
+        return $metadata;
38
+    }
39
+
40
+    /**
41
+     * @param WP_Term $ingredient
42
+     *
43
+     * @return array void
44
+     */
45
+    private function __term_id_to_jsonld( $ingredient ) {
46
+        return json_decode( get_term_meta( $ingredient->term_id, '_wl_jsonld', true ), true );
47
+    }
48 48
 
49 49
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 class Jsonld {
9 9
 
10 10
 	public function register_hooks() {
11
-		add_action( 'wprm_recipe_metadata', array( $this, '__recipe_metadata' ), 10, 2 );
11
+		add_action('wprm_recipe_metadata', array($this, '__recipe_metadata'), 10, 2);
12 12
 	}
13 13
 
14 14
 	/**
@@ -17,22 +17,22 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @return array
19 19
 	 */
20
-	public function __recipe_metadata( $metadata, $recipe ) {
20
+	public function __recipe_metadata($metadata, $recipe) {
21 21
 
22
-		$ingredients = get_the_terms( $recipe->id(), 'wprm_ingredient' );
23
-		if ( ! $ingredients ) {
22
+		$ingredients = get_the_terms($recipe->id(), 'wprm_ingredient');
23
+		if ( ! $ingredients) {
24 24
 			return $metadata;
25 25
 		}
26
-		$jsonlds = array_filter( array_map( array( $this, '__term_id_to_jsonld' ), $ingredients ) );
26
+		$jsonlds = array_filter(array_map(array($this, '__term_id_to_jsonld'), $ingredients));
27 27
 
28
-		if ( empty( $jsonlds ) ) {
28
+		if (empty($jsonlds)) {
29 29
 			return $metadata;
30 30
 		}
31 31
 
32 32
 		// We're embedding the full json-ld here because WL doesn't output its own markup, so it makes no sense
33 33
 		// to hook to wl_after_json_ld.
34
-		$metadata['mentions'] = isset( $metadata['mentions'] ) ? $metadata['mentions'] : array();
35
-		$metadata['mentions'] = array_merge( $metadata['mentions'], $jsonlds );
34
+		$metadata['mentions'] = isset($metadata['mentions']) ? $metadata['mentions'] : array();
35
+		$metadata['mentions'] = array_merge($metadata['mentions'], $jsonlds);
36 36
 
37 37
 		return $metadata;
38 38
 	}
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return array void
44 44
 	 */
45
-	private function __term_id_to_jsonld( $ingredient ) {
46
-		return json_decode( get_term_meta( $ingredient->term_id, '_wl_jsonld', true ), true );
45
+	private function __term_id_to_jsonld($ingredient) {
46
+		return json_decode(get_term_meta($ingredient->term_id, '_wl_jsonld', true), true);
47 47
 	}
48 48
 
49 49
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-entity-service.php 2 patches
Indentation   +577 added lines, -577 removed lines patch added patch discarded remove patch
@@ -21,498 +21,498 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Entity_Service {
23 23
 
24
-	/**
25
-	 * The Log service.
26
-	 *
27
-	 * @since  3.2.0
28
-	 * @access private
29
-	 * @var \Wordlift_Log_Service $log The Log service.
30
-	 */
31
-	private $log;
32
-
33
-	/**
34
-	 * The {@link Wordlift_Relation_Service} instance.
35
-	 *
36
-	 * @since  3.15.0
37
-	 * @access private
38
-	 * @var \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
39
-	 */
40
-	private $relation_service;
41
-
42
-	/**
43
-	 * The {@link Wordlift_Entity_Uri_Service} instance.
44
-	 *
45
-	 * @since  3.16.3
46
-	 * @access private
47
-	 * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance.
48
-	 */
49
-	private $entity_uri_service;
50
-
51
-	/**
52
-	 * The entity post type name.
53
-	 *
54
-	 * @since 3.1.0
55
-	 */
56
-	const TYPE_NAME = 'entity';
57
-
58
-	/**
59
-	 * The alternative label meta key.
60
-	 *
61
-	 * @since 3.2.0
62
-	 */
63
-	const ALTERNATIVE_LABEL_META_KEY = '_wl_alt_label';
64
-
65
-	/**
66
-	 * The alternative label input template.
67
-	 *
68
-	 * @since 3.2.0
69
-	 */
70
-	// TODO: this should be moved to a class that deals with HTML code.
71
-	const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
24
+    /**
25
+     * The Log service.
26
+     *
27
+     * @since  3.2.0
28
+     * @access private
29
+     * @var \Wordlift_Log_Service $log The Log service.
30
+     */
31
+    private $log;
32
+
33
+    /**
34
+     * The {@link Wordlift_Relation_Service} instance.
35
+     *
36
+     * @since  3.15.0
37
+     * @access private
38
+     * @var \Wordlift_Relation_Service $relation_service The {@link Wordlift_Relation_Service} instance.
39
+     */
40
+    private $relation_service;
41
+
42
+    /**
43
+     * The {@link Wordlift_Entity_Uri_Service} instance.
44
+     *
45
+     * @since  3.16.3
46
+     * @access private
47
+     * @var \Wordlift_Entity_Uri_Service $entity_uri_service The {@link Wordlift_Entity_Uri_Service} instance.
48
+     */
49
+    private $entity_uri_service;
50
+
51
+    /**
52
+     * The entity post type name.
53
+     *
54
+     * @since 3.1.0
55
+     */
56
+    const TYPE_NAME = 'entity';
57
+
58
+    /**
59
+     * The alternative label meta key.
60
+     *
61
+     * @since 3.2.0
62
+     */
63
+    const ALTERNATIVE_LABEL_META_KEY = '_wl_alt_label';
64
+
65
+    /**
66
+     * The alternative label input template.
67
+     *
68
+     * @since 3.2.0
69
+     */
70
+    // TODO: this should be moved to a class that deals with HTML code.
71
+    const ALTERNATIVE_LABEL_INPUT_TEMPLATE = '<div class="wl-alternative-label">
72 72
                 <label class="screen-reader-text" id="wl-alternative-label-prompt-text" for="wl-alternative-label">Enter alternative label here</label>
73 73
                 <input name="wl_alternative_label[]" size="30" value="%s" id="wl-alternative-label" type="text">
74 74
                 <button class="button wl-delete-button">%s</button>
75 75
                 </div>';
76 76
 
77
-	/**
78
-	 * Create a Wordlift_Entity_Service instance.
79
-	 *
80
-	 * @throws Exception if the `$content_service` is not of the `Content_Service` type.
81
-	 * @since 3.2.0
82
-	 */
83
-	protected function __construct() {
84
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
85
-
86
-		$this->entity_uri_service = Wordlift_Entity_Uri_Service::get_instance();
87
-		$this->relation_service   = Wordlift_Relation_Service::get_instance();
88
-
89
-	}
90
-
91
-	/**
92
-	 * A singleton instance of the Entity service.
93
-	 *
94
-	 * @since  3.2.0
95
-	 * @access private
96
-	 * @var Wordlift_Entity_Service $instance A singleton instance of the Entity service.
97
-	 */
98
-	private static $instance = null;
99
-
100
-	/**
101
-	 * Get the singleton instance of the Entity service.
102
-	 *
103
-	 * @return Wordlift_Entity_Service The singleton instance of the Entity service.
104
-	 * @since 3.2.0
105
-	 */
106
-	public static function get_instance() {
107
-
108
-		if ( ! isset( self::$instance ) ) {
109
-			self::$instance = new self();
110
-		}
111
-
112
-		return self::$instance;
113
-	}
114
-
115
-	/**
116
-	 * Determines whether a post is an entity or not. Entity is in this context
117
-	 * something which is not an article.
118
-	 *
119
-	 * @param int $post_id A post id.
120
-	 *
121
-	 * @return bool Return true if the post is an entity otherwise false.
122
-	 * @since 3.1.0
123
-	 */
124
-	public function is_entity( $post_id ) {
125
-
126
-		// Improve performance by giving for granted that a product is an entity.
127
-		if ( 'product' === get_post_type( $post_id ) ) {
128
-			return true;
129
-		}
130
-
131
-		$terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
132
-
133
-		if ( is_wp_error( $terms ) ) {
134
-			$this->log->error( "Cannot get the terms for post $post_id: " . $terms->get_error_message() );
135
-
136
-			return false;
137
-		}
138
-
139
-		if ( empty( $terms ) ) {
140
-			return false;
141
-		}
142
-
143
-		/*
77
+    /**
78
+     * Create a Wordlift_Entity_Service instance.
79
+     *
80
+     * @throws Exception if the `$content_service` is not of the `Content_Service` type.
81
+     * @since 3.2.0
82
+     */
83
+    protected function __construct() {
84
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
85
+
86
+        $this->entity_uri_service = Wordlift_Entity_Uri_Service::get_instance();
87
+        $this->relation_service   = Wordlift_Relation_Service::get_instance();
88
+
89
+    }
90
+
91
+    /**
92
+     * A singleton instance of the Entity service.
93
+     *
94
+     * @since  3.2.0
95
+     * @access private
96
+     * @var Wordlift_Entity_Service $instance A singleton instance of the Entity service.
97
+     */
98
+    private static $instance = null;
99
+
100
+    /**
101
+     * Get the singleton instance of the Entity service.
102
+     *
103
+     * @return Wordlift_Entity_Service The singleton instance of the Entity service.
104
+     * @since 3.2.0
105
+     */
106
+    public static function get_instance() {
107
+
108
+        if ( ! isset( self::$instance ) ) {
109
+            self::$instance = new self();
110
+        }
111
+
112
+        return self::$instance;
113
+    }
114
+
115
+    /**
116
+     * Determines whether a post is an entity or not. Entity is in this context
117
+     * something which is not an article.
118
+     *
119
+     * @param int $post_id A post id.
120
+     *
121
+     * @return bool Return true if the post is an entity otherwise false.
122
+     * @since 3.1.0
123
+     */
124
+    public function is_entity( $post_id ) {
125
+
126
+        // Improve performance by giving for granted that a product is an entity.
127
+        if ( 'product' === get_post_type( $post_id ) ) {
128
+            return true;
129
+        }
130
+
131
+        $terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
132
+
133
+        if ( is_wp_error( $terms ) ) {
134
+            $this->log->error( "Cannot get the terms for post $post_id: " . $terms->get_error_message() );
135
+
136
+            return false;
137
+        }
138
+
139
+        if ( empty( $terms ) ) {
140
+            return false;
141
+        }
142
+
143
+        /*
144 144
 		 * We don't consider an `article` to be an entity.
145 145
 		 *
146 146
 		 * @since 3.20.0 At least one associated mustn't be an `article`.
147 147
 		 *
148 148
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/835
149 149
 		 */
150
-		foreach ( $terms as $term ) {
151
-			if ( 1 !== preg_match( '~(^|-)article$~', $term->slug ) ) {
152
-				return true;
153
-			}
154
-		}
155
-
156
-		return false;
157
-	}
158
-
159
-	/**
160
-	 * Get the proper classification scope for a given entity post
161
-	 *
162
-	 * @param integer $post_id An entity post id.
163
-	 *
164
-	 * @param string  $default The default classification scope, `what` if not
165
-	 *                            provided.
166
-	 *
167
-	 * @return string Returns a classification scope (e.g. 'what').
168
-	 * @since 3.5.0
169
-	 */
170
-	public function get_classification_scope_for( $post_id, $default = WL_WHAT_RELATION ) {
171
-
172
-		if ( false === $this->is_entity( $post_id ) ) {
173
-			return $default;
174
-		}
175
-
176
-		// Retrieve the entity type
177
-		$entity_type_arr = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
178
-		$entity_type     = str_replace( 'wl-', '', $entity_type_arr['css_class'] );
179
-		// Retrieve classification boxes configuration
180
-		// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
181
-		$classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES );
182
-		foreach ( $classification_boxes as $cb ) {
183
-			if ( in_array( $entity_type, $cb['registeredTypes'], true ) ) {
184
-				return $cb['id'];
185
-			}
186
-		}
187
-
188
-		return $default;
189
-	}
190
-
191
-	/**
192
-	 * Check whether a {@link WP_Post} is used.
193
-	 *
194
-	 * @param int $post_id The {@link WP_Post}'s id.
195
-	 *
196
-	 * @return bool|null Null if it's not an entity, otherwise true if it's used.
197
-	 */
198
-	public function is_used( $post_id ) {
199
-
200
-		if ( false === $this->is_entity( $post_id ) ) {
201
-			return null;
202
-		}
203
-		// Retrieve the post
204
-		$entity = get_post( $post_id );
205
-
206
-		global $wpdb;
207
-
208
-		// Perform the query
209
-		$relation_instances = (int) $wpdb->get_var(
210
-			$wpdb->prepare(
211
-				"SELECT COUNT(*) FROM {$wpdb->prefix}wl_relation_instances WHERE  object_id = %d",
212
-				$entity->ID
213
-			)
214
-		);
215
-		// If there is at least one relation instance for the current entity, then it's used
216
-		if ( 0 < $relation_instances ) {
217
-			return true;
218
-		}
219
-
220
-		// Perform the query
221
-		$meta_instances = (int) $wpdb->get_var(
222
-			$wpdb->prepare(
223
-				"SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s",
224
-				$entity->ID,
225
-				wl_get_entity_uri( $entity->ID )
226
-			)
227
-		);
228
-
229
-		// If there is at least one meta that refers the current entity uri, then current entity is used
230
-		if ( 0 < $meta_instances ) {
231
-			return true;
232
-		}
233
-
234
-		// If we are here, it means the current entity is not used at the moment
235
-		return false;
236
-	}
237
-
238
-	/**
239
-	 * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
240
-	 *
241
-	 * @param string $uri The entity URI.
242
-	 *
243
-	 * @return WP_Post|null A WP_Post instance or null if not found.
244
-	 * @deprecated in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );
245
-	 *
246
-	 * @since      3.16.3 deprecated in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );
247
-	 * @since      3.2.0
248
-	 */
249
-	public function get_entity_post_by_uri( $uri ) {
250
-
251
-		return $this->entity_uri_service->get_entity( $uri );
252
-	}
253
-
254
-	/**
255
-	 * Fires once a post has been saved. This function uses the $_REQUEST, therefore
256
-	 * we check that the post we're saving is the current post.
257
-	 *
258
-	 * This function is called by a hook, so we're not the ones that need to check the `nonce`.
259
-	 *
260
-	 * @see   https://github.com/insideout10/wordlift-plugin/issues/363
261
-	 *
262
-	 * @since 3.2.0
263
-	 *
264
-	 * @param int     $post_id Post ID.
265
-	 * @param WP_Post $post Post object.
266
-	 */
267
-	public function save_post( $post_id, $post ) {
268
-		// Avoid doing anything if post is autosave or a revision.
269
-		if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) ) {
270
-			return;
271
-		}
272
-
273
-		// We expect a numeric value here.
274
-		if ( ! isset( $_REQUEST['post_ID'] ) || ! is_numeric( $_REQUEST['post_ID'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
275
-			return;
276
-		}
277
-
278
-		// Get the numeric post ID from the request.
279
-		$request_post_id = intval( $_REQUEST['post_ID'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
280
-
281
-		// We're setting the alternative label that have been provided via the UI
282
-		// (in fact we're using $_REQUEST), while save_post may be also called
283
-		// programmatically by some other function: we need to check therefore if
284
-		// the $post_id in the save_post call matches the post id set in the request.
285
-		//
286
-		// If this is not the current post being saved or if it's not an entity, return.
287
-		if ( $request_post_id !== $post_id || ! $this->is_entity( $post_id ) ) {
288
-			return;
289
-		}
290
-
291
-		if ( isset( $_REQUEST['wl_alternative_label'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
292
-			$data = filter_var_array( $_REQUEST, array( 'wl_alternative_label' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
293
-			// Get the alt labels from the request (or empty array).
294
-			$alt_labels = isset( $data['wl_alternative_label'] ) ? $data['wl_alternative_label'] : array();
295
-			// This is via classic editor, so set the alternative labels.
296
-			$this->set_alternative_labels( $post_id, $alt_labels );
297
-		}
298
-
299
-	}
300
-
301
-	/**
302
-	 * Set the alternative labels.
303
-	 *
304
-	 * @param int   $post_id The post id.
305
-	 * @param array $alt_labels An array of labels.
306
-	 *
307
-	 * @since 3.2.0
308
-	 */
309
-	public function set_alternative_labels( $post_id, $alt_labels ) {
310
-
311
-		// Bail out if post id is not numeric. We add this check as we found a WP install that was sending a WP_Error
312
-		// instead of post id.
313
-		if ( ! is_numeric( $post_id ) ) {
314
-			return;
315
-		}
316
-
317
-		// Force $alt_labels to be an array
318
-		if ( ! is_array( $alt_labels ) ) {
319
-			$alt_labels = array( $alt_labels );
320
-		}
321
-
322
-		$this->log->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . ' ]' );
323
-
324
-		// Delete all the existing alternate labels.
325
-		delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
326
-
327
-		// Save only unique synonymns.
328
-		$alt_labels = array_unique( $alt_labels );
329
-
330
-		// Set the alternative labels.
331
-		foreach ( $alt_labels as $alt_label ) {
332
-
333
-			// Strip html code from synonym.
334
-			$alt_label = wp_strip_all_tags( $alt_label );
335
-
336
-			if ( ! empty( $alt_label ) ) {
337
-				add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, (string) $alt_label );
338
-			}
339
-		}
340
-
341
-	}
342
-
343
-	public function append_alternative_labels( $post_id, $labels_to_append ) {
344
-
345
-		$merged_labels = $this->get_alternative_labels( $post_id );
346
-
347
-		// Append new synonyms to the end.
348
-		$merged_labels = array_merge( $merged_labels, $labels_to_append );
349
-
350
-		$this->set_alternative_labels( $post_id, $merged_labels );
351
-
352
-	}
353
-
354
-	/**
355
-	 * Retrieve the alternate labels.
356
-	 *
357
-	 * @param int $post_id Post id.
358
-	 *
359
-	 * @return mixed An array  of alternative labels.
360
-	 * @since 3.2.0
361
-	 */
362
-	public function get_alternative_labels( $post_id ) {
363
-
364
-		return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
365
-	}
366
-
367
-	/**
368
-	 * Retrieve the labels for an entity, i.e. the title + the synonyms.
369
-	 *
370
-	 * @param int $post_id The entity {@link WP_Post} id.
371
-	 * @param int $object_type The object type {@link Object_Type_Enum}
372
-	 *
373
-	 * @return array An array with the entity title and labels.
374
-	 * @since 3.12.0
375
-	 */
376
-	public function get_labels( $post_id, $object_type = Object_Type_Enum::POST ) {
377
-		if ( Object_Type_Enum::POST === $object_type ) {
378
-			return array_merge( (array) get_the_title( $post_id ), $this->get_alternative_labels( $post_id ) );
379
-		}
380
-
381
-		// Term Reference dont have synonyms yet.
382
-		return array();
383
-	}
384
-
385
-	/**
386
-	 * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
387
-	 *
388
-	 * @param WP_Post $post Post object.
389
-	 *
390
-	 * @since 3.2.0
391
-	 */
392
-	public function edit_form_before_permalink( $post ) {
393
-
394
-		// If it's not an entity, return.
395
-		if ( ! $this->is_entity( $post->ID ) ) {
396
-			return;
397
-		}
398
-
399
-		// If disabled by filter, return.
400
-		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
401
-		if ( ! apply_filters( 'wl_feature__enable__add-synonyms', true ) ) {
402
-			return;
403
-		}
404
-
405
-		// Print the input template.
406
-		Wordlift_UI_Service::print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
407
-
408
-		// Print all the currently set alternative labels.
409
-		foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
410
-
411
-			echo wp_kses( $this->get_alternative_label_input( $alt_label ), Wordlift_UI_Service::get_template_allowed_html() );
412
-
413
-		};
414
-
415
-		// Print the button.
416
-		Wordlift_UI_Service::print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
417
-
418
-	}
419
-
420
-	public function get_uri( $object_id, $type = Object_Type_Enum::POST ) {
421
-		$content_service = Wordpress_Content_Service::get_instance();
422
-		$entity_id       = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
423
-		$dataset_uri     = Wordlift_Configuration_Service::get_instance()->get_dataset_uri();
424
-
425
-		if ( ! isset( $entity_id ) ||
426
-			 ( ! empty( $dataset_uri ) && 0 !== strpos( $entity_id, $dataset_uri ) ) ) {
427
-			$rel_uri = Entity_Uri_Generator::create_uri( $type, $object_id );
428
-			try {
429
-				$content_service->set_entity_id( new Wordpress_Content_Id( $object_id, $type ), $rel_uri );
430
-				$entity_id = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
431
-			} catch ( Exception $e ) {
432
-				return null;
433
-			}
434
-		}
435
-
436
-		return $entity_id;
437
-	}
438
-
439
-	/**
440
-	 * Get the alternative label input HTML code.
441
-	 *
442
-	 * @param string $value The input value.
443
-	 *
444
-	 * @return string The input HTML code.
445
-	 * @since 3.2.0
446
-	 */
447
-	private function get_alternative_label_input( $value = '' ) {
448
-
449
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), esc_html__( 'Delete', 'wordlift' ) );
450
-	}
451
-
452
-	/**
453
-	 * Get the number of entity posts published in this blog.
454
-	 *
455
-	 * @return int The number of published entity posts.
456
-	 * @since 3.6.0
457
-	 */
458
-	public function count() {
459
-		global $wpdb;
460
-
461
-		// Try to get the count from the transient.
462
-		$count = get_transient( '_wl_entity_service__count' );
463
-		if ( false !== $count ) {
464
-			return $count;
465
-		}
466
-
467
-		// Query the count.
468
-		$count = $wpdb->get_var(
469
-			$wpdb->prepare(
470
-				'SELECT COUNT( DISTINCT( tr.object_id ) )'
471
-				. " FROM {$wpdb->term_relationships} tr"
472
-				. " INNER JOIN {$wpdb->term_taxonomy} tt"
473
-				. '  ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id'
474
-				. " INNER JOIN {$wpdb->terms} t"
475
-				. '  ON t.term_id = tt.term_id AND t.name != %s',
476
-				Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
477
-				'article'
478
-			)
479
-		);
480
-
481
-		// Store the count in cache.
482
-		set_transient( '_wl_entity_service__count', $count, 900 );
483
-
484
-		return $count;
485
-	}
486
-
487
-	/**
488
-	 * Add the entity filtering criterias to the arguments for a `get_posts`
489
-	 * call.
490
-	 *
491
-	 * @param array $args The arguments for a `get_posts` call.
492
-	 *
493
-	 * @return array The arguments for a `get_posts` call.
494
-	 * @since 3.15.0
495
-	 */
496
-	public static function add_criterias( $args ) {
497
-
498
-		// Build an optimal tax-query.
499
-		$tax_query = array(
500
-			'relation' => 'AND',
501
-			array(
502
-				'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
503
-				'operator' => 'EXISTS',
504
-			),
505
-			array(
506
-				'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
507
-				'field'    => 'slug',
508
-				'terms'    => 'article',
509
-				'operator' => 'NOT IN',
510
-			),
511
-		);
512
-
513
-		return $args + array(
514
-			'post_type' => self::valid_entity_post_types(),
515
-			/*
150
+        foreach ( $terms as $term ) {
151
+            if ( 1 !== preg_match( '~(^|-)article$~', $term->slug ) ) {
152
+                return true;
153
+            }
154
+        }
155
+
156
+        return false;
157
+    }
158
+
159
+    /**
160
+     * Get the proper classification scope for a given entity post
161
+     *
162
+     * @param integer $post_id An entity post id.
163
+     *
164
+     * @param string  $default The default classification scope, `what` if not
165
+     *                            provided.
166
+     *
167
+     * @return string Returns a classification scope (e.g. 'what').
168
+     * @since 3.5.0
169
+     */
170
+    public function get_classification_scope_for( $post_id, $default = WL_WHAT_RELATION ) {
171
+
172
+        if ( false === $this->is_entity( $post_id ) ) {
173
+            return $default;
174
+        }
175
+
176
+        // Retrieve the entity type
177
+        $entity_type_arr = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
178
+        $entity_type     = str_replace( 'wl-', '', $entity_type_arr['css_class'] );
179
+        // Retrieve classification boxes configuration
180
+        // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
181
+        $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES );
182
+        foreach ( $classification_boxes as $cb ) {
183
+            if ( in_array( $entity_type, $cb['registeredTypes'], true ) ) {
184
+                return $cb['id'];
185
+            }
186
+        }
187
+
188
+        return $default;
189
+    }
190
+
191
+    /**
192
+     * Check whether a {@link WP_Post} is used.
193
+     *
194
+     * @param int $post_id The {@link WP_Post}'s id.
195
+     *
196
+     * @return bool|null Null if it's not an entity, otherwise true if it's used.
197
+     */
198
+    public function is_used( $post_id ) {
199
+
200
+        if ( false === $this->is_entity( $post_id ) ) {
201
+            return null;
202
+        }
203
+        // Retrieve the post
204
+        $entity = get_post( $post_id );
205
+
206
+        global $wpdb;
207
+
208
+        // Perform the query
209
+        $relation_instances = (int) $wpdb->get_var(
210
+            $wpdb->prepare(
211
+                "SELECT COUNT(*) FROM {$wpdb->prefix}wl_relation_instances WHERE  object_id = %d",
212
+                $entity->ID
213
+            )
214
+        );
215
+        // If there is at least one relation instance for the current entity, then it's used
216
+        if ( 0 < $relation_instances ) {
217
+            return true;
218
+        }
219
+
220
+        // Perform the query
221
+        $meta_instances = (int) $wpdb->get_var(
222
+            $wpdb->prepare(
223
+                "SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s",
224
+                $entity->ID,
225
+                wl_get_entity_uri( $entity->ID )
226
+            )
227
+        );
228
+
229
+        // If there is at least one meta that refers the current entity uri, then current entity is used
230
+        if ( 0 < $meta_instances ) {
231
+            return true;
232
+        }
233
+
234
+        // If we are here, it means the current entity is not used at the moment
235
+        return false;
236
+    }
237
+
238
+    /**
239
+     * Find entity posts by the entity URI. Entity as searched by their entity URI or same as.
240
+     *
241
+     * @param string $uri The entity URI.
242
+     *
243
+     * @return WP_Post|null A WP_Post instance or null if not found.
244
+     * @deprecated in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );
245
+     *
246
+     * @since      3.16.3 deprecated in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );
247
+     * @since      3.2.0
248
+     */
249
+    public function get_entity_post_by_uri( $uri ) {
250
+
251
+        return $this->entity_uri_service->get_entity( $uri );
252
+    }
253
+
254
+    /**
255
+     * Fires once a post has been saved. This function uses the $_REQUEST, therefore
256
+     * we check that the post we're saving is the current post.
257
+     *
258
+     * This function is called by a hook, so we're not the ones that need to check the `nonce`.
259
+     *
260
+     * @see   https://github.com/insideout10/wordlift-plugin/issues/363
261
+     *
262
+     * @since 3.2.0
263
+     *
264
+     * @param int     $post_id Post ID.
265
+     * @param WP_Post $post Post object.
266
+     */
267
+    public function save_post( $post_id, $post ) {
268
+        // Avoid doing anything if post is autosave or a revision.
269
+        if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) ) {
270
+            return;
271
+        }
272
+
273
+        // We expect a numeric value here.
274
+        if ( ! isset( $_REQUEST['post_ID'] ) || ! is_numeric( $_REQUEST['post_ID'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
275
+            return;
276
+        }
277
+
278
+        // Get the numeric post ID from the request.
279
+        $request_post_id = intval( $_REQUEST['post_ID'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
280
+
281
+        // We're setting the alternative label that have been provided via the UI
282
+        // (in fact we're using $_REQUEST), while save_post may be also called
283
+        // programmatically by some other function: we need to check therefore if
284
+        // the $post_id in the save_post call matches the post id set in the request.
285
+        //
286
+        // If this is not the current post being saved or if it's not an entity, return.
287
+        if ( $request_post_id !== $post_id || ! $this->is_entity( $post_id ) ) {
288
+            return;
289
+        }
290
+
291
+        if ( isset( $_REQUEST['wl_alternative_label'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
292
+            $data = filter_var_array( $_REQUEST, array( 'wl_alternative_label' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
293
+            // Get the alt labels from the request (or empty array).
294
+            $alt_labels = isset( $data['wl_alternative_label'] ) ? $data['wl_alternative_label'] : array();
295
+            // This is via classic editor, so set the alternative labels.
296
+            $this->set_alternative_labels( $post_id, $alt_labels );
297
+        }
298
+
299
+    }
300
+
301
+    /**
302
+     * Set the alternative labels.
303
+     *
304
+     * @param int   $post_id The post id.
305
+     * @param array $alt_labels An array of labels.
306
+     *
307
+     * @since 3.2.0
308
+     */
309
+    public function set_alternative_labels( $post_id, $alt_labels ) {
310
+
311
+        // Bail out if post id is not numeric. We add this check as we found a WP install that was sending a WP_Error
312
+        // instead of post id.
313
+        if ( ! is_numeric( $post_id ) ) {
314
+            return;
315
+        }
316
+
317
+        // Force $alt_labels to be an array
318
+        if ( ! is_array( $alt_labels ) ) {
319
+            $alt_labels = array( $alt_labels );
320
+        }
321
+
322
+        $this->log->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . ' ]' );
323
+
324
+        // Delete all the existing alternate labels.
325
+        delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
326
+
327
+        // Save only unique synonymns.
328
+        $alt_labels = array_unique( $alt_labels );
329
+
330
+        // Set the alternative labels.
331
+        foreach ( $alt_labels as $alt_label ) {
332
+
333
+            // Strip html code from synonym.
334
+            $alt_label = wp_strip_all_tags( $alt_label );
335
+
336
+            if ( ! empty( $alt_label ) ) {
337
+                add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, (string) $alt_label );
338
+            }
339
+        }
340
+
341
+    }
342
+
343
+    public function append_alternative_labels( $post_id, $labels_to_append ) {
344
+
345
+        $merged_labels = $this->get_alternative_labels( $post_id );
346
+
347
+        // Append new synonyms to the end.
348
+        $merged_labels = array_merge( $merged_labels, $labels_to_append );
349
+
350
+        $this->set_alternative_labels( $post_id, $merged_labels );
351
+
352
+    }
353
+
354
+    /**
355
+     * Retrieve the alternate labels.
356
+     *
357
+     * @param int $post_id Post id.
358
+     *
359
+     * @return mixed An array  of alternative labels.
360
+     * @since 3.2.0
361
+     */
362
+    public function get_alternative_labels( $post_id ) {
363
+
364
+        return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
365
+    }
366
+
367
+    /**
368
+     * Retrieve the labels for an entity, i.e. the title + the synonyms.
369
+     *
370
+     * @param int $post_id The entity {@link WP_Post} id.
371
+     * @param int $object_type The object type {@link Object_Type_Enum}
372
+     *
373
+     * @return array An array with the entity title and labels.
374
+     * @since 3.12.0
375
+     */
376
+    public function get_labels( $post_id, $object_type = Object_Type_Enum::POST ) {
377
+        if ( Object_Type_Enum::POST === $object_type ) {
378
+            return array_merge( (array) get_the_title( $post_id ), $this->get_alternative_labels( $post_id ) );
379
+        }
380
+
381
+        // Term Reference dont have synonyms yet.
382
+        return array();
383
+    }
384
+
385
+    /**
386
+     * Fires before the permalink field in the edit form (this event is available in WP from 4.1.0).
387
+     *
388
+     * @param WP_Post $post Post object.
389
+     *
390
+     * @since 3.2.0
391
+     */
392
+    public function edit_form_before_permalink( $post ) {
393
+
394
+        // If it's not an entity, return.
395
+        if ( ! $this->is_entity( $post->ID ) ) {
396
+            return;
397
+        }
398
+
399
+        // If disabled by filter, return.
400
+        // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
401
+        if ( ! apply_filters( 'wl_feature__enable__add-synonyms', true ) ) {
402
+            return;
403
+        }
404
+
405
+        // Print the input template.
406
+        Wordlift_UI_Service::print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
407
+
408
+        // Print all the currently set alternative labels.
409
+        foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
410
+
411
+            echo wp_kses( $this->get_alternative_label_input( $alt_label ), Wordlift_UI_Service::get_template_allowed_html() );
412
+
413
+        };
414
+
415
+        // Print the button.
416
+        Wordlift_UI_Service::print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
417
+
418
+    }
419
+
420
+    public function get_uri( $object_id, $type = Object_Type_Enum::POST ) {
421
+        $content_service = Wordpress_Content_Service::get_instance();
422
+        $entity_id       = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
423
+        $dataset_uri     = Wordlift_Configuration_Service::get_instance()->get_dataset_uri();
424
+
425
+        if ( ! isset( $entity_id ) ||
426
+             ( ! empty( $dataset_uri ) && 0 !== strpos( $entity_id, $dataset_uri ) ) ) {
427
+            $rel_uri = Entity_Uri_Generator::create_uri( $type, $object_id );
428
+            try {
429
+                $content_service->set_entity_id( new Wordpress_Content_Id( $object_id, $type ), $rel_uri );
430
+                $entity_id = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
431
+            } catch ( Exception $e ) {
432
+                return null;
433
+            }
434
+        }
435
+
436
+        return $entity_id;
437
+    }
438
+
439
+    /**
440
+     * Get the alternative label input HTML code.
441
+     *
442
+     * @param string $value The input value.
443
+     *
444
+     * @return string The input HTML code.
445
+     * @since 3.2.0
446
+     */
447
+    private function get_alternative_label_input( $value = '' ) {
448
+
449
+        return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), esc_html__( 'Delete', 'wordlift' ) );
450
+    }
451
+
452
+    /**
453
+     * Get the number of entity posts published in this blog.
454
+     *
455
+     * @return int The number of published entity posts.
456
+     * @since 3.6.0
457
+     */
458
+    public function count() {
459
+        global $wpdb;
460
+
461
+        // Try to get the count from the transient.
462
+        $count = get_transient( '_wl_entity_service__count' );
463
+        if ( false !== $count ) {
464
+            return $count;
465
+        }
466
+
467
+        // Query the count.
468
+        $count = $wpdb->get_var(
469
+            $wpdb->prepare(
470
+                'SELECT COUNT( DISTINCT( tr.object_id ) )'
471
+                . " FROM {$wpdb->term_relationships} tr"
472
+                . " INNER JOIN {$wpdb->term_taxonomy} tt"
473
+                . '  ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id'
474
+                . " INNER JOIN {$wpdb->terms} t"
475
+                . '  ON t.term_id = tt.term_id AND t.name != %s',
476
+                Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
477
+                'article'
478
+            )
479
+        );
480
+
481
+        // Store the count in cache.
482
+        set_transient( '_wl_entity_service__count', $count, 900 );
483
+
484
+        return $count;
485
+    }
486
+
487
+    /**
488
+     * Add the entity filtering criterias to the arguments for a `get_posts`
489
+     * call.
490
+     *
491
+     * @param array $args The arguments for a `get_posts` call.
492
+     *
493
+     * @return array The arguments for a `get_posts` call.
494
+     * @since 3.15.0
495
+     */
496
+    public static function add_criterias( $args ) {
497
+
498
+        // Build an optimal tax-query.
499
+        $tax_query = array(
500
+            'relation' => 'AND',
501
+            array(
502
+                'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
503
+                'operator' => 'EXISTS',
504
+            ),
505
+            array(
506
+                'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
507
+                'field'    => 'slug',
508
+                'terms'    => 'article',
509
+                'operator' => 'NOT IN',
510
+            ),
511
+        );
512
+
513
+        return $args + array(
514
+            'post_type' => self::valid_entity_post_types(),
515
+            /*
516 516
 			 * Ensure compatibility with Polylang.
517 517
 			 *
518 518
 			 * @see https://github.com/insideout10/wordlift-plugin/issues/855.
@@ -520,101 +520,101 @@  discard block
 block discarded – undo
520 520
 			 *
521 521
 			 * @since 3.19.5
522 522
 			 */
523
-			'lang'      => '',
524
-			'tax_query' => $tax_query,
525
-		);
526
-	}
527
-
528
-	/**
529
-	 * Create a new entity.
530
-	 *
531
-	 * @param string $name The entity name.
532
-	 * @param string $type_uri The entity's type URI.
533
-	 * @param null   $logo The entity logo id (or NULL if none).
534
-	 * @param string $status The post status, by default 'publish'.
535
-	 *
536
-	 * @return int|WP_Error The entity post id or a {@link WP_Error} in case the `wp_insert_post` call fails.
537
-	 * @since 3.9.0
538
-	 */
539
-	public function create( $name, $type_uri, $logo = null, $status = 'publish' ) {
540
-
541
-		// Create an entity for the publisher.
542
-		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
543
-		$post_id = @wp_insert_post(
544
-			array(
545
-				'post_type'    => self::TYPE_NAME,
546
-				'post_title'   => $name,
547
-				'post_status'  => $status,
548
-				'post_content' => '',
549
-			)
550
-		);
551
-
552
-		// Return the error if any.
553
-		if ( is_wp_error( $post_id ) ) {
554
-			return $post_id;
555
-		}
556
-
557
-		// Set the entity logo.
558
-		if ( $logo && is_numeric( $logo ) ) {
559
-			set_post_thumbnail( $post_id, $logo );
560
-		}
561
-
562
-		// Set the entity type.
563
-		Wordlift_Entity_Type_Service::get_instance()->set( $post_id, $type_uri );
564
-
565
-		return $post_id;
566
-	}
567
-
568
-	/**
569
-	 * Get the entities related to the one with the specified id. By default only
570
-	 * published entities will be returned.
571
-	 *
572
-	 * @param int    $id The post id.
573
-	 * @param string $post_status The target post status (default = publish).
574
-	 *
575
-	 * @return array An array of post ids.
576
-	 * @since 3.10.0
577
-	 */
578
-	public function get_related_entities( $id, $post_status = 'publish' ) {
579
-
580
-		return $this->relation_service->get_objects( $id, 'ids', null, $post_status );
581
-	}
582
-
583
-	/**
584
-	 * Get the list of entities.
585
-	 *
586
-	 * @param array $params Custom parameters for WordPress' own {@link get_posts} function.
587
-	 *
588
-	 * @return array An array of entity posts.
589
-	 * @since 3.12.2
590
-	 */
591
-	public function get( $params = array() ) {
592
-
593
-		// Set the defaults.
594
-		$defaults = array( 'post_type' => 'entity' );
595
-
596
-		// Merge the defaults with the provided parameters.
597
-		$args = wp_parse_args( $params, $defaults );
598
-
599
-		// Call the `get_posts` function.
600
-		return get_posts( $args );
601
-	}
602
-
603
-	/**
604
-	 * The list of post type names which can be used for entities
605
-	 *
606
-	 * Criteria is that the post type is public. The list of valid post types
607
-	 * can be overridden with a filter.
608
-	 *
609
-	 * @return array Array containing the names of the valid post types.
610
-	 * @since 3.15.0
611
-	 */
612
-	public static function valid_entity_post_types() {
613
-
614
-		// Ignore builtins in the call to avoid getting attachments.
615
-		$post_types = array( 'post', 'page', self::TYPE_NAME, 'product' );
616
-
617
-		return apply_filters( 'wl_valid_entity_post_types', $post_types );
618
-	}
523
+            'lang'      => '',
524
+            'tax_query' => $tax_query,
525
+        );
526
+    }
527
+
528
+    /**
529
+     * Create a new entity.
530
+     *
531
+     * @param string $name The entity name.
532
+     * @param string $type_uri The entity's type URI.
533
+     * @param null   $logo The entity logo id (or NULL if none).
534
+     * @param string $status The post status, by default 'publish'.
535
+     *
536
+     * @return int|WP_Error The entity post id or a {@link WP_Error} in case the `wp_insert_post` call fails.
537
+     * @since 3.9.0
538
+     */
539
+    public function create( $name, $type_uri, $logo = null, $status = 'publish' ) {
540
+
541
+        // Create an entity for the publisher.
542
+        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
543
+        $post_id = @wp_insert_post(
544
+            array(
545
+                'post_type'    => self::TYPE_NAME,
546
+                'post_title'   => $name,
547
+                'post_status'  => $status,
548
+                'post_content' => '',
549
+            )
550
+        );
551
+
552
+        // Return the error if any.
553
+        if ( is_wp_error( $post_id ) ) {
554
+            return $post_id;
555
+        }
556
+
557
+        // Set the entity logo.
558
+        if ( $logo && is_numeric( $logo ) ) {
559
+            set_post_thumbnail( $post_id, $logo );
560
+        }
561
+
562
+        // Set the entity type.
563
+        Wordlift_Entity_Type_Service::get_instance()->set( $post_id, $type_uri );
564
+
565
+        return $post_id;
566
+    }
567
+
568
+    /**
569
+     * Get the entities related to the one with the specified id. By default only
570
+     * published entities will be returned.
571
+     *
572
+     * @param int    $id The post id.
573
+     * @param string $post_status The target post status (default = publish).
574
+     *
575
+     * @return array An array of post ids.
576
+     * @since 3.10.0
577
+     */
578
+    public function get_related_entities( $id, $post_status = 'publish' ) {
579
+
580
+        return $this->relation_service->get_objects( $id, 'ids', null, $post_status );
581
+    }
582
+
583
+    /**
584
+     * Get the list of entities.
585
+     *
586
+     * @param array $params Custom parameters for WordPress' own {@link get_posts} function.
587
+     *
588
+     * @return array An array of entity posts.
589
+     * @since 3.12.2
590
+     */
591
+    public function get( $params = array() ) {
592
+
593
+        // Set the defaults.
594
+        $defaults = array( 'post_type' => 'entity' );
595
+
596
+        // Merge the defaults with the provided parameters.
597
+        $args = wp_parse_args( $params, $defaults );
598
+
599
+        // Call the `get_posts` function.
600
+        return get_posts( $args );
601
+    }
602
+
603
+    /**
604
+     * The list of post type names which can be used for entities
605
+     *
606
+     * Criteria is that the post type is public. The list of valid post types
607
+     * can be overridden with a filter.
608
+     *
609
+     * @return array Array containing the names of the valid post types.
610
+     * @since 3.15.0
611
+     */
612
+    public static function valid_entity_post_types() {
613
+
614
+        // Ignore builtins in the call to avoid getting attachments.
615
+        $post_types = array( 'post', 'page', self::TYPE_NAME, 'product' );
616
+
617
+        return apply_filters( 'wl_valid_entity_post_types', $post_types );
618
+    }
619 619
 
620 620
 }
Please login to merge, or discard this patch.
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * @since 3.2.0
82 82
 	 */
83 83
 	protected function __construct() {
84
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' );
84
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Entity_Service');
85 85
 
86 86
 		$this->entity_uri_service = Wordlift_Entity_Uri_Service::get_instance();
87 87
 		$this->relation_service   = Wordlift_Relation_Service::get_instance();
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	public static function get_instance() {
107 107
 
108
-		if ( ! isset( self::$instance ) ) {
108
+		if ( ! isset(self::$instance)) {
109 109
 			self::$instance = new self();
110 110
 		}
111 111
 
@@ -121,22 +121,22 @@  discard block
 block discarded – undo
121 121
 	 * @return bool Return true if the post is an entity otherwise false.
122 122
 	 * @since 3.1.0
123 123
 	 */
124
-	public function is_entity( $post_id ) {
124
+	public function is_entity($post_id) {
125 125
 
126 126
 		// Improve performance by giving for granted that a product is an entity.
127
-		if ( 'product' === get_post_type( $post_id ) ) {
127
+		if ('product' === get_post_type($post_id)) {
128 128
 			return true;
129 129
 		}
130 130
 
131
-		$terms = wp_get_object_terms( $post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
131
+		$terms = wp_get_object_terms($post_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
132 132
 
133
-		if ( is_wp_error( $terms ) ) {
134
-			$this->log->error( "Cannot get the terms for post $post_id: " . $terms->get_error_message() );
133
+		if (is_wp_error($terms)) {
134
+			$this->log->error("Cannot get the terms for post $post_id: ".$terms->get_error_message());
135 135
 
136 136
 			return false;
137 137
 		}
138 138
 
139
-		if ( empty( $terms ) ) {
139
+		if (empty($terms)) {
140 140
 			return false;
141 141
 		}
142 142
 
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 		 *
148 148
 		 * @see https://github.com/insideout10/wordlift-plugin/issues/835
149 149
 		 */
150
-		foreach ( $terms as $term ) {
151
-			if ( 1 !== preg_match( '~(^|-)article$~', $term->slug ) ) {
150
+		foreach ($terms as $term) {
151
+			if (1 !== preg_match('~(^|-)article$~', $term->slug)) {
152 152
 				return true;
153 153
 			}
154 154
 		}
@@ -167,20 +167,20 @@  discard block
 block discarded – undo
167 167
 	 * @return string Returns a classification scope (e.g. 'what').
168 168
 	 * @since 3.5.0
169 169
 	 */
170
-	public function get_classification_scope_for( $post_id, $default = WL_WHAT_RELATION ) {
170
+	public function get_classification_scope_for($post_id, $default = WL_WHAT_RELATION) {
171 171
 
172
-		if ( false === $this->is_entity( $post_id ) ) {
172
+		if (false === $this->is_entity($post_id)) {
173 173
 			return $default;
174 174
 		}
175 175
 
176 176
 		// Retrieve the entity type
177
-		$entity_type_arr = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
178
-		$entity_type     = str_replace( 'wl-', '', $entity_type_arr['css_class'] );
177
+		$entity_type_arr = Wordlift_Entity_Type_Service::get_instance()->get($post_id);
178
+		$entity_type     = str_replace('wl-', '', $entity_type_arr['css_class']);
179 179
 		// Retrieve classification boxes configuration
180 180
 		// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
181
-		$classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES );
182
-		foreach ( $classification_boxes as $cb ) {
183
-			if ( in_array( $entity_type, $cb['registeredTypes'], true ) ) {
181
+		$classification_boxes = unserialize(WL_CORE_POST_CLASSIFICATION_BOXES);
182
+		foreach ($classification_boxes as $cb) {
183
+			if (in_array($entity_type, $cb['registeredTypes'], true)) {
184 184
 				return $cb['id'];
185 185
 			}
186 186
 		}
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
 	 *
196 196
 	 * @return bool|null Null if it's not an entity, otherwise true if it's used.
197 197
 	 */
198
-	public function is_used( $post_id ) {
198
+	public function is_used($post_id) {
199 199
 
200
-		if ( false === $this->is_entity( $post_id ) ) {
200
+		if (false === $this->is_entity($post_id)) {
201 201
 			return null;
202 202
 		}
203 203
 		// Retrieve the post
204
-		$entity = get_post( $post_id );
204
+		$entity = get_post($post_id);
205 205
 
206 206
 		global $wpdb;
207 207
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 			)
214 214
 		);
215 215
 		// If there is at least one relation instance for the current entity, then it's used
216
-		if ( 0 < $relation_instances ) {
216
+		if (0 < $relation_instances) {
217 217
 			return true;
218 218
 		}
219 219
 
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
 			$wpdb->prepare(
223 223
 				"SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s",
224 224
 				$entity->ID,
225
-				wl_get_entity_uri( $entity->ID )
225
+				wl_get_entity_uri($entity->ID)
226 226
 			)
227 227
 		);
228 228
 
229 229
 		// If there is at least one meta that refers the current entity uri, then current entity is used
230
-		if ( 0 < $meta_instances ) {
230
+		if (0 < $meta_instances) {
231 231
 			return true;
232 232
 		}
233 233
 
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
 	 * @since      3.16.3 deprecated in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );
247 247
 	 * @since      3.2.0
248 248
 	 */
249
-	public function get_entity_post_by_uri( $uri ) {
249
+	public function get_entity_post_by_uri($uri) {
250 250
 
251
-		return $this->entity_uri_service->get_entity( $uri );
251
+		return $this->entity_uri_service->get_entity($uri);
252 252
 	}
253 253
 
254 254
 	/**
@@ -264,19 +264,19 @@  discard block
 block discarded – undo
264 264
 	 * @param int     $post_id Post ID.
265 265
 	 * @param WP_Post $post Post object.
266 266
 	 */
267
-	public function save_post( $post_id, $post ) {
267
+	public function save_post($post_id, $post) {
268 268
 		// Avoid doing anything if post is autosave or a revision.
269
-		if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) ) {
269
+		if (wp_is_post_autosave($post) || wp_is_post_revision($post)) {
270 270
 			return;
271 271
 		}
272 272
 
273 273
 		// We expect a numeric value here.
274
-		if ( ! isset( $_REQUEST['post_ID'] ) || ! is_numeric( $_REQUEST['post_ID'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
274
+		if ( ! isset($_REQUEST['post_ID']) || ! is_numeric($_REQUEST['post_ID'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
275 275
 			return;
276 276
 		}
277 277
 
278 278
 		// Get the numeric post ID from the request.
279
-		$request_post_id = intval( $_REQUEST['post_ID'] ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
279
+		$request_post_id = intval($_REQUEST['post_ID']); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
280 280
 
281 281
 		// We're setting the alternative label that have been provided via the UI
282 282
 		// (in fact we're using $_REQUEST), while save_post may be also called
@@ -284,16 +284,16 @@  discard block
 block discarded – undo
284 284
 		// the $post_id in the save_post call matches the post id set in the request.
285 285
 		//
286 286
 		// If this is not the current post being saved or if it's not an entity, return.
287
-		if ( $request_post_id !== $post_id || ! $this->is_entity( $post_id ) ) {
287
+		if ($request_post_id !== $post_id || ! $this->is_entity($post_id)) {
288 288
 			return;
289 289
 		}
290 290
 
291
-		if ( isset( $_REQUEST['wl_alternative_label'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
292
-			$data = filter_var_array( $_REQUEST, array( 'wl_alternative_label' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
291
+		if (isset($_REQUEST['wl_alternative_label'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
292
+			$data = filter_var_array($_REQUEST, array('wl_alternative_label' => array('flags' => FILTER_REQUIRE_ARRAY))); //phpcs:ignore WordPress.Security.NonceVerification.Recommended
293 293
 			// Get the alt labels from the request (or empty array).
294
-			$alt_labels = isset( $data['wl_alternative_label'] ) ? $data['wl_alternative_label'] : array();
294
+			$alt_labels = isset($data['wl_alternative_label']) ? $data['wl_alternative_label'] : array();
295 295
 			// This is via classic editor, so set the alternative labels.
296
-			$this->set_alternative_labels( $post_id, $alt_labels );
296
+			$this->set_alternative_labels($post_id, $alt_labels);
297 297
 		}
298 298
 
299 299
 	}
@@ -306,48 +306,48 @@  discard block
 block discarded – undo
306 306
 	 *
307 307
 	 * @since 3.2.0
308 308
 	 */
309
-	public function set_alternative_labels( $post_id, $alt_labels ) {
309
+	public function set_alternative_labels($post_id, $alt_labels) {
310 310
 
311 311
 		// Bail out if post id is not numeric. We add this check as we found a WP install that was sending a WP_Error
312 312
 		// instead of post id.
313
-		if ( ! is_numeric( $post_id ) ) {
313
+		if ( ! is_numeric($post_id)) {
314 314
 			return;
315 315
 		}
316 316
 
317 317
 		// Force $alt_labels to be an array
318
-		if ( ! is_array( $alt_labels ) ) {
319
-			$alt_labels = array( $alt_labels );
318
+		if ( ! is_array($alt_labels)) {
319
+			$alt_labels = array($alt_labels);
320 320
 		}
321 321
 
322
-		$this->log->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . ' ]' );
322
+		$this->log->debug("Setting alternative labels [ post id :: $post_id ][ alt labels :: ".implode(',', $alt_labels).' ]');
323 323
 
324 324
 		// Delete all the existing alternate labels.
325
-		delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
325
+		delete_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY);
326 326
 
327 327
 		// Save only unique synonymns.
328
-		$alt_labels = array_unique( $alt_labels );
328
+		$alt_labels = array_unique($alt_labels);
329 329
 
330 330
 		// Set the alternative labels.
331
-		foreach ( $alt_labels as $alt_label ) {
331
+		foreach ($alt_labels as $alt_label) {
332 332
 
333 333
 			// Strip html code from synonym.
334
-			$alt_label = wp_strip_all_tags( $alt_label );
334
+			$alt_label = wp_strip_all_tags($alt_label);
335 335
 
336
-			if ( ! empty( $alt_label ) ) {
337
-				add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, (string) $alt_label );
336
+			if ( ! empty($alt_label)) {
337
+				add_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY, (string) $alt_label);
338 338
 			}
339 339
 		}
340 340
 
341 341
 	}
342 342
 
343
-	public function append_alternative_labels( $post_id, $labels_to_append ) {
343
+	public function append_alternative_labels($post_id, $labels_to_append) {
344 344
 
345
-		$merged_labels = $this->get_alternative_labels( $post_id );
345
+		$merged_labels = $this->get_alternative_labels($post_id);
346 346
 
347 347
 		// Append new synonyms to the end.
348
-		$merged_labels = array_merge( $merged_labels, $labels_to_append );
348
+		$merged_labels = array_merge($merged_labels, $labels_to_append);
349 349
 
350
-		$this->set_alternative_labels( $post_id, $merged_labels );
350
+		$this->set_alternative_labels($post_id, $merged_labels);
351 351
 
352 352
 	}
353 353
 
@@ -359,9 +359,9 @@  discard block
 block discarded – undo
359 359
 	 * @return mixed An array  of alternative labels.
360 360
 	 * @since 3.2.0
361 361
 	 */
362
-	public function get_alternative_labels( $post_id ) {
362
+	public function get_alternative_labels($post_id) {
363 363
 
364
-		return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY );
364
+		return get_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY);
365 365
 	}
366 366
 
367 367
 	/**
@@ -373,9 +373,9 @@  discard block
 block discarded – undo
373 373
 	 * @return array An array with the entity title and labels.
374 374
 	 * @since 3.12.0
375 375
 	 */
376
-	public function get_labels( $post_id, $object_type = Object_Type_Enum::POST ) {
377
-		if ( Object_Type_Enum::POST === $object_type ) {
378
-			return array_merge( (array) get_the_title( $post_id ), $this->get_alternative_labels( $post_id ) );
376
+	public function get_labels($post_id, $object_type = Object_Type_Enum::POST) {
377
+		if (Object_Type_Enum::POST === $object_type) {
378
+			return array_merge((array) get_the_title($post_id), $this->get_alternative_labels($post_id));
379 379
 		}
380 380
 
381 381
 		// Term Reference dont have synonyms yet.
@@ -389,46 +389,46 @@  discard block
 block discarded – undo
389 389
 	 *
390 390
 	 * @since 3.2.0
391 391
 	 */
392
-	public function edit_form_before_permalink( $post ) {
392
+	public function edit_form_before_permalink($post) {
393 393
 
394 394
 		// If it's not an entity, return.
395
-		if ( ! $this->is_entity( $post->ID ) ) {
395
+		if ( ! $this->is_entity($post->ID)) {
396 396
 			return;
397 397
 		}
398 398
 
399 399
 		// If disabled by filter, return.
400 400
 		// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
401
-		if ( ! apply_filters( 'wl_feature__enable__add-synonyms', true ) ) {
401
+		if ( ! apply_filters('wl_feature__enable__add-synonyms', true)) {
402 402
 			return;
403 403
 		}
404 404
 
405 405
 		// Print the input template.
406
-		Wordlift_UI_Service::print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() );
406
+		Wordlift_UI_Service::print_template('wl-tmpl-alternative-label-input', $this->get_alternative_label_input());
407 407
 
408 408
 		// Print all the currently set alternative labels.
409
-		foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) {
409
+		foreach ($this->get_alternative_labels($post->ID) as $alt_label) {
410 410
 
411
-			echo wp_kses( $this->get_alternative_label_input( $alt_label ), Wordlift_UI_Service::get_template_allowed_html() );
411
+			echo wp_kses($this->get_alternative_label_input($alt_label), Wordlift_UI_Service::get_template_allowed_html());
412 412
 
413 413
 		};
414 414
 
415 415
 		// Print the button.
416
-		Wordlift_UI_Service::print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) );
416
+		Wordlift_UI_Service::print_button('wl-add-alternative-labels-button', __('Add more titles', 'wordlift'));
417 417
 
418 418
 	}
419 419
 
420
-	public function get_uri( $object_id, $type = Object_Type_Enum::POST ) {
420
+	public function get_uri($object_id, $type = Object_Type_Enum::POST) {
421 421
 		$content_service = Wordpress_Content_Service::get_instance();
422
-		$entity_id       = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
422
+		$entity_id       = $content_service->get_entity_id(new Wordpress_Content_Id($object_id, $type));
423 423
 		$dataset_uri     = Wordlift_Configuration_Service::get_instance()->get_dataset_uri();
424 424
 
425
-		if ( ! isset( $entity_id ) ||
426
-			 ( ! empty( $dataset_uri ) && 0 !== strpos( $entity_id, $dataset_uri ) ) ) {
427
-			$rel_uri = Entity_Uri_Generator::create_uri( $type, $object_id );
425
+		if ( ! isset($entity_id) ||
426
+			 ( ! empty($dataset_uri) && 0 !== strpos($entity_id, $dataset_uri))) {
427
+			$rel_uri = Entity_Uri_Generator::create_uri($type, $object_id);
428 428
 			try {
429
-				$content_service->set_entity_id( new Wordpress_Content_Id( $object_id, $type ), $rel_uri );
430
-				$entity_id = $content_service->get_entity_id( new Wordpress_Content_Id( $object_id, $type ) );
431
-			} catch ( Exception $e ) {
429
+				$content_service->set_entity_id(new Wordpress_Content_Id($object_id, $type), $rel_uri);
430
+				$entity_id = $content_service->get_entity_id(new Wordpress_Content_Id($object_id, $type));
431
+			} catch (Exception $e) {
432 432
 				return null;
433 433
 			}
434 434
 		}
@@ -444,9 +444,9 @@  discard block
 block discarded – undo
444 444
 	 * @return string The input HTML code.
445 445
 	 * @since 3.2.0
446 446
 	 */
447
-	private function get_alternative_label_input( $value = '' ) {
447
+	private function get_alternative_label_input($value = '') {
448 448
 
449
-		return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), esc_html__( 'Delete', 'wordlift' ) );
449
+		return sprintf(self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr($value), esc_html__('Delete', 'wordlift'));
450 450
 	}
451 451
 
452 452
 	/**
@@ -459,8 +459,8 @@  discard block
 block discarded – undo
459 459
 		global $wpdb;
460 460
 
461 461
 		// Try to get the count from the transient.
462
-		$count = get_transient( '_wl_entity_service__count' );
463
-		if ( false !== $count ) {
462
+		$count = get_transient('_wl_entity_service__count');
463
+		if (false !== $count) {
464 464
 			return $count;
465 465
 		}
466 466
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 		);
480 480
 
481 481
 		// Store the count in cache.
482
-		set_transient( '_wl_entity_service__count', $count, 900 );
482
+		set_transient('_wl_entity_service__count', $count, 900);
483 483
 
484 484
 		return $count;
485 485
 	}
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 	 * @return array The arguments for a `get_posts` call.
494 494
 	 * @since 3.15.0
495 495
 	 */
496
-	public static function add_criterias( $args ) {
496
+	public static function add_criterias($args) {
497 497
 
498 498
 		// Build an optimal tax-query.
499 499
 		$tax_query = array(
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 	 * @return int|WP_Error The entity post id or a {@link WP_Error} in case the `wp_insert_post` call fails.
537 537
 	 * @since 3.9.0
538 538
 	 */
539
-	public function create( $name, $type_uri, $logo = null, $status = 'publish' ) {
539
+	public function create($name, $type_uri, $logo = null, $status = 'publish') {
540 540
 
541 541
 		// Create an entity for the publisher.
542 542
 		// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
@@ -550,17 +550,17 @@  discard block
 block discarded – undo
550 550
 		);
551 551
 
552 552
 		// Return the error if any.
553
-		if ( is_wp_error( $post_id ) ) {
553
+		if (is_wp_error($post_id)) {
554 554
 			return $post_id;
555 555
 		}
556 556
 
557 557
 		// Set the entity logo.
558
-		if ( $logo && is_numeric( $logo ) ) {
559
-			set_post_thumbnail( $post_id, $logo );
558
+		if ($logo && is_numeric($logo)) {
559
+			set_post_thumbnail($post_id, $logo);
560 560
 		}
561 561
 
562 562
 		// Set the entity type.
563
-		Wordlift_Entity_Type_Service::get_instance()->set( $post_id, $type_uri );
563
+		Wordlift_Entity_Type_Service::get_instance()->set($post_id, $type_uri);
564 564
 
565 565
 		return $post_id;
566 566
 	}
@@ -575,9 +575,9 @@  discard block
 block discarded – undo
575 575
 	 * @return array An array of post ids.
576 576
 	 * @since 3.10.0
577 577
 	 */
578
-	public function get_related_entities( $id, $post_status = 'publish' ) {
578
+	public function get_related_entities($id, $post_status = 'publish') {
579 579
 
580
-		return $this->relation_service->get_objects( $id, 'ids', null, $post_status );
580
+		return $this->relation_service->get_objects($id, 'ids', null, $post_status);
581 581
 	}
582 582
 
583 583
 	/**
@@ -588,16 +588,16 @@  discard block
 block discarded – undo
588 588
 	 * @return array An array of entity posts.
589 589
 	 * @since 3.12.2
590 590
 	 */
591
-	public function get( $params = array() ) {
591
+	public function get($params = array()) {
592 592
 
593 593
 		// Set the defaults.
594
-		$defaults = array( 'post_type' => 'entity' );
594
+		$defaults = array('post_type' => 'entity');
595 595
 
596 596
 		// Merge the defaults with the provided parameters.
597
-		$args = wp_parse_args( $params, $defaults );
597
+		$args = wp_parse_args($params, $defaults);
598 598
 
599 599
 		// Call the `get_posts` function.
600
-		return get_posts( $args );
600
+		return get_posts($args);
601 601
 	}
602 602
 
603 603
 	/**
@@ -612,9 +612,9 @@  discard block
 block discarded – undo
612 612
 	public static function valid_entity_post_types() {
613 613
 
614 614
 		// Ignore builtins in the call to avoid getting attachments.
615
-		$post_types = array( 'post', 'page', self::TYPE_NAME, 'product' );
615
+		$post_types = array('post', 'page', self::TYPE_NAME, 'product');
616 616
 
617
-		return apply_filters( 'wl_valid_entity_post_types', $post_types );
617
+		return apply_filters('wl_valid_entity_post_types', $post_types);
618 618
 	}
619 619
 
620 620
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-ui-service.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -7,110 +7,110 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_UI_Service {
9 9
 
10
-	/**
11
-	 * The button element HTML code.
12
-	 *
13
-	 * @since 3.2.0
14
-	 */
15
-	const BUTTON_HTML = '<a id="%s" class="button wl-button">%s</a>';
10
+    /**
11
+     * The button element HTML code.
12
+     *
13
+     * @since 3.2.0
14
+     */
15
+    const BUTTON_HTML = '<a id="%s" class="button wl-button">%s</a>';
16 16
 
17
-	/**
18
-	 * The template HTML code.
19
-	 *
20
-	 * @since 3.2.0
21
-	 */
22
-	const TEMPLATE_HTML = '<script id="%s" type="text/template">%s</script>';
17
+    /**
18
+     * The template HTML code.
19
+     *
20
+     * @since 3.2.0
21
+     */
22
+    const TEMPLATE_HTML = '<script id="%s" type="text/template">%s</script>';
23 23
 
24
-	/**
25
-	 * Get the button HTML.
26
-	 *
27
-	 * @param string $element_id The button element id.
28
-	 * @param string $label The button (translated) label.
29
-	 *
30
-	 * @return string The button HTML code.
31
-	 * @since 3.2.0
32
-	 */
33
-	public static function get_button_html( $element_id, $label ) {
24
+    /**
25
+     * Get the button HTML.
26
+     *
27
+     * @param string $element_id The button element id.
28
+     * @param string $label The button (translated) label.
29
+     *
30
+     * @return string The button HTML code.
31
+     * @since 3.2.0
32
+     */
33
+    public static function get_button_html( $element_id, $label ) {
34 34
 
35
-		return sprintf( self::BUTTON_HTML, $element_id, esc_html( $label ) );
36
-	}
35
+        return sprintf( self::BUTTON_HTML, $element_id, esc_html( $label ) );
36
+    }
37 37
 
38
-	/**
39
-	 * Echo the button HTML.
40
-	 *
41
-	 * @param string $element_id The button element id.
42
-	 * @param string $label The button (translated) label.
43
-	 *
44
-	 * @since 3.2.0
45
-	 */
46
-	public static function print_button( $element_id, $label ) {
38
+    /**
39
+     * Echo the button HTML.
40
+     *
41
+     * @param string $element_id The button element id.
42
+     * @param string $label The button (translated) label.
43
+     *
44
+     * @since 3.2.0
45
+     */
46
+    public static function print_button( $element_id, $label ) {
47 47
 
48
-		echo wp_kses(
49
-			self::get_button_html( $element_id, $label ),
50
-			array(
51
-				'a' => array(
52
-					'id'    => array(),
53
-					'class' => array(),
54
-				),
55
-			)
56
-		);
48
+        echo wp_kses(
49
+            self::get_button_html( $element_id, $label ),
50
+            array(
51
+                'a' => array(
52
+                    'id'    => array(),
53
+                    'class' => array(),
54
+                ),
55
+            )
56
+        );
57 57
 
58
-	}
58
+    }
59 59
 
60
-	/**
61
-	 * Get the HTML code for a template tag.
62
-	 *
63
-	 * @param string $element_id The element id.
64
-	 * @param string $body The element content.
65
-	 *
66
-	 * @return string The HTML code.
67
-	 * @since 3.2.0
68
-	 */
69
-	public static function get_template_html( $element_id, $body ) {
60
+    /**
61
+     * Get the HTML code for a template tag.
62
+     *
63
+     * @param string $element_id The element id.
64
+     * @param string $body The element content.
65
+     *
66
+     * @return string The HTML code.
67
+     * @since 3.2.0
68
+     */
69
+    public static function get_template_html( $element_id, $body ) {
70 70
 
71
-		return sprintf( self::TEMPLATE_HTML, $element_id, $body );
72
-	}
71
+        return sprintf( self::TEMPLATE_HTML, $element_id, $body );
72
+    }
73 73
 
74
-	/**
75
-	 * Echo the HTML code for a template tag.
76
-	 *
77
-	 * @param string $element_id The element id.
78
-	 * @param string $body The element content.
79
-	 *
80
-	 * @since 3.2.0
81
-	 */
82
-	public static function print_template( $element_id, $body ) {
74
+    /**
75
+     * Echo the HTML code for a template tag.
76
+     *
77
+     * @param string $element_id The element id.
78
+     * @param string $body The element content.
79
+     *
80
+     * @since 3.2.0
81
+     */
82
+    public static function print_template( $element_id, $body ) {
83 83
 
84
-		echo wp_kses(
85
-			self::get_template_html( $element_id, $body ),
86
-			self::get_template_allowed_html()
87
-		);
88
-	}
84
+        echo wp_kses(
85
+            self::get_template_html( $element_id, $body ),
86
+            self::get_template_allowed_html()
87
+        );
88
+    }
89 89
 
90
-	/**
91
-	 * @return array[]
92
-	 */
93
-	public static function get_template_allowed_html() {
94
-		return array(
95
-			'div'    => array( 'class' => array() ),
96
-			'label'  => array(
97
-				'class' => array(),
98
-				'id'    => array(),
99
-				'for'   => array(),
100
-			),
101
-			'input'  => array(
102
-				'name'  => array(),
103
-				'size'  => array(),
104
-				'value' => array(),
105
-				'id'    => array(),
106
-				'type'  => array(),
107
-			),
108
-			'button' => array( 'class' => array() ),
109
-			'script' => array(
110
-				'id'   => array(),
111
-				'type' => array(),
112
-			),
113
-		);
114
-	}
90
+    /**
91
+     * @return array[]
92
+     */
93
+    public static function get_template_allowed_html() {
94
+        return array(
95
+            'div'    => array( 'class' => array() ),
96
+            'label'  => array(
97
+                'class' => array(),
98
+                'id'    => array(),
99
+                'for'   => array(),
100
+            ),
101
+            'input'  => array(
102
+                'name'  => array(),
103
+                'size'  => array(),
104
+                'value' => array(),
105
+                'id'    => array(),
106
+                'type'  => array(),
107
+            ),
108
+            'button' => array( 'class' => array() ),
109
+            'script' => array(
110
+                'id'   => array(),
111
+                'type' => array(),
112
+            ),
113
+        );
114
+    }
115 115
 
116 116
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 	 * @return string The button HTML code.
31 31
 	 * @since 3.2.0
32 32
 	 */
33
-	public static function get_button_html( $element_id, $label ) {
33
+	public static function get_button_html($element_id, $label) {
34 34
 
35
-		return sprintf( self::BUTTON_HTML, $element_id, esc_html( $label ) );
35
+		return sprintf(self::BUTTON_HTML, $element_id, esc_html($label));
36 36
 	}
37 37
 
38 38
 	/**
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
 	 *
44 44
 	 * @since 3.2.0
45 45
 	 */
46
-	public static function print_button( $element_id, $label ) {
46
+	public static function print_button($element_id, $label) {
47 47
 
48 48
 		echo wp_kses(
49
-			self::get_button_html( $element_id, $label ),
49
+			self::get_button_html($element_id, $label),
50 50
 			array(
51 51
 				'a' => array(
52 52
 					'id'    => array(),
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 	 * @return string The HTML code.
67 67
 	 * @since 3.2.0
68 68
 	 */
69
-	public static function get_template_html( $element_id, $body ) {
69
+	public static function get_template_html($element_id, $body) {
70 70
 
71
-		return sprintf( self::TEMPLATE_HTML, $element_id, $body );
71
+		return sprintf(self::TEMPLATE_HTML, $element_id, $body);
72 72
 	}
73 73
 
74 74
 	/**
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @since 3.2.0
81 81
 	 */
82
-	public static function print_template( $element_id, $body ) {
82
+	public static function print_template($element_id, $body) {
83 83
 
84 84
 		echo wp_kses(
85
-			self::get_template_html( $element_id, $body ),
85
+			self::get_template_html($element_id, $body),
86 86
 			self::get_template_allowed_html()
87 87
 		);
88 88
 	}
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 */
93 93
 	public static function get_template_allowed_html() {
94 94
 		return array(
95
-			'div'    => array( 'class' => array() ),
95
+			'div'    => array('class' => array()),
96 96
 			'label'  => array(
97 97
 				'class' => array(),
98 98
 				'id'    => array(),
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 				'id'    => array(),
106 106
 				'type'  => array(),
107 107
 			),
108
-			'button' => array( 'class' => array() ),
108
+			'button' => array('class' => array()),
109 109
 			'script' => array(
110 110
 				'id'   => array(),
111 111
 				'type' => array(),
Please login to merge, or discard this patch.