Test Failed
Push — develop ( 266ee2...ce70fb )
by J.D.
05:51
created

wordpoints_extension_license_row()   F

Complexity

Conditions 30
Paths 504

Size

Total Lines 116
Code Lines 77

Duplication

Lines 22
Ratio 18.97 %

Importance

Changes 0
Metric Value
cc 30
eloc 77
nc 504
nop 2
dl 22
loc 116
rs 2.871
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
/**
4
 * Admin-side functions.
5
 *
6
 * @package WordPoints\Admin
7
 * @since 2.1.0
8
 */
9
10
/**
11
 * Register the admin apps when the main app is initialized.
12
 *
13
 * @since 2.1.0
14
 *
15
 * @WordPress\action wordpoints_init_app-apps
16
 *
17
 * @param WordPoints_App $app The main WordPoints app.
18
 */
19
function wordpoints_hooks_register_admin_apps( $app ) {
20
21
	$apps = $app->sub_apps();
22
23
	$apps->register( 'admin', 'WordPoints_App' );
24
25
	/** @var WordPoints_App $admin */
26
	$admin = $apps->get( 'admin' );
27
28
	$admin->sub_apps()->register( 'screen', 'WordPoints_Admin_Screens' );
29
}
30
31
/**
32
 * Get the slug of the main administration menu item for the plugin.
33
 *
34
 * The main item changes in multisite when the plugin is network activated. In the
35
 * network admin it is the usual 'wordpoints_configure', while everywhere else it is
36
 * 'wordpoints_extensions' instead.
37
 *
38
 * @since 1.2.0
39
 *
40
 * @return string The slug for the plugin's main top level admin menu item.
41
 */
