Completed
Pull Request — develop (#1175)
by Naveen
02:40
created

wordlift.php ➔ run_wordlift()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 67
rs 8.72
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * The plugin bootstrap file
4
 *
5
 * This file is read by WordPress to generate the plugin information in the plugin
6
 * admin area. This file also includes all of the dependencies used by the plugin,
7
 * registers the activation and deactivation functions, and defines a function
8
 * that starts the plugin.
9
 *
10
 * @link              https://wordlift.io
11
 * @since             1.0.0
12
 * @package           Wordlift
13
 *
14
 * @wordpress-plugin
15
 * Plugin Name:       WordLift
16
 * Plugin URI:        https://wordlift.io
17
 * Description:       WordLift brings the power of AI to organize content, attract new readers and get their attention. To activate the plugin <a href="https://wordlift.io/">visit our website</a>.
18
 * Version:           3.27.5
19
 * Author:            WordLift, Insideout10
20
 * Author URI:        https://wordlift.io
21
 * License:           GPL-2.0+
22
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
23
 * Text Domain:       wordlift
24
 * Domain Path:       /languages
25
 */
26
27
use Wordlift\Api\Default_Api_Service;
28
use Wordlift\Api\User_Agent;
29
use Wordlift\Cache\Ttl_Cache;
30
use Wordlift\Cache\Ttl_Cache_Cleaner;
31
use Wordlift\Images_Licenses\Admin\Image_License_Page;
32
use Wordlift\Images_Licenses\Cached_Image_License_Service;
33
use Wordlift\Images_Licenses\Image_License_Cleanup_Service;
34
use Wordlift\Images_Licenses\Image_License_Factory;
35
use Wordlift\Images_Licenses\Image_License_Notifier;
36
use Wordlift\Images_Licenses\Image_License_Scheduler;
37
use Wordlift\Images_Licenses\Image_License_Service;
38
use Wordlift\Images_Licenses\Tasks\Add_License_Caption_Or_Remove_Page;
39
use Wordlift\Images_Licenses\Tasks\Add_License_Caption_Or_Remove_Task;
40
use Wordlift\Images_Licenses\Tasks\Reload_Data_Page;
41
use Wordlift\Images_Licenses\Tasks\Reload_Data_Task;
42
use Wordlift\Images_Licenses\Tasks\Remove_All_Images_Page;
43
use Wordlift\Images_Licenses\Tasks\Remove_All_Images_Task;
44
use Wordlift\Post\Post_Adapter;
45
use Wordlift\Tasks\Task_Ajax_Adapter;
46
use Wordlift\Tasks\Task_Ajax_Adapters_Registry;
47
48
// If this file is called directly, abort.
49
if ( ! defined( 'WPINC' ) ) {
50
	die;
51
}
52
53
// Include WordLift constants.
54
require_once( 'wordlift_constants.php' );
55
56
// Load modules.
57
require_once( 'modules/core/wordlift_core.php' );
58
59
/**
60
 * Log to the debug.log file.
61
 *
62
 * @param string|mixed $log The log data.
63
 *
64
 * @since      3.0.0
65
 *
66
 * @deprecated use Wordlift_Log_Service::get_instance()->info( $log );
67
 *
68
 */
69
function wl_write_log( $log ) {
70
71
	Wordlift_Log_Service::get_instance()->debug( $log );
72
73
}
74
75
/**
76
 * Hide the WordLift Key from the provided text.
77
 *
78
 * @param string $text A text that may potentially contain a WL key.
79
 *
80
 * @return string A text with the key hidden.
81
 * @deprecated
82
 *
83
 * @since 3.0.0
84
 *
85
 */
86
function wl_write_log_hide_key( $text ) {
87
88
	return str_ireplace( wl_configuration_get_key(), '<hidden>', $text );
0 ignored issues
show
Deprecated Code introduced by
The function wl_configuration_get_key() has been deprecated with message: use Wordlift_Configuration_Service::get_instance()->get_key()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
89
}
90
91
/**
92
 * Enable microdata schema.org tagging.
93
 * see http://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
94
 */
95
function wordlift_allowed_post_tags() {
96
	global $allowedposttags;
97
98
	$tags           = array( 'span' );
99
	$new_attributes = array(
100
		'itemscope' => array(),
101
		'itemtype'  => array(),
102
		'itemprop'  => array(),
103
		'itemid'    => array(),
104
	);
105
106
	foreach ( $tags as $tag ) {
107
		if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) ) {
108
			$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
109
		}
110
	}