42
function wordpoints_get_main_admin_menu() {
43
44
	$slug = 'wordpoints_configure';
45
46
	/*
47
	 * If the plugin is network active and we are displaying the regular admin menu,
48
	 * the modules screen should be the main one (the configure menu is only for the
49
	 * network admin when network active).
50
	 */
51
	if ( is_wordpoints_network_active() && 'admin_menu' === current_filter() ) {
0 ignored issues
show
Bug introduced by
The function current_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
	if ( is_wordpoints_network_active() && 'admin_menu' === /** @scrutinizer ignore-call */ current_filter() ) {
Loading history...
52
		$slug = 'wordpoints_extensions';
53
	}
54
55
	return $slug;
56
}
57
58
/**
59
 * Add admin screens to the administration menu.
60
 *
61
 * @since 1.0.0
62
 *
63
 * @WordPress\action admin_menu
64
 * @WordPress\action network_admin_menu
65
 */
66
function wordpoints_admin_menu() {
67
68
	$main_menu  = wordpoints_get_main_admin_menu();
69
	$wordpoints = __( 'WordPoints', 'wordpoints' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
	$wordpoints = /** @scrutinizer ignore-call */ __( 'WordPoints', 'wordpoints' );
Loading history...
70
71
	/*
72
	 * The settings page is always the main menu, except when the plugin is network
73
	 * active on multisite. Then it is only the main menu when in the network admin.
74
	 */
75
	if ( 'wordpoints_configure' === $main_menu ) {
76
77
		// Main page.
78
		add_menu_page(
0 ignored issues
show
Bug introduced by
The function add_menu_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
		/** @scrutinizer ignore-call */ 
79
  add_menu_page(
Loading history...
79
			$wordpoints
80
			, esc_html( $wordpoints )
0 ignored issues
show
Bug introduced by
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

80
			, /** @scrutinizer ignore-call */ esc_html( $wordpoints )
Loading history...
81
			, 'manage_options'
82
			, 'wordpoints_configure'
83
			, 'wordpoints_admin_screen_configure'
84
		);
85
86
		// Settings page.
87
		add_submenu_page(
0 ignored issues
show
Bug introduced by
The function add_submenu_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
		/** @scrutinizer ignore-call */ 
88
  add_submenu_page(
Loading history...
88
			'wordpoints_configure'
89
			, __( 'WordPoints — Settings', 'wordpoints' )
90
			, esc_html__( 'Settings', 'wordpoints' )
0 ignored issues
show
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
			, /** @scrutinizer ignore-call */ esc_html__( 'Settings', 'wordpoints' )
Loading history...
91
			, 'manage_options'
92
			, 'wordpoints_configure'
93
			, 'wordpoints_admin_screen_configure'
94
		);
95
96
	} else {
97
98
		/*
99
		 * When network-active and displaying the admin menu, we don't display the
100
		 * settings page, instead we display the modules page as the main page.
101
		 */
102
103
		// Main page.
104
		add_menu_page(
105
			$wordpoints
106
			, esc_html( $wordpoints )
107
			, 'activate_wordpoints_extensions'
108
			, 'wordpoints_extensions'
109
			, 'wordpoints_admin_screen_modules'
110
		);
111
112
	} // End if ( configure is main menu ) else.
113
114
	// Extensions page.
115
	add_submenu_page(
116
		$main_menu
117
		, __( 'WordPoints — Extensions', 'wordpoints' )
118
		, esc_html__( 'Extensions', 'wordpoints' )
119
		, 'activate_wordpoints_extensions'
120
		, 'wordpoints_extensions'
121
		, 'wordpoints_admin_screen_modules'
122
	);
123
124
	// Back-compat for extensions page when the slug was "modules".
125
	add_menu_page(
126
		__( 'WordPoints — Extensions', 'wordpoints' )
127
		, esc_html__( 'Extensions', 'wordpoints' )
128
		, 'activate_wordpoints_extensions'
129
		, 'wordpoints_modules'
130
		, 'wordpoints_admin_screen_modules'
131
	);
132
133
	// Hack so that this page isn't displayed in the menu.
134
	remove_menu_page( 'wordpoints_modules' );
0 ignored issues
show
Bug introduced by
The function remove_menu_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

134
	/** @scrutinizer ignore-call */ 
135
 remove_menu_page( 'wordpoints_modules' );
Loading history...
135
136
	// Extensions install page.
137
	add_submenu_page(
138
		'_wordpoints_extensions' // Fake menu.
139
		, __( 'WordPoints — Install Extensions', 'wordpoints' )
140
		, esc_html__( 'Install Extensions', 'wordpoints' )
141
		, 'install_wordpoints_extensions'
142
		, 'wordpoints_install_extensions'
143
		, 'wordpoints_admin_screen_install_modules'
144
	);
145
146
	// Back-compat for extensions install page when the slug was "modules".
147
	add_submenu_page(
148
		'_wordpoints_extensions' // Fake menu.
149
		, __( 'WordPoints — Install Extensions', 'wordpoints' )
150
		, esc_html__( 'Install Extensions', 'wordpoints' )
151
		, 'install_wordpoints_extensions'
152
		, 'wordpoints_install_modules'
153
		, 'wordpoints_admin_screen_install_modules'
154
	);
155
}
156
157
/**
158
 * Display the modules admin screen.
159
 *
160
 * @since 1.2.0
161
 */
162
function wordpoints_admin_screen_modules() {
163
164
	/**
165
	 * The modules administration screen.
166
	 *
167
	 * @since 1.1.0
168
	 */
169
	require WORDPOINTS_DIR . 'admin/screens/modules.php';
170
}
171
172
/**
173
 * Set up for the modules screen.
174
 *
175
 * @since 1.1.0
176
 *
177
 * @WordPress\action load-wordpoints_page_wordpoints_extensions
178
 * @WordPress\action load-toplevel_page_wordpoints_extensions
179
 */
180
function wordpoints_admin_screen_modules_load() {
181
182
	/**
183
	 * Set up for the modules page.
184
	 *
185
	 * @since 1.1.0
186
	 */
187
	require WORDPOINTS_DIR . 'admin/screens/modules-load.php';
188
}
189
190
/**
191
 * Display the install modules admin screen.
192
 *
193
 * @since 1.1.0
194
 */
195
function wordpoints_admin_screen_install_modules() {
196
197
	/**
198
	 * The WordPoints > Install Modules admin panel.
199
	 *
200
	 * @since 1.1.0
201
	 */
202
	require WORDPOINTS_DIR . 'admin/screens/module-install.php';
203
}
204
205
/**
206
 * Set up for the configure screen.
207
 *
208
 * @since 1.5.0 As wordpoints_admin_sreen_configure_load().
209
 * @since 2.3.0
210
 *
211
 * @WordPress\action load-toplevel_page_wordpoints_configure
212
 */
213
function wordpoints_admin_screen_configure_load() {
214
215
	/**
216
	 * Set up for the WordPoints » Settings administration screen.
217
	 *
218
	 * @since 1.5.0
219
	 */
220
	require WORDPOINTS_DIR . 'admin/screens/configure-settings-load.php';
221
}
222
223
/**
224
 * Set up for the configure screen.
225
 *
226
 * @since 1.5.0
227
 * @deprecated 2.3.0 Use wordpoints_admin_screen_configure_load() instead.
228
 */
229
function wordpoints_admin_sreen_configure_load() {
230
231
	_deprecated_function(
0 ignored issues
show
Bug introduced by
The function _deprecated_function was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

231
	/** @scrutinizer ignore-call */ 
232
 _deprecated_function(
Loading history...
232
		__FUNCTION__
233
		, '2.3.0'
234
		, 'wordpoints_admin_screen_configure_load()'
235
	);
236
237
	wordpoints_admin_screen_configure_load();
238
}
239
240
/**
241
 * Activate/deactivate components.
242
 *
243
 * This function handles activation and deactivation of components from the
244
 * WordPoints » Settings » Components administration screen.
245
 *
246
 * @since 1.0.1
247
 *
248
 * @WordPress\action load-toplevel_page_wordpoints_configure
249
 */
250
function wordpoints_admin_activate_components() {
251
252
	/**
253
	 * Set up for the WordPoints > Components administration screen.
254
	 *
255
	 * @since 1.1.0
256
	 */
257
	require WORDPOINTS_DIR . 'admin/screens/configure-components-load.php';
258
}
259
260
/**
261
 * Register admin scripts and styles.
262
 *
263
 * @since 2.1.0
264
 *
265
 * @WordPress\action admin_init
266
 */
267
function wordpoints_register_admin_scripts() {
268
269
	$assets_url        = WORDPOINTS_URL . '/admin/assets';
270
	$suffix            = SCRIPT_DEBUG ? '' : '.min';
0 ignored issues
show
Bug introduced by
The constant SCRIPT_DEBUG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
271
	$manifested_suffix = SCRIPT_DEBUG ? '.manifested' : '.min';
272
273
	// CSS
274
275
	wp_register_style(
0 ignored issues
show
Bug introduced by
The function wp_register_style was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

275
	/** @scrutinizer ignore-call */ 
276
 wp_register_style(
Loading history...
276
		'wordpoints-admin-extensions-list-table'
277
		, "{$assets_url}/css/extensions-list-table{$suffix}.css"
278
		, array()
279
		, WORDPOINTS_VERSION
280
	);
281
282
	wp_register_style(
283
		'wordpoints-admin-extension-updates-table'
284
		, "{$assets_url}/css/extension-updates-table{$suffix}.css"
285
		, array()
286
		, WORDPOINTS_VERSION
287
	);
288
289
	wp_register_style(
290
		'wordpoints-hooks-admin'
291
		, "{$assets_url}/css/hooks{$suffix}.css"
292
		, array( 'dashicons', 'wp-jquery-ui-dialog' )
293
		, WORDPOINTS_VERSION
294
	);
295
296
	$styles = wp_styles();
0 ignored issues
show
Bug introduced by
The function wp_styles was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

296
	$styles = /** @scrutinizer ignore-call */ wp_styles();
Loading history...
297
	$styles->add_data( 'wordpoints-admin-extensions-list-table', 'rtl', 'replace' );
298
	$styles->add_data( 'wordpoints-hooks-admin', 'rtl', 'replace' );
299
300
	if ( $suffix ) {
301
		$styles->add_data( 'wordpoints-admin-extensions-list-table', 'suffix', $suffix );
302
		$styles->add_data( 'wordpoints-hooks-admin', 'suffix', $suffix );
303
	}
304
305
	// JS
306
307
	wp_register_script(
0 ignored issues
show
Bug introduced by
The function wp_register_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

307
	/** @scrutinizer ignore-call */ 
308
 wp_register_script(
Loading history...
308
		'wordpoints-admin-dismiss-notice'
309
		, "{$assets_url}/js/dismiss-notice{$suffix}.js"
310
		, array( 'jquery', 'wp-util' )
311
		, WORDPOINTS_VERSION
312
	);
313
314
	wp_register_script(
315
		'wordpoints-hooks-models'
316
		, "{$assets_url}/js/hooks/models{$manifested_suffix}.js"
317
		, array( 'backbone', 'jquery-ui-dialog', 'wp-util' )
318
		, WORDPOINTS_VERSION
319
	);
320
321
	wp_register_script(
322
		'wordpoints-hooks-views'
323
		, "{$assets_url}/js/hooks/views{$manifested_suffix}.js"
324
		, array( 'wordpoints-hooks-models', 'wp-a11y' )
325
		, WORDPOINTS_VERSION
326
	);
327
328
	wp_localize_script(
0 ignored issues
show
Bug introduced by
The function wp_localize_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

328
	/** @scrutinizer ignore-call */ 
329
 wp_localize_script(
Loading history...
329
		'wordpoints-hooks-views'
330
		, 'WordPointsHooksAdminL10n'
331
		, array(
332
			'unexpectedError'   => __( 'There was an unexpected error. Try reloading the page.', 'wordpoints' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

332
			'unexpectedError'   => /** @scrutinizer ignore-call */ __( 'There was an unexpected error. Try reloading the page.', 'wordpoints' ),
Loading history...
333
			'changesSaved'      => __( 'Your changes have been saved.', 'wordpoints' ),
334
			// translators: Form field name.
335
			'emptyField'        => sprintf( __( '%s cannot be empty.', 'wordpoints' ), '{{ data.label }}' ),
336
			'confirmAboutTo'    => __( 'You are about to delete the following reaction:', 'wordpoints' ),
337
			'confirmDelete'     => __( 'Are you sure that you want to delete this reaction? This action cannot be undone.', 'wordpoints' ),
338
			'confirmTitle'      => __( 'Are you sure?', 'wordpoints' ),
339
			'deleteText'        => __( 'Delete', 'wordpoints' ),
340
			'cancelText'        => __( 'Cancel', 'wordpoints' ),
341
			'separator'         => is_rtl() ? ' « ' : ' » ',
0 ignored issues
show
Bug introduced by
The function is_rtl was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

341
			'separator'         => /** @scrutinizer ignore-call */ is_rtl() ? ' « ' : ' » ',
Loading history...
342
			'target_label'      => __( 'Target', 'wordpoints' ),
343
			// translators: Form field.
344
			'cannotBeChanged'   => __( '(cannot be changed)', 'wordpoints' ),
345
			'fieldsInvalid'     => __( 'Error: the values of some fields are invalid. Please correct these and then try again.', 'wordpoints' ),
346
			'discardedReaction' => __( 'Discarded reaction.', 'wordpoints' ),
347
			'discardedChanges'  => __( 'Discarded changes.', 'wordpoints' ),
348
			'saving'            => __( 'Saving&hellp;', 'wordpoints' ),
349
			'deleting'          => __( 'Deleting&hellp;', 'wordpoints' ),
350
			'reactionDeleted'   => __( 'Reaction deleted successfully.', 'wordpoints' ),
351
			'reactionSaved'     => __( 'Reaction saved successfully.', 'wordpoints' ),
352
		)
353
	);
354
355
	wp_script_add_data(
0 ignored issues
show
Bug introduced by
The function wp_script_add_data was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

355
	/** @scrutinizer ignore-call */ 
356
 wp_script_add_data(
Loading history...
356
		'wordpoints-hooks-views'
357
		, 'wordpoints-templates'
358
		, '
359
		<script type="text/template" id="tmpl-wordpoints-hook-reaction">
360
			<div class="view">
361
				<div class="title"></div>
362
				<button type="button" class="edit button-secondary">
363
					' . esc_html__( 'Edit', 'wordpoints' ) . '
0 ignored issues
show
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

363
					' . /** @scrutinizer ignore-call */ esc_html__( 'Edit', 'wordpoints' ) . '
Loading history...
364
				</button>
365
				<button type="button" class="close button-secondary">
366
					' . esc_html__( 'Close', 'wordpoints' ) . '
367
				</button>
368
			</div>
369
			<div class="form">
370
				<form>
371
					<div class="fields">
372
						<div class="settings"></div>
373
						<div class="target"></div>
374
					</div>
375
					<div class="messages">
376
						<div class="success"></div>
377
						<div class="err"></div>
378
					</div>
379
					<div class="actions">
380
						<div class="spinner-overlay">
381
							<span class="spinner is-active"></span>
382
						</div>
383
						<div class="action-buttons">
384
							<button type="button" class="save button-primary" disabled>
385
								' . esc_html__( 'Save', 'wordpoints' ) . '
386
							</button>
387
							<button type="button" class="cancel button-secondary">
388
								' . esc_html__( 'Cancel', 'wordpoints' ) . '
389
							</button>
390
							<button type="button" class="close button-secondary">
391
								' . esc_html__( 'Close', 'wordpoints' ) . '
392
							</button>
393
							<button type="button" class="delete button-secondary">
394
								' . esc_html__( 'Delete', 'wordpoints' ) . '
395
							</button>
396
						</div>
397
					</div>
398
				</form>
399
			</div>
400
		</script>
401
402
		<script type="text/template" id="tmpl-wordpoints-hook-arg-selector">
403
			<div class="arg-selector">
404
				<label>
405
					{{ data.label }}
406
					<select name="{{ data.name }}"></select>
407
				</label>
408
			</div>
409
		</script>
410
411
		<script type="text/template" id="tmpl-wordpoints-hook-arg-option">
412
			<option value="{{ data.slug }}">{{ data.title }}</option>
413
		</script>
414
415
		<script type="text/template" id="tmpl-wordpoints-hook-reaction-field">
416
			<p class="description description-thin">
417
				<label>
418
					{{ data.label }}
419
					<input type="{{ data.type }}" class="widefat" name="{{ data.name }}"
420
					       value="{{ data.value }}"/>
421
				</label>
422
			</p>
423
		</script>
424
425
		<script type="text/template" id="tmpl-wordpoints-hook-reaction-select-field">
426
			<p class="description description-thin">
427
				<label>
428
					{{ data.label }}
429
					<select name="{{ data.name }}" class="widefat"></select>
430
				</label>
431
			</p>
432
		</script>
433
434
		<script type="text/template" id="tmpl-wordpoints-hook-reaction-hidden-field">
435
			<input type="hidden" name="{{ data.name }}" value="{{ data.value }}"/>
436
		</script>
437
		'
438
	);
439
440
	wp_register_script(
441
		'wordpoints-hooks-extension-conditions'
442
		, "{$assets_url}/js/hooks/extensions/conditions{$manifested_suffix}.js"
443
		, array( 'wordpoints-hooks-views' )
444
		, WORDPOINTS_VERSION
445
	);
446
447
	wp_script_add_data(
448
		'wordpoints-hooks-extension-conditions'
449
		, 'wordpoints-templates'
450
		, '
451
			<script type="text/template" id="tmpl-wordpoints-hook-condition-groups">
452
				<div class="conditions-title section-title">
453
					<h4>' . esc_html__( 'Conditions', 'wordpoints' ) . '</h4>
454
					<button type="button" class="add-new button-secondary wordpoints-hooks-icon-button">
455
						<span class="screen-reader-text">' . esc_html__( 'Add New Condition', 'wordpoints' ) . '</span>
456
						<span class="dashicons dashicons-plus"></span>
457
					</button>
458
				</div>
459
				<div class="add-condition-form hidden">
460
					<div class="no-conditions hidden">
461
						' . esc_html__( 'No conditions available.', 'wordpoints' ) . '
462
					</div>
463
					<div class="condition-selectors">
464
						<div class="arg-selectors"></div>
465
						<div class="condition-selector"></div>
466
					</div>
467
					<button type="button" class="confirm-add-new button-secondary" disabled aria-label="' . esc_attr__( 'Add Condition', 'wordpoints' ) . '">
0 ignored issues
show
Bug introduced by
The function esc_attr__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

467
					<button type="button" class="confirm-add-new button-secondary" disabled aria-label="' . /** @scrutinizer ignore-call */ esc_attr__( 'Add Condition', 'wordpoints' ) . '">
Loading history...
468
						' . esc_html_x( 'Add', 'reaction condition', 'wordpoints' ) . '
0 ignored issues
show
Bug introduced by
The function esc_html_x was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

468
						' . /** @scrutinizer ignore-call */ esc_html_x( 'Add', 'reaction condition', 'wordpoints' ) . '
Loading history...
469
					</button>
470
					<button type="button" class="cancel-add-new button-secondary" aria-label="' . esc_attr__( 'Cancel Adding New Condition', 'wordpoints' ) . '">
471
						' . esc_html_x( 'Cancel', 'reaction condition', 'wordpoints' ) . '
472
					</button>
473
				</div>
474
				<div class="condition-groups section-content"></div>
475
			</script>
476
477
			<script type="text/template" id="tmpl-wordpoints-hook-reaction-condition-group">
478
				<div class="condition-group-title"></div>
479
			</script>
480
481
			<script type="text/template" id="tmpl-wordpoints-hook-reaction-condition">
482
				<div class="condition-controls">
483
					<div class="condition-title"></div>
484
					<button type="button" class="delete button-secondary wordpoints-hooks-icon-button">
485
						<span class="screen-reader-text">' . esc_html__( 'Remove Condition', 'wordpoints' ) . '</span>
486
						<span class="dashicons dashicons-no"></span>
487
					</button>
488
				</div>
489
				<div class="condition-settings"></div>
490
			</script>
491
492
			<script type="text/template" id="tmpl-wordpoints-hook-condition-selector">
493
				<label>
494
					{{ data.label }}
495
					<select name="{{ data.name }}"></select>
496
				</label>
497
			</script>
498
		'
499
	);
500
501
	wp_register_script(
502
		'wordpoints-hooks-extension-periods'
503
		, "{$assets_url}/js/hooks/extensions/periods{$manifested_suffix}.js"
504
		, array( 'wordpoints-hooks-views' )
505
		, WORDPOINTS_VERSION
506
	);
507
508
	wp_script_add_data(
509
		'wordpoints-hooks-extension-periods'
510
		, 'wordpoints-templates'
511
		, '
512
			<script type="text/template" id="tmpl-wordpoints-hook-periods">
513
				<div class="wordpoints-hook-periods">
514
					<div class="periods-title section-title">
515
						<h4>' . esc_html__( 'Rate Limit', 'wordpoints' ) . '</h4>
516
					</div>
517
					<div class="periods section-content"></div>
518
				</div>
519
			</script>
520
			
521
			<script type="text/template" id="tmpl-wordpoints-hook-reaction-simple-period">
522
				<div class="wordpoints-period">
523
					<input type="hidden" name="{{ data.name }}" value="{{ data.length }}" class="widefat wordpoints-hook-period-length" />
524
					<fieldset>
525
						<p class="description description-thin">
526
							<legend>{{ data.length_in_units_label }}</legend>
527
							<label>
528
								<span class="screen-reader-text">' . esc_html__( 'Time Units:', 'wordpoints' ) . '</span>
529
								<select class="widefat wordpoints-hook-period-sync wordpoints-hook-period-units"></select>
530
							</label>
531
							<label>
532
								<span class="screen-reader-text">' . esc_html__( 'Number:', 'wordpoints' ) . '</span>
533
								<input type="number" value="{{ data.length_in_units }}" class="widefat wordpoints-hook-period-sync wordpoints-hook-period-length-in-units" />
534
							</label>
535
						</p>
536
					</fieldset>
537
				</div>
538
			</script>
539
		'
540
	);
541
542
	wp_register_script(
543
		'wordpoints-hooks-extension-disable'
544
		, "{$assets_url}/js/hooks/extensions/disable{$manifested_suffix}.js"
545
		, array( 'wordpoints-hooks-views' )
546
		, WORDPOINTS_VERSION
547
	);
548
549
	wp_script_add_data(
550
		'wordpoints-hooks-extension-disable'
551
		, 'wordpoints-templates'
552
		, '
553
			<script type="text/template" id="tmpl-wordpoints-hook-disable">
554
				<div class="disable">
555
					<div class="section-title">
556
						<h4>' . esc_html__( 'Disable', 'wordpoints' ) . '</h4>
557
					</div>
558
					<div class="section-content">
559
						<p class="description description-thin">
560
							<label>
561
								<input type="checkbox" name="disable" value="1" />
562
								' . esc_html__( 'Disable (make this reaction inactive without deleting it)', 'wordpoints' ) . '
563
							</label>
564
						</p>
565
					</div>
566
				</div>
567
			</script>
568
			
569
			<script type="text/template" id="tmpl-wordpoints-hook-disabled-text">
570
				<span class="wordpoints-hook-disabled-text">' . esc_html__( '(Disabled)', 'wordpoints' ) . '</span>
571
			</script>
572
		'
573
	);
574
}
575
576
/**
577
 * Export the data for the scripts needed to make the hooks UI work.
578
 *
579
 * @since 2.1.0
580
 */
581
function wordpoints_hooks_ui_setup_script_data() {
582
583
	$hooks = wordpoints_hooks();
584
585
	$extensions_data = wordpoints_hooks_ui_get_script_data_from_objects(
586
		$hooks->get_sub_app( 'extensions' )->get_all()
0 ignored issues
show
Bug introduced by
It seems like $hooks->get_sub_app('extensions')->get_all() can also be of type array<mixed,array<mixed,object>>; however, parameter $objects of wordpoints_hooks_ui_get_script_data_from_objects() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

586
		/** @scrutinizer ignore-type */ $hooks->get_sub_app( 'extensions' )->get_all()
Loading history...
Bug introduced by
The method get_all() does not exist on WordPoints_App. It seems like you code against a sub-type of WordPoints_App such as WordPoints_App_Registry. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

586
		$hooks->get_sub_app( 'extensions' )->/** @scrutinizer ignore-call */ get_all()
Loading history...
Bug introduced by
The method get_all() does not exist on WordPoints_Hook_Router. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

586
		$hooks->get_sub_app( 'extensions' )->/** @scrutinizer ignore-call */ get_all()
Loading history...
587
		, 'extension'
588
	);
589
590
	$reactor_data = wordpoints_hooks_ui_get_script_data_from_objects(
591
		$hooks->get_sub_app( 'reactors' )->get_all()
592
		, 'reactor'
593
	);
594
595
	$event_action_types = wordpoints_hooks_ui_get_script_data_event_action_types();
596
	$entities_data      = wordpoints_hooks_ui_get_script_data_entities();
597
598
	$data = array(
599
		'fields'             => (object) array(),
600
		'reactions'          => (object) array(),
601
		'events'             => (object) array(),
602
		'extensions'         => $extensions_data,
603
		'entities'           => $entities_data,
604
		'reactors'           => $reactor_data,
605
		'event_action_types' => $event_action_types,
606
	);
607
608
	/**
609
	 * Filter the hooks data used to provide the UI.
610
	 *
611
	 * This is currently exported as JSON to the Backbone.js powered UI. But
612
	 * that could change in the future. The important thing is that the data is
613
	 * bing exported and will be used by something somehow.
614
	 *
615
	 * @param array $data The data.
616
	 */
617
	$data = apply_filters( 'wordpoints_hooks_ui_data', $data );
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

617
	$data = /** @scrutinizer ignore-call */ apply_filters( 'wordpoints_hooks_ui_data', $data );
Loading history...
618
619
	wp_localize_script(
0 ignored issues
show
Bug introduced by
The function wp_localize_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

619
	/** @scrutinizer ignore-call */ 
620
 wp_localize_script(
Loading history...
620
		'wordpoints-hooks-models'
621
		, 'WordPointsHooksAdminData'
622
		, $data
623
	);
624
}
625
626
/**
627
 * Get the UI script data from a bunch of objects.
628
 *
629
 * @since 2.1.0
630
 *
631
 * @param object[] $objects Objects that might provide script UI data.
632
 * @param string   $type    The type of objects. Used to automatically enqueue
633
 *                          scripts for the objects.
634
 *
635
 * @return array The data extracted from the objects.
636
 */
637
function wordpoints_hooks_ui_get_script_data_from_objects( $objects, $type ) {
638
639
	$data = array();
640
641
	foreach ( $objects as $slug => $object ) {
642
643
		if ( $object instanceof WordPoints_Hook_UI_Script_Data_ProviderI ) {
644
			$data[ $slug ] = $object->get_ui_script_data();
645
		}
646
647
		if ( wp_script_is( "wordpoints-hooks-{$type}-{$slug}", 'registered' ) ) {
0 ignored issues
show
Bug introduced by
The function wp_script_is was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

647
		if ( /** @scrutinizer ignore-call */ wp_script_is( "wordpoints-hooks-{$type}-{$slug}", 'registered' ) ) {
Loading history...
648
			wp_enqueue_script( "wordpoints-hooks-{$type}-{$slug}" );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

648
			/** @scrutinizer ignore-call */ 
649
   wp_enqueue_script( "wordpoints-hooks-{$type}-{$slug}" );
Loading history...
649
		}
650
	}
651
652
	return $data;
653
}
654
655
/**
656
 * Get the entities data for use in the hooks UI.
657
 *
658
 * @since 2.1.0
659
 *
660
 * @return array The entities data for use in the hooks UI.
661
 */
662
function wordpoints_hooks_ui_get_script_data_entities() {
663
664
	$entities = wordpoints_entities();
665
666
	$entities_data = array();
667
668
	/** @var WordPoints_Class_Registry_Children $entity_children */
669
	$entity_children = $entities->get_sub_app( 'children' );
670
671
	/** @var WordPoints_Entity $entity */
672
	foreach ( $entities->get_all() as $slug => $entity ) {
673
674
		$child_data = array();
675
676
		/** @var WordPoints_EntityishI $child */
677
		foreach ( $entity_children->get_children( $slug ) as $child_slug => $child ) {
678
679
			$child_data[ $child_slug ] = array(
680
				'slug'  => $child_slug,
681
				'title' => $child->get_title(),
682
			);
683
684
			if ( $child instanceof WordPoints_Entity_Attr ) {
685
686
				$child_data[ $child_slug ]['_type']     = 'attr';
687
				$child_data[ $child_slug ]['data_type'] = $child->get_data_type();
688
689
			} elseif ( $child instanceof WordPoints_Entity_Relationship ) {
690
691
				$child_data[ $child_slug ]['_type']     = 'relationship';
692
				$child_data[ $child_slug ]['primary']   = $child->get_primary_entity_slug();
693
				$child_data[ $child_slug ]['secondary'] = $child->get_related_entity_slug();
694
			}
695
696
			/**
697
			 * Filter the data for an entity child.
698
			 *
699
			 * Entity children include attributes and relationships.
700
			 *
701
			 * @param array                $data  The data for the entity child.
702
			 * @param WordPoints_Entityish $child The child's object.
703
			 */
704
			$child_data[ $child_slug ] = apply_filters(
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

704
			$child_data[ $child_slug ] = /** @scrutinizer ignore-call */ apply_filters(
Loading history...
705
				'wordpoints_hooks_ui_data_entity_child'
706
				, $child_data[ $child_slug ]
707
				, $child
708
			);
709
		}
710
711
		$entities_data[ $slug ] = array(
712
			'slug'     => $slug,
713
			'title'    => $entity->get_title(),
714
			'children' => $child_data,
715
			'id_field' => $entity->get_id_field(),
716
			'_type'    => 'entity',
717
		);
718
719
		if ( $entity instanceof WordPoints_Entity_EnumerableI ) {
720
721
			$values = array();
722
723
			foreach ( $entity->get_enumerated_values() as $value ) {
724
				if ( $entity->set_the_value( $value ) ) {
0 ignored issues
show
Bug introduced by
The method set_the_value() does not exist on WordPoints_Entity_EnumerableI. Since it exists in all sub-types, consider adding an abstract or default implementation to WordPoints_Entity_EnumerableI. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

724
				if ( $entity->/** @scrutinizer ignore-call */ set_the_value( $value ) ) {
Loading history...
725
					$values[] = array(
726
						'value' => $entity->get_the_id(),
0 ignored issues
show
Bug introduced by
The method get_the_id() does not exist on WordPoints_Entity_EnumerableI. Since it exists in all sub-types, consider adding an abstract or default implementation to WordPoints_Entity_EnumerableI. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

726
						'value' => $entity->/** @scrutinizer ignore-call */ get_the_id(),
Loading history...
727
						'label' => $entity->get_the_human_id(),
0 ignored issues
show
Bug introduced by
The method get_the_human_id() does not exist on WordPoints_Entity_EnumerableI. Since it exists in all sub-types, consider adding an abstract or default implementation to WordPoints_Entity_EnumerableI. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

727
						'label' => $entity->/** @scrutinizer ignore-call */ get_the_human_id(),
Loading history...
728
					);
729
				}
730
			}
731
732
			$entities_data[ $slug ]['values'] = $values;
733
		}
734
735
		/**
736
		 * Filter the data for an entity.
737
		 *
738
		 * @param array             $data   The data for the entity.
739
		 * @param WordPoints_Entity $entity The entity object.
740
		 */
741
		$entities_data[ $slug ] = apply_filters(
742
			'wordpoints_hooks_ui_data_entity'
743
			, $entities_data[ $slug ]
744
			, $entity
745
		);
746
747
	} // End foreach ( entities ).
748
749
	return $entities_data;
750
}
751
752
/**
753
 * Get a list of action types for each event for the hooks UI script data.
754
 *
755
 * @since 2.1.0
756
 *
757
 * @return array The event action types.
758
 */
759
function wordpoints_hooks_ui_get_script_data_event_action_types() {
760
761
	// We want a list of the action types for each event. We can start with this list
762
	// but it is indexed by action slug and then action type and then event slug, so
763
	// we ned to do some processing.
764
	$event_index = wordpoints_hooks()->get_sub_app( 'router' )->get_event_index();
0 ignored issues
show
Bug introduced by
The method get_event_index() does not exist on WordPoints_Class_Registry. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

764
	$event_index = wordpoints_hooks()->get_sub_app( 'router' )->/** @scrutinizer ignore-call */ get_event_index();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method get_event_index() does not exist on WordPoints_App. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

764
	$event_index = wordpoints_hooks()->get_sub_app( 'router' )->/** @scrutinizer ignore-call */ get_event_index();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method get_event_index() does not exist on WordPoints_Hook_Events. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

764
	$event_index = wordpoints_hooks()->get_sub_app( 'router' )->/** @scrutinizer ignore-call */ get_event_index();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method get_event_index() does not exist on WordPoints_Hook_Actions. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

764
	$event_index = wordpoints_hooks()->get_sub_app( 'router' )->/** @scrutinizer ignore-call */ get_event_index();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method get_event_index() does not exist on WordPoints_Class_Registry_ChildrenI. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

764
	$event_index = wordpoints_hooks()->get_sub_app( 'router' )->/** @scrutinizer ignore-call */ get_event_index();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
765
766
	// We don't care about the action slugs, so first we get rid of that bottom level
767
	// of the array.
768
	$event_index = call_user_func_array( 'array_merge_recursive', $event_index );
769
770
	$event_action_types = array();
771
772
	// This leaves us the event indexed by action type. But we actually need to flip
773
	// this, so that we have the action types indexed by event slug.
774
	foreach ( $event_index as $action_type => $events ) {
775
		foreach ( $events as $event => $unused ) {
776
			$event_action_types[ $event ][ $action_type ] = true;
777
		}
778
	}
779
780
	return $event_action_types;
781
}
782
783
/**
784
 * Append templates registered in wordpoints-templates script data to scripts.
785
 *
786
 * One day templates will probably be stored in separate files instead.
787
 *
788
 * @link https://core.trac.wordpress.org/ticket/31281
789
 *
790
 * @since 2.1.0
791
 *
792
 * @WordPress\filter script_loader_tag
793
 *
794
 * @param string $html   The HTML for the script.
795
 * @param string $handle The handle of the script.
796
 *
797
 * @return string The HTML with templates appended.
798
 */
799
function wordpoints_script_templates_filter( $html, $handle ) {
800
801
	global $wp_scripts;
802
803
	$templates = $wp_scripts->get_data( $handle, 'wordpoints-templates' );
804
805
	if ( $templates ) {
806
		$html .= $templates;
807
	}
808
809
	return $html;
810
}
811
812
/**
813
 * Display an error message.
814
 *
815
 * @since 1.0.0
816
 * @since 1.8.0 The $args parameter was added.
817
 *
818
 * @uses wordpoints_show_admin_message()
819
 *
820
 * @param string $message The text for the error message.
821
 * @param array  $args    Other optional arguments.
822
 */
823
function wordpoints_show_admin_error( $message, array $args = array() ) {
824
825
	wordpoints_show_admin_message( $message, 'error', $args );
826
}
827
828
/**
829
 * Display an update message.
830
 *
831
 * You should use {@see wordpoints_show_admin_error()} instead for showing error
832
 * messages. Currently there aren't wrappers for the other types, as they aren't used
833
 * in WordPoints core.
834
 *
835
 * @since 1.0.0
836
 * @since 1.2.0  The $type parameter is now properly escaped.
837
 * @since 1.8.0  The $message will be passed through wp_kses().
838
 * @since 1.8.0  The $args parameter was added with "dismissable" and "option" args.
839
 * @since 1.10.0 The "dismissable" arg was renamed to "dismissible".
840
 * @since 2.1.0  Now supports 'warning' and 'info' message types, and 'updated' is
841
 *               deprecated in favor of 'success'.
842
 *
843
 * @param string $message The text for the message.
844
 * @param string $type    The type of message to display, 'success' (default),
845
 *                        'error', 'warning' or 'info'.
846
 * @param array  $args    {
847
 *        Other optional arguments.
848
 *
849
 *        @type bool   $dismissible Whether this notice can be dismissed. Default is
850
 *                                  false (not dismissible).
851
 *        @type string $option      An option to delete when if message is dismissed.
852
 *                                  Required when $dismissible is true.
853
 * }
854
 */
855
function wordpoints_show_admin_message( $message, $type = 'success', array $args = array() ) {
856
857
	$defaults = array(
858
		'dismissible' => false,
859
		'option'      => '',
860
	);
861
862
	$args = array_merge( $defaults, $args );
863
864
	if ( isset( $args['dismissable'] ) ) {
865
866
		$args['dismissible'] = $args['dismissable'];
867
868
		_deprecated_argument(
0 ignored issues
show
Bug introduced by
The function _deprecated_argument was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

868
		/** @scrutinizer ignore-call */ 
869
  _deprecated_argument(
Loading history...
869
			__FUNCTION__
870
			, '1.10.0'
871
			, 'The "dismissable" argument has been replaced by the correct spelling, "dismissible".'
872
		);
873
	}
874
875
	if ( 'updated' === $type ) {
876
877
		$type = 'success';
878
879
		_deprecated_argument(
880
			__FUNCTION__
881
			, '2.1.0'
882
			, 'Use "success" instead of "updated" for the $type argument.'
883
		);
884
	}
885
886
	if ( $args['dismissible'] && $args['option'] ) {
887
		wp_enqueue_script( 'wordpoints-admin-dismiss-notice' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

887
		/** @scrutinizer ignore-call */ 
888
  wp_enqueue_script( 'wordpoints-admin-dismiss-notice' );
Loading history...
888
	}
889
890
	?>
891
892
	<div
893
		class="notice notice-<?php echo sanitize_html_class( $type, 'success' ); ?><?php echo ( $args['dismissible'] ) ? ' is-dismissible' : ''; ?>"
0 ignored issues
show
Bug introduced by
The function sanitize_html_class was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

893
		class="notice notice-<?php echo /** @scrutinizer ignore-call */ sanitize_html_class( $type, 'success' ); ?><?php echo ( $args['dismissible'] ) ? ' is-dismissible' : ''; ?>"
Loading history...
894
		<?php if ( $args['dismissible'] && $args['option'] ) : ?>
895
			data-nonce="<?php echo esc_attr( wp_create_nonce( "wordpoints_dismiss_notice-{$args['option']}" ) ); ?>"
0 ignored issues
show
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

895
			data-nonce="<?php echo /** @scrutinizer ignore-call */ esc_attr( wp_create_nonce( "wordpoints_dismiss_notice-{$args['option']}" ) ); ?>"
Loading history...
Bug introduced by
The function wp_create_nonce was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

895
			data-nonce="<?php echo esc_attr( /** @scrutinizer ignore-call */ wp_create_nonce( "wordpoints_dismiss_notice-{$args['option']}" ) ); ?>"
Loading history...
896
			data-option="<?php echo esc_attr( $args['option'] ); ?>"
897
		<?php endif; ?>
898
		>
899
		<p>
900
			<?php echo wp_kses( $message, 'wordpoints_admin_message' ); ?>
0 ignored issues
show
Bug introduced by
The function wp_kses was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

900
			<?php echo /** @scrutinizer ignore-call */ wp_kses( $message, 'wordpoints_admin_message' ); ?>
Loading history...
901
		</p>
902
		<?php if ( $args['dismissible'] && $args['option'] ) : ?>
903
			<form method="post" class="wordpoints-notice-dismiss-form" style="padding-bottom: 5px;">
904
				<input type="hidden" name="wordpoints_notice" value="<?php echo esc_html( $args['option'] ); ?>" />
0 ignored issues
show
Bug introduced by
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

904
				<input type="hidden" name="wordpoints_notice" value="<?php echo /** @scrutinizer ignore-call */ esc_html( $args['option'] ); ?>" />
Loading history...
905
				<?php wp_nonce_field( "wordpoints_dismiss_notice-{$args['option']}" ); ?>
0 ignored issues
show
Bug introduced by
The function wp_nonce_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

905
				<?php /** @scrutinizer ignore-call */ wp_nonce_field( "wordpoints_dismiss_notice-{$args['option']}" ); ?>
Loading history...
906
				<?php submit_button( __( 'Hide This Notice', 'wordpoints' ), 'secondary', 'wordpoints_dismiss_notice', false ); ?>
0 ignored issues
show
Bug introduced by
The function submit_button was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

906
				<?php /** @scrutinizer ignore-call */ submit_button( __( 'Hide This Notice', 'wordpoints' ), 'secondary', 'wordpoints_dismiss_notice', false ); ?>
Loading history...
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

906
				<?php submit_button( /** @scrutinizer ignore-call */ __( 'Hide This Notice', 'wordpoints' ), 'secondary', 'wordpoints_dismiss_notice', false ); ?>
Loading history...
907
			</form>
908
		<?php endif; ?>
909
	</div>
910
911
	<?php
912
}
913
914
/**
915
 * Get the current tab.
916
 *
917
 * @since 1.0.0
918
 *
919
 * @param array $tabs The tabs. If passed, the first key will be returned if
920
 *        $_GET['tab'] is not set, or not one of the values in $tabs.
921
 *
922
 * @return string
923
 */
924
function wordpoints_admin_get_current_tab( array $tabs = null ) {
925
926
	$tab = '';
927
928
	if ( isset( $_GET['tab'] ) ) { // WPCS: CSRF OK.
929
930
		$tab = sanitize_key( $_GET['tab'] ); // WPCS: CSRF OK.
0 ignored issues
show
Bug introduced by
The function sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

930
		$tab = /** @scrutinizer ignore-call */ sanitize_key( $_GET['tab'] ); // WPCS: CSRF OK.
Loading history...
931
	}
932
933
	if ( isset( $tabs ) && ! isset( $tabs[ $tab ] ) ) {
934
935
		reset( $tabs );
936
		$tab = key( $tabs );
937
	}
938
939
	return $tab;
940
}
941
942
/**
943
 * Display a set of tabs.
944
 *
945
 * @since 1.0.0
946
 *
947
 * @uses wordpoints_admin_get_current_tab()
948
 *
949
 * @param string[] $tabs         The tabs. Keys are slugs, values displayed text.
950
 * @param bool     $show_heading Whether to show an <h1> element using the current
951
 *                               tab. Default is true.
952
 */
953
function wordpoints_admin_show_tabs( $tabs, $show_heading = true ) {
954
955
	$current = wordpoints_admin_get_current_tab( $tabs );
956
957
	if ( $show_heading ) {
958
959
		// translators: Current tab name.
960
		echo '<h1>', esc_html( sprintf( __( 'WordPoints — %s', 'wordpoints' ), $tabs[ $current ] ) ), '</h1>';
0 ignored issues
show
Bug introduced by
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

960
		echo '<h1>', /** @scrutinizer ignore-call */ esc_html( sprintf( __( 'WordPoints — %s', 'wordpoints' ), $tabs[ $current ] ) ), '</h1>';
Loading history...
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

960
		echo '<h1>', esc_html( sprintf( /** @scrutinizer ignore-call */ __( 'WordPoints — %s', 'wordpoints' ), $tabs[ $current ] ) ), '</h1>';
Loading history...
961
	}
962
963
	echo '<h2 class="nav-tab-wrapper">';
964
965
	$page = '';
966
967
	if ( isset( $_GET['page'] ) ) { // WPCS: CSRF OK.
968
		$page = sanitize_key( $_GET['page'] ); // WPCS: CSRF OK.
0 ignored issues
show
Bug introduced by
The function sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

968
		$page = /** @scrutinizer ignore-call */ sanitize_key( $_GET['page'] ); // WPCS: CSRF OK.
Loading history...
969
	}
970
971
	foreach ( $tabs as $tab => $name ) {
972
973
		$class = ( $tab === $current ) ? ' nav-tab-active' : '';
974
975
		echo '<a class="nav-tab ', sanitize_html_class( $class ), '" href="?page=', rawurlencode( $page ), '&amp;tab=', rawurlencode( $tab ), '">', esc_html( $name ), '</a>';
0 ignored issues
show
Bug introduced by
The function sanitize_html_class was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

975
		echo '<a class="nav-tab ', /** @scrutinizer ignore-call */ sanitize_html_class( $class ), '" href="?page=', rawurlencode( $page ), '&amp;tab=', rawurlencode( $tab ), '">', esc_html( $name ), '</a>';
Loading history...
976
	}
977
978
	echo '</h2>';
979
}
980
981
/**
982
 * Display the upload module from zip form.
983
 *
984
 * @since 1.1.0
985
 *
986
 * @WordPress\action wordpoints_install_extensions-upload
987
 */
988
function wordpoints_install_modules_upload() {
989
990
	?>
991
992
	<style type="text/css">
993
		.wordpoints-upload-module {
994
			display: block;
995
		}
996
	</style>
997
998
	<div class="upload-plugin wordpoints-upload-module">
999
		<p class="install-help"><?php esc_html_e( 'If you have an extension in a .zip format, you may install it by uploading it here.', 'wordpoints' ); ?></p>
0 ignored issues
show
Bug introduced by
The function esc_html_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

999
		<p class="install-help"><?php /** @scrutinizer ignore-call */ esc_html_e( 'If you have an extension in a .zip format, you may install it by uploading it here.', 'wordpoints' ); ?></p>
Loading history...
1000
		<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo esc_url( self_admin_url( 'update.php?action=upload-wordpoints-module' ) ); ?>">
0 ignored issues
show
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1000
		<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo /** @scrutinizer ignore-call */ esc_url( self_admin_url( 'update.php?action=upload-wordpoints-module' ) ); ?>">
Loading history...
Bug introduced by
The function self_admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1000
		<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo esc_url( /** @scrutinizer ignore-call */ self_admin_url( 'update.php?action=upload-wordpoints-module' ) ); ?>">
Loading history...
1001
			<?php wp_nonce_field( 'wordpoints-module-upload' ); ?>
0 ignored issues
show
Bug introduced by
The function wp_nonce_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1001
			<?php /** @scrutinizer ignore-call */ wp_nonce_field( 'wordpoints-module-upload' ); ?>
Loading history...
1002
			<label class="screen-reader-text" for="modulezip"><?php esc_html_e( 'Extension zip file', 'wordpoints' ); ?></label>
1003
			<input type="file" id="modulezip" name="modulezip" />
1004
			<?php submit_button( __( 'Install Now', 'wordpoints' ), 'button', 'install-module-submit', false ); ?>
0 ignored issues
show
Bug introduced by
The function submit_button was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1004
			<?php /** @scrutinizer ignore-call */ submit_button( __( 'Install Now', 'wordpoints' ), 'button', 'install-module-submit', false ); ?>
Loading history...
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1004
			<?php submit_button( /** @scrutinizer ignore-call */ __( 'Install Now', 'wordpoints' ), 'button', 'install-module-submit', false ); ?>
Loading history...
1005
		</form>
1006
	</div>
1007
1008
	<?php
1009
}
1010
1011
/**
1012
 * Perform module upload from .zip file.
1013
 *
1014
 * @since 1.1.0
1015
 *
1016
 * @WordPress\action update-custom_upload-wordpoints-module
1017
 */
1018
function wordpoints_upload_module_zip() {
1019
1020
	global $title, $parent_file, $submenu_file;
1021
1022 View Code Duplication
	if ( ! current_user_can( 'install_wordpoints_extensions' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1022
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'install_wordpoints_extensions' ) ) {
Loading history...
1023
		wp_die( esc_html__( 'Sorry, you are not allowed to install WordPoints extensions on this site.', 'wordpoints' ), '', array( 'response' => 403 ) );
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1023
		/** @scrutinizer ignore-call */ 
1024
  wp_die( esc_html__( 'Sorry, you are not allowed to install WordPoints extensions on this site.', 'wordpoints' ), '', array( 'response' => 403 ) );
Loading history...
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1023
		wp_die( /** @scrutinizer ignore-call */ esc_html__( 'Sorry, you are not allowed to install WordPoints extensions on this site.', 'wordpoints' ), '', array( 'response' => 403 ) );
Loading history...
1024
	}
1025
1026
	check_admin_referer( 'wordpoints-module-upload' );
0 ignored issues
show
Bug introduced by
The function check_admin_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1026
	/** @scrutinizer ignore-call */ 
1027
 check_admin_referer( 'wordpoints-module-upload' );
Loading history...
1027
1028
	$file_upload = new File_Upload_Upgrader( 'modulezip', 'package' );
0 ignored issues
show
Bug introduced by
The type File_Upload_Upgrader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1029
1030
	$title        = esc_html__( 'Upload WordPoints Extension', 'wordpoints' );
1031
	$parent_file  = 'admin.php';
1032
	$submenu_file = 'admin.php';
1033
1034
	require_once ABSPATH . 'wp-admin/admin-header.php';
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1035
1036
	$upgrader = new WordPoints_Module_Installer(
1037
		new WordPoints_Module_Installer_Skin(
1038
			array(
1039
				// translators: File name.
1040
				'title' => sprintf( esc_html__( 'Installing Extension from uploaded file: %s', 'wordpoints' ), esc_html( basename( $file_upload->filename ) ) ),
0 ignored issues
show
Bug introduced by
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1040
				'title' => sprintf( esc_html__( 'Installing Extension from uploaded file: %s', 'wordpoints' ), /** @scrutinizer ignore-call */ esc_html( basename( $file_upload->filename ) ) ),
Loading history...
1041
				'nonce' => 'wordpoints-module-upload',
1042
				'url'   => add_query_arg( array( 'package' => $file_upload->id ), self_admin_url( 'update.php?action=upload-wordpoints-module' ) ),
0 ignored issues
show
Bug introduced by
The function add_query_arg was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1042
				'url'   => /** @scrutinizer ignore-call */ add_query_arg( array( 'package' => $file_upload->id ), self_admin_url( 'update.php?action=upload-wordpoints-module' ) ),
Loading history...
Bug introduced by
The function self_admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1042
				'url'   => add_query_arg( array( 'package' => $file_upload->id ), /** @scrutinizer ignore-call */ self_admin_url( 'update.php?action=upload-wordpoints-module' ) ),
Loading history...
1043
				'type'  => 'upload',
1044
			)
1045
		)
1046
	);
1047
1048
	$result = $upgrader->install( $file_upload->package );
1049
1050
	if ( $result || is_wp_error( $result ) ) {
0 ignored issues
show
Bug introduced by
The function is_wp_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1050
	if ( $result || /** @scrutinizer ignore-call */ is_wp_error( $result ) ) {
Loading history...
1051
		$file_upload->cleanup();
1052
	}
1053
1054
	require ABSPATH . 'wp-admin/admin-footer.php';
1055
}
1056
1057
/**
1058
 * Handles a request to upgrade an extension, displaying the extension upgrade screen.
1059
 *
1060
 * @since 2.4.0
1061
 *
1062
 * @WordPress\action update-custom_wordpoints-upgrade-extension
1063
 */
1064
function wordpoints_admin_screen_upgrade_extension() {
1065
1066
	global $title, $parent_file;
1067
1068
	if ( ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1068
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1069
		wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1069
		/** @scrutinizer ignore-call */ 
1070
  wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1069
		wp_die( /** @scrutinizer ignore-call */ esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1070
	}
1071
1072
	$extension = ( isset( $_REQUEST['extension'] ) )
1073
		? sanitize_text_field( wp_unslash( $_REQUEST['extension'] ) ) // WPCS: CSRF OK.
0 ignored issues
show
Bug introduced by
The function sanitize_text_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1073
		? /** @scrutinizer ignore-call */ sanitize_text_field( wp_unslash( $_REQUEST['extension'] ) ) // WPCS: CSRF OK.
Loading history...
Bug introduced by
The function wp_unslash was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1073
		? sanitize_text_field( /** @scrutinizer ignore-call */ wp_unslash( $_REQUEST['extension'] ) ) // WPCS: CSRF OK.
Loading history...
1074
		: '';
1075
1076
	check_admin_referer( 'upgrade-extension_' . $extension );
0 ignored issues
show
Bug introduced by
The function check_admin_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1076
	/** @scrutinizer ignore-call */ 
1077
 check_admin_referer( 'upgrade-extension_' . $extension );
Loading history...
1077
1078
	$title       = __( 'Update WordPoints Extension', 'wordpoints' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1078
	$title       = /** @scrutinizer ignore-call */ __( 'Update WordPoints Extension', 'wordpoints' );
Loading history...
1079
	$parent_file = 'admin.php';
1080
1081
	require_once ABSPATH . 'wp-admin/admin-header.php';
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1082
1083
	$upgrader = new WordPoints_Extension_Upgrader(
1084
		new WordPoints_Extension_Upgrader_Skin(
1085
			array(
1086
				'title'     => $title,
1087
				'nonce'     => 'upgrade-extension_' . $extension,
1088
				'url'       => 'update.php?action=wordpoints-upgrade-extension&extension=' . rawurlencode( $extension ),
1089
				'extension' => $extension,
1090
			)
1091
		)
1092
	);
1093
1094
	$upgrader->upgrade( $extension );
1095
1096
	require ABSPATH . 'wp-admin/admin-footer.php';
1097
}
1098
1099
/**
1100
 * Reactivates an extension in an iframe after it was updated.
1101
 *
1102
 * @since 2.4.0
1103
 *
1104
 * @WordPress\action update-custom_wordpoints-reactivate-extension
1105
 */
1106
function wordpoints_admin_iframe_reactivate_extension() {
1107
1108
	if ( ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1108
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1109
		wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1109
		/** @scrutinizer ignore-call */ 
1110
  wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1109
		wp_die( /** @scrutinizer ignore-call */ esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1110
	}
1111
1112
	$extension = ( isset( $_REQUEST['extension'] ) )
1113
		? sanitize_text_field( wp_unslash( $_REQUEST['extension'] ) ) // WPCS: CSRF OK.
0 ignored issues
show
Bug introduced by
The function wp_unslash was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1113
		? sanitize_text_field( /** @scrutinizer ignore-call */ wp_unslash( $_REQUEST['extension'] ) ) // WPCS: CSRF OK.
Loading history...
Bug introduced by
The function sanitize_text_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1113
		? /** @scrutinizer ignore-call */ sanitize_text_field( wp_unslash( $_REQUEST['extension'] ) ) // WPCS: CSRF OK.
Loading history...
1114
		: '';
1115
1116
	check_admin_referer( 'reactivate-extension_' . $extension );
0 ignored issues
show
Bug introduced by
The function check_admin_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1116
	/** @scrutinizer ignore-call */ 
1117
 check_admin_referer( 'reactivate-extension_' . $extension );
Loading history...
1117
1118
	// First, activate the extension.
1119
	if ( ! isset( $_GET['failure'] ) && ! isset( $_GET['success'] ) ) {
1120
1121
		$nonce = sanitize_key( $_GET['_wpnonce'] ); // @codingStandardsIgnoreLine
0 ignored issues
show
Bug introduced by
The function sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1121
		$nonce = /** @scrutinizer ignore-call */ sanitize_key( $_GET['_wpnonce'] ); // @codingStandardsIgnoreLine
Loading history...
1122
		$url   = admin_url( 'update.php?action=wordpoints-reactivate-extension&extension=' . rawurlencode( $extension ) . '&_wpnonce=' . $nonce );
0 ignored issues
show
Bug introduced by
The function admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1122
		$url   = /** @scrutinizer ignore-call */ admin_url( 'update.php?action=wordpoints-reactivate-extension&extension=' . rawurlencode( $extension ) . '&_wpnonce=' . $nonce );
Loading history...
1123
1124
		wp_safe_redirect( $url . '&failure=true' );
0 ignored issues
show
Bug introduced by
The function wp_safe_redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1124
		/** @scrutinizer ignore-call */ 
1125
  wp_safe_redirect( $url . '&failure=true' );
Loading history...
1125
		wordpoints_activate_module( $extension, '', ! empty( $_GET['network_wide'] ), true );
1126
		wp_safe_redirect( $url . '&success=true' );
1127
1128
		die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
1129
	}
1130
1131
	// Then we redirect back here to display the success or error message.
1132
	iframe_header( __( 'WordPoints Extension Reactivation', 'wordpoints' ) );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1132
	iframe_header( /** @scrutinizer ignore-call */ __( 'WordPoints Extension Reactivation', 'wordpoints' ) );
Loading history...
Bug introduced by
The function iframe_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1132
	/** @scrutinizer ignore-call */ 
1133
 iframe_header( __( 'WordPoints Extension Reactivation', 'wordpoints' ) );
Loading history...
1133
1134
	if ( isset( $_GET['success'] ) ) {
1135
1136
		echo '<p>' . esc_html__( 'Extension reactivated successfully.', 'wordpoints' ) . '</p>';
1137
1138
	} elseif ( isset( $_GET['failure'] ) ) {
1139
1140
		echo '<p>' . esc_html__( 'Extension failed to reactivate due to a fatal error.', 'wordpoints' ) . '</p>';
1141
1142
		// Ensure that Fatal errors are displayed.
1143
		// @codingStandardsIgnoreStart
1144
		error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
1145
		@ini_set( 'display_errors', true );
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for ini_set(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

1145
		/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', true );

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
true of type true is incompatible with the type string expected by parameter $newvalue of ini_set(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1145
		@ini_set( 'display_errors', /** @scrutinizer ignore-type */ true );
Loading history...
1146
		// @codingStandardsIgnoreEnd
1147
1148
		$file = wordpoints_extensions_dir() . '/' . $extension;
1149
		WordPoints_Module_Paths::register( $file );
1150
		include $file;
1151
	}
1152
1153
	iframe_footer();
0 ignored issues
show
Bug introduced by
The function iframe_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1153
	/** @scrutinizer ignore-call */ 
1154
 iframe_footer();
Loading history...
1154
}
1155
1156
/**
1157
 * Handle updating multiple extensions on the extensions administration screen.
1158
 *
1159
 * @since 2.4.0
1160
 */
1161
function wordpoints_admin_screen_update_selected_extensions() {
1162
1163
	if ( ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1163
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1164
		wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
0 ignored issues
show
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1164
		wp_die( /** @scrutinizer ignore-call */ esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1164
		/** @scrutinizer ignore-call */ 
1165
  wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1165
	}
1166
1167
	global $parent_file;
1168
1169
	check_admin_referer( 'bulk-wordpoints-extensions', 'nonce' );
0 ignored issues
show
Bug introduced by
The function check_admin_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1169
	/** @scrutinizer ignore-call */ 
1170
 check_admin_referer( 'bulk-wordpoints-extensions', 'nonce' );
Loading history...
1170
1171
	if ( isset( $_GET['extensions'] ) ) {
1172
		$extensions = explode( ',', sanitize_text_field( wp_unslash( $_GET['extensions'] ) ) );
0 ignored issues
show
Bug introduced by
The function wp_unslash was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1172
		$extensions = explode( ',', sanitize_text_field( /** @scrutinizer ignore-call */ wp_unslash( $_GET['extensions'] ) ) );
Loading history...
Bug introduced by
The function sanitize_text_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1172
		$extensions = explode( ',', /** @scrutinizer ignore-call */ sanitize_text_field( wp_unslash( $_GET['extensions'] ) ) );
Loading history...
1173
	} elseif ( isset( $_POST['checked'] ) ) {
1174
		$extensions = array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['checked'] ) );
1175
	} else {
1176
		$extensions = array();
1177
	}
1178
1179
	$url = self_admin_url( 'update.php?action=update-selected-wordpoints-extensions&amp;extensions=' . rawurlencode( implode( ',', $extensions ) ) );
0 ignored issues
show
Bug introduced by
The function self_admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1179
	$url = /** @scrutinizer ignore-call */ self_admin_url( 'update.php?action=update-selected-wordpoints-extensions&amp;extensions=' . rawurlencode( implode( ',', $extensions ) ) );
Loading history...
1180
	$url = wp_nonce_url( $url, 'bulk-update-extensions' );
0 ignored issues
show
Bug introduced by
The function wp_nonce_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1180
	$url = /** @scrutinizer ignore-call */ wp_nonce_url( $url, 'bulk-update-extensions' );
Loading history...
1181
1182
	$parent_file = 'admin.php';
1183
1184
	require_once ABSPATH . 'wp-admin/admin-header.php';
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1185
1186
	?>
1187
1188
	<div class="wrap">
1189
		<h1><?php esc_html_e( 'Update WordPoints Extensions', 'wordpoints' ); ?></h1>
0 ignored issues
show
Bug introduced by
The function esc_html_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1189
		<h1><?php /** @scrutinizer ignore-call */ esc_html_e( 'Update WordPoints Extensions', 'wordpoints' ); ?></h1>
Loading history...
1190
1191
		<iframe name="wordpoints_extension_updates" src="<?php echo esc_url( $url ); ?>" style="width: 100%; height:100%; min-height:850px;"></iframe>
0 ignored issues
show
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1191
		<iframe name="wordpoints_extension_updates" src="<?php echo /** @scrutinizer ignore-call */ esc_url( $url ); ?>" style="width: 100%; height:100%; min-height:850px;"></iframe>
Loading history...
1192
	</div>
1193
1194
	<?php
1195
1196
	require_once ABSPATH . 'wp-admin/admin-footer.php';
1197
1198
	exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
1199
}
1200
1201
/**
1202
 * Handle bulk extension update requests from within an iframe.
1203
 *
1204
 * @since 2.4.0
1205
 */
1206
function wordpoints_iframe_update_extensions() {
1207
1208
	if ( ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1208
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1209
		wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1209
		/** @scrutinizer ignore-call */ 
1210
  wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1209
		wp_die( /** @scrutinizer ignore-call */ esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1210
	}
1211
1212
	check_admin_referer( 'bulk-update-extensions' );
0 ignored issues
show
Bug introduced by
The function check_admin_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1212
	/** @scrutinizer ignore-call */ 
1213
 check_admin_referer( 'bulk-update-extensions' );
Loading history...
1213
1214
	$extensions = array();
1215
1216
	if ( isset( $_GET['extensions'] ) ) {
1217
		$extensions = explode( ',', sanitize_text_field( wp_unslash( $_GET['extensions'] ) ) );
0 ignored issues
show
Bug introduced by
The function sanitize_text_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1217
		$extensions = explode( ',', /** @scrutinizer ignore-call */ sanitize_text_field( wp_unslash( $_GET['extensions'] ) ) );
Loading history...
Bug introduced by
The function wp_unslash was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1217
		$extensions = explode( ',', sanitize_text_field( /** @scrutinizer ignore-call */ wp_unslash( $_GET['extensions'] ) ) );
Loading history...
1218
	}
1219
1220
	$extensions = array_map( 'rawurldecode', $extensions );
1221
1222
	wp_enqueue_script( 'jquery' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1222
	/** @scrutinizer ignore-call */ 
1223
 wp_enqueue_script( 'jquery' );
Loading history...
1223
	iframe_header();
0 ignored issues
show
Bug introduced by
The function iframe_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1223
	/** @scrutinizer ignore-call */ 
1224
 iframe_header();
Loading history...
1224
1225
	$upgrader = new WordPoints_Extension_Upgrader(
1226
		new WordPoints_Extension_Upgrader_Skin_Bulk(
1227
			array(
1228
				'nonce' => 'bulk-update-extensions',
1229
				'url'   => 'update.php?action=update-selected-wordpoints-extensions&amp;extensions=' . rawurlencode( implode( ',', $extensions ) ),
1230
			)
1231
		)
1232
	);
1233
1234
	$upgrader->bulk_upgrade( $extensions );
1235
1236
	iframe_footer();
0 ignored issues
show
Bug introduced by
The function iframe_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1236
	/** @scrutinizer ignore-call */ 
1237
 iframe_footer();
Loading history...
1237
}
1238
1239
/**
1240
 * Sets up the action hooks to display the extension update rows.
1241
 *
1242
 * @since 2.4.0
1243
 */
1244
function wordpoints_extension_update_rows() {
1245
1246
	if ( ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1246
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1247
		return;
1248
	}
1249
1250
	$updates = wordpoints_get_extension_updates();
1251
1252
	foreach ( $updates->get_new_versions() as $extension_file => $version ) {
1253
		add_action( "wordpoints_after_module_row_{$extension_file}", 'wordpoints_extension_update_row', 10, 2 );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1253
		/** @scrutinizer ignore-call */ 
1254
  add_action( "wordpoints_after_module_row_{$extension_file}", 'wordpoints_extension_update_row', 10, 2 );
Loading history...
1254
	}
1255
}
1256
1257
/**
1258
 * Displays the update message for an extension in the extensions list table.
1259
 *
1260
 * @since 2.4.0
1261
 *
1262
 * @WordPress\action wordpoints_after_module_row_{$extension_file} Added by
1263
 *                   wordpoints_extension_update_rows().
1264
 */
1265
function wordpoints_extension_update_row( $file, $extension_data ) {
1266
1267
	$updates = wordpoints_get_extension_updates();
1268
1269
	if ( ! $updates->has_update( $file ) ) {
1270
		return;
1271
	}
1272
1273
	$server = wordpoints_get_server_for_extension( $extension_data );
1274
1275
	if ( ! $server ) {
1276
		return;
1277
	}
1278
1279
	$api = $server->get_api();
1280
1281
	if ( ! $api instanceof WordPoints_Extension_Server_API_UpdatesI ) {
1282
		return;
1283
	}
1284
1285
	wp_enqueue_script( 'thickbox' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1285
	/** @scrutinizer ignore-call */ 
1286
 wp_enqueue_script( 'thickbox' );
Loading history...
1286
	wp_enqueue_style( 'thickbox' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_style was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1286
	/** @scrutinizer ignore-call */ 
1287
 wp_enqueue_style( 'thickbox' );
Loading history...
1287
1288
	$new_version = $updates->get_new_version( $file );
1289
1290
	$extension_name = wp_kses(
0 ignored issues
show
Bug introduced by
The function wp_kses was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1290
	$extension_name = /** @scrutinizer ignore-call */ wp_kses(
Loading history...
1291
		$extension_data['name']
1292
		, array(
1293
			'a'       => array( 'href' => array(), 'title' => array() ),
1294
			'abbr'    => array( 'title' => array() ),
1295
			'acronym' => array( 'title' => array() ),
1296
			'code'    => array(),
1297
			'em'      => array(),
1298
			'strong'  => array(),
1299
		)
1300
	);
1301
1302
	if ( is_network_admin() ) {
0 ignored issues
show
Bug introduced by
The function is_network_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1302
	if ( /** @scrutinizer ignore-call */ is_network_admin() ) {
Loading history...
1303
		$is_active = is_wordpoints_module_active_for_network( $file );
1304
	} else {
1305
		$is_active = is_wordpoints_module_active( $file );
1306
	}
1307
1308
	?>
1309
1310
	<tr class="plugin-update-tr wordpoints-extension-update-tr <?php echo ( $is_active ) ? 'active' : 'inactive'; ?>">
1311
		<td colspan="<?php echo (int) WordPoints_Admin_List_Table_Extensions::instance()->get_column_count(); ?>" class="plugin-update wordpoints-extension-update colspanchange">
1312
			<div class="update-message notice inline notice-warning notice-alt">
1313
				<p>
1314
					<?php
1315
1316
					printf( // WPCS: XSS OK.
1317
						// translators: Extension name.
1318
						esc_html__( 'There is a new version of %1$s available.', 'wordpoints' )
0 ignored issues
show
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1318
						/** @scrutinizer ignore-call */ 
1319
      esc_html__( 'There is a new version of %1$s available.', 'wordpoints' )
Loading history...
1319
						, $extension_name
1320
					);
1321
1322
					?>
1323
1324
					<?php if ( $api instanceof WordPoints_Extension_Server_API_Updates_ChangelogI ) : ?>
1325
						<?php
1326
1327
						// translators: 1. Extension name; 2. Version.
1328
						$message = __( 'View %1$s version %2$s details', 'wordpoints' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1328
						$message = /** @scrutinizer ignore-call */ __( 'View %1$s version %2$s details', 'wordpoints' );
Loading history...
1329
1330
						?>
1331
						<a
1332
							href="<?php echo esc_url( admin_url( 'update.php?action=wordpoints-iframe-extension-changelog&extension=' . rawurlencode( $file ) ) ); ?>"
0 ignored issues
show
Bug introduced by
The function admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1332
							href="<?php echo esc_url( /** @scrutinizer ignore-call */ admin_url( 'update.php?action=wordpoints-iframe-extension-changelog&extension=' . rawurlencode( $file ) ) ); ?>"
Loading history...
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1332
							href="<?php echo /** @scrutinizer ignore-call */ esc_url( admin_url( 'update.php?action=wordpoints-iframe-extension-changelog&extension=' . rawurlencode( $file ) ) ); ?>"
Loading history...
1333
							class="thickbox wordpoints-open-extension-details-modal"
1334
							aria-label="<?php echo esc_attr( sprintf( $message, $extension_name, $new_version ) ); ?>"
0 ignored issues
show
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1334
							aria-label="<?php echo /** @scrutinizer ignore-call */ esc_attr( sprintf( $message, $extension_name, $new_version ) ); ?>"
Loading history...
Bug introduced by
It seems like $new_version can also be of type false; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1334
							aria-label="<?php echo esc_attr( sprintf( $message, $extension_name, /** @scrutinizer ignore-type */ $new_version ) ); ?>"
Loading history...
1335
						>
1336
							<?php
1337
1338
							printf(
1339
								// translators: Version number.
1340
								esc_html__( 'View version %1$s details', 'wordpoints' )
1341
								, esc_html( $new_version )
0 ignored issues
show
Bug introduced by
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1341
								, /** @scrutinizer ignore-call */ esc_html( $new_version )
Loading history...
1342
							);
1343
1344
							?>
1345
						</a>
1346
					<?php endif; ?>
1347
1348
					<?php if ( current_user_can( 'update_wordpoints_extensions' ) ) : ?>
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1348
					<?php if ( /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) : ?>
Loading history...
1349
						<span class="wordpoints-update-action-separator">|</span>
1350
						<?php if ( $api instanceof WordPoints_Extension_Server_API_Updates_InstallableI ) : ?>
1351
							<?php
1352
1353
							// translators: Extension name.
1354
							$message = sprintf( __( 'Update %s now', 'wordpoints' ), $extension_name );
1355
1356
							?>
1357
							<a
1358
								href="<?php echo esc_url( wp_nonce_url( self_admin_url( 'update.php?action=wordpoints-upgrade-extension&extension=' ) . $file, 'upgrade-extension_' . $file ) ); ?>"
0 ignored issues
show
Bug introduced by
The function wp_nonce_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1358
								href="<?php echo esc_url( /** @scrutinizer ignore-call */ wp_nonce_url( self_admin_url( 'update.php?action=wordpoints-upgrade-extension&extension=' ) . $file, 'upgrade-extension_' . $file ) ); ?>"
Loading history...
Bug introduced by
The function self_admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1358
								href="<?php echo esc_url( wp_nonce_url( /** @scrutinizer ignore-call */ self_admin_url( 'update.php?action=wordpoints-upgrade-extension&extension=' ) . $file, 'upgrade-extension_' . $file ) ); ?>"
Loading history...
1359
								aria-label="<?php echo esc_attr( $message ); ?>"
1360
							>
1361
								<?php esc_html_e( 'Update now', 'wordpoints' ); ?>
0 ignored issues
show
Bug introduced by
The function esc_html_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1361
								<?php /** @scrutinizer ignore-call */ esc_html_e( 'Update now', 'wordpoints' ); ?>
Loading history...
1362
							</a>
1363
						<?php else : ?>
1364
							<em>
1365
								<?php esc_html_e( 'Automatic update is unavailable for this extension.', 'wordpoints' ); ?>
1366
							</em>
1367
						<?php endif; ?>
1368
					<?php endif; ?>
1369
1370
					<?php
1371
1372
					/**
1373
					 * Fires at the end of the update message container in each row
1374
					 * of the extensions list table.
1375
					 *
1376
					 * The dynamic portion of the hook name, `$file`, refers to the
1377
					 * path of the extension's primary file relative to the
1378
					 * extensions directory.
1379
					 *
1380
					 * @since 2.4.0
1381
					 *
1382
					 * @param array  $extension_data The extension's data.
1383
					 * @param string $new_version    The new version of the extension.
1384
					 */
1385
					do_action( "wordpoints_in_extension_update_message-{$file}", $extension_data, $new_version );
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1385
					/** @scrutinizer ignore-call */ 
1386
     do_action( "wordpoints_in_extension_update_message-{$file}", $extension_data, $new_version );
Loading history...
1386
1387
					?>
1388
				</p>
1389
			</div>
1390
		</td>
1391
	</tr>
1392
1393
	<?php
1394
}
1395
1396
/**
1397
 * Save extension license forms on submit.
1398
 *
1399
 * @since 2.4.0
1400
 *
1401
 * @WordPress\action wordpoints_modules_list_table_items
1402
 */
1403
function wordpoints_admin_save_extension_licenses( $extensions ) {
1404
1405
	if ( ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1405
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1406
		return $extensions;
1407
	}
1408
1409
	foreach ( $extensions['all'] as $extension ) {
1410
1411
		if ( empty( $extension['ID'] ) ) {
1412
			continue;
1413
		}
1414
1415
		$server = wordpoints_get_server_for_extension( $extension );
1416
1417
		if ( ! $server ) {
1418
			continue;
1419
		}
1420
1421
		$api = $server->get_api();
1422
1423
		if ( ! $api instanceof WordPoints_Extension_Server_API_LicensesI ) {
1424
			continue;
1425
		}
1426
1427
		$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
1428
			$extension['ID']
1429
			, $server
1430
		);
1431
1432
		$url = sanitize_title_with_dashes( $server->get_slug() );
0 ignored issues
show
Bug introduced by
The function sanitize_title_with_dashes was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1432
		$url = /** @scrutinizer ignore-call */ sanitize_title_with_dashes( $server->get_slug() );
Loading history...
1433
1434
		if ( ! isset( $_POST[ "license_key-{$url}-{$extension['ID']}" ] ) ) {
1435
			continue;
1436
		}
1437
1438
		$license_key = sanitize_key(
0 ignored issues
show
Bug introduced by
The function sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1438
		$license_key = /** @scrutinizer ignore-call */ sanitize_key(
Loading history...
1439
			$_POST[ "license_key-{$url}-{$extension['ID']}" ]
1440
		);
1441
1442
		$license = $api->get_extension_license_object( $extension_data, $license_key );
1443
1444
		if (
1445
			isset(
1446
				$_POST[ "activate-license-{$extension['ID']}" ]
1447
				, $_POST[ "wordpoints_activate_license_key-{$extension['ID']}" ]
1448
			)
1449
			&& wordpoints_verify_nonce(
1450
				"wordpoints_activate_license_key-{$extension['ID']}"
1451
				, "wordpoints_activate_license_key-{$extension['ID']}"
1452
				, null
1453
				, 'post'
1454
			)
1455
		) {
1456
1457
			if ( ! $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI ) {
1458
				continue;
1459
			}
1460
1461
			$result = $license->activate();
1462
1463
			if ( true === $result ) {
1464
				wordpoints_show_admin_message( esc_html__( 'License activated.', 'wordpoints' ) );
0 ignored issues
show
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1464
				wordpoints_show_admin_message( /** @scrutinizer ignore-call */ esc_html__( 'License activated.', 'wordpoints' ) );
Loading history...
1465
				$extension_data->set( 'license_key', $license_key );
1466
				wordpoints_check_for_extension_updates_now();
1467
			} elseif ( is_wp_error( $result ) ) {
0 ignored issues
show
Bug introduced by
The function is_wp_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1467
			} elseif ( /** @scrutinizer ignore-call */ is_wp_error( $result ) ) {
Loading history...
1468
				// translators: Error message.
1469
				wordpoints_show_admin_error( sprintf( esc_html__( 'Sorry, there was an error while trying to activate the license: %s', 'wordpoints' ), $result->get_error_message() ) );
1470
			} elseif ( ! $license->is_valid() ) {
1471
				wordpoints_show_admin_error( esc_html__( 'That license key is invalid.', 'wordpoints' ) );
1472
			} elseif ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI && $license->is_expired() ) {
1473
				if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_RenewableI && $license->is_renewable() ) {
1474 View Code Duplication
					if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_Renewable_URLI ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1475
						wordpoints_show_admin_error(
1476
							esc_html__( 'Sorry, that license key is expired, and must be renewed.', 'wordpoints' )
1477
							. ' <a href="' . esc_url( $license->get_renewal_url() ) . '">' . esc_html__( 'Renew License', 'wordpoints' ) . '</a>'
0 ignored issues
show
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1477
							. ' <a href="' . /** @scrutinizer ignore-call */ esc_url( $license->get_renewal_url() ) . '">' . esc_html__( 'Renew License', 'wordpoints' ) . '</a>'
Loading history...
1478
						);
1479
					} else {
1480
						wordpoints_show_admin_error( esc_html__( 'Sorry, that license key is expired, and must be renewed.', 'wordpoints' ) );
1481
					}
1482
				} else {
1483
					wordpoints_show_admin_error( esc_html__( 'Sorry, that license key is expired.', 'wordpoints' ) );
1484
				}
1485
1486
				$extension_data->set( 'license_key', $license_key );
1487
			} else {
1488
				wordpoints_show_admin_error( esc_html__( 'Sorry, that license key cannot be activated.', 'wordpoints' ) );
1489
			}
1490
1491
		} elseif (
1492
			isset(
1493
				$_POST[ "deactivate-license-{$extension['ID']}" ]
1494
				, $_POST[ "wordpoints_deactivate_license_key-{$extension['ID']}" ]
1495
			)
1496
			&& wordpoints_verify_nonce(
1497
				"wordpoints_deactivate_license_key-{$extension['ID']}"
1498
				, "wordpoints_deactivate_license_key-{$extension['ID']}"
1499
				, null
1500
				, 'post'
1501
			)
1502
		) {
1503
1504
			if ( ! $license instanceof WordPoints_Extension_Server_API_Extension_License_DeactivatableI ) {
1505
				continue;
1506
			}
1507
1508
			$result = $license->deactivate();
1509
1510
			if ( true === $result ) {
1511
				wordpoints_show_admin_message( esc_html__( 'License deactivated.', 'wordpoints' ) );
1512
			} elseif ( is_wp_error( $result ) ) {
1513
				// translators: Error message.
1514
				wordpoints_show_admin_error( sprintf( esc_html__( 'Sorry, there was an error while trying to deactivate the license: %s', 'wordpoints' ), $result->get_error_message() ) );
1515
			} else {
1516
				wordpoints_show_admin_error( esc_html__( 'Sorry, there was an unknown error while trying to deactivate that license key.', 'wordpoints' ) );
1517
			}
1518
1519
		} // End if ( activating license ) elseif ( deactivating license ).
1520
1521
	} // End foreach ( extension ).
1522
1523
	return $extensions;
1524
}
1525
1526
/**
1527
 * Filter the classes for a row in the WordPoints extensions list table.
1528
 *
1529
 * @since 2.4.0
1530
 *
1531
 * @WordPress\filter wordpoints_module_list_row_class
1532
 *
1533
 * @param string $classes        The HTML classes for this extension row.
1534
 * @param string $extension_file The extension file.
1535
 * @param array  $extension_data The extension data.
1536
 *
1537
 * @return string The filtered classes.
1538
 */
1539
function wordpoints_extension_list_row_license_classes( $classes, $extension_file, $extension_data ) {
0 ignored issues
show
Unused Code introduced by
The parameter $extension_file is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1539
function wordpoints_extension_list_row_license_classes( $classes, /** @scrutinizer ignore-unused */ $extension_file, $extension_data ) {

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

Loading history...
1540
1541
	// Add license information if this user is allowed to see it.
1542
	if ( empty( $extension_data['ID'] ) || ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1542
	if ( empty( $extension_data['ID'] ) || ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1543
		return $classes;
1544
	}
1545
1546
	$server = wordpoints_get_server_for_extension( $extension_data );
1547
1548
	if ( ! $server ) {
1549
		return $classes;
1550
	}
1551
1552
	$api = $server->get_api();
1553
1554
	if ( ! $api instanceof WordPoints_Extension_Server_API_LicensesI ) {
1555
		return $classes;
1556
	}
1557
1558
	$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
1559
		$extension_data['ID'],
1560
		$server
1561
	);
1562
1563
	if ( ! $api->extension_requires_license( $extension_data ) ) {
1564
		return $classes;
1565
	}
1566
1567
	$classes .= ' wordpoints-extension-has-license';
1568
1569
	$license = $api->get_extension_license_object(
1570
		$extension_data,
1571
		$extension_data->get( 'license_key' )
1572
	);
1573
1574
	if ( $license->is_valid() ) {
1575
		$classes .= ' wordpoints-extension-license-valid';
1576
	} else {
1577
		$classes .= ' wordpoints-extension-license-invalid';
1578
	}
1579
1580
	if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI ) {
1581
		if ( $license->is_active() ) {
1582
			$classes .= ' wordpoints-extension-license-active';
1583
		} else {
1584
			$classes .= ' wordpoints-extension-license-inactive';
1585
		}
1586
	}
1587
1588
	if (
1589
		$license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI
1590
		&& $license->is_expired()
1591
	) {
1592
		$classes .= ' wordpoints-extension-license-expired';
1593
	}
1594
1595
	return $classes;
1596
}
1597
1598
/**
1599
 * Add the license key rows to the extensions list table.
1600
 *
1601
 * @since 2.4.0
1602
 *
1603
 * @WordPress\action wordpoints_after_module_row
1604
 */
1605
function wordpoints_extension_license_row( $extension_file, $extension ) {
1606
1607
	if ( empty( $extension['ID'] ) || ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1607
	if ( empty( $extension['ID'] ) || ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1608
		return;
1609
	}
1610
1611
	$server = wordpoints_get_server_for_extension( $extension );
1612
1613
	if ( ! $server ) {
1614
		return;
1615
	}
1616
1617
	$api = $server->get_api();
1618
1619
	if ( ! $api instanceof WordPoints_Extension_Server_API_LicensesI ) {
1620
		return;
1621
	}
1622
1623
	$extension_id = $extension['ID'];
1624
1625
	$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
1626
		$extension_id
1627
		, $server
1628
	);
1629
1630
	if ( ! $api->extension_requires_license( $extension_data ) ) {
1631
		return;
1632
	}
1633
1634
	$license_key = $extension_data->get( 'license_key' );
1635
	$license     = $api->get_extension_license_object( $extension_data, $license_key );
1636
	$server_url  = sanitize_title_with_dashes( $server->get_slug() );
0 ignored issues
show
Bug introduced by
The function sanitize_title_with_dashes was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1636
	$server_url  = /** @scrutinizer ignore-call */ sanitize_title_with_dashes( $server->get_slug() );
Loading history...
1637
1638
	$notice_type = 'error';
1639
1640
	if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI ) {
1641
		if ( ! empty( $license_key ) && $license->is_active() ) {
1642
			$notice_type = 'success';
1643
		} elseif ( empty( $license_key ) || $license->is_activatable() ) {
1644
			$notice_type = 'error';
1645
		}
1646
	}
1647
1648
	if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI ) {
1649
		if ( ! empty( $license_key ) && $license->is_expired() ) {
1650
			if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_RenewableI ) {
1651
				if ( $license->is_renewable() ) {
1652
					$notice_type = 'warning';
1653
				}
1654
			}
1655
		}
1656
	}
1657
1658
	// translators: Extension name.
1659
	$aria_label = __( 'License key for %s', 'wordpoints' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1659
	$aria_label = /** @scrutinizer ignore-call */ __( 'License key for %s', 'wordpoints' );
Loading history...
1660
1661
	?>
1662
	<tr class="wordpoints-extension-license-tr plugin-update-tr <?php echo ( is_wordpoints_module_active( $extension_file ) ) ? 'active' : 'inactive'; ?>">
1663
		<td colspan="<?php echo (int) WordPoints_Admin_List_Table_Extensions::instance()->get_column_count(); ?>" class="colspanchange">
1664
			<div class="wordpoints-license-box notice inline notice-alt notice-<?php echo esc_attr( $notice_type ); ?>">
0 ignored issues
show
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1664
			<div class="wordpoints-license-box notice inline notice-alt notice-<?php echo /** @scrutinizer ignore-call */ esc_attr( $notice_type ); ?>">
Loading history...
1665
				<p>
1666
				<label class="description" for="license_key-<?php echo esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>" aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension['name'] ) ); ?>">
1667
					<?php esc_html_e( 'License key:', 'wordpoints' ); ?>
0 ignored issues
show
Bug introduced by
The function esc_html_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1667
					<?php /** @scrutinizer ignore-call */ esc_html_e( 'License key:', 'wordpoints' ); ?>
Loading history...
1668
				</label>
1669
				<input
1670
					id="license_key-<?php echo esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>"
1671
					name="license_key-<?php echo esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>"
1672
					type="password"
1673
					class="regular-text"
1674
					autocomplete="off"
1675
					value="<?php echo esc_attr( $license_key ); ?>"
1676
				/>
1677
				<?php if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI ) : ?>
1678
					<?php if ( ! empty( $license_key ) && $license->is_active() ) : ?>
1679 View Code Duplication
						<?php if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_DeactivatableI && $license->is_deactivatable() ) : ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1680
							<?php
1681
1682
							wp_nonce_field( "wordpoints_deactivate_license_key-{$extension_id}", "wordpoints_deactivate_license_key-{$extension_id}" );
0 ignored issues
show
Bug introduced by
The function wp_nonce_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1682
							/** @scrutinizer ignore-call */ 
1683
       wp_nonce_field( "wordpoints_deactivate_license_key-{$extension_id}", "wordpoints_deactivate_license_key-{$extension_id}" );
Loading history...
1683
1684
							// translators: Extension name.
1685
							$aria_label = __( 'Deactivate License for %s', 'wordpoints' );
1686
1687
							?>
1688
							<input type="submit" name="deactivate-license-<?php echo esc_attr( $extension_id ); ?>" class="button-secondary" value="<?php esc_attr_e( 'Deactivate License', 'wordpoints' ); ?>" aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension['name'] ) ); ?>" />
0 ignored issues
show
Bug introduced by
The function esc_attr_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1688
							<input type="submit" name="deactivate-license-<?php echo esc_attr( $extension_id ); ?>" class="button-secondary" value="<?php /** @scrutinizer ignore-call */ esc_attr_e( 'Deactivate License', 'wordpoints' ); ?>" aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension['name'] ) ); ?>" />
Loading history...
1689
						<?php endif; ?>
1690 View Code Duplication
					<?php elseif ( empty( $license_key ) || $license->is_activatable() ) : ?>
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1691
						<?php
1692
1693
						wp_nonce_field( "wordpoints_activate_license_key-{$extension_id}", "wordpoints_activate_license_key-{$extension_id}" );
1694
1695
						// translators: Extension name.
1696
						$aria_label = __( 'Activate License for %s', 'wordpoints' );
1697
1698
						?>
1699
						<input type="submit" name="activate-license-<?php echo esc_attr( $extension_id ); ?>" class="button-secondary" value="<?php esc_attr_e( 'Activate License', 'wordpoints' ); ?>" aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension['name'] ) ); ?>" />
1700
					<?php endif; ?>
1701
				<?php endif; ?>
1702
					<?php if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI ) : ?>
1703
						<?php if ( ! empty( $license_key ) && $license->is_expired() ) : ?>
1704
							<?php if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_RenewableI && $license->is_renewable() ) : ?>
1705
								<?php esc_html_e( 'This license key is expired and must be renewed.', 'wordpoints' ); ?>
1706
								<?php if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_Renewable_URLI ) : ?>
1707
									<?php
1708
1709
									// translators: Extension name.
1710
									$aria_label = __( 'Renew License for %s', 'wordpoints' );
1711
1712
									?>
1713
									<a href="<?php echo esc_url( $license->get_renewal_url() ); ?>" aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension['name'] ) ); ?>"><?php esc_html_e( 'Renew License', 'wordpoints' ); ?></a>
0 ignored issues
show
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1713
									<a href="<?php echo /** @scrutinizer ignore-call */ esc_url( $license->get_renewal_url() ); ?>" aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension['name'] ) ); ?>"><?php esc_html_e( 'Renew License', 'wordpoints' ); ?></a>
Loading history...
1714
								<?php endif; ?>
1715
							<?php else : ?>
1716
								<?php esc_html_e( 'This license key is expired.', 'wordpoints' ); ?>
1717
							<?php endif; ?>
1718
						<?php endif; ?>
1719
					<?php endif; ?>
1720
				</p>
1721
			</div>
1722
		</td>
1723
	</tr>
1724
	<?php
1725
}
1726
1727
/**
1728
 * Displays the changelog for an extension.
1729
 *
1730
 * @since 2.4.0
1731
 */
1732
function wordpoints_iframe_extension_changelog() {
1733
1734
	if ( ! defined( 'IFRAME_REQUEST' ) ) {
1735
		define( 'IFRAME_REQUEST', true ); // WPCS: prefix OK.
1736
	}
1737
1738
	if ( ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1738
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1739
		wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
0 ignored issues
show
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1739
		wp_die( /** @scrutinizer ignore-call */ esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1739
		/** @scrutinizer ignore-call */ 
1740
  wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1740
	}
1741
1742
	if ( empty( $_GET['extension'] ) ) { // WPCS: CSRF OK.
1743
		wp_die( esc_html__( 'No extension supplied.', 'wordpoints' ), 200 );
1744
	}
1745
1746
	$extension_file = sanitize_text_field( rawurldecode( wp_unslash( $_GET['extension'] ) ) ); // WPCS: CSRF, sanitization OK.
0 ignored issues
show
Bug introduced by
The function wp_unslash was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1746
	$extension_file = sanitize_text_field( rawurldecode( /** @scrutinizer ignore-call */ wp_unslash( $_GET['extension'] ) ) ); // WPCS: CSRF, sanitization OK.
Loading history...
Bug introduced by
The function sanitize_text_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1746
	$extension_file = /** @scrutinizer ignore-call */ sanitize_text_field( rawurldecode( wp_unslash( $_GET['extension'] ) ) ); // WPCS: CSRF, sanitization OK.
Loading history...
1747
1748
	$extensions = wordpoints_get_modules();
1749
1750
	if ( ! isset( $extensions[ $extension_file ] ) ) {
1751
		wp_die( esc_html__( 'That extension does not exist.', 'wordpoints' ), 200 );
1752
	}
1753
1754
	$server = wordpoints_get_server_for_extension( $extensions[ $extension_file ] );
1755
1756
	if ( ! $server ) {
1757
		wp_die( esc_html__( 'There is no server specified for this extension.', 'wordpoints' ), 200 );
1758
	}
1759
1760
	$api = $server->get_api();
1761
1762
	if ( ! $api instanceof WordPoints_Extension_Server_API_Updates_ChangelogI ) {
1763
		wp_die( esc_html__( 'The server for this extension uses an unsupported API.', 'wordpoints' ), 200 );
1764
	}
1765
1766
	$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
1767
		$extensions[ $extension_file ]['ID']
1768
		, $server
0 ignored issues
show
Bug introduced by
It seems like $server can also be of type false; however, parameter $server of WordPoints_Extension_Ser...ion_Data::__construct() does only seem to accept WordPoints_Extension_ServerI, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1768
		, /** @scrutinizer ignore-type */ $server
Loading history...
1769
	);
1770
1771
	iframe_header();
0 ignored issues
show
Bug introduced by
The function iframe_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1771
	/** @scrutinizer ignore-call */ 
1772
 iframe_header();
Loading history...
1772
1773
	echo '<div style="margin-left: 10px;">';
1774
	echo wp_kses(
0 ignored issues
show
Bug introduced by
The function wp_kses was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1774
	echo /** @scrutinizer ignore-call */ wp_kses(
Loading history...
1775
		$api->get_extension_changelog( $extension_data )
0 ignored issues
show
Bug introduced by
The method get_extension_changelog() does not exist on WordPoints_Extension_Server_APII. Since it exists in all sub-types, consider adding an abstract or default implementation to WordPoints_Extension_Server_APII. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1775
		$api->/** @scrutinizer ignore-call */ 
1776
        get_extension_changelog( $extension_data )
Loading history...
1776
		, 'wordpoints_extension_changelog'
1777
	);
1778
	echo '</div>';
1779
1780
	iframe_footer();
0 ignored issues
show
Bug introduced by
The function iframe_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1780
	/** @scrutinizer ignore-call */ 
1781
 iframe_footer();
Loading history...
1781
}
1782
1783
/**
1784
 * Supply the list of HTML tags allowed in an extension changelog.
1785
 *
1786
 * @since 2.4.0
1787
 *
1788
 * @WordPress\filter wp_kses_allowed_html
1789
 */
1790
function wordpoints_extension_changelog_allowed_html( $allowed_tags, $context ) {
1791
1792
	if ( 'wordpoints_extension_changelog' !== $context ) {
1793
		return $allowed_tags;
1794
	}
1795
1796
	return array(
1797
		'a'       => array( 'href' => array(), 'title' => array(), 'target' => array() ),
1798
		'abbr'    => array( 'title' => array() ),
1799
		'acronym' => array( 'title' => array() ),
1800
		'code'    => array(),
1801
		'pre'     => array(),
1802
		'em'      => array(),
1803
		'strong'  => array(),
1804
		'div'     => array( 'class' => array() ),
1805
		'span'    => array( 'class' => array() ),
1806
		'p'       => array(),
1807
		'ul'      => array(),
1808
		'ol'      => array(),
1809
		'li'      => array(),
1810
		'h1'      => array(),
1811
		'h2'      => array(),
1812
		'h3'      => array(),
1813
		'h4'      => array(),
1814
		'h5'      => array(),
1815
		'h6'      => array(),
1816
		'img'     => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
1817
	);
1818
}
1819
1820
/**
1821
 * List the available extension updates on the Updates screen.
1822
 *
1823
 * @since 2.4.0
1824
 */
1825
function wordpoints_list_extension_updates() {
1826
1827
	wp_enqueue_style( 'wordpoints-admin-extension-updates-table' );
0 ignored issues
show
Bug introduced by
The function wp_enqueue_style was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1827
	/** @scrutinizer ignore-call */ 
1828
 wp_enqueue_style( 'wordpoints-admin-extension-updates-table' );
Loading history...
1828
1829
	$updates      = wordpoints_get_extension_updates();
1830
	$new_versions = $updates->get_new_versions();
1831
1832
	?>
1833
1834
	<h2><?php esc_html_e( 'WordPoints Extensions', 'wordpoints' ); ?></h2>
0 ignored issues
show
Bug introduced by
The function esc_html_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1834
	<h2><?php /** @scrutinizer ignore-call */ esc_html_e( 'WordPoints Extensions', 'wordpoints' ); ?></h2>
Loading history...
1835
1836
	<?php if ( empty( $new_versions ) ) : ?>
1837
		<p><?php esc_html_e( 'Your extensions are all up to date.', 'wordpoints' ); ?></p>
1838
		<?php return; // @codingStandardsIgnoreLine ?>
1839
	<?php endif; ?>
0 ignored issues
show
Unused Code introduced by
InlineHTMLNode is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
1840
1841
	<p><?php esc_html_e( 'The following extensions have new versions available. Check the ones you want to update and then click &#8220;Update Extensions&#8221;.', 'wordpoints' ); ?></p>
1842
1843
	<form method="post" action="update-core.php?action=do-wordpoints-extension-upgrade" name="upgrade-wordpoints-extensions" class="upgrade">
1844
		<?php wp_nonce_field( 'bulk-wordpoints-extensions', 'nonce' ); ?>
0 ignored issues
show
Bug introduced by
The function wp_nonce_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1844
		<?php /** @scrutinizer ignore-call */ wp_nonce_field( 'bulk-wordpoints-extensions', 'nonce' ); ?>
Loading history...
1845
1846
		<p><input id="upgrade-wordpoints-extensions" class="button" type="submit" value="<?php esc_attr_e( 'Update Extensions', 'wordpoints' ); ?>" name="upgrade" /></p>
0 ignored issues
show
Bug introduced by
The function esc_attr_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1846
		<p><input id="upgrade-wordpoints-extensions" class="button" type="submit" value="<?php /** @scrutinizer ignore-call */ esc_attr_e( 'Update Extensions', 'wordpoints' ); ?>" name="upgrade" /></p>
Loading history...
1847
1848
		<table class="widefat" id="update-wordpoints-extensions-table">
1849
			<thead>
1850
			<tr>
1851
				<td scope="col" class="manage-column check-column">
1852
					<input type="checkbox" id="wordpoints-extensions-select-all" />
1853
				</td>
1854
				<th scope="col" class="manage-column">
1855
					<label for="wordpoints-extensions-select-all"><?php esc_html_e( 'Select All', 'wordpoints' ); ?></label>
1856
				</th>
1857
			</tr>
1858
			</thead>
1859
1860
			<tbody class="wordpoints-extensions">
1861
			<?php foreach ( $new_versions as $extension_file => $new_version ) : ?>
1862
				<?php $extension_data = wordpoints_get_module_data( wordpoints_extensions_dir() . $extension_file ); ?>
1863
				<tr>
1864
					<th scope="row" class="check-column">
1865
						<input id="checkbox_<?php echo esc_attr( sanitize_key( $extension_file ) ); ?>" type="checkbox" name="checked[]" value="<?php echo esc_attr( $extension_file ); ?>" />
0 ignored issues
show
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1865
						<input id="checkbox_<?php echo /** @scrutinizer ignore-call */ esc_attr( sanitize_key( $extension_file ) ); ?>" type="checkbox" name="checked[]" value="<?php echo esc_attr( $extension_file ); ?>" />
Loading history...
Bug introduced by
The function sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1865
						<input id="checkbox_<?php echo esc_attr( /** @scrutinizer ignore-call */ sanitize_key( $extension_file ) ); ?>" type="checkbox" name="checked[]" value="<?php echo esc_attr( $extension_file ); ?>" />
Loading history...
1866
						<label for="checkbox_<?php echo esc_attr( sanitize_key( $extension_file ) ); ?>" class="screen-reader-text">
1867
							<?php
1868
1869
							echo esc_html(
0 ignored issues
show
Bug introduced by
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1869
							echo /** @scrutinizer ignore-call */ esc_html(
Loading history...
1870
								sprintf(
1871
									// translators: Extension name.
1872
									__( 'Select %s', 'wordpoints' )
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1872
									/** @scrutinizer ignore-call */ 
1873
         __( 'Select %s', 'wordpoints' )
Loading history...
1873
									, $extension_data['name']
1874
								)
1875
							);
1876
1877
							?>
1878
						</label>
1879
					</th>
1880
					<td>
1881
						<p>
1882
							<strong><?php echo esc_html( $extension_data['name'] ); ?></strong>
1883
							<br />
1884
							<?php
1885
1886
							echo esc_html(
1887
								sprintf(
1888
									// translators: 1. Installed version number; 2. Update version number.
1889
									__( 'You have version %1$s installed. Update to %2$s.', 'wordpoints' )
1890
									, $extension_data['version']
1891
									, $new_version
1892
								)
1893
							);
1894
1895
							?>
1896
							<a href="<?php echo esc_url( self_admin_url( 'update.php?action=wordpoints-iframe-extension-changelog&extension=' . rawurlencode( $extension_file ) . '&TB_iframe=true&width=640&height=662' ) ); ?>" class="thickbox" title="<?php echo esc_attr( $extension_data['name'] ); ?>">
0 ignored issues
show
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1896
							<a href="<?php echo /** @scrutinizer ignore-call */ esc_url( self_admin_url( 'update.php?action=wordpoints-iframe-extension-changelog&extension=' . rawurlencode( $extension_file ) . '&TB_iframe=true&width=640&height=662' ) ); ?>" class="thickbox" title="<?php echo esc_attr( $extension_data['name'] ); ?>">
Loading history...
Bug introduced by
The function self_admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1896
							<a href="<?php echo esc_url( /** @scrutinizer ignore-call */ self_admin_url( 'update.php?action=wordpoints-iframe-extension-changelog&extension=' . rawurlencode( $extension_file ) . '&TB_iframe=true&width=640&height=662' ) ); ?>" class="thickbox" title="<?php echo esc_attr( $extension_data['name'] ); ?>">
Loading history...
1897
								<?php
1898
1899
								echo esc_html(
1900
									sprintf(
1901
										// translators: Version number.
1902
										__( 'View version %1$s details.', 'wordpoints' )
1903
										, $new_version
1904
									)
1905
								);
1906
1907
								?>
1908
							</a>
1909
						</p>
1910
					</td>
1911
				</tr>
1912
			<?php endforeach; ?>
1913
			</tbody>
1914
1915
			<tfoot>
1916
			<tr>
1917
				<td scope="col" class="manage-column check-column">
1918
					<input type="checkbox" id="wordpoints-extensions-select-all-2" />
1919
				</td>
1920
				<th scope="col" class="manage-column">
1921
					<label for="wordpoints-extensions-select-all-2"><?php esc_html_e( 'Select All', 'wordpoints' ); ?></label>
1922
				</th>
1923
			</tr>
1924
			</tfoot>
1925
		</table>
1926
		<p><input id="upgrade-wordpoints-extensions-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Extensions', 'wordpoints' ); ?>" name="upgrade" /></p>
1927
	</form>
1928
1929
	<?php
1930
}
1931
1932
/**
1933
 * Notify the user when they try to install a module on the plugins screen.
1934
 *
1935
 * The function is hooked to the upgrader_source_selection action twice. The first
1936
 * time it is called, we just save a local copy of the source path. This is
1937
 * necessary because the second time around the source will be a WP_Error if there
1938
 * are no plugins in it, but we have to have the source location so that we can check
1939
 * if it is a module instead of a plugin.
1940
 *
1941
 * @since 1.9.0
1942
 *
1943
 * @WordPress\action upgrader_source_selection See above for more info.
1944
 *
1945
 * @param string|WP_Error $source The module source.
1946
 *
1947
 * @return string|WP_Error The filtered module source.
1948
 */
1949
function wordpoints_plugin_upload_error_filter( $source ) {
1950
1951
	static $_source;
1952
1953
	if ( ! isset( $_source ) ) {
1954
1955
		$_source = $source;
1956
1957
	} else {
1958
1959
		global $wp_filesystem;
1960
1961
		if (
1962
			! is_wp_error( $_source )
0 ignored issues
show
Bug introduced by
The function is_wp_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1962
			! /** @scrutinizer ignore-call */ is_wp_error( $_source )
Loading history...
1963
			&& is_wp_error( $source )
1964
			&& 'incompatible_archive_no_plugins' === $source->get_error_code()
1965
		) {
1966
1967
			$working_directory = str_replace(
1968
				$wp_filesystem->wp_content_dir()
1969
				, trailingslashit( WP_CONTENT_DIR )
0 ignored issues
show
Bug introduced by
The constant WP_CONTENT_DIR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function trailingslashit was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1969
				, /** @scrutinizer ignore-call */ trailingslashit( WP_CONTENT_DIR )
Loading history...
1970
				, $_source
1971
			);
1972
1973
			if ( is_dir( $working_directory ) ) {
1974
1975
				$files = glob( $working_directory . '*.php' );
1976
1977
				if ( is_array( $files ) ) {
1978
1979
					// Check if the folder contains a module.
1980
					foreach ( $files as $file ) {
1981
1982
						$info = wordpoints_get_module_data( $file, false, false );
1983
1984
						if ( ! empty( $info['name'] ) ) {
1985
							$source = new WP_Error(
0 ignored issues
show
Bug introduced by
The type WP_Error was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1986
								'wordpoints_module_archive_not_plugin'
1987
								, $source->get_error_message()
1988
								, __( 'This appears to be a WordPoints extension archive. Try installing it on the WordPoints extension install screen instead.', 'wordpoints' )
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1988
								, /** @scrutinizer ignore-call */ __( 'This appears to be a WordPoints extension archive. Try installing it on the WordPoints extension install screen instead.', 'wordpoints' )
Loading history...
1989
							);
1990
1991
							break;
1992
						}
1993
					}
1994
				}
1995
			}
1996
		}
1997
1998
		unset( $_source );
1999
2000
	} // End if ( ! isset( $_source ) ) else.
2001
2002
	return $source;
2003
}
2004
2005
/**
2006
 * Add a sidebar to the general settings page.
2007
 *
2008
 * @since 1.1.0
2009
 *
2010
 * @WordPress\action wordpoints_admin_settings_bottom 5 Before other items are added.
2011
 */
2012
function wordpoints_admin_settings_screen_sidebar() {
2013
2014
	?>
2015
2016
	<div class="notice notice-info inline" style="height: 120px; margin-top: 50px;">
2017
		<div style="width:48%;float:left;">
2018
			<h3><?php esc_html_e( 'Like this plugin?', 'wordpoints' ); ?></h3>
0 ignored issues
show
Bug introduced by
The function esc_html_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2018
			<h3><?php /** @scrutinizer ignore-call */ esc_html_e( 'Like this plugin?', 'wordpoints' ); ?></h3>
Loading history...
2019
			<p>
2020
				<?php
2021
2022
				echo wp_kses(
0 ignored issues
show
Bug introduced by
The function wp_kses was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2022
				echo /** @scrutinizer ignore-call */ wp_kses(
Loading history...
2023
					sprintf(
2024
						// translators: URL for leaving a review of WordPoints on WordPress.org.
2025
						__( 'If you think WordPoints is great, let everyone know by giving it a <a href="%s">5 star rating</a>.', 'wordpoints' )
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2025
						/** @scrutinizer ignore-call */ 
2026
      __( 'If you think WordPoints is great, let everyone know by giving it a <a href="%s">5 star rating</a>.', 'wordpoints' )
Loading history...
2026
						, 'https://wordpress.org/support/view/plugin-reviews/wordpoints?rate=5#postform'
2027
					)
2028
					, array( 'a' => array( 'href' => true ) )
2029
				);
2030
2031
				?>
2032
			</p>
2033
			<p><?php esc_html_e( 'If you don&#8217;t think this plugin deserves 5 stars, please let us know how we can improve it.', 'wordpoints' ); ?></p>
2034
		</div>
2035
		<div style="width:48%;float:left;">
2036
			<h3><?php esc_html_e( 'Need help?', 'wordpoints' ); ?></h3>
2037
			<p>
2038
				<?php
2039
2040
				echo wp_kses(
2041
					sprintf(
2042
						// translators: URL of WordPoints plugin support forums WordPress.org.
2043
						__( 'Post your feature request or support question in the <a href="%s">support forums</a>', 'wordpoints' )
2044
						, 'https://wordpress.org/support/plugin/wordpoints'
2045
					)
2046
					, array( 'a' => array( 'href' => true ) )
2047
				);
2048
2049
				?>
2050
			</p>
2051
			<p><em><?php esc_html_e( 'Thank you for using WordPoints!', 'wordpoints' ); ?></em></p>
2052
		</div>
2053
	</div>
2054
2055
	<?php
2056
}
2057
2058
/**
2059
 * Display notices to the user on the administration panels.
2060
 *
2061
 * @since 1.8.0
2062
 *
2063
 * @WordPress\action admin_notices
2064
 */
2065
function wordpoints_admin_notices() {
2066
2067
	wordpoints_delete_admin_notice_option();
2068
2069
	if ( current_user_can( 'activate_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2069
	if ( /** @scrutinizer ignore-call */ current_user_can( 'activate_wordpoints_extensions' ) ) {
Loading history...
2070
2071
		if ( is_network_admin() ) {
0 ignored issues
show
Bug introduced by
The function is_network_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2071
		if ( /** @scrutinizer ignore-call */ is_network_admin() ) {
Loading history...
2072
2073
			$deactivated_modules = get_site_option( 'wordpoints_breaking_deactivated_modules' );
0 ignored issues
show
Bug introduced by
The function get_site_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2073
			$deactivated_modules = /** @scrutinizer ignore-call */ get_site_option( 'wordpoints_breaking_deactivated_modules' );
Loading history...
2074
2075 View Code Duplication
			if ( is_array( $deactivated_modules ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2076
				wordpoints_show_admin_error(
2077
					sprintf(
2078
						// translators: 1. Plugin version; 2. List of extensions.
2079
						__( 'WordPoints has deactivated the following extensions because of incompatibilities with WordPoints %1$s: %2$s', 'wordpoints' )
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2079
						/** @scrutinizer ignore-call */ 
2080
      __( 'WordPoints has deactivated the following extensions because of incompatibilities with WordPoints %1$s: %2$s', 'wordpoints' )
Loading history...
2080
						, WORDPOINTS_VERSION
2081
						, implode( ', ', $deactivated_modules )
2082
					)
2083
					, array(
2084
						'dismissible' => true,
2085
						'option'      => 'wordpoints_breaking_deactivated_modules',
2086
					)
2087
				);
2088
			}
2089
2090
			$incompatible_modules = get_site_option( 'wordpoints_incompatible_modules' );
2091
2092 View Code Duplication
			if ( is_array( $incompatible_modules ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2093
				wordpoints_show_admin_error(
2094
					sprintf(
2095
						// translators: 1. Plugin version; 2. List of extensions.
2096
						__( 'WordPoints has deactivated the following network-active extensions because of incompatibilities with WordPoints %1$s: %2$s', 'wordpoints' )
2097
						, WORDPOINTS_VERSION
2098
						, implode( ', ', $incompatible_modules )
2099
					)
2100
					, array(
2101
						'dismissible' => true,
2102
						'option'      => 'wordpoints_incompatible_modules',
2103
					)
2104
				);
2105
			}
2106
2107 View Code Duplication
		} else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2108
2109
			$incompatible_modules = get_option( 'wordpoints_incompatible_modules' );
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2109
			$incompatible_modules = /** @scrutinizer ignore-call */ get_option( 'wordpoints_incompatible_modules' );
Loading history...
2110
2111
			if ( is_array( $incompatible_modules ) ) {
2112
				wordpoints_show_admin_error(
2113
					sprintf(
2114
						// translators: 1. Plugin version; 2. List of extensions.
2115
						__( 'WordPoints has deactivated the following extensions on this site because of incompatibilities with WordPoints %1$s: %2$s', 'wordpoints' )
2116
						, WORDPOINTS_VERSION
2117
						, implode( ', ', $incompatible_modules )
2118
					)
2119
					, array(
2120
						'dismissible' => true,
2121
						'option'      => 'wordpoints_incompatible_modules',
2122
					)
2123
				);
2124
			}
2125
2126
		} // End if ( is_network_admin() ) else.
2127
2128
	} // End if ( user can activate modules ).
2129
2130
	if (
2131
		current_user_can( 'delete_wordpoints_extensions' )
2132
		&& (
2133
			! isset( $_REQUEST['action'] ) // WPCS: CSRF OK.
2134
			|| 'delete-selected' !== $_REQUEST['action'] // WPCS: CSRF OK.
2135
		)
2136
	) {
2137
2138
		$merged_extensions = get_site_option( 'wordpoints_merged_extensions' );
2139
2140
		if ( is_array( $merged_extensions ) && ! empty( $merged_extensions ) ) {
2141
2142
			foreach ( $merged_extensions as $i => $extension ) {
2143
				if ( true !== wordpoints_validate_module( $extension ) ) {
2144
					unset( $merged_extensions[ $i ] );
2145
				}
2146
			}
2147
2148
			update_site_option( 'wordpoints_merged_extensions', $merged_extensions );
0 ignored issues
show
Bug introduced by
The function update_site_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2148
			/** @scrutinizer ignore-call */ 
2149
   update_site_option( 'wordpoints_merged_extensions', $merged_extensions );
Loading history...
2149
2150
			if ( ! empty( $merged_extensions ) ) {
2151
2152
				$message = sprintf(
2153
					// translators: 1. Plugin version; 2. List of extensions.
2154
					__( 'WordPoints has deactivated the following extensions because their features have now been merged into WordPoints %1$s: %2$s.', 'wordpoints' )
2155
					, WORDPOINTS_VERSION
2156
					, implode( ', ', $merged_extensions )
2157
				);
2158
2159
				$message .= ' ';
2160
				$message .= __( 'You can now safely delete these extensions.', 'wordpoints' );
2161
				$message .= ' ';
2162
2163
				$url = admin_url(
0 ignored issues
show
Bug introduced by
The function admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2163
				$url = /** @scrutinizer ignore-call */ admin_url(
Loading history...
2164
					'admin.php?page=wordpoints_extensions&action=delete-selected'
2165
				);
2166
2167
				foreach ( $merged_extensions as $extension ) {
2168
					$url .= '&checked[]=' . rawurlencode( $extension );
2169
				}
2170
2171
				$url = wp_nonce_url( $url, 'bulk-modules' );
0 ignored issues
show
Bug introduced by
The function wp_nonce_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2171
				$url = /** @scrutinizer ignore-call */ wp_nonce_url( $url, 'bulk-modules' );
Loading history...
2172
2173
				$message .= '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Delete Unneeded Extensions', 'wordpoints' ) . '</a>';
0 ignored issues
show
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2173
				$message .= '<a href="' . /** @scrutinizer ignore-call */ esc_url( $url ) . '">' . esc_html__( 'Delete Unneeded Extensions', 'wordpoints' ) . '</a>';
Loading history...
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2173
				$message .= '<a href="' . esc_url( $url ) . '">' . /** @scrutinizer ignore-call */ esc_html__( 'Delete Unneeded Extensions', 'wordpoints' ) . '</a>';
Loading history...
2174
2175
				wordpoints_show_admin_message(
2176
					$message
2177
					, 'warning'
2178
					, array(
2179
						'dismissible' => true,
2180
						'option'      => 'wordpoints_merged_extensions',
2181
					)
2182
				);
2183
			}
2184
2185
		} // End if ( merged extensions ).
2186
2187
	} // End if ( user can delete and aren't deleting ).
2188
2189
	if ( is_wordpoints_network_active() ) {
2190
		wordpoints_admin_show_update_skipped_notices( 'install' );
2191
		wordpoints_admin_show_update_skipped_notices( 'update' );
2192
	}
2193
}
2194
2195
/**
2196
 * Handle a request to delete an option tied to an admin notice.
2197
 *
2198
 * @since 2.1.0
2199
 *
2200
 * @WordPress\action wp_ajax_wordpoints-delete-admin-notice-option
2201
 */
2202
function wordpoints_delete_admin_notice_option() {
2203
2204
	// Check if any notices have been dismissed.
2205
	$is_notice_dismissed = wordpoints_verify_nonce(
2206
		'_wpnonce'
2207
		, 'wordpoints_dismiss_notice-%s'
2208
		, array( 'wordpoints_notice' )
2209
		, 'post'
2210
	);
2211
2212
	if ( $is_notice_dismissed && isset( $_POST['wordpoints_notice'] ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $is_notice_dismissed of type integer|false is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
2213
2214
		$option = sanitize_key( $_POST['wordpoints_notice'] );
0 ignored issues
show
Bug introduced by
The function sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2214
		$option = /** @scrutinizer ignore-call */ sanitize_key( $_POST['wordpoints_notice'] );
Loading history...
2215
2216
		if ( ! is_network_admin() && 'wordpoints_incompatible_modules' === $option ) {
0 ignored issues
show
Bug introduced by
The function is_network_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2216
		if ( ! /** @scrutinizer ignore-call */ is_network_admin() && 'wordpoints_incompatible_modules' === $option ) {
Loading history...
2217
			delete_option( $option );
0 ignored issues
show
Bug introduced by
The function delete_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2217
			/** @scrutinizer ignore-call */ 
2218
   delete_option( $option );
Loading history...
2218
		} else {
2219
			wordpoints_delete_maybe_network_option( $option );
2220
		}
2221
	}
2222
2223
	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
0 ignored issues
show
Bug introduced by
The constant DOING_AJAX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
2224
		wp_die( '', 200 );
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2224
		/** @scrutinizer ignore-call */ 
2225
  wp_die( '', 200 );
Loading history...
2225
	}
2226
}
2227
2228
/**
2229
 * Save the screen options.
2230
 *
2231
 * @since 2.0.0
2232
 *
2233
 * @WordPress\action set-screen-option
2234
 *
2235
 * @param mixed  $sanitized The sanitized option value, or false if not sanitized.
2236
 * @param string $option    The option being saved.
2237
 * @param mixed  $value     The raw value supplied by the user.
2238
 *
2239
 * @return mixed The option value, sanitized if it is for one of the plugin's screens.
2240
 */
2241
function wordpoints_admin_set_screen_option( $sanitized, $option, $value ) {
2242
2243
	switch ( $option ) {
2244
2245
		case 'wordpoints_page_wordpoints_extensions_per_page':
2246
		case 'wordpoints_page_wordpoints_extensions_network_per_page':
2247
		case 'toplevel_page_wordpoints_extensions_per_page':
2248
			$sanitized = wordpoints_posint( $value );
2249
			break;
2250
	}
2251
2252
	return $sanitized;
2253
}
2254
2255
/**
2256
 * Ajax callback to load the modules admin screen when running module compat checks.
2257
 *
2258
 * We run this Ajax action to check module compatibility before loading modules
2259
 * after WordPoints is updated to a new major version. This avoids breaking the site
2260
 * if some modules aren't compatible with the backward-incompatible changes that are
2261
 * present in a major version.
2262
 *
2263
 * @since 2.0.0
2264
 *
2265
 * @WordPress\action wp_ajax_nopriv_wordpoints_breaking_module_check
2266
 */
2267
function wordpoints_admin_ajax_breaking_module_check() {
2268
2269
	if ( ! isset( $_GET['wordpoints_module_check'] ) ) { // WPCS: CSRF OK.
2270
		wp_die( '', 400 );
0 ignored issues
show
Bug introduced by
The function wp_die was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2270
		/** @scrutinizer ignore-call */ 
2271
  wp_die( '', 400 );
Loading history...
2271
	}
2272
2273
	if ( is_network_admin() ) {
0 ignored issues
show
Bug introduced by
The function is_network_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2273
	if ( /** @scrutinizer ignore-call */ is_network_admin() ) {
Loading history...
2274
		$nonce = get_site_option( 'wordpoints_module_check_nonce' );
0 ignored issues
show
Bug introduced by
The function get_site_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2274
		$nonce = /** @scrutinizer ignore-call */ get_site_option( 'wordpoints_module_check_nonce' );
Loading history...
2275
	} else {
2276
		$nonce = get_option( 'wordpoints_module_check_nonce' );
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2276
		$nonce = /** @scrutinizer ignore-call */ get_option( 'wordpoints_module_check_nonce' );
Loading history...
2277
	}
2278
2279
	if ( ! $nonce || ! hash_equals( $nonce, sanitize_key( $_GET['wordpoints_module_check'] ) ) ) { // WPCS: CSRF OK.
0 ignored issues
show
Bug introduced by
The function sanitize_key was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2279
	if ( ! $nonce || ! hash_equals( $nonce, /** @scrutinizer ignore-call */ sanitize_key( $_GET['wordpoints_module_check'] ) ) ) { // WPCS: CSRF OK.
Loading history...
2280
		wp_die( '', 403 );
2281
	}
2282
2283
	// The list table constructor calls WP_Screen::get(), which expects this.
2284
	$GLOBALS['hook_suffix'] = null;
2285
2286
	wordpoints_admin_screen_modules();
2287
2288
	wp_die( '', 200 );
2289
}
2290
2291
/**
2292
 * Initialize the Ajax actions.
2293
 *
2294
 * @since 2.1.0
2295
 *
2296
 * @WordPress\action admin_init
2297
 */
2298
function wordpoints_hooks_admin_ajax() {
2299
2300
	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
0 ignored issues
show
Bug introduced by
The constant DOING_AJAX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
2301
		new WordPoints_Admin_Ajax_Hooks();
2302
	}
2303
}
2304
2305
/**
2306
 * Get the PHP version required for an update for the plugin.
2307
 *
2308
 * @since 2.3.0
2309
 *
2310
 * @return string|false The PHP version number, or false if no requirement could be
2311
 *                      determined. The version may be in x.y or x.y.z format.
2312
 */
2313
function wordpoints_admin_get_php_version_required_for_update() {
2314
2315
	$plugin_basename = plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
0 ignored issues
show
Bug introduced by
The function plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2315
	$plugin_basename = /** @scrutinizer ignore-call */ plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
Loading history...
2316
2317
	// We store this as a special field on the update plugins transient. That way it
2318
	// is cached, and we don't need to worry about keeping the cache in sync with
2319
	// this transient.
2320
	$updates = get_site_transient( 'update_plugins' );
0 ignored issues
show
Bug introduced by
The function get_site_transient was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2320
	$updates = /** @scrutinizer ignore-call */ get_site_transient( 'update_plugins' );
Loading history...
2321
2322
	if ( ! isset( $updates->response[ $plugin_basename ] ) ) {
2323
		return false;
2324
	}
2325
2326
	if ( ! isset( $updates->response[ $plugin_basename ]->wordpoints_required_php ) ) {
2327
2328
		/**
2329
		 * The plugin install functions.
2330
		 *
2331
		 * @since 2.3.0
2332
		 */
2333
		require_once ABSPATH . '/wp-admin/includes/plugin-install.php';
0 ignored issues
show
Bug introduced by
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
2334
2335
		$info = plugins_api(
0 ignored issues
show
Bug introduced by
The function plugins_api was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2335
		$info = /** @scrutinizer ignore-call */ plugins_api(
Loading history...
2336
			'plugin_information'
2337
			, array(
2338
				'slug'   => 'wordpoints',
2339
				// We need to use the default locale in case the pattern we need to
2340
				// search for would have gotten lost in translation.
2341
				'locale' => 'en_US',
2342
			)
2343
		);
2344
2345
		if ( is_wp_error( $info ) ) {
0 ignored issues
show
Bug introduced by
The function is_wp_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2345
		if ( /** @scrutinizer ignore-call */ is_wp_error( $info ) ) {
Loading history...
2346
			return false;
2347
		}
2348
2349
		preg_match(
2350
			'/requires php (\d+\.\d+(?:\.\d)?)/i'
2351
			, $info->sections['description']
2352
			, $matches
2353
		);
2354
2355
		$version = false;
2356
2357
		if ( ! empty( $matches[1] ) ) {
2358
			$version = $matches[1];
2359
		}
2360
2361
		$updates->response[ $plugin_basename ]->wordpoints_required_php = $version;
2362
2363
		set_site_transient( 'update_plugins', $updates );
0 ignored issues
show
Bug introduced by
The function set_site_transient was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2363
		/** @scrutinizer ignore-call */ 
2364
  set_site_transient( 'update_plugins', $updates );
Loading history...
2364
2365
	} // End if ( PHP requirements not in cache ).
2366
2367
	return $updates->response[ $plugin_basename ]->wordpoints_required_php;
2368
}
2369
2370
/**
2371
 * Checks if the PHP version meets the requirements of the next WordPoints update.
2372
 *
2373
 * @since 2.3.0
2374
 *
2375
 * @return bool Whether the PHP version meets the requirements of the next update.
2376
 */
2377
function wordpoints_admin_is_running_php_version_required_for_update() {
2378
2379
	$required_version = wordpoints_admin_get_php_version_required_for_update();
2380
2381
	// If there is no required version, then the requirement is met.
2382
	if ( ! $required_version ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $required_version of type false|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
2383
		return true;
2384
	}
2385
2386
	return version_compare( PHP_VERSION, $required_version, '>=' );
2387
}
2388
2389
/**
2390
 * Replaces the update notice with an error message when PHP requirements aren't met.
2391
 *
2392
 * Normally WordPress displays an update notice row in the plugins list table on the
2393
 * Plugins screen. However, if the next version of WordPoints requires a greater PHP
2394
 * version than is currently in use, we replace that row with an error message
2395
 * informing the user of the situation instead.
2396
 *
2397
 * @since 2.3.0
2398
 *
2399
 * @WordPress\action load-plugins.php
2400
 */
2401
function wordpoints_admin_maybe_disable_update_row_for_php_version_requirement() {
2402
2403
	if ( wordpoints_admin_is_running_php_version_required_for_update() ) {
2404
		return;
2405
	}
2406
2407
	$plugin_basename = plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
0 ignored issues
show
Bug introduced by
The function plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2407
	$plugin_basename = /** @scrutinizer ignore-call */ plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
Loading history...
2408
2409
	// Remove the default update row function.
2410
	remove_action( "after_plugin_row_{$plugin_basename}", 'wp_plugin_update_row', 10 );
0 ignored issues
show
Bug introduced by
The function remove_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2410
	/** @scrutinizer ignore-call */ 
2411
 remove_action( "after_plugin_row_{$plugin_basename}", 'wp_plugin_update_row', 10 );
Loading history...
2411
2412
	// And add a custom function of our own to output an error message.
2413
	add_action(
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2413
	/** @scrutinizer ignore-call */ 
2414
 add_action(
Loading history...
2414
		"after_plugin_row_{$plugin_basename}"
2415
		, 'wordpoints_admin_not_running_php_version_required_for_update_plugin_row'
2416
		, 10
2417
		, 2
2418
	);
2419
}
2420
2421
/**
2422
 * Outputs an error row for an update requiring a greater PHP version than is in use.
2423
 *
2424
 * This is used to replace the default update notice row that WordPress displays in
2425
 * the plugins table if an update for WordPoints requires a greater version of PHP
2426
 * than the site is currently running. This prevents the user from being able to
2427
 * update, and informs them of the situation so that they can take action to update
2428
 * their version of PHP.
2429
 *
2430
 * @since 2.3.0
2431
 *
2432
 * @WordPress\action after_plugin_row_wordpoints/wordpoints.php
2433
 *
2434
 * @param string $file        Plugin basename.
2435
 * @param array  $plugin_data Plugin data, as returned by the plugins API.
2436
 */
2437
function wordpoints_admin_not_running_php_version_required_for_update_plugin_row(
2438
	$file,
2439
	$plugin_data
2440
) {
2441
2442
	if ( is_multisite() && ! is_network_admin() ) {
0 ignored issues
show
Bug introduced by
The function is_network_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2442
	if ( is_multisite() && ! /** @scrutinizer ignore-call */ is_network_admin() ) {
Loading history...
Bug introduced by
The function is_multisite was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2442
	if ( /** @scrutinizer ignore-call */ is_multisite() && ! is_network_admin() ) {
Loading history...
2443
		return;
2444
	}
2445
2446
	// First check that there is actually an update available.
2447
	$updates = get_site_transient( 'update_plugins' );
0 ignored issues
show
Bug introduced by
The function get_site_transient was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2447
	$updates = /** @scrutinizer ignore-call */ get_site_transient( 'update_plugins' );
Loading history...
2448
2449
	if ( ! isset( $updates->response[ $file ] ) ) {
2450
		return;
2451
	}
2452
2453
	$response = $updates->response[ $file ];
2454
2455
	$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
0 ignored issues
show
Bug introduced by
The function _get_list_table was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2455
	$wp_list_table = /** @scrutinizer ignore-call */ _get_list_table( 'WP_Plugins_List_Table' );
Loading history...
2456
2457
	if ( is_network_admin() ) {
2458
		$active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
0 ignored issues
show
Bug introduced by
The function is_plugin_active_for_network was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2458
		$active_class = /** @scrutinizer ignore-call */ is_plugin_active_for_network( $file ) ? ' active' : '';
Loading history...
2459
	} else {
2460
		$active_class = is_plugin_active( $file ) ? ' active' : '';
0 ignored issues
show
Bug introduced by
The function is_plugin_active was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2460
		$active_class = /** @scrutinizer ignore-call */ is_plugin_active( $file ) ? ' active' : '';
Loading history...
2461
	}
2462
2463
	?>
2464
2465
	<tr
2466
		class="plugin-update-tr <?php echo esc_attr( $active_class ); ?>"
0 ignored issues
show
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2466
		class="plugin-update-tr <?php echo /** @scrutinizer ignore-call */ esc_attr( $active_class ); ?>"
Loading history...
2467
		id="<?php echo esc_attr( $response->slug . '-update' ); ?>"
2468
		data-slug="<?php echo esc_attr( $response->slug ); ?>"
2469
		data-plugin="<?php echo esc_attr( $file ); ?>"
2470
	>
2471
		<td
2472
			colspan="<?php echo esc_attr( $wp_list_table->get_column_count() ); ?>"
2473
			class="plugin-update colspanchange"
2474
		>
2475
			<div class="update-message inline notice notice-error notice-alt">
2476
				<p>
2477
					<?php esc_html_e( 'A WordPoints update is available, but your system is not compatible because it is running an outdated version of PHP.', 'wordpoints' ); ?>
0 ignored issues
show
Bug introduced by
The function esc_html_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2477
					<?php /** @scrutinizer ignore-call */ esc_html_e( 'A WordPoints update is available, but your system is not compatible because it is running an outdated version of PHP.', 'wordpoints' ); ?>
Loading history...
2478
					<?php
2479
2480
					echo wp_kses(
0 ignored issues
show
Bug introduced by
The function wp_kses was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2480
					echo /** @scrutinizer ignore-call */ wp_kses(
Loading history...
2481
						sprintf(
2482
							// translators: URL of WordPoints PHP Compatibility docs.
2483
							__( 'See <a href="%s">the WordPoints user guide</a> for more information.', 'wordpoints' )
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2483
							/** @scrutinizer ignore-call */ 
2484
       __( 'See <a href="%s">the WordPoints user guide</a> for more information.', 'wordpoints' )
Loading history...
2484
							, 'https://wordpoints.org/user-guide/php-compatibility/'
2485
						)
2486
						, array( 'a' => array( 'href' => true ) )
2487
					);
2488
2489
					?>
2490
				</p>
2491
			</div>
2492
		</td>
2493
	</tr>
2494
2495
	<?php
2496
2497
	// JavaScript to disable the bulk upgrade checkbox.
2498
	// See WP_Plugins_List_Table::single_row().
2499
	$checkbox_id = 'checkbox_' . md5( $plugin_data['Name'] );
2500
2501
	?>
2502
2503
	<script type="text/javascript">
2504
		document.getElementById(
2505
			<?php echo wp_json_encode( $checkbox_id ); ?>
0 ignored issues
show
Bug introduced by
The function wp_json_encode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2505
			<?php echo /** @scrutinizer ignore-call */ wp_json_encode( $checkbox_id ); ?>
Loading history...
2506
		).disabled = true;
2507
	</script>
2508
2509
	<?php
2510
}
2511
2512
/**
2513
 * Hides the plugin on the Updates screen if the PHP version requirements aren't met.
2514
 *
2515
 * On the Dashboard » Updates screen, WordPress displays a table of the available
2516
 * plugin updates. This function will prevent an update for WordPoints form being
2517
 * displayed in that table, if the PHP version requirements for that update are not
2518
 * met by the site.
2519
 *
2520
 * It is also used to hide the "Install Update Now" button in the plugin information
2521
 * dialog.
2522
 *
2523
 * @since 2.3.0
2524
 *
2525
 * @WordPress\action load-update-core.php
2526
 * @WordPress\action install_plugins_pre_plugin-information
2527
 */
2528
function wordpoints_admin_maybe_remove_from_updates_screen() {
2529
2530
	if ( wordpoints_admin_is_running_php_version_required_for_update() ) {
2531
		return;
2532
	}
2533
2534
	// Add filter to remove WordPoints from the update plugins list.
2535
	add_filter(
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2535
	/** @scrutinizer ignore-call */ 
2536
 add_filter(
Loading history...
2536
		'site_transient_update_plugins'
2537
		, 'wordpoints_admin_remove_wordpoints_from_update_plugins_transient'
2538
	);
2539
}
2540
2541
/**
2542
 * Filter callback to remove WordPoints from the update plugins list.
2543
 *
2544
 * @since 2.3.0
2545
 *
2546
 * @WordPress\filter site_transient_update_plugins
2547
 *                   Added by wordpoints_admin_maybe_remove_from_updates_screen().
2548
 *
2549
 * @param object $data Object of plugin update data.
2550
 *
2551
 * @return object The filtered object.
2552
 */
2553
function wordpoints_admin_remove_wordpoints_from_update_plugins_transient( $data ) {
2554
2555
	$plugin_basename = plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
0 ignored issues
show
Bug introduced by
The function plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2555
	$plugin_basename = /** @scrutinizer ignore-call */ plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
Loading history...
2556
2557
	if ( isset( $data->response[ $plugin_basename ] ) ) {
2558
		unset( $data->response[ $plugin_basename ] );
2559
	}
2560
2561
	return $data;
2562
}
2563
2564
/**
2565
 * Displays notices to admins when extension licenses are invalid, expired, etc.
2566
 *
2567
 * @since 2.4.0
2568
 *
2569
 * @WordPress\action admin_notices
2570
 */
2571
function wordpoints_admin_show_extension_license_notices() {
2572
2573
	// Don't show them on the extensions screen, because they would be shown before
2574
	// license activation notices, etc.
2575
	if ( isset( $_GET['page'] ) && 'wordpoints_extensions' === $_GET['page'] ) { // WPCS: CSRF OK.
2576
		return;
2577
	}
2578
2579
	if ( ! current_user_can( 'update_wordpoints_extensions' ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2579
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
2580
		return;
2581
	}
2582
2583
	foreach ( wordpoints_get_modules() as $extension ) {
2584
2585
		if ( empty( $extension['ID'] ) ) {
2586
			continue;
2587
		}
2588
2589
		$server = wordpoints_get_server_for_extension( $extension );
2590
2591
		if ( ! $server ) {
2592
			continue;
2593
		}
2594
2595
		$api = $server->get_api();
2596
2597
		if ( ! $api instanceof WordPoints_Extension_Server_API_LicensesI ) {
2598
			continue;
2599
		}
2600
2601
		$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
2602
			$extension['ID']
2603
			, $server
2604
		);
2605
2606
		if ( ! $api->extension_requires_license( $extension_data ) ) {
2607
			continue;
2608
		}
2609
2610
		$license_key = $extension_data->get( 'license_key' );
2611
2612 View Code Duplication
		if ( empty( $license_key ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2613
2614
			wordpoints_show_admin_error(
2615
				sprintf(
2616
					// translators: Extension name.
2617
					esc_html__( 'Please fill in your license key for the %s extension for WordPoints, so that you can receive updates.', 'wordpoints' )
0 ignored issues
show
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2617
					/** @scrutinizer ignore-call */ 
2618
     esc_html__( 'Please fill in your license key for the %s extension for WordPoints, so that you can receive updates.', 'wordpoints' )
Loading history...
2618
					, $extension['name']
2619
				)
2620
				. ' <a href="' . esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ) . '">' . esc_html__( 'WordPoints Extensions screen &raquo;', 'wordpoints' ) . '</a>'
0 ignored issues
show
Bug introduced by
The function self_admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2620
				. ' <a href="' . esc_url( /** @scrutinizer ignore-call */ self_admin_url( 'admin.php?page=wordpoints_extensions' ) ) . '">' . esc_html__( 'WordPoints Extensions screen &raquo;', 'wordpoints' ) . '</a>'
Loading history...
Bug introduced by
The function esc_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2620
				. ' <a href="' . /** @scrutinizer ignore-call */ esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ) . '">' . esc_html__( 'WordPoints Extensions screen &raquo;', 'wordpoints' ) . '</a>'
Loading history...
2621
			);
2622
2623
			continue;
2624
		}
2625
2626
		$license = $api->get_extension_license_object( $extension_data, $license_key );
2627
2628
		if ( ! $license->is_valid() ) {
2629
2630
			wordpoints_show_admin_error(
2631
				sprintf(
2632
					// translators: Extension name.
2633
					esc_html__( 'Your license key for the %s extension for WordPoints appears to be invalid. Please enter a valid license key so that you can receive updates.', 'wordpoints' )
2634
					, $extension['name']
2635
				)
2636
				. ' <a href="' . esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ) . '">' . esc_html__( 'WordPoints Extensions screen &raquo;', 'wordpoints' ) . '</a>'
2637
			);
2638
2639
		} elseif ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI && $license->is_expired() ) {
2640
2641
			if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_RenewableI && $license->is_renewable() ) {
2642
2643
				if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_Renewable_URLI ) {
2644
2645
					wordpoints_show_admin_error(
2646
						sprintf(
2647
							// translators: Extension name.
2648
							esc_html__( 'Your license key for the %s extension for WordPoints is expired. Please renew your license key so that you can receive updates.', 'wordpoints' )
2649
							, $extension['name']
2650
						)
2651
						. ' <a href="' . esc_url( $license->get_renewal_url() ) . '">' . esc_html__( 'Renew License', 'wordpoints' ) . '</a>'
2652
					);
2653
2654
				} else {
2655
2656
					wordpoints_show_admin_error(
2657
						sprintf(
2658
							// translators: Extension name.
2659
							esc_html__( 'Your license key for the %s extension for WordPoints is expired. Please renew your license key so that you can receive updates.', 'wordpoints' )
2660
							, $extension['name']
2661
						)
2662
						. ' <a href="' . esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ) . '">' . esc_html__( 'WordPoints Extensions screen &raquo;', 'wordpoints' ) . '</a>'
2663
					);
2664
				}
2665
2666
			} else {
2667
2668
				wordpoints_show_admin_error(
2669
					sprintf(
2670
						// translators: Extension name.
2671
						esc_html__( 'Your license key for the %s extension for WordPoints is expired. Please enter a valid license key so that you can receive updates.', 'wordpoints' )
2672
						, $extension['name']
2673
					)
2674
					. ' <a href="' . esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ) . '">' . esc_html__( 'WordPoints Extensions screen &raquo;', 'wordpoints' ) . '</a>'
2675
				);
2676
			}
2677
2678
		} elseif ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI && $license->is_activatable() && ! $license->is_active() ) {
2679
2680
			$extension_id = $extension['ID'];
2681
			$server_url   = sanitize_title_with_dashes( $server->get_slug() );
0 ignored issues
show
Bug introduced by
The function sanitize_title_with_dashes was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2681
			$server_url   = /** @scrutinizer ignore-call */ sanitize_title_with_dashes( $server->get_slug() );
Loading history...
2682
2683
			// translators: Extension name.
2684
			$aria_label = __( 'Activate License for %s WordPoints Extension', 'wordpoints' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2684
			$aria_label = /** @scrutinizer ignore-call */ __( 'Activate License for %s WordPoints Extension', 'wordpoints' );
Loading history...
2685
2686
			?>
2687
			<div class="notice notice-error">
2688
				<p>
2689
					<?php
2690
2691
					echo esc_html(
0 ignored issues
show
Bug introduced by
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2691
					echo /** @scrutinizer ignore-call */ esc_html(
Loading history...
2692
						sprintf(
2693
							// translators: Extension name.
2694
							__( 'Your license key for the %s extension for WordPoints is not active. Please activate it so that you can receive updates.', 'wordpoints' )
2695
							, $extension['name']
2696
						)
2697
					);
2698
2699
					?>
2700
				</p>
2701
				<form method="post" action="<?php echo esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ); ?>">
2702
					<input
2703
						id="license_key-<?php echo esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>"
0 ignored issues
show
Bug introduced by
The function esc_attr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2703
						id="license_key-<?php echo /** @scrutinizer ignore-call */ esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>"
Loading history...
2704
						name="license_key-<?php echo esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>"
2705
						type="hidden"
2706
						class="regular-text"
2707
						autocomplete="off"
2708
						value="<?php echo esc_attr( $license_key ); ?>"
2709
					/>
2710
					<?php wp_nonce_field( "wordpoints_activate_license_key-{$extension_id}", "wordpoints_activate_license_key-{$extension_id}" ); ?>
0 ignored issues
show
Bug introduced by
The function wp_nonce_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2710
					<?php /** @scrutinizer ignore-call */ wp_nonce_field( "wordpoints_activate_license_key-{$extension_id}", "wordpoints_activate_license_key-{$extension_id}" ); ?>
Loading history...
2711
					<p>
2712
						<input
2713
							type="submit"
2714
							name="activate-license-<?php echo esc_attr( $extension_id ); ?>"
2715
							class="button-secondary"
2716
							value="<?php esc_attr_e( 'Activate License', 'wordpoints' ); ?>"
0 ignored issues
show
Bug introduced by
The function esc_attr_e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2716
							value="<?php /** @scrutinizer ignore-call */ esc_attr_e( 'Activate License', 'wordpoints' ); ?>"
Loading history...
2717
							aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension_data['name'] ) ); ?>"
2718
						/>
2719
					</p>
2720
				</form>
2721
			</div>
2722
			<?php
2723
		}
2724
	}
2725
}
2726
2727
/**
2728
 * Shows the admin a notice if the update/install for an installable was skipped.
2729
 *
2730
 * @since 2.4.0
2731
 *
2732
 * @param string $notice_type The type of notices to display, 'update', or 'install'.
2733
 */
2734
function wordpoints_admin_show_update_skipped_notices( $notice_type = 'update' ) {
2735
2736
	$all_skipped = array_filter(
2737
		wordpoints_get_array_option( "wordpoints_network_{$notice_type}_skipped", 'site' )
2738
	);
2739
2740
	if ( empty( $all_skipped ) ) {
2741
		return;
2742
	}
2743
2744
	$messages = array();
2745
2746
	if ( 'install' === $notice_type ) {
2747
		// translators: 1. Extension/plugin name; 2. "extension", "plugin", or "component".
2748
		$message_template = __( 'WordPoints detected a large network and has skipped part of the installation process for &#8220;%1$s&#8221; %2$s.', 'wordpoints' );
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2748
		$message_template = /** @scrutinizer ignore-call */ __( 'WordPoints detected a large network and has skipped part of the installation process for &#8220;%1$s&#8221; %2$s.', 'wordpoints' );
Loading history...
2749
	} else {
2750
		// translators: 1. Extension/plugin name; 2. "extension", "plugin", or "component"; 3. Version number.
2751
		$message_template = __( 'WordPoints detected a large network and has skipped part of the update process for &#8220;%1$s&#8221; %2$s for version %3$s (and possibly later versions).', 'wordpoints' );
2752
	}
2753
2754
	foreach ( $all_skipped as $type => $skipped ) {
2755
2756
		switch ( $type ) {
2757
2758
			case 'module':
2759
				$capability = 'wordpoints_manage_network_modules';
2760
			break;
2761
2762
			default:
2763
				$capability = 'manage_network_plugins';
2764
		}
2765
2766
		if ( ! current_user_can( $capability ) ) {
0 ignored issues
show
Bug introduced by
The function current_user_can was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2766
		if ( ! /** @scrutinizer ignore-call */ current_user_can( $capability ) ) {
Loading history...
2767
			continue;
2768
		}
2769
2770
		switch ( $type ) {
2771
2772
			case 'module':
2773
				$type_name = __( '(extension)', 'wordpoints' );
2774
			break;
2775
2776
			case 'component':
2777
				$type_name = __( '(component)', 'wordpoints' );
2778
			break;
2779
2780
			default:
2781
				$type_name = __( '(plugin)', 'wordpoints' );
2782
		}
2783
2784
		foreach ( $skipped as $slug => $version ) {
2785
2786
			// Normally we might have used the installable's fancy name instead
2787
			// of the slug, but this is such an edge case to start with that I
2788
			// decided not to. Also of note: the version is only used in the
2789
			// update message.
2790
			$messages[] = esc_html(
0 ignored issues
show
Bug introduced by
The function esc_html was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2790
			$messages[] = /** @scrutinizer ignore-call */ esc_html(
Loading history...
2791
				sprintf(
2792
					$message_template
2793
					, $slug
2794
					, $type_name
2795
					, $version
2796
				)
2797
			);
2798
		}
2799
2800
	} // End foreach ( $all_skipped ).
2801
2802
	if ( ! empty( $messages ) ) {
2803
2804
		$message  = '<p>' . implode( '</p><p>', $messages ) . '</p>';
2805
		$message .= '<p>' . esc_html__( 'The rest of the process needs to be completed manually. If this has not been done already, some features may not function properly.', 'wordpoints' );
0 ignored issues
show
Bug introduced by
The function esc_html__ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2805
		$message .= '<p>' . /** @scrutinizer ignore-call */ esc_html__( 'The rest of the process needs to be completed manually. If this has not been done already, some features may not function properly.', 'wordpoints' );
Loading history...
2806
		$message .= ' <a href="https://wordpoints.org/user-guide/multisite/">' . esc_html__( 'Learn more.', 'wordpoints' ) . '</a></p>';
2807
2808
		$args = array(
2809
			'dismissible' => true,
2810
			'option'      => "wordpoints_network_{$notice_type}_skipped",
2811
		);
2812
2813
		wordpoints_show_admin_error( $message, $args );
2814
	}
2815
}
2816
2817
// EOF
2818