111
}
112
113
// add allowed post tags.
114
add_action( 'init', 'wordlift_allowed_post_tags' );
115
116
/**
117
 * Register additional scripts for the admin UI.
118
 */
119
function wordlift_admin_enqueue_scripts() {
120
121
	// Added for compatibility with WordPress 3.9 (see http://make.wordpress.org/core/2014/04/16/jquery-ui-and-wpdialogs-in-wordpress-3-9/)
122
	wp_enqueue_script( 'wpdialogs' );
123
	wp_enqueue_style( 'wp-jquery-ui-dialog' );
124
125
	wp_enqueue_style( 'wordlift-reloaded', plugin_dir_url( __FILE__ ) . 'css/wordlift-reloaded.min.css' );
126
127
	wp_enqueue_script( 'jquery-ui-autocomplete' );
128
129
	// Disable auto-save for custom entity posts only
130
	if ( Wordlift_Entity_Service::TYPE_NAME === get_post_type() ) {
131
		wp_dequeue_script( 'autosave' );
132
	}
133
134
}
135
136
add_action( 'admin_enqueue_scripts', 'wordlift_admin_enqueue_scripts' );
137
138
/**
139
 * Hooked to *wp_kses_allowed_html* filter, adds microdata attributes.
140
 *
141
 * @param array $allowedtags The array with the currently configured elements and attributes.
142
 * @param string $context The context.
143
 *
144
 * @return array An array which contains allowed microdata attributes.
145
 */
146
function wordlift_allowed_html( $allowedtags, $context ) {
147
148
	if ( 'post' !== $context ) {
149
		return $allowedtags;
150
	}
151
152
	return array_merge_recursive( $allowedtags, array(
153
		'span' => array(
154
			'itemscope' => true,
155
			'itemtype'  => true,
156
			'itemid'    => true,
157
			'itemprop'  => true,
158
		),
159
	) );
160
}
161
162
add_filter( 'wp_kses_allowed_html', 'wordlift_allowed_html', 10, 2 );
163
164
/**
165
 * Get the coordinates for the specified post ID.
166
 *
167
 * @param int $post_id The post ID.
168
 *
169
 * @return array|null An array of coordinates or null.
170
 */
171
function wl_get_coordinates( $post_id ) {
172
173
	$latitude  = wl_schema_get_value( $post_id, 'latitude' );
174
	$longitude = wl_schema_get_value( $post_id, 'longitude' );
175
176
	// DO NOT set latitude/longitude to 0/0 as default values. It's a specific
177
	// place on the globe:"The zero/zero point of this system is located in the
178
	// Gulf of Guinea about 625 km (390 mi) south of Tema, Ghana."
179
	return array(
180
		'latitude'  => isset( $latitude[0] ) && is_numeric( $latitude[0] ) ? $latitude[0] : '',
181
		'longitude' => isset( $longitude[0] ) && is_numeric( $longitude[0] ) ? $longitude[0] : '',
182
	);
183
}
184
185
/**
186
 * Get all the images bound to a post.
187
 *
188
 * @param int $post_id The post ID.
189
 *
190
 * @return array An array of image URLs.
191
 * @deprecated use Wordlift_Storage_Factory::get_instance()->post_images()->get( $post_id )
192
 *
193
 */
194
function wl_get_image_urls( $post_id ) {
195
196
	return Wordlift_Storage_Factory::get_instance()
197
	                               ->post_images()
198
	                               ->get( $post_id );
199
200
}
201
202
/**
203
 * Get an attachment with the specified parent post ID and source URL.
204
 *
205
 * @param int $parent_post_id The parent post ID.
206
 * @param string $source_url The source URL.
207
 *
208
 * @return WP_Post|null A post instance or null if not found.
209
 */
210
function wl_get_attachment_for_source_url( $parent_post_id, $source_url ) {
211
212
	// wl_write_log( "wl_get_attachment_for_source_url [ parent post id :: $parent_post_id ][ source url :: $source_url ]" );
213
214
	$posts = get_posts( array(
215
		'post_type'      => 'attachment',
216
		'posts_per_page' => 1,
217
		'post_status'    => 'any',
218
		'post_parent'    => $parent_post_id,
219
		'meta_key'       => 'wl_source_url',
220
		'meta_value'     => $source_url,
221
	) );
222
223
	// Return the found post.
224
	if ( 1 === count( $posts ) ) {
225
		return $posts[0];
226
	}
227
228
	// Return null.
229
	return null;
230
}
231
232
/**
233
 * Set the source URL.
234
 *
235
 * @param int $post_id The post ID.
236
 * @param string $source_url The source URL.
237
 */
238
function wl_set_source_url( $post_id, $source_url ) {
239
240
	delete_post_meta( $post_id, 'wl_source_url' );
241
	add_post_meta( $post_id, 'wl_source_url', $source_url );
242
}
243
244
/**
245
 * Sanitizes an URI path by replacing the non allowed characters with an underscore.
246
 *
247
 * @param string $path The path to sanitize.
248
 * @param string $char The replacement character (by default an underscore).
249
 *
250
 * @return string The sanitized path.
251
 * @uses       sanitize_title() to manage not ASCII chars
252
 * @deprecated use Wordlift_Uri_Service::get_instance()->sanitize_path();
253
 * @see        https://codex.wordpress.org/Function_Reference/sanitize_title
254
 *
255
 */
256
function wl_sanitize_uri_path( $path, $char = '_' ) {
257
258
	return Wordlift_Uri_Service::get_instance()->sanitize_path( $path, $char );
259
}
260
261
/**
262
 * Replaces the *itemid* attributes URIs with the WordLift URIs.
263
 *
264
 * @param string $content The post content.
265
 *
266
 * @return string The updated post content.
267
 */
268
function wl_replace_item_id_with_uri( $content ) {
269
270
	$log = Wordlift_Log_Service::get_logger( 'wl_replace_item_id_with_uri' );
271
	$log->trace( 'Replacing item IDs with URIs...' );
272
273
	// Strip slashes, see https://core.trac.wordpress.org/ticket/21767
274
	$content = stripslashes( $content );
275
276
	// If any match are found.
277
	$matches = array();
278
	if ( 0 < preg_match_all( '/ itemid="([^"]+)"/i', $content, $matches, PREG_SET_ORDER ) ) {
279
280
		foreach ( $matches as $match ) {
0 ignored issues
show
Bug introduced by
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
281
282
			// Get the item ID.
283
			$item_id = $match[1];
284
285
			// Get the post bound to that item ID (looking both in the 'official' URI and in the 'same-as' .
286
			$post = Wordlift_Entity_Service::get_instance()
0 ignored issues
show
Deprecated Code introduced by
The method Wordlift_Entity_Service::get_entity_post_by_uri() has been deprecated with message: in favor of Wordlift_Entity_Uri_Service->get_entity( $uri );

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
287
			                               ->get_entity_post_by_uri( $item_id );
288
289
			// If no entity is found, continue to the next one.
290
			if ( null === $post ) {
291
				continue;
292
			}
293
294
			// Get the URI for that post.
295
			$uri = wl_get_entity_uri( $post->ID );
0 ignored issues
show
Deprecated Code introduced by
The function wl_get_entity_uri() has been deprecated with message: use Wordlift_Entity_Service::get_instance()->get_uri( $post_id )

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
296
297
			// wl_write_log( "wl_replace_item_id_with_uri [ item id :: $item_id ][ uri :: $uri ]" );
298
299
			// If the item ID and the URI differ, replace the item ID with the URI saved in WordPress.
300
			if ( $item_id !== $uri ) {
301
				$uri_e   = esc_html( $uri );
302
				$content = str_replace( " itemid=\"$item_id\"", " itemid=\"$uri_e\"", $content );
303
			}
304
		}
305
	}
306
307
	// Reapply slashes.
308
	$content = addslashes( $content );
309
310
	return $content;
311
}
312
313
add_filter( 'content_save_pre', 'wl_replace_item_id_with_uri', 1, 1 );
314
315
require_once( 'wordlift_entity_functions.php' );
316
317
// add editor related methods.
318
require_once( 'wordlift_editor.php' );
319
320
// add the WordLift entity custom type.
321
require_once( 'wordlift_entity_type.php' );
322
323
// add callbacks on post save to notify data changes from wp to redlink triple store
324
require_once( 'wordlift_to_redlink_data_push_callbacks.php' );
325
326
require_once( 'modules/configuration/wordlift_configuration_settings.php' );
327
328
// Load modules
329
require_once( 'modules/analyzer/wordlift_analyzer.php' );
330
require_once( 'modules/linked_data/wordlift_linked_data.php' );
331
require_once( 'modules/prefixes/wordlift_prefixes.php' );
332
333
// Shortcodes
334
335
require_once( 'modules/geo_widget/wordlift_geo_widget.php' );
336
require_once( 'shortcodes/class-wordlift-shortcode-rest.php' );
337
require_once( 'shortcodes/wordlift_shortcode_chord.php' );
338
require_once( 'shortcodes/wordlift_shortcode_geomap.php' );
339
require_once( 'shortcodes/wordlift_shortcode_field.php' );
340
require_once( 'shortcodes/wordlift_shortcode_faceted_search.php' );
341
require_once( 'shortcodes/wordlift_shortcode_navigator.php' );
342
require_once( 'shortcodes/class-wordlift-products-navigator-shortcode-rest.php' );
343
344
require_once( 'widgets/wordlift_widget_geo.php' );
345
require_once( 'widgets/class-wordlift-chord-widget.php' );
346
require_once( 'widgets/wordlift_widget_timeline.php' );
347
348
require_once( 'wordlift_redlink.php' );
349
350
// Add admin functions.
351
// TODO: find a way to make 'admin' UI tests work.
352
//if ( is_admin() ) {
353
354
require_once( 'admin/wordlift_admin.php' );
355
require_once( 'admin/wordlift_admin_edit_post.php' );
356
require_once( 'admin/wordlift_admin_save_post.php' );
357
358
// add the entities meta box.
359
require_once( 'admin/wordlift_admin_meta_box_entities.php' );
360
361
// add the entity creation AJAX.
362
require_once( 'admin/wordlift_admin_ajax_related_posts.php' );
363
364
// Load the wl_chord TinyMCE button and configuration dialog.
365
require_once( 'admin/wordlift_admin_shortcodes.php' );
366
367
/**
368
 * The code that runs during plugin activation.
369
 * This action is documented in includes/class-wordlift-activator.php
370
 */
371
function activate_wordlift() {
372
373
	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
374
375
	$log->info( 'Activating WordLift...' );
376
377
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
378
	Wordlift_Activator::activate();
379
380
	/**
381
	 * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
382
	 *
383
	 * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
384
	 * @since 3.19.2
385
	 */
386
	Wordlift_Http_Api::activate();
387
388
	// Ensure the post type is registered before flushing the rewrite rules.
389
	Wordlift_Entity_Post_Type_Service::get_instance()->register();
390
	flush_rewrite_rules();
391
}
392
393
/**
394
 * The code that runs during plugin deactivation.
395
 * This action is documented in includes/class-wordlift-deactivator.php
396
 */
397
function deactivate_wordlift() {
398
399
	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
400
	Wordlift_Deactivator::deactivate();
401
	Wordlift_Http_Api::deactivate();
402
	Ttl_Cache_Cleaner::deactivate();
403
	flush_rewrite_rules();
404
405
}
406
407
register_activation_hook( __FILE__, 'activate_wordlift' );
408
register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
409
410
/**
411
 * The core plugin class that is used to define internationalization,
412
 * admin-specific hooks, and public-facing site hooks.
413
 */
414
require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
415
416
/**
417
 * Begins execution of the plugin.
418
 *
419
 * Since everything within the plugin is registered via hooks,
420
 * then kicking off the plugin from this point in the file does
421
 * not affect the page life cycle.
422
 *
423
 * @since    1.0.0
424
 */
425
function run_wordlift() {
426
	/**
427
	 * Filter: wl_feature__enable__widgets.
428
	 *
429
	 * @param bool whether the widgets needed to be registered, defaults to true.
430
	 *
431
	 * @return bool
432
	 * @since 3.27.6
433
	 */
434
	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
435
		add_action( 'widgets_init', 'wl_register_chord_widget' );
436
		add_filter( 'widget_text', 'do_shortcode' );
437
		add_action( 'widgets_init', 'wl_register_geo_widget' );
438
		add_action( 'widgets_init', 'wl_register_timeline_widget' );
439
		add_filter( 'widget_text', 'do_shortcode' );
440
	}
441
	/*
442
	 * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
443
	 *
444
	 * @since 3.21.2
445
	 */
446
	wordlift_plugin_autoload_register();
447
448
	$plugin = new Wordlift();
449
	$plugin->run();
450
451
	// Initialize the TTL Cache Cleaner.
452
	new Ttl_Cache_Cleaner();
453
454
	// Load the new Post Adapter.
455
	new Post_Adapter();
456
457
	// Licenses Images.
458
	$user_agent                   = User_Agent::get_user_agent();
459
	$wordlift_key                 = Wordlift_Configuration_Service::get_instance()->get_key();
460
	$api_service                  = new Default_Api_Service( 'https://api.wordlift.io', 60, $user_agent, $wordlift_key );
461
	$image_license_factory        = new Image_License_Factory();
462
	$image_license_service        = new Image_License_Service( $api_service, $image_license_factory );
463
	$image_license_cache          = new Ttl_Cache( 'image-license', 86400 * 30 ); // 30 days.
464
	$cached_image_license_service = new Cached_Image_License_Service( $image_license_service, $image_license_cache );
465
466
	$image_license_scheduler       = new Image_License_Scheduler( $image_license_service, $image_license_cache );
0 ignored issues
show
Unused Code introduced by
$image_license_scheduler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
467
	$image_license_cleanup_service = new Image_License_Cleanup_Service();
0 ignored issues
show
Unused Code introduced by
$image_license_cleanup_service is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
468
469
	// Get the cached data. If we have cached data, we load the notifier.
470
	$image_license_data = $image_license_cache->get( Cached_Image_License_Service::GET_NON_PUBLIC_DOMAIN_IMAGES );
471
	if ( null !== $image_license_data ) {
472
		$image_license_page = new Image_License_Page( $image_license_data, Wordlift::get_instance()->get_version() );
473
		new Image_License_Notifier( $image_license_data, $image_license_page );
474
	}
475
476
	$remove_all_images_task         = new Remove_All_Images_Task( $cached_image_license_service );
477
	$remove_all_images_task_adapter = new Task_Ajax_Adapter( $remove_all_images_task );
478
479
	$reload_data_task         = new Reload_Data_Task();
480
	$reload_data_task_adapter = new Task_Ajax_Adapter( $reload_data_task );
481
482
	$add_license_caption_or_remove_task         = new Add_License_Caption_Or_Remove_Task( $cached_image_license_service );
483
	$add_license_caption_or_remove_task_adapter = new Task_Ajax_Adapter( $add_license_caption_or_remove_task );
484
485
	$remove_all_images_task_page             = new Remove_All_Images_Page( new Task_Ajax_Adapters_Registry( $remove_all_images_task_adapter ), $plugin->get_version() );
0 ignored issues
show
Documentation introduced by
$remove_all_images_task_adapter is of type object<Wordlift\Tasks\Task_Ajax_Adapter>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$remove_all_images_task_page is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
486
	$reload_data_task_page                   = new Reload_Data_Page( new Task_Ajax_Adapters_Registry( $reload_data_task_adapter ), $plugin->get_version() );
0 ignored issues
show
Documentation introduced by
$reload_data_task_adapter is of type object<Wordlift\Tasks\Task_Ajax_Adapter>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$reload_data_task_page is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
487
	$add_license_caption_or_remove_task_page = new Add_License_Caption_Or_Remove_Page( new Task_Ajax_Adapters_Registry( $add_license_caption_or_remove_task_adapter ), $plugin->get_version() );
0 ignored issues
show
Documentation introduced by
$add_license_caption_or_remove_task_adapter is of type object<Wordlift\Tasks\Task_Ajax_Adapter>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$add_license_caption_or_remove_task_page is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
488
489
	new Wordlift_Products_Navigator_Shortcode_REST();
490
491
}
492
493
run_wordlift();
494
495
/**
496
 * Register our autoload routine.
497
 *
498
 * @throws Exception
499
 * @since 3.21.2
500
 */
501
function wordlift_plugin_autoload_register() {
502
503
	spl_autoload_register( function ( $class_name ) {
504
505
		// Bail out if these are not our classes.
506
		if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
507
			return false;
508
		}
509
510
		$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
511
512
		preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
513
514
		$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
515
		$file = 'class-' . $matches[2] . '.php';
516
517
		$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
518
519
		if ( ! file_exists( $full_path ) ) {
520
			echo( "Class $class_name not found at $full_path." );
521
522
			return false;
523
		}
524
525
		require_once $full_path;
526
527
		return true;
528
	} );
529
530
}
531
532
function wl_block_categories( $categories, $post ) {
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
533
	return array_merge(
534
		$categories,
535
		array(
536
			array(
537
				'slug'  => 'wordlift',
538
				'title' => __( 'WordLift', 'wordlift' ),
539
			),
540
		)
541
	);
542
}
543
544
add_filter( 'block_categories', 'wl_block_categories', 10, 2 );
545