wordpoints_extension_license_row()   F
last analyzed

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_submenu_page(
126
		$main_menu
127
		, __( 'WordPoints — Extensions', 'wordpoints' )
128
		, esc_html__( 'Extensions', 'wordpoints' )
129
		, 'activate_wordpoints_extensions'
130
		, 'wordpoints_modules'
131
		, 'wordpoints_admin_screen_modules'
132
	);
133
134
	// Extensions install page.
135
	add_submenu_page(
136
		$main_menu
137
		, __( 'WordPoints — Install Extensions', 'wordpoints' )
138
		, esc_html__( 'Install Extensions', 'wordpoints' )
139
		, 'install_wordpoints_extensions'
140
		, 'wordpoints_install_extensions'
141
		, 'wordpoints_admin_screen_install_modules'
142
	);
143
144
	// Back-compat for extensions install page when the slug was "modules".
145
	add_submenu_page(
146
		$main_menu
147
		, __( 'WordPoints — Install Extensions', 'wordpoints' )
148
		, esc_html__( 'Install Extensions', 'wordpoints' )
149
		, 'install_wordpoints_extensions'
150
		, 'wordpoints_install_modules'
151
		, 'wordpoints_admin_screen_install_modules'
152
	);
153
}
154
155
/**
156
 * Corrects the display of "hidden" submenu items.
157
 *
158
 * @since 2.5.0
159
 *
160
 * @WordPress\filter submenu_file
161
 *
162
 * @param string $submenu_file The submenu file/slug.
163
 *
164
 * @return string The filtered submenu file/slug.
165
 */
166
function wordpoints_admin_submenu_filter( $submenu_file ) {
167
168
	global $plugin_page;
169
170
	$hidden_submenus = array(
171
		'wordpoints_install_extensions' => true,
172
		'wordpoints_install_modules'    => true,
173
		'wordpoints_modules'            => true,
174
	);
175
176
	if ( $plugin_page && isset( $hidden_submenus[ $plugin_page ] ) ) {
177
		$submenu_file = 'wordpoints_extensions';
178
	}
179
180
	$menu_slug = wordpoints_get_main_admin_menu();
181
182
	foreach ( $hidden_submenus as $submenu => $unused ) {
183
		remove_submenu_page( $menu_slug, $submenu );
0 ignored issues
show
Bug introduced by
The function remove_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

183
		/** @scrutinizer ignore-call */ 
184
  remove_submenu_page( $menu_slug, $submenu );
Loading history...
184
	}
185
186
	return $submenu_file;
187
}
188
189
/**
190
 * Display the modules admin screen.
191
 *
192
 * @since 1.2.0
193
 */
194
function wordpoints_admin_screen_modules() {
195
196
	/**
197
	 * The modules administration screen.
198
	 *
199
	 * @since 1.1.0
200
	 */
201
	require WORDPOINTS_DIR . 'admin/screens/modules.php';
202
}
203
204
/**
205
 * Set up for the modules screen.
206
 *
207
 * @since 1.1.0
208
 *
209
 * @WordPress\action load-wordpoints_page_wordpoints_extensions
210
 * @WordPress\action load-toplevel_page_wordpoints_extensions
211
 */
212
function wordpoints_admin_screen_modules_load() {
213
214
	/**
215
	 * Set up for the modules page.
216
	 *
217
	 * @since 1.1.0
218
	 */
219
	require WORDPOINTS_DIR . 'admin/screens/modules-load.php';
220
}
221
222
/**
223
 * Display the install modules admin screen.
224
 *
225
 * @since 1.1.0
226
 */
227
function wordpoints_admin_screen_install_modules() {
228
229
	/**
230
	 * The WordPoints > Install Modules admin panel.
231
	 *
232
	 * @since 1.1.0
233
	 */
234
	require WORDPOINTS_DIR . 'admin/screens/module-install.php';
235
}
236
237
/**
238
 * Set up for the configure screen.
239
 *
240
 * @since 1.5.0 As wordpoints_admin_sreen_configure_load().
241
 * @since 2.3.0
242
 *
243
 * @WordPress\action load-toplevel_page_wordpoints_configure
244
 */
245
function wordpoints_admin_screen_configure_load() {
246
247
	/**
248
	 * Set up for the WordPoints » Settings administration screen.
249
	 *
250
	 * @since 1.5.0
251
	 */
252
	require WORDPOINTS_DIR . 'admin/screens/configure-settings-load.php';
253
}
254
255
/**
256
 * Set up for the configure screen.
257
 *
258
 * @since 1.5.0
259
 * @deprecated 2.3.0 Use wordpoints_admin_screen_configure_load() instead.
260
 */
261
function wordpoints_admin_sreen_configure_load() {
262
263
	_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

263
	/** @scrutinizer ignore-call */ 
264
 _deprecated_function(
Loading history...
264
		__FUNCTION__
265
		, '2.3.0'
266
		, 'wordpoints_admin_screen_configure_load()'
267
	);
268
269
	wordpoints_admin_screen_configure_load();
270
}
271
272
/**
273
 * Activate/deactivate components.
274
 *
275
 * This function handles activation and deactivation of components from the
276
 * WordPoints » Settings » Components administration screen.
277
 *
278
 * @since 1.0.1
279
 *
280
 * @WordPress\action load-toplevel_page_wordpoints_configure
281
 */
282
function wordpoints_admin_activate_components() {
283
284
	/**
285
	 * Set up for the WordPoints > Components administration screen.
286
	 *
287
	 * @since 1.1.0
288
	 */
289
	require WORDPOINTS_DIR . 'admin/screens/configure-components-load.php';
290
}
291
292
/**
293
 * Register admin scripts and styles.
294
 *
295
 * @since 2.1.0
296
 *
297
 * @WordPress\action admin_init
298
 */
299
function wordpoints_register_admin_scripts() {
300
301
	$assets_url        = WORDPOINTS_URL . '/admin/assets';
302
	$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...
303
	$manifested_suffix = SCRIPT_DEBUG ? '.manifested' : '.min';
304
305
	// CSS
306
307
	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

307
	/** @scrutinizer ignore-call */ 
308
 wp_register_style(
Loading history...
308
		'wordpoints-admin-extensions-list-table'
309
		, "{$assets_url}/css/extensions-list-table{$suffix}.css"
310
		, array()
311
		, WORDPOINTS_VERSION
312
	);
313
314
	wp_register_style(
315
		'wordpoints-admin-extension-updates-table'
316
		, "{$assets_url}/css/extension-updates-table{$suffix}.css"
317
		, array()
318
		, WORDPOINTS_VERSION
319
	);
320
321
	wp_register_style(
322
		'wordpoints-hooks-admin'
323
		, "{$assets_url}/css/hooks{$suffix}.css"
324
		, array( 'dashicons', 'wp-jquery-ui-dialog' )
325
		, WORDPOINTS_VERSION
326
	);
327
328
	$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

328
	$styles = /** @scrutinizer ignore-call */ wp_styles();
Loading history...
329
	$styles->add_data( 'wordpoints-admin-extensions-list-table', 'rtl', 'replace' );
330
	$styles->add_data( 'wordpoints-hooks-admin', 'rtl', 'replace' );
331
332
	if ( $suffix ) {
333
		$styles->add_data( 'wordpoints-admin-extensions-list-table', 'suffix', $suffix );
334
		$styles->add_data( 'wordpoints-hooks-admin', 'suffix', $suffix );
335
	}
336
337
	// JS
338
339
	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

339
	/** @scrutinizer ignore-call */ 
340
 wp_register_script(
Loading history...
340
		'wordpoints-admin-dismiss-notice'
341
		, "{$assets_url}/js/dismiss-notice{$suffix}.js"
342
		, array( 'jquery', 'wp-util' )
343
		, WORDPOINTS_VERSION
344
	);
345
346
	wp_register_script(
347
		'wordpoints-hooks-models'
348
		, "{$assets_url}/js/hooks/models{$manifested_suffix}.js"
349
		, array( 'backbone', 'jquery-ui-dialog', 'wp-util' )
350
		, WORDPOINTS_VERSION
351
	);
352
353
	wp_register_script(
354
		'wordpoints-hooks-views'
355
		, "{$assets_url}/js/hooks/views{$manifested_suffix}.js"
356
		, array( 'wordpoints-hooks-models', 'wp-a11y' )
357
		, WORDPOINTS_VERSION
358
	);
359
360
	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

360
	/** @scrutinizer ignore-call */ 
361
 wp_localize_script(
Loading history...
361
		'wordpoints-hooks-views'
362
		, 'WordPointsHooksAdminL10n'
363
		, array(
364
			'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

364
			'unexpectedError'   => /** @scrutinizer ignore-call */ __( 'There was an unexpected error. Try reloading the page.', 'wordpoints' ),
Loading history...
365
			'changesSaved'      => __( 'Your changes have been saved.', 'wordpoints' ),
366
			// translators: Form field name.
367
			'emptyField'        => sprintf( __( '%s cannot be empty.', 'wordpoints' ), '{{ data.label }}' ),
368
			'confirmAboutTo'    => __( 'You are about to delete the following reaction:', 'wordpoints' ),
369
			'confirmDelete'     => __( 'Are you sure that you want to delete this reaction? This action cannot be undone.', 'wordpoints' ),
370
			'confirmTitle'      => __( 'Are you sure?', 'wordpoints' ),
371
			'deleteText'        => __( 'Delete', 'wordpoints' ),
372
			'cancelText'        => __( 'Cancel', 'wordpoints' ),
373
			'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

373
			'separator'         => /** @scrutinizer ignore-call */ is_rtl() ? ' « ' : ' » ',
Loading history...
374
			'target_label'      => __( 'Target', 'wordpoints' ),
375
			// translators: Form field.
376
			'cannotBeChanged'   => __( '(cannot be changed)', 'wordpoints' ),
377
			'fieldsInvalid'     => __( 'Error: the values of some fields are invalid. Please correct these and then try again.', 'wordpoints' ),
378
			'discardedReaction' => __( 'Discarded reaction.', 'wordpoints' ),
379
			'discardedChanges'  => __( 'Discarded changes.', 'wordpoints' ),
380
			'saving'            => __( 'Saving&hellp;', 'wordpoints' ),
381
			'deleting'          => __( 'Deleting&hellp;', 'wordpoints' ),
382
			'reactionDeleted'   => __( 'Reaction deleted successfully.', 'wordpoints' ),
383
			'reactionSaved'     => __( 'Reaction saved successfully.', 'wordpoints' ),
384
		)
385
	);
386
387
	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

387
	/** @scrutinizer ignore-call */ 
388
 wp_script_add_data(
Loading history...
388
		'wordpoints-hooks-views'
389
		, 'wordpoints-templates'
390
		, '
391
		<script type="text/template" id="tmpl-wordpoints-hook-reaction">
392
			<div class="view">
393
				<div class="title"></div>
394
				<button type="button" class="edit button">
395
					' . 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

395
					' . /** @scrutinizer ignore-call */ esc_html__( 'Edit', 'wordpoints' ) . '
Loading history...
396
				</button>
397
				<button type="button" class="close button">
398
					' . esc_html__( 'Close', 'wordpoints' ) . '
399
				</button>
400
			</div>
401
			<div class="form">
402
				<form>
403
					<div class="fields">
404
						<div class="settings"></div>
405
						<div class="target"></div>
406
					</div>
407
					<div class="messages">
408
						<div class="success"></div>
409
						<div class="err"></div>
410
					</div>
411
					<div class="actions">
412
						<div class="spinner-overlay">
413
							<span class="spinner is-active"></span>
414
						</div>
415
						<div class="action-buttons">
416
							<button type="button" class="save button button-primary" disabled>
417
								' . esc_html__( 'Save', 'wordpoints' ) . '
418
							</button>
419
							<button type="button" class="cancel button">
420
								' . esc_html__( 'Cancel', 'wordpoints' ) . '
421
							</button>
422
							<button type="button" class="close button">
423
								' . esc_html__( 'Close', 'wordpoints' ) . '
424
							</button>
425
							<button type="button" class="delete button">
426
								' . esc_html__( 'Delete', 'wordpoints' ) . '
427
							</button>
428
						</div>
429
					</div>
430
				</form>
431
			</div>
432
		</script>
433
434
		<script type="text/template" id="tmpl-wordpoints-hook-arg-selector">
435
			<div class="arg-selector">
436
				<label>
437
					{{ data.label }}
438
					<select name="{{ data.name }}"></select>
439
				</label>
440
			</div>
441
		</script>
442
443
		<script type="text/template" id="tmpl-wordpoints-hook-arg-option">
444
			<option value="{{ data.slug }}">{{ data.title }}</option>
445
		</script>
446
447
		<script type="text/template" id="tmpl-wordpoints-hook-reaction-field">
448
			<p class="description description-thin">
449
				<label>
450
					{{ data.label }}
451
					<input type="{{ data.type }}" class="widefat" name="{{ data.name }}"
452
					       value="{{ data.value }}"/>
453
				</label>
454
			</p>
455
		</script>
456
457
		<script type="text/template" id="tmpl-wordpoints-hook-reaction-select-field">
458
			<p class="description description-thin">
459
				<label>
460
					{{ data.label }}
461
					<select name="{{ data.name }}" class="widefat"></select>
462
				</label>
463
			</p>
464
		</script>
465
466
		<script type="text/template" id="tmpl-wordpoints-hook-reaction-hidden-field">
467
			<input type="hidden" name="{{ data.name }}" value="{{ data.value }}"/>
468
		</script>
469
		'
470
	);
471
472
	wp_register_script(
473
		'wordpoints-hooks-extension-conditions'
474
		, "{$assets_url}/js/hooks/extensions/conditions{$manifested_suffix}.js"
475
		, array( 'wordpoints-hooks-views' )
476
		, WORDPOINTS_VERSION
477
	);
478
479
	wp_script_add_data(
480
		'wordpoints-hooks-extension-conditions'
481
		, 'wordpoints-templates'
482
		, '
483
			<script type="text/template" id="tmpl-wordpoints-hook-condition-groups">
484
				<div class="conditions-title section-title">
485
					<h4>' . esc_html__( 'Conditions', 'wordpoints' ) . '</h4>
486
					<button type="button" class="add-new button wordpoints-hooks-icon-button">
487
						<span class="screen-reader-text">' . esc_html__( 'Add New Condition', 'wordpoints' ) . '</span>
488
						<span class="dashicons dashicons-plus"></span>
489
					</button>
490
				</div>
491
				<div class="add-condition-form hidden">
492
					<div class="no-conditions hidden">
493
						' . esc_html__( 'No conditions available.', 'wordpoints' ) . '
494
					</div>
495
					<div class="condition-selectors">
496
						<div class="arg-selectors"></div>
497
						<div class="condition-selector"></div>
498
					</div>
499
					<button type="button" class="confirm-add-new button" 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

499
					<button type="button" class="confirm-add-new button" disabled aria-label="' . /** @scrutinizer ignore-call */ esc_attr__( 'Add Condition', 'wordpoints' ) . '">
Loading history...
500
						' . 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

500
						' . /** @scrutinizer ignore-call */ esc_html_x( 'Add', 'reaction condition', 'wordpoints' ) . '
Loading history...
501
					</button>
502
					<button type="button" class="cancel-add-new button" aria-label="' . esc_attr__( 'Cancel Adding New Condition', 'wordpoints' ) . '">
503
						' . esc_html_x( 'Cancel', 'reaction condition', 'wordpoints' ) . '
504
					</button>
505
				</div>
506
				<div class="condition-groups section-content"></div>
507
			</script>
508
509
			<script type="text/template" id="tmpl-wordpoints-hook-reaction-condition-group">
510
				<div class="condition-group-title"></div>
511
			</script>
512
513
			<script type="text/template" id="tmpl-wordpoints-hook-reaction-condition">
514
				<div class="condition-controls">
515
					<div class="condition-title"></div>
516
					<button type="button" class="delete button wordpoints-hooks-icon-button">
517
						<span class="screen-reader-text">' . esc_html__( 'Remove Condition', 'wordpoints' ) . '</span>
518
						<span class="dashicons dashicons-no"></span>
519
					</button>
520
				</div>
521
				<div class="condition-settings"></div>
522
			</script>
523
524
			<script type="text/template" id="tmpl-wordpoints-hook-condition-selector">
525
				<label>
526
					{{ data.label }}
527
					<select name="{{ data.name }}"></select>
528
				</label>
529
			</script>
530
		'
531
	);
532
533
	wp_register_script(
534
		'wordpoints-hooks-extension-periods'
535
		, "{$assets_url}/js/hooks/extensions/periods{$manifested_suffix}.js"
536
		, array( 'wordpoints-hooks-views' )
537
		, WORDPOINTS_VERSION
538
	);
539
540
	wp_script_add_data(
541
		'wordpoints-hooks-extension-periods'
542
		, 'wordpoints-templates'
543
		, '
544
			<script type="text/template" id="tmpl-wordpoints-hook-periods">
545
				<div class="wordpoints-hook-periods">
546
					<div class="periods-title section-title">
547
						<h4>' . esc_html__( 'Rate Limit', 'wordpoints' ) . '</h4>
548
					</div>
549
					<div class="periods section-content"></div>
550
				</div>
551
			</script>
552
			
553
			<script type="text/template" id="tmpl-wordpoints-hook-reaction-simple-period">
554
				<div class="wordpoints-period">
555
					<input type="hidden" name="{{ data.name }}" value="{{ data.length }}" class="widefat wordpoints-hook-period-length" />
556
					<fieldset>
557
						<p class="description description-thin">
558
							<legend>{{ data.length_in_units_label }}</legend>
559
							<label>
560
								<span class="screen-reader-text">' . esc_html__( 'Time Units:', 'wordpoints' ) . '</span>
561
								<select class="widefat wordpoints-hook-period-sync wordpoints-hook-period-units"></select>
562
							</label>
563
							<label>
564
								<span class="screen-reader-text">' . esc_html__( 'Number:', 'wordpoints' ) . '</span>
565
								<input type="number" value="{{ data.length_in_units }}" class="widefat wordpoints-hook-period-sync wordpoints-hook-period-length-in-units" />
566
							</label>
567
						</p>
568
					</fieldset>
569
				</div>
570
			</script>
571
		'
572
	);
573
574
	wp_register_script(
575
		'wordpoints-hooks-extension-disable'
576
		, "{$assets_url}/js/hooks/extensions/disable{$manifested_suffix}.js"
577
		, array( 'wordpoints-hooks-views' )
578
		, WORDPOINTS_VERSION
579
	);
580
581
	wp_script_add_data(
582
		'wordpoints-hooks-extension-disable'
583
		, 'wordpoints-templates'
584
		, '
585
			<script type="text/template" id="tmpl-wordpoints-hook-disable">
586
				<div class="disable">
587
					<div class="section-title">
588
						<h4>' . esc_html__( 'Disable', 'wordpoints' ) . '</h4>
589
					</div>
590
					<div class="section-content">
591
						<p class="description description-thin">
592
							<label>
593
								<input type="checkbox" name="disable" value="1" />
594
								' . esc_html__( 'Disable (make this reaction inactive without deleting it)', 'wordpoints' ) . '
595
							</label>
596
						</p>
597
					</div>
598
				</div>
599
			</script>
600
			
601
			<script type="text/template" id="tmpl-wordpoints-hook-disabled-text">
602
				<span class="wordpoints-hook-disabled-text">' . esc_html__( '(Disabled)', 'wordpoints' ) . '</span>
603
			</script>
604
		'
605
	);
606
}
607
608
/**
609
 * Export the data for the scripts needed to make the hooks UI work.
610
 *
611
 * @since 2.1.0
612
 * @since 2.5.0 The $reactions_data and $events_data args were added.
613
 *
614
 * @param array $reactions_data Reaction data to send to the script.
615
 * @param array $events_data    Event data to send to the script.
616
 */
617
function wordpoints_hooks_ui_setup_script_data(
618
	array $reactions_data = array(),
619
	array $events_data = array()
620
) {
621
622
	$hooks = wordpoints_hooks();
623
624
	$extensions_data = wordpoints_hooks_ui_get_script_data_from_objects(
625
		$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

625
		/** @scrutinizer ignore-type */ $hooks->get_sub_app( 'extensions' )->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

625
		$hooks->get_sub_app( 'extensions' )->/** @scrutinizer ignore-call */ 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

625
		$hooks->get_sub_app( 'extensions' )->/** @scrutinizer ignore-call */ get_all()
Loading history...
626
		, 'extension'
627
	);
628
629
	$reactor_data = wordpoints_hooks_ui_get_script_data_from_objects(
630
		$hooks->get_sub_app( 'reactors' )->get_all()
631
		, 'reactor'
632
	);
633
634
	$event_action_types = wordpoints_hooks_ui_get_script_data_event_action_types();
635
	$entities_data      = wordpoints_hooks_ui_get_script_data_entities();
636
637
	$data = array(
638
		'fields'             => (object) array(),
639
		'reactions'          => (object) $reactions_data,
640
		'events'             => (object) $events_data,
641
		'extensions'         => $extensions_data,
642
		'entities'           => $entities_data,
643
		'reactors'           => $reactor_data,
644
		'event_action_types' => $event_action_types,
645
	);
646
647
	/**
648
	 * Filter the hooks data used to provide the UI.
649
	 *
650
	 * This is currently exported as JSON to the Backbone.js powered UI. But
651
	 * that could change in the future. The important thing is that the data is
652
	 * bing exported and will be used by something somehow.
653
	 *
654
	 * @param array $data The data.
655
	 */
656
	$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

656
	$data = /** @scrutinizer ignore-call */ apply_filters( 'wordpoints_hooks_ui_data', $data );
Loading history...
657
658
	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

658
	/** @scrutinizer ignore-call */ 
659
 wp_localize_script(
Loading history...
659
		'wordpoints-hooks-models'
660
		, 'WordPointsHooksAdminData'
661
		, $data
662
	);
663
}
664
665
/**
666
 * Get the UI script data from a bunch of objects.
667
 *
668
 * @since 2.1.0
669
 *
670
 * @param object[] $objects Objects that might provide script UI data.
671
 * @param string   $type    The type of objects. Used to automatically enqueue
672
 *                          scripts for the objects.
673
 *
674
 * @return array The data extracted from the objects.
675
 */
676
function wordpoints_hooks_ui_get_script_data_from_objects( $objects, $type ) {
677
678
	$data = array();
679
680
	foreach ( $objects as $slug => $object ) {
681
682
		if ( $object instanceof WordPoints_Hook_UI_Script_Data_ProviderI ) {
683
			$data[ $slug ] = $object->get_ui_script_data();
684
		}
685
686
		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

686
		if ( /** @scrutinizer ignore-call */ wp_script_is( "wordpoints-hooks-{$type}-{$slug}", 'registered' ) ) {
Loading history...
687
			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

687
			/** @scrutinizer ignore-call */ 
688
   wp_enqueue_script( "wordpoints-hooks-{$type}-{$slug}" );
Loading history...
688
		}
689
	}
690
691
	return $data;
692
}
693
694
/**
695
 * Get the entities data for use in the hooks UI.
696
 *
697
 * @since 2.1.0
698
 *
699
 * @return array The entities data for use in the hooks UI.
700
 */
701
function wordpoints_hooks_ui_get_script_data_entities() {
702
703
	$entities = wordpoints_entities();
704
705
	$entities_data = array();
706
707
	/** @var WordPoints_Class_Registry_Children $entity_children */
708
	$entity_children = $entities->get_sub_app( 'children' );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $entity_children is correct as $entities->get_sub_app('children') targeting WordPoints_App::get_sub_app() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
709
710
	/** @var WordPoints_Entity $entity */
711
	foreach ( $entities->get_all() as $slug => $entity ) {
712
713
		$child_data = array();
714
715
		/** @var WordPoints_EntityishI $child */
716
		foreach ( $entity_children->get_children( $slug ) as $child_slug => $child ) {
717
718
			$child_data[ $child_slug ] = array(
719
				'slug'  => $child_slug,
720
				'title' => $child->get_title(),
721
			);
722
723
			if ( $child instanceof WordPoints_Entity_Attr ) {
724
725
				$child_data[ $child_slug ]['_type']     = 'attr';
726
				$child_data[ $child_slug ]['data_type'] = $child->get_data_type();
727
728
			} elseif ( $child instanceof WordPoints_Entity_Relationship ) {
729
730
				$child_data[ $child_slug ]['_type']     = 'relationship';
731
				$child_data[ $child_slug ]['primary']   = $child->get_primary_entity_slug();
732
				$child_data[ $child_slug ]['secondary'] = $child->get_related_entity_slug();
733
			}
734
735
			/**
736
			 * Filter the data for an entity child.
737
			 *
738
			 * Entity children include attributes and relationships.
739
			 *
740
			 * @param array                $data  The data for the entity child.
741
			 * @param WordPoints_Entityish $child The child's object.
742
			 */
743
			$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

743
			$child_data[ $child_slug ] = /** @scrutinizer ignore-call */ apply_filters(
Loading history...
744
				'wordpoints_hooks_ui_data_entity_child'
745
				, $child_data[ $child_slug ]
746
				, $child
747
			);
748
		}
749
750
		$entities_data[ $slug ] = array(
751
			'slug'     => $slug,
752
			'title'    => $entity->get_title(),
753
			'children' => $child_data,
754
			'id_field' => $entity->get_id_field(),
755
			'_type'    => 'entity',
756
		);
757
758
		if ( $entity instanceof WordPoints_Entity_EnumerableI ) {
759
760
			$values = array();
761
762
			foreach ( $entity->get_enumerated_values() as $value ) {
763
				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

763
				if ( $entity->/** @scrutinizer ignore-call */ set_the_value( $value ) ) {
Loading history...
764
					$values[] = array(
765
						'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

765
						'value' => $entity->/** @scrutinizer ignore-call */ get_the_id(),
Loading history...
766
						'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

766
						'label' => $entity->/** @scrutinizer ignore-call */ get_the_human_id(),
Loading history...
767
					);
768
				}
769
			}
770
771
			$entities_data[ $slug ]['values'] = $values;
772
		}
773
774
		/**
775
		 * Filter the data for an entity.
776
		 *
777
		 * @param array             $data   The data for the entity.
778
		 * @param WordPoints_Entity $entity The entity object.
779
		 */
780
		$entities_data[ $slug ] = apply_filters(
781
			'wordpoints_hooks_ui_data_entity'
782
			, $entities_data[ $slug ]
783
			, $entity
784
		);
785
786
	} // End foreach ( entities ).
787
788
	return $entities_data;
789
}
790
791
/**
792
 * Get a list of action types for each event for the hooks UI script data.
793
 *
794
 * @since 2.1.0
795
 *
796
 * @return array The event action types.
797
 */
798
function wordpoints_hooks_ui_get_script_data_event_action_types() {
799
800
	// We want a list of the action types for each event. We can start with this list
801
	// but it is indexed by action slug and then action type and then event slug, so
802
	// we ned to do some processing.
803
	$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_App. ( Ignorable by Annotation )

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

803
	$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. ( Ignorable by Annotation )

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

803
	$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

803
	$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

803
	$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

803
	$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...
804
805
	// We don't care about the action slugs, so first we get rid of that bottom level
806
	// of the array.
807
	$event_index = call_user_func_array( 'array_merge_recursive', $event_index );
808
809
	$event_action_types = array();
810
811
	// This leaves us the event indexed by action type. But we actually need to flip
812
	// this, so that we have the action types indexed by event slug.
813
	foreach ( $event_index as $action_type => $events ) {
814
		foreach ( $events as $event => $unused ) {
815
			$event_action_types[ $event ][ $action_type ] = true;
816
		}
817
	}
818
819
	return $event_action_types;
820
}
821
822
/**
823
 * Append templates registered in wordpoints-templates script data to scripts.
824
 *
825
 * One day templates will probably be stored in separate files instead.
826
 *
827
 * @link https://core.trac.wordpress.org/ticket/31281
828
 *
829
 * @since 2.1.0
830
 *
831
 * @WordPress\filter script_loader_tag
832
 *
833
 * @param string $html   The HTML for the script.
834
 * @param string $handle The handle of the script.
835
 *
836
 * @return string The HTML with templates appended.
837
 */
838
function wordpoints_script_templates_filter( $html, $handle ) {
839
840
	global $wp_scripts;
841
842
	$templates = $wp_scripts->get_data( $handle, 'wordpoints-templates' );
843
844
	if ( $templates ) {
845
		$html .= $templates;
846
	}
847
848
	return $html;
849
}
850
851
/**
852
 * Display an error message.
853
 *
854
 * @since 1.0.0
855
 * @since 1.8.0 The $args parameter was added.
856
 *
857
 * @uses wordpoints_show_admin_message()
858
 *
859
 * @param string $message The text for the error message.
860
 * @param array  $args    Other optional arguments.
861
 */
862
function wordpoints_show_admin_error( $message, array $args = array() ) {
863
864
	wordpoints_show_admin_message( $message, 'error', $args );
865
}
866
867
/**
868
 * Display an update message.
869
 *
870
 * You should use {@see wordpoints_show_admin_error()} instead for showing error
871
 * messages. Currently there aren't wrappers for the other types, as they aren't used
872
 * in WordPoints core.
873
 *
874
 * @since 1.0.0
875
 * @since 1.2.0  The $type parameter is now properly escaped.
876
 * @since 1.8.0  The $message will be passed through wp_kses().
877
 * @since 1.8.0  The $args parameter was added with "dismissable" and "option" args.
878
 * @since 1.10.0 The "dismissable" arg was renamed to "dismissible".
879
 * @since 2.1.0  Now supports 'warning' and 'info' message types, and 'updated' is
880
 *               deprecated in favor of 'success'.
881
 *
882
 * @param string $message The text for the message.
883
 * @param string $type    The type of message to display, 'success' (default),
884
 *                        'error', 'warning' or 'info'.
885
 * @param array  $args    {
886
 *        Other optional arguments.
887
 *
888
 *        @type bool   $dismissible Whether this notice can be dismissed. Default is
889
 *                                  false (not dismissible).
890
 *        @type string $option      An option to delete when if message is dismissed.
891
 *                                  Required when $dismissible is true.
892
 * }
893
 */
894
function wordpoints_show_admin_message( $message, $type = 'success', array $args = array() ) {
895
896
	$defaults = array(
897
		'dismissible' => false,
898
		'option'      => '',
899
	);
900
901
	$args = array_merge( $defaults, $args );
902
903
	if ( isset( $args['dismissable'] ) ) {
904
905
		$args['dismissible'] = $args['dismissable'];
906
907
		_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

907
		/** @scrutinizer ignore-call */ 
908
  _deprecated_argument(
Loading history...
908
			__FUNCTION__
909
			, '1.10.0'
910
			, 'The "dismissable" argument has been replaced by the correct spelling, "dismissible".'
911
		);
912
	}
913
914
	if ( 'updated' === $type ) {
915
916
		$type = 'success';
917
918
		_deprecated_argument(
919
			__FUNCTION__
920
			, '2.1.0'
921
			, 'Use "success" instead of "updated" for the $type argument.'
922
		);
923
	}
924
925
	if ( $args['dismissible'] && $args['option'] ) {
926
		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

926
		/** @scrutinizer ignore-call */ 
927
  wp_enqueue_script( 'wordpoints-admin-dismiss-notice' );
Loading history...
927
	}
928
929
	?>
930
931
	<div
932
		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

932
		class="notice notice-<?php echo /** @scrutinizer ignore-call */ sanitize_html_class( $type, 'success' ); ?><?php echo ( $args['dismissible'] ) ? ' is-dismissible' : ''; ?>"
Loading history...
933
		<?php if ( $args['dismissible'] && $args['option'] ) : ?>
934
			data-nonce="<?php echo esc_attr( wp_create_nonce( "wordpoints_dismiss_notice-{$args['option']}" ) ); ?>"
0 ignored issues
show
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

934
			data-nonce="<?php echo esc_attr( /** @scrutinizer ignore-call */ wp_create_nonce( "wordpoints_dismiss_notice-{$args['option']}" ) ); ?>"
Loading history...
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

934
			data-nonce="<?php echo /** @scrutinizer ignore-call */ esc_attr( wp_create_nonce( "wordpoints_dismiss_notice-{$args['option']}" ) ); ?>"
Loading history...
935
			data-option="<?php echo esc_attr( $args['option'] ); ?>"
936
		<?php endif; ?>
937
		>
938
		<p>
939
			<?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

939
			<?php echo /** @scrutinizer ignore-call */ wp_kses( $message, 'wordpoints_admin_message' ); ?>
Loading history...
940
		</p>
941
		<?php if ( $args['dismissible'] && $args['option'] ) : ?>
942
			<form method="post" class="wordpoints-notice-dismiss-form" style="padding-bottom: 5px;">
943
				<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

943
				<input type="hidden" name="wordpoints_notice" value="<?php echo /** @scrutinizer ignore-call */ esc_html( $args['option'] ); ?>" />
Loading history...
944
				<?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

944
				<?php /** @scrutinizer ignore-call */ wp_nonce_field( "wordpoints_dismiss_notice-{$args['option']}" ); ?>
Loading history...
945
				<?php submit_button( __( 'Hide This Notice', 'wordpoints' ), '', '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

945
				<?php /** @scrutinizer ignore-call */ submit_button( __( 'Hide This Notice', 'wordpoints' ), '', '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

945
				<?php submit_button( /** @scrutinizer ignore-call */ __( 'Hide This Notice', 'wordpoints' ), '', 'wordpoints_dismiss_notice', false ); ?>
Loading history...
946
			</form>
947
		<?php endif; ?>
948
	</div>
949
950
	<?php
951
}
952
953
/**
954
 * Get the current tab.
955
 *
956
 * @since 1.0.0
957
 *
958
 * @param array $tabs The tabs. If passed, the first key will be returned if
959
 *        $_GET['tab'] is not set, or not one of the values in $tabs.
960
 *
961
 * @return string
962
 */
963
function wordpoints_admin_get_current_tab( array $tabs = null ) {
964
965
	$tab = '';
966
967
	if ( isset( $_GET['tab'] ) ) { // WPCS: CSRF OK.
968
969
		$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

969
		$tab = /** @scrutinizer ignore-call */ sanitize_key( $_GET['tab'] ); // WPCS: CSRF OK.
Loading history...
970
	}
971
972
	if ( isset( $tabs ) && ! isset( $tabs[ $tab ] ) ) {
973
974
		reset( $tabs );
975
		$tab = key( $tabs );
976
	}
977
978
	return $tab;
979
}
980
981
/**
982
 * Display a set of tabs.
983
 *
984
 * @since 1.0.0
985
 *
986
 * @uses wordpoints_admin_get_current_tab()
987
 *
988
 * @param string[] $tabs         The tabs. Keys are slugs, values displayed text.
989
 * @param bool     $show_heading Whether to show an <h1> element using the current
990
 *                               tab. Default is true.
991
 */
992
function wordpoints_admin_show_tabs( $tabs, $show_heading = true ) {
993
994
	$current = wordpoints_admin_get_current_tab( $tabs );
995
996
	if ( $show_heading ) {
997
998
		// translators: Current tab name.
999
		echo '<h1>', esc_html( sprintf( __( 'WordPoints — %s', 'wordpoints' ), $tabs[ $current ] ) ), '</h1>';
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

999
		echo '<h1>', esc_html( sprintf( /** @scrutinizer ignore-call */ __( 'WordPoints — %s', 'wordpoints' ), $tabs[ $current ] ) ), '</h1>';
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

999
		echo '<h1>', /** @scrutinizer ignore-call */ esc_html( sprintf( __( 'WordPoints — %s', 'wordpoints' ), $tabs[ $current ] ) ), '</h1>';
Loading history...
1000
	}
1001
1002
	echo '<h2 class="nav-tab-wrapper">';
1003
1004
	$page = '';
1005
1006
	if ( isset( $_GET['page'] ) ) { // WPCS: CSRF OK.
1007
		$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

1007
		$page = /** @scrutinizer ignore-call */ sanitize_key( $_GET['page'] ); // WPCS: CSRF OK.
Loading history...
1008
	}
1009
1010
	foreach ( $tabs as $tab => $name ) {
1011
1012
		$class = ( $tab === $current ) ? ' nav-tab-active' : '';
1013
1014
		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

1014
		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...
1015
	}
1016
1017
	echo '</h2>';
1018
}
1019
1020
/**
1021
 * Display the upload module from zip form.
1022
 *
1023
 * @since 1.1.0
1024
 *
1025
 * @WordPress\action wordpoints_install_extensions-upload
1026
 */
1027
function wordpoints_install_modules_upload() {
1028
1029
	?>
1030
1031
	<style type="text/css">
1032
		.wordpoints-upload-module {
1033
			display: block;
1034
		}
1035
	</style>
1036
1037
	<div class="upload-plugin wordpoints-upload-module">
1038
		<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

1038
		<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...
1039
		<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

1039
		<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

1039
		<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...
1040
			<?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

1040
			<?php /** @scrutinizer ignore-call */ wp_nonce_field( 'wordpoints-module-upload' ); ?>
Loading history...
1041
			<label class="screen-reader-text" for="modulezip"><?php esc_html_e( 'Extension zip file', 'wordpoints' ); ?></label>
1042
			<input type="file" id="modulezip" name="modulezip" />
1043
			<?php submit_button( __( 'Install Now', 'wordpoints' ), '', '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

1043
			<?php /** @scrutinizer ignore-call */ submit_button( __( 'Install Now', 'wordpoints' ), '', '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

1043
			<?php submit_button( /** @scrutinizer ignore-call */ __( 'Install Now', 'wordpoints' ), '', 'install-module-submit', false ); ?>
Loading history...
1044
		</form>
1045
	</div>
1046
1047
	<?php
1048
}
1049
1050
/**
1051
 * Perform module upload from .zip file.
1052
 *
1053
 * @since 1.1.0
1054
 *
1055
 * @WordPress\action update-custom_upload-wordpoints-module
1056
 */
1057
function wordpoints_upload_module_zip() {
1058
1059
	global $title, $parent_file, $submenu_file;
1060
1061 View Code Duplication
	if ( ! current_user_can( 'install_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

1061
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'install_wordpoints_extensions' ) ) {
Loading history...
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...
1062
		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

1062
		/** @scrutinizer ignore-call */ 
1063
  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

1062
		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...
1063
	}
1064
1065
	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

1065
	/** @scrutinizer ignore-call */ 
1066
 check_admin_referer( 'wordpoints-module-upload' );
Loading history...
1066
1067
	$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...
1068
1069
	$title        = esc_html__( 'Upload WordPoints Extension', 'wordpoints' );
1070
	$parent_file  = 'admin.php';
1071
	$submenu_file = 'admin.php';
1072
1073
	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...
1074
1075
	$upgrader = new WordPoints_Module_Installer(
1076
		new WordPoints_Module_Installer_Skin(
1077
			array(
1078
				// translators: File name.
1079
				'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

1079
				'title' => sprintf( esc_html__( 'Installing Extension from uploaded file: %s', 'wordpoints' ), /** @scrutinizer ignore-call */ esc_html( basename( $file_upload->filename ) ) ),
Loading history...
1080
				'nonce' => 'wordpoints-module-upload',
1081
				'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

1081
				'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

1081
				'url'   => add_query_arg( array( 'package' => $file_upload->id ), /** @scrutinizer ignore-call */ self_admin_url( 'update.php?action=upload-wordpoints-module' ) ),
Loading history...
1082
				'type'  => 'upload',
1083
			)
1084
		)
1085
	);
1086
1087
	$result = $upgrader->install( $file_upload->package );
1088
1089
	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

1089
	if ( $result || /** @scrutinizer ignore-call */ is_wp_error( $result ) ) {
Loading history...
1090
		$file_upload->cleanup();
1091
	}
1092
1093
	require ABSPATH . 'wp-admin/admin-footer.php';
1094
}
1095
1096
/**
1097
 * Handles a request to upgrade an extension, displaying the extension upgrade screen.
1098
 *
1099
 * @since 2.4.0
1100
 *
1101
 * @WordPress\action update-custom_wordpoints-upgrade-extension
1102
 */
1103
function wordpoints_admin_screen_upgrade_extension() {
1104
1105
	global $title, $parent_file;
1106
1107
	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

1107
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1108
		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

1108
		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

1108
		/** @scrutinizer ignore-call */ 
1109
  wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1109
	}
1110
1111
	$extension = ( isset( $_REQUEST['extension'] ) )
1112
		? 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

1112
		? 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

1112
		? /** @scrutinizer ignore-call */ sanitize_text_field( wp_unslash( $_REQUEST['extension'] ) ) // WPCS: CSRF OK.
Loading history...
1113
		: '';
1114
1115
	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

1115
	/** @scrutinizer ignore-call */ 
1116
 check_admin_referer( 'upgrade-extension_' . $extension );
Loading history...
1116
1117
	$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

1117
	$title       = /** @scrutinizer ignore-call */ __( 'Update WordPoints Extension', 'wordpoints' );
Loading history...
1118
	$parent_file = 'admin.php';
1119
1120
	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...
1121
1122
	$upgrader = new WordPoints_Extension_Upgrader(
1123
		new WordPoints_Extension_Upgrader_Skin(
1124
			array(
1125
				'title'     => $title,
1126
				'nonce'     => 'upgrade-extension_' . $extension,
1127
				'url'       => 'update.php?action=wordpoints-upgrade-extension&extension=' . rawurlencode( $extension ),
1128
				'extension' => $extension,
1129
			)
1130
		)
1131
	);
1132
1133
	$upgrader->upgrade( $extension );
1134
1135
	require ABSPATH . 'wp-admin/admin-footer.php';
1136
}
1137
1138
/**
1139
 * Reactivates an extension in an iframe after it was updated.
1140
 *
1141
 * @since 2.4.0
1142
 *
1143
 * @WordPress\action update-custom_wordpoints-reactivate-extension
1144
 */
1145
function wordpoints_admin_iframe_reactivate_extension() {
1146
1147
	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

1147
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1148
		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

1148
		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

1148
		/** @scrutinizer ignore-call */ 
1149
  wp_die( esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1149
	}
1150
1151
	$extension = ( isset( $_REQUEST['extension'] ) )
1152
		? 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

1152
		? 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

1152
		? /** @scrutinizer ignore-call */ sanitize_text_field( wp_unslash( $_REQUEST['extension'] ) ) // WPCS: CSRF OK.
Loading history...
1153
		: '';
1154
1155
	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

1155
	/** @scrutinizer ignore-call */ 
1156
 check_admin_referer( 'reactivate-extension_' . $extension );
Loading history...
1156
1157
	// First, activate the extension.
1158
	if ( ! isset( $_GET['failure'] ) && ! isset( $_GET['success'] ) ) {
1159
1160
		$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

1160
		$nonce = /** @scrutinizer ignore-call */ sanitize_key( $_GET['_wpnonce'] ); // @codingStandardsIgnoreLine
Loading history...
1161
		$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

1161
		$url   = /** @scrutinizer ignore-call */ admin_url( 'update.php?action=wordpoints-reactivate-extension&extension=' . rawurlencode( $extension ) . '&_wpnonce=' . $nonce );
Loading history...
1162
1163
		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

1163
		/** @scrutinizer ignore-call */ 
1164
  wp_safe_redirect( $url . '&failure=true' );
Loading history...
1164
		wordpoints_activate_module( $extension, '', ! empty( $_GET['network_wide'] ), true );
1165
		wp_safe_redirect( $url . '&success=true' );
1166
1167
		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...
1168
	}
1169
1170
	// Then we redirect back here to display the success or error message.
1171
	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

1171
	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

1171
	/** @scrutinizer ignore-call */ 
1172
 iframe_header( __( 'WordPoints Extension Reactivation', 'wordpoints' ) );
Loading history...
1172
1173
	if ( isset( $_GET['success'] ) ) {
1174
1175
		echo '<p>' . esc_html__( 'Extension reactivated successfully.', 'wordpoints' ) . '</p>';
1176
1177
	} elseif ( isset( $_GET['failure'] ) ) {
1178
1179
		echo '<p>' . esc_html__( 'Extension failed to reactivate due to a fatal error.', 'wordpoints' ) . '</p>';
1180
1181
		// Ensure that Fatal errors are displayed.
1182
		// @codingStandardsIgnoreStart
1183
		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 );
1184
		@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

1184
		/** @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

1184
		@ini_set( 'display_errors', /** @scrutinizer ignore-type */ true );
Loading history...
1185
		// @codingStandardsIgnoreEnd
1186
1187
		$file = wordpoints_extensions_dir() . '/' . $extension;
1188
		WordPoints_Module_Paths::register( $file );
1189
		include $file;
1190
	}
1191
1192
	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

1192
	/** @scrutinizer ignore-call */ 
1193
 iframe_footer();
Loading history...
1193
}
1194
1195
/**
1196
 * Handle updating multiple extensions on the extensions administration screen.
1197
 *
1198
 * @since 2.4.0
1199
 */
1200
function wordpoints_admin_screen_update_selected_extensions() {
1201
1202
	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

1202
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1203
		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

1203
		/** @scrutinizer ignore-call */ 
1204
  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

1203
		wp_die( /** @scrutinizer ignore-call */ esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1204
	}
1205
1206
	global $parent_file;
1207
1208
	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

1208
	/** @scrutinizer ignore-call */ 
1209
 check_admin_referer( 'bulk-wordpoints-extensions', 'nonce' );
Loading history...
1209
1210
	if ( isset( $_GET['extensions'] ) ) {
1211
		$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

1211
		$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

1211
		$extensions = explode( ',', sanitize_text_field( /** @scrutinizer ignore-call */ wp_unslash( $_GET['extensions'] ) ) );
Loading history...
1212
	} elseif ( isset( $_POST['checked'] ) ) {
1213
		$extensions = array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['checked'] ) );
1214
	} else {
1215
		$extensions = array();
1216
	}
1217
1218
	$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

1218
	$url = /** @scrutinizer ignore-call */ self_admin_url( 'update.php?action=update-selected-wordpoints-extensions&amp;extensions=' . rawurlencode( implode( ',', $extensions ) ) );
Loading history...
1219
	$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

1219
	$url = /** @scrutinizer ignore-call */ wp_nonce_url( $url, 'bulk-update-extensions' );
Loading history...
1220
1221
	$parent_file = 'admin.php';
1222
1223
	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...
1224
1225
	?>
1226
1227
	<div class="wrap">
1228
		<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

1228
		<h1><?php /** @scrutinizer ignore-call */ esc_html_e( 'Update WordPoints Extensions', 'wordpoints' ); ?></h1>
Loading history...
1229
1230
		<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

1230
		<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...
1231
	</div>
1232
1233
	<?php
1234
1235
	require_once ABSPATH . 'wp-admin/admin-footer.php';
1236
1237
	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...
1238
}
1239
1240
/**
1241
 * Handle bulk extension update requests from within an iframe.
1242
 *
1243
 * @since 2.4.0
1244
 */
1245
function wordpoints_iframe_update_extensions() {
1246
1247
	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

1247
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1248
		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

1248
		/** @scrutinizer ignore-call */ 
1249
  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

1248
		wp_die( /** @scrutinizer ignore-call */ esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1249
	}
1250
1251
	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

1251
	/** @scrutinizer ignore-call */ 
1252
 check_admin_referer( 'bulk-update-extensions' );
Loading history...
1252
1253
	$extensions = array();
1254
1255
	if ( isset( $_GET['extensions'] ) ) {
1256
		$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

1256
		$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

1256
		$extensions = explode( ',', /** @scrutinizer ignore-call */ sanitize_text_field( wp_unslash( $_GET['extensions'] ) ) );
Loading history...
1257
	}
1258
1259
	$extensions = array_map( 'rawurldecode', $extensions );
1260
1261
	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

1261
	/** @scrutinizer ignore-call */ 
1262
 wp_enqueue_script( 'jquery' );
Loading history...
1262
	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

1262
	/** @scrutinizer ignore-call */ 
1263
 iframe_header();
Loading history...
1263
1264
	$upgrader = new WordPoints_Extension_Upgrader(
1265
		new WordPoints_Extension_Upgrader_Skin_Bulk(
1266
			array(
1267
				'nonce' => 'bulk-update-extensions',
1268
				'url'   => 'update.php?action=update-selected-wordpoints-extensions&amp;extensions=' . rawurlencode( implode( ',', $extensions ) ),
1269
			)
1270
		)
1271
	);
1272
1273
	$upgrader->bulk_upgrade( $extensions );
1274
1275
	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

1275
	/** @scrutinizer ignore-call */ 
1276
 iframe_footer();
Loading history...
1276
}
1277
1278
/**
1279
 * Sets up the action hooks to display the extension update rows.
1280
 *
1281
 * @since 2.4.0
1282
 */
1283
function wordpoints_extension_update_rows() {
1284
1285
	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

1285
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1286
		return;
1287
	}
1288
1289
	$updates = wordpoints_get_extension_updates();
1290
1291
	foreach ( $updates->get_new_versions() as $extension_file => $version ) {
1292
		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

1292
		/** @scrutinizer ignore-call */ 
1293
  add_action( "wordpoints_after_module_row_{$extension_file}", 'wordpoints_extension_update_row', 10, 2 );
Loading history...
1293
	}
1294
}
1295
1296
/**
1297
 * Displays the update message for an extension in the extensions list table.
1298
 *
1299
 * @since 2.4.0
1300
 *
1301
 * @WordPress\action wordpoints_after_module_row_{$extension_file} Added by
1302
 *                   wordpoints_extension_update_rows().
1303
 */
1304
function wordpoints_extension_update_row( $file, $extension_data ) {
1305
1306
	$updates = wordpoints_get_extension_updates();
1307
1308
	if ( ! $updates->has_update( $file ) ) {
1309
		return;
1310
	}
1311
1312
	$server = wordpoints_get_server_for_extension( $extension_data );
1313
1314
	if ( ! $server ) {
1315
		return;
1316
	}
1317
1318
	$api = $server->get_api();
1319
1320
	if ( ! $api instanceof WordPoints_Extension_Server_API_UpdatesI ) {
1321
		return;
1322
	}
1323
1324
	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

1324
	/** @scrutinizer ignore-call */ 
1325
 wp_enqueue_script( 'thickbox' );
Loading history...
1325
	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

1325
	/** @scrutinizer ignore-call */ 
1326
 wp_enqueue_style( 'thickbox' );
Loading history...
1326
1327
	$new_version = $updates->get_new_version( $file );
1328
1329
	$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

1329
	$extension_name = /** @scrutinizer ignore-call */ wp_kses(
Loading history...
1330
		$extension_data['name']
1331
		, array(
1332
			'a'       => array( 'href' => array(), 'title' => array() ),
1333
			'abbr'    => array( 'title' => array() ),
1334
			'acronym' => array( 'title' => array() ),
1335
			'code'    => array(),
1336
			'em'      => array(),
1337
			'strong'  => array(),
1338
		)
1339
	);
1340
1341
	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

1341
	if ( /** @scrutinizer ignore-call */ is_network_admin() ) {
Loading history...
1342
		$is_active = is_wordpoints_module_active_for_network( $file );
1343
	} else {
1344
		$is_active = is_wordpoints_module_active( $file );
1345
	}
1346
1347
	?>
1348
1349
	<tr class="plugin-update-tr wordpoints-extension-update-tr <?php echo ( $is_active ) ? 'active' : 'inactive'; ?>">
1350
		<td colspan="<?php echo (int) WordPoints_Admin_List_Table_Extensions::instance()->get_column_count(); ?>" class="plugin-update wordpoints-extension-update colspanchange">
1351
			<div class="update-message notice inline notice-warning notice-alt">
1352
				<p>
1353
					<?php
1354
1355
					printf( // WPCS: XSS OK.
1356
						// translators: Extension name.
1357
						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

1357
						/** @scrutinizer ignore-call */ 
1358
      esc_html__( 'There is a new version of %1$s available.', 'wordpoints' )
Loading history...
1358
						, $extension_name
1359
					);
1360
1361
					?>
1362
1363
					<?php if ( $api instanceof WordPoints_Extension_Server_API_Updates_ChangelogI ) : ?>
1364
						<?php
1365
1366
						// translators: 1. Extension name; 2. Version.
1367
						$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

1367
						$message = /** @scrutinizer ignore-call */ __( 'View %1$s version %2$s details', 'wordpoints' );
Loading history...
1368
1369
						?>
1370
						<a
1371
							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

1371
							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

1371
							href="<?php echo /** @scrutinizer ignore-call */ esc_url( admin_url( 'update.php?action=wordpoints-iframe-extension-changelog&extension=' . rawurlencode( $file ) ) ); ?>"
Loading history...
1372
							class="thickbox wordpoints-open-extension-details-modal"
1373
							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

1373
							aria-label="<?php echo /** @scrutinizer ignore-call */ esc_attr( sprintf( $message, $extension_name, $new_version ) ); ?>"
Loading history...
1374
						>
1375
							<?php
1376
1377
							printf(
1378
								// translators: Version number.
1379
								esc_html__( 'View version %1$s details', 'wordpoints' )
1380
								, 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

1380
								, /** @scrutinizer ignore-call */ esc_html( $new_version )
Loading history...
1381
							);
1382
1383
							?>
1384
						</a>
1385
					<?php endif; ?>
1386
1387
					<?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

1387
					<?php if ( /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) : ?>
Loading history...
1388
						<span class="wordpoints-update-action-separator">|</span>
1389
						<?php if ( $api instanceof WordPoints_Extension_Server_API_Updates_InstallableI ) : ?>
1390
							<?php
1391
1392
							// translators: Extension name.
1393
							$message = sprintf( __( 'Update %s now', 'wordpoints' ), $extension_name );
1394
1395
							?>
1396
							<a
1397
								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 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

1397
								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...
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

1397
								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...
1398
								aria-label="<?php echo esc_attr( $message ); ?>"
1399
							>
1400
								<?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

1400
								<?php /** @scrutinizer ignore-call */ esc_html_e( 'Update now', 'wordpoints' ); ?>
Loading history...
1401
							</a>
1402
						<?php else : ?>
1403
							<em>
1404
								<?php esc_html_e( 'Automatic update is unavailable for this extension.', 'wordpoints' ); ?>
1405
							</em>
1406
						<?php endif; ?>
1407
					<?php endif; ?>
1408
1409
					<?php
1410
1411
					/**
1412
					 * Fires at the end of the update message container in each row
1413
					 * of the extensions list table.
1414
					 *
1415
					 * The dynamic portion of the hook name, `$file`, refers to the
1416
					 * path of the extension's primary file relative to the
1417
					 * extensions directory.
1418
					 *
1419
					 * @since 2.4.0
1420
					 *
1421
					 * @param array  $extension_data The extension's data.
1422
					 * @param string $new_version    The new version of the extension.
1423
					 */
1424
					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

1424
					/** @scrutinizer ignore-call */ 
1425
     do_action( "wordpoints_in_extension_update_message-{$file}", $extension_data, $new_version );
Loading history...
1425
1426
					?>
1427
				</p>
1428
			</div>
1429
		</td>
1430
	</tr>
1431
1432
	<?php
1433
}
1434
1435
/**
1436
 * Save extension license forms on submit.
1437
 *
1438
 * @since 2.4.0
1439
 *
1440
 * @WordPress\action wordpoints_modules_list_table_items
1441
 */
1442
function wordpoints_admin_save_extension_licenses( $extensions ) {
1443
1444
	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

1444
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1445
		return $extensions;
1446
	}
1447
1448
	foreach ( $extensions['all'] as $extension ) {
1449
1450
		if ( empty( $extension['ID'] ) ) {
1451
			continue;
1452
		}
1453
1454
		$server = wordpoints_get_server_for_extension( $extension );
1455
1456
		if ( ! $server ) {
1457
			continue;
1458
		}
1459
1460
		$api = $server->get_api();
1461
1462
		if ( ! $api instanceof WordPoints_Extension_Server_API_LicensesI ) {
1463
			continue;
1464
		}
1465
1466
		$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
1467
			$extension['ID']
1468
			, $server
1469
		);
1470
1471
		$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

1471
		$url = /** @scrutinizer ignore-call */ sanitize_title_with_dashes( $server->get_slug() );
Loading history...
1472
1473
		if ( ! isset( $_POST[ "license_key-{$url}-{$extension['ID']}" ] ) ) {
1474
			continue;
1475
		}
1476
1477
		$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

1477
		$license_key = /** @scrutinizer ignore-call */ sanitize_key(
Loading history...
1478
			$_POST[ "license_key-{$url}-{$extension['ID']}" ]
1479
		);
1480
1481
		$license = $api->get_extension_license_object( $extension_data, $license_key );
1482
1483
		if (
1484
			isset(
1485
				$_POST[ "activate-license-{$extension['ID']}" ]
1486
				, $_POST[ "wordpoints_activate_license_key-{$extension['ID']}" ]
1487
			)
1488
			&& wordpoints_verify_nonce(
1489
				"wordpoints_activate_license_key-{$extension['ID']}"
1490
				, "wordpoints_activate_license_key-{$extension['ID']}"
1491
				, null
1492
				, 'post'
1493
			)
1494
		) {
1495
1496
			if ( ! $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI ) {
1497
				continue;
1498
			}
1499
1500
			$result = $license->activate();
1501
1502
			if ( true === $result ) {
1503
				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

1503
				wordpoints_show_admin_message( /** @scrutinizer ignore-call */ esc_html__( 'License activated.', 'wordpoints' ) );
Loading history...
1504
				$extension_data->set( 'license_key', $license_key );
1505
				wordpoints_check_for_extension_updates_now();
1506
			} 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

1506
			} elseif ( /** @scrutinizer ignore-call */ is_wp_error( $result ) ) {
Loading history...
1507
				// translators: Error message.
1508
				wordpoints_show_admin_error( sprintf( esc_html__( 'Sorry, there was an error while trying to activate the license: %s', 'wordpoints' ), $result->get_error_message() ) );
1509
			} elseif ( ! $license->is_valid() ) {
1510
				wordpoints_show_admin_error( esc_html__( 'That license key is invalid.', 'wordpoints' ) );
1511
			} elseif ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI && $license->is_expired() ) {
1512
				if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_RenewableI && $license->is_renewable() ) {
1513 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...
1514
						wordpoints_show_admin_error(
1515
							esc_html__( 'Sorry, that license key is expired, and must be renewed.', 'wordpoints' )
1516
							. ' <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

1516
							. ' <a href="' . /** @scrutinizer ignore-call */ esc_url( $license->get_renewal_url() ) . '">' . esc_html__( 'Renew License', 'wordpoints' ) . '</a>'
Loading history...
1517
						);
1518
					} else {
1519
						wordpoints_show_admin_error( esc_html__( 'Sorry, that license key is expired, and must be renewed.', 'wordpoints' ) );
1520
					}
1521
				} else {
1522
					wordpoints_show_admin_error( esc_html__( 'Sorry, that license key is expired.', 'wordpoints' ) );
1523
				}
1524
1525
				$extension_data->set( 'license_key', $license_key );
1526
			} else {
1527
				wordpoints_show_admin_error( esc_html__( 'Sorry, that license key cannot be activated.', 'wordpoints' ) );
1528
			}
1529
1530
		} elseif (
1531
			isset(
1532
				$_POST[ "deactivate-license-{$extension['ID']}" ]
1533
				, $_POST[ "wordpoints_deactivate_license_key-{$extension['ID']}" ]
1534
			)
1535
			&& wordpoints_verify_nonce(
1536
				"wordpoints_deactivate_license_key-{$extension['ID']}"
1537
				, "wordpoints_deactivate_license_key-{$extension['ID']}"
1538
				, null
1539
				, 'post'
1540
			)
1541
		) {
1542
1543
			if ( ! $license instanceof WordPoints_Extension_Server_API_Extension_License_DeactivatableI ) {
1544
				continue;
1545
			}
1546
1547
			$result = $license->deactivate();
1548
1549
			if ( true === $result ) {
1550
				wordpoints_show_admin_message( esc_html__( 'License deactivated.', 'wordpoints' ) );
1551
			} elseif ( is_wp_error( $result ) ) {
1552
				// translators: Error message.
1553
				wordpoints_show_admin_error( sprintf( esc_html__( 'Sorry, there was an error while trying to deactivate the license: %s', 'wordpoints' ), $result->get_error_message() ) );
1554
			} else {
1555
				wordpoints_show_admin_error( esc_html__( 'Sorry, there was an unknown error while trying to deactivate that license key.', 'wordpoints' ) );
1556
			}
1557
1558
		} // End if ( activating license ) elseif ( deactivating license ).
1559
1560
	} // End foreach ( extension ).
1561
1562
	return $extensions;
1563
}
1564
1565
/**
1566
 * Filter the classes for a row in the WordPoints extensions list table.
1567
 *
1568
 * @since 2.4.0
1569
 *
1570
 * @WordPress\filter wordpoints_module_list_row_class
1571
 *
1572
 * @param string $classes        The HTML classes for this extension row.
1573
 * @param string $extension_file The extension file.
1574
 * @param array  $extension_data The extension data.
1575
 *
1576
 * @return string The filtered classes.
1577
 */
1578
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

1578
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...
1579
1580
	// Add license information if this user is allowed to see it.
1581
	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

1581
	if ( empty( $extension_data['ID'] ) || ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1582
		return $classes;
1583
	}
1584
1585
	$server = wordpoints_get_server_for_extension( $extension_data );
1586
1587
	if ( ! $server ) {
1588
		return $classes;
1589
	}
1590
1591
	$api = $server->get_api();
1592
1593
	if ( ! $api instanceof WordPoints_Extension_Server_API_LicensesI ) {
1594
		return $classes;
1595
	}
1596
1597
	$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
1598
		$extension_data['ID'],
1599
		$server
1600
	);
1601
1602
	if ( ! $api->extension_requires_license( $extension_data ) ) {
1603
		return $classes;
1604
	}
1605
1606
	$classes .= ' wordpoints-extension-has-license';
1607
1608
	$license = $api->get_extension_license_object(
1609
		$extension_data,
1610
		$extension_data->get( 'license_key' )
1611
	);
1612
1613
	if ( $license->is_valid() ) {
1614
		$classes .= ' wordpoints-extension-license-valid';
1615
	} else {
1616
		$classes .= ' wordpoints-extension-license-invalid';
1617
	}
1618
1619
	if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI ) {
1620
		if ( $license->is_active() ) {
1621
			$classes .= ' wordpoints-extension-license-active';
1622
		} else {
1623
			$classes .= ' wordpoints-extension-license-inactive';
1624
		}
1625
	}
1626
1627
	if (
1628
		$license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI
1629
		&& $license->is_expired()
1630
	) {
1631
		$classes .= ' wordpoints-extension-license-expired';
1632
	}
1633
1634
	return $classes;
1635
}
1636
1637
/**
1638
 * Add the license key rows to the extensions list table.
1639
 *
1640
 * @since 2.4.0
1641
 *
1642
 * @WordPress\action wordpoints_after_module_row
1643
 */
1644
function wordpoints_extension_license_row( $extension_file, $extension ) {
1645
1646
	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

1646
	if ( empty( $extension['ID'] ) || ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1647
		return;
1648
	}
1649
1650
	$server = wordpoints_get_server_for_extension( $extension );
1651
1652
	if ( ! $server ) {
1653
		return;
1654
	}
1655
1656
	$api = $server->get_api();
1657
1658
	if ( ! $api instanceof WordPoints_Extension_Server_API_LicensesI ) {
1659
		return;
1660
	}
1661
1662
	$extension_id = $extension['ID'];
1663
1664
	$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
1665
		$extension_id
1666
		, $server
1667
	);
1668
1669
	if ( ! $api->extension_requires_license( $extension_data ) ) {
1670
		return;
1671
	}
1672
1673
	$license_key = $extension_data->get( 'license_key' );
1674
	$license     = $api->get_extension_license_object( $extension_data, $license_key );
1675
	$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

1675
	$server_url  = /** @scrutinizer ignore-call */ sanitize_title_with_dashes( $server->get_slug() );
Loading history...
1676
1677
	$notice_type = 'error';
1678
1679
	if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI ) {
1680
		if ( ! empty( $license_key ) && $license->is_active() ) {
1681
			$notice_type = 'success';
1682
		} elseif ( empty( $license_key ) || $license->is_activatable() ) {
1683
			$notice_type = 'error';
1684
		}
1685
	}
1686
1687
	if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI ) {
1688
		if ( ! empty( $license_key ) && $license->is_expired() ) {
1689
			if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_RenewableI ) {
1690
				if ( $license->is_renewable() ) {
1691
					$notice_type = 'warning';
1692
				}
1693
			}
1694
		}
1695
	}
1696
1697
	// translators: Extension name.
1698
	$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

1698
	$aria_label = /** @scrutinizer ignore-call */ __( 'License key for %s', 'wordpoints' );
Loading history...
1699
1700
	?>
1701
	<tr class="wordpoints-extension-license-tr plugin-update-tr <?php echo ( is_wordpoints_module_active( $extension_file ) ) ? 'active' : 'inactive'; ?>">
1702
		<td colspan="<?php echo (int) WordPoints_Admin_List_Table_Extensions::instance()->get_column_count(); ?>" class="colspanchange">
1703
			<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

1703
			<div class="wordpoints-license-box notice inline notice-alt notice-<?php echo /** @scrutinizer ignore-call */ esc_attr( $notice_type ); ?>">
Loading history...
1704
				<p>
1705
				<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'] ) ); ?>">
1706
					<?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

1706
					<?php /** @scrutinizer ignore-call */ esc_html_e( 'License key:', 'wordpoints' ); ?>
Loading history...
1707
				</label>
1708
				<input
1709
					id="license_key-<?php echo esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>"
1710
					name="license_key-<?php echo esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>"
1711
					type="password"
1712
					class="regular-text"
1713
					autocomplete="off"
1714
					value="<?php echo esc_attr( $license_key ); ?>"
1715
				/>
1716
				<?php if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI ) : ?>
1717
					<?php if ( ! empty( $license_key ) && $license->is_active() ) : ?>
1718 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...
1719
							<?php
1720
1721
							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

1721
							/** @scrutinizer ignore-call */ 
1722
       wp_nonce_field( "wordpoints_deactivate_license_key-{$extension_id}", "wordpoints_deactivate_license_key-{$extension_id}" );
Loading history...
1722
1723
							// translators: Extension name.
1724
							$aria_label = __( 'Deactivate License for %s', 'wordpoints' );
1725
1726
							?>
1727
							<input type="submit" name="deactivate-license-<?php echo esc_attr( $extension_id ); ?>" class="button" 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

1727
							<input type="submit" name="deactivate-license-<?php echo esc_attr( $extension_id ); ?>" class="button" value="<?php /** @scrutinizer ignore-call */ esc_attr_e( 'Deactivate License', 'wordpoints' ); ?>" aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension['name'] ) ); ?>" />
Loading history...
1728
						<?php endif; ?>
1729 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...
1730
						<?php
1731
1732
						wp_nonce_field( "wordpoints_activate_license_key-{$extension_id}", "wordpoints_activate_license_key-{$extension_id}" );
1733
1734
						// translators: Extension name.
1735
						$aria_label = __( 'Activate License for %s', 'wordpoints' );
1736
1737
						?>
1738
						<input type="submit" name="activate-license-<?php echo esc_attr( $extension_id ); ?>" class="button" value="<?php esc_attr_e( 'Activate License', 'wordpoints' ); ?>" aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension['name'] ) ); ?>" />
1739
					<?php endif; ?>
1740
				<?php endif; ?>
1741
					<?php if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI ) : ?>
1742
						<?php if ( ! empty( $license_key ) && $license->is_expired() ) : ?>
1743
							<?php if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_RenewableI && $license->is_renewable() ) : ?>
1744
								<?php esc_html_e( 'This license key is expired and must be renewed.', 'wordpoints' ); ?>
1745
								<?php if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_Renewable_URLI ) : ?>
1746
									<?php
1747
1748
									// translators: Extension name.
1749
									$aria_label = __( 'Renew License for %s', 'wordpoints' );
1750
1751
									?>
1752
									<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

1752
									<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...
1753
								<?php endif; ?>
1754
							<?php else : ?>
1755
								<?php esc_html_e( 'This license key is expired.', 'wordpoints' ); ?>
1756
							<?php endif; ?>
1757
						<?php endif; ?>
1758
					<?php endif; ?>
1759
				</p>
1760
			</div>
1761
		</td>
1762
	</tr>
1763
	<?php
1764
}
1765
1766
/**
1767
 * Displays the changelog for an extension.
1768
 *
1769
 * @since 2.4.0
1770
 */
1771
function wordpoints_iframe_extension_changelog() {
1772
1773
	if ( ! defined( 'IFRAME_REQUEST' ) ) {
1774
		define( 'IFRAME_REQUEST', true ); // WPCS: prefix OK.
1775
	}
1776
1777
	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

1777
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
1778
		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

1778
		/** @scrutinizer ignore-call */ 
1779
  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

1778
		wp_die( /** @scrutinizer ignore-call */ esc_html__( 'Sorry, you are not allowed to update WordPoints extensions for this site.', 'wordpoints' ), 403 );
Loading history...
1779
	}
1780
1781
	if ( empty( $_GET['extension'] ) ) { // WPCS: CSRF OK.
1782
		wp_die( esc_html__( 'No extension supplied.', 'wordpoints' ), 200 );
1783
	}
1784
1785
	$extension_file = sanitize_text_field( rawurldecode( wp_unslash( $_GET['extension'] ) ) ); // WPCS: CSRF, sanitization 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

1785
	$extension_file = /** @scrutinizer ignore-call */ sanitize_text_field( rawurldecode( wp_unslash( $_GET['extension'] ) ) ); // WPCS: CSRF, sanitization 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

1785
	$extension_file = sanitize_text_field( rawurldecode( /** @scrutinizer ignore-call */ wp_unslash( $_GET['extension'] ) ) ); // WPCS: CSRF, sanitization OK.
Loading history...
1786
1787
	$extensions = wordpoints_get_modules();
1788
1789
	if ( ! isset( $extensions[ $extension_file ] ) ) {
1790
		wp_die( esc_html__( 'That extension does not exist.', 'wordpoints' ), 200 );
1791
	}
1792
1793
	$server = wordpoints_get_server_for_extension( $extensions[ $extension_file ] );
1794
1795
	if ( ! $server ) {
1796
		wp_die( esc_html__( 'There is no server specified for this extension.', 'wordpoints' ), 200 );
1797
	}
1798
1799
	$api = $server->get_api();
1800
1801
	if ( ! $api instanceof WordPoints_Extension_Server_API_Updates_ChangelogI ) {
1802
		wp_die( esc_html__( 'The server for this extension uses an unsupported API.', 'wordpoints' ), 200 );
1803
	}
1804
1805
	$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
1806
		$extensions[ $extension_file ]['ID']
1807
		, $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

1807
		, /** @scrutinizer ignore-type */ $server
Loading history...
1808
	);
1809
1810
	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

1810
	/** @scrutinizer ignore-call */ 
1811
 iframe_header();
Loading history...
1811
1812
	echo '<div style="margin-left: 10px;">';
1813
	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

1813
	echo /** @scrutinizer ignore-call */ wp_kses(
Loading history...
1814
		$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

1814
		$api->/** @scrutinizer ignore-call */ 
1815
        get_extension_changelog( $extension_data )
Loading history...
1815
		, 'wordpoints_extension_changelog'
1816
	);
1817
	echo '</div>';
1818
1819
	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

1819
	/** @scrutinizer ignore-call */ 
1820
 iframe_footer();
Loading history...
1820
}
1821
1822
/**
1823
 * Supply the list of HTML tags allowed in an extension changelog.
1824
 *
1825
 * @since 2.4.0
1826
 *
1827
 * @WordPress\filter wp_kses_allowed_html
1828
 */
1829
function wordpoints_extension_changelog_allowed_html( $allowed_tags, $context ) {
1830
1831
	if ( 'wordpoints_extension_changelog' !== $context ) {
1832
		return $allowed_tags;
1833
	}
1834
1835
	return array(
1836
		'a'       => array( 'href' => array(), 'title' => array(), 'target' => array() ),
1837
		'abbr'    => array( 'title' => array() ),
1838
		'acronym' => array( 'title' => array() ),
1839
		'code'    => array(),
1840
		'pre'     => array(),
1841
		'em'      => array(),
1842
		'strong'  => array(),
1843
		'div'     => array( 'class' => array() ),
1844
		'span'    => array( 'class' => array() ),
1845
		'p'       => array(),
1846
		'ul'      => array(),
1847
		'ol'      => array(),
1848
		'li'      => array(),
1849
		'h1'      => array(),
1850
		'h2'      => array(),
1851
		'h3'      => array(),
1852
		'h4'      => array(),
1853
		'h5'      => array(),
1854
		'h6'      => array(),
1855
		'img'     => array( 'src' => array(), 'class' => array(), 'alt' => array() ),
1856
	);
1857
}
1858
1859
/**
1860
 * List the available extension updates on the Updates screen.
1861
 *
1862
 * @since 2.4.0
1863
 */
1864
function wordpoints_list_extension_updates() {
1865
1866
	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

1866
	/** @scrutinizer ignore-call */ 
1867
 wp_enqueue_style( 'wordpoints-admin-extension-updates-table' );
Loading history...
1867
1868
	$updates      = wordpoints_get_extension_updates();
1869
	$new_versions = $updates->get_new_versions();
1870
1871
	?>
1872
1873
	<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

1873
	<h2><?php /** @scrutinizer ignore-call */ esc_html_e( 'WordPoints Extensions', 'wordpoints' ); ?></h2>
Loading history...
1874
1875
	<?php if ( empty( $new_versions ) ) : ?>
1876
		<p><?php esc_html_e( 'Your extensions are all up to date.', 'wordpoints' ); ?></p>
1877
		<?php return; // @codingStandardsIgnoreLine ?>
1878
	<?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...
1879
1880
	<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>
1881
1882
	<form method="post" action="update-core.php?action=do-wordpoints-extension-upgrade" name="upgrade-wordpoints-extensions" class="upgrade">
1883
		<?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

1883
		<?php /** @scrutinizer ignore-call */ wp_nonce_field( 'bulk-wordpoints-extensions', 'nonce' ); ?>
Loading history...
1884
1885
		<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

1885
		<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...
1886
1887
		<table class="widefat" id="update-wordpoints-extensions-table">
1888
			<thead>
1889
			<tr>
1890
				<td scope="col" class="manage-column check-column">
1891
					<input type="checkbox" id="wordpoints-extensions-select-all" />
1892
				</td>
1893
				<th scope="col" class="manage-column">
1894
					<label for="wordpoints-extensions-select-all"><?php esc_html_e( 'Select All', 'wordpoints' ); ?></label>
1895
				</th>
1896
			</tr>
1897
			</thead>
1898
1899
			<tbody class="wordpoints-extensions">
1900
			<?php foreach ( $new_versions as $extension_file => $new_version ) : ?>
1901
				<?php $extension_data = wordpoints_get_module_data( wordpoints_extensions_dir() . $extension_file ); ?>
1902
				<tr>
1903
					<th scope="row" class="check-column">
1904
						<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 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

1904
						<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...
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

1904
						<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...
1905
						<label for="checkbox_<?php echo esc_attr( sanitize_key( $extension_file ) ); ?>" class="screen-reader-text">
1906
							<?php
1907
1908
							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

1908
							echo /** @scrutinizer ignore-call */ esc_html(
Loading history...
1909
								sprintf(
1910
									// translators: Extension name.
1911
									__( '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

1911
									/** @scrutinizer ignore-call */ 
1912
         __( 'Select %s', 'wordpoints' )
Loading history...
1912
									, $extension_data['name']
1913
								)
1914
							);
1915
1916
							?>
1917
						</label>
1918
					</th>
1919
					<td>
1920
						<p>
1921
							<strong><?php echo esc_html( $extension_data['name'] ); ?></strong>
1922
							<br />
1923
							<?php
1924
1925
							echo esc_html(
1926
								sprintf(
1927
									// translators: 1. Installed version number; 2. Update version number.
1928
									__( 'You have version %1$s installed. Update to %2$s.', 'wordpoints' )
1929
									, $extension_data['version']
1930
									, $new_version
1931
								)
1932
							);
1933
1934
							?>
1935
							<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 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

1935
							<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...
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

1935
							<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...
1936
								<?php
1937
1938
								echo esc_html(
1939
									sprintf(
1940
										// translators: Version number.
1941
										__( 'View version %1$s details.', 'wordpoints' )
1942
										, $new_version
1943
									)
1944
								);
1945
1946
								?>
1947
							</a>
1948
						</p>
1949
					</td>
1950
				</tr>
1951
			<?php endforeach; ?>
1952
			</tbody>
1953
1954
			<tfoot>
1955
			<tr>
1956
				<td scope="col" class="manage-column check-column">
1957
					<input type="checkbox" id="wordpoints-extensions-select-all-2" />
1958
				</td>
1959
				<th scope="col" class="manage-column">
1960
					<label for="wordpoints-extensions-select-all-2"><?php esc_html_e( 'Select All', 'wordpoints' ); ?></label>
1961
				</th>
1962
			</tr>
1963
			</tfoot>
1964
		</table>
1965
		<p><input id="upgrade-wordpoints-extensions-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Extensions', 'wordpoints' ); ?>" name="upgrade" /></p>
1966
	</form>
1967
1968
	<?php
1969
}
1970
1971
/**
1972
 * Notify the user when they try to install a module on the plugins screen.
1973
 *
1974
 * The function is hooked to the upgrader_source_selection action twice. The first
1975
 * time it is called, we just save a local copy of the source path. This is
1976
 * necessary because the second time around the source will be a WP_Error if there
1977
 * are no plugins in it, but we have to have the source location so that we can check
1978
 * if it is a module instead of a plugin.
1979
 *
1980
 * @since 1.9.0
1981
 *
1982
 * @WordPress\action upgrader_source_selection See above for more info.
1983
 *
1984
 * @param string|WP_Error $source The module source.
1985
 *
1986
 * @return string|WP_Error The filtered module source.
1987
 */
1988
function wordpoints_plugin_upload_error_filter( $source ) {
1989
1990
	static $_source;
1991
1992
	if ( ! isset( $_source ) ) {
1993
1994
		$_source = $source;
1995
1996
	} else {
1997
1998
		global $wp_filesystem;
1999
2000
		if (
2001
			! 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

2001
			! /** @scrutinizer ignore-call */ is_wp_error( $_source )
Loading history...
2002
			&& is_wp_error( $source )
2003
			&& 'incompatible_archive_no_plugins' === $source->get_error_code()
2004
		) {
2005
2006
			$working_directory = str_replace(
2007
				$wp_filesystem->wp_content_dir()
2008
				, trailingslashit( WP_CONTENT_DIR )
0 ignored issues
show
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

2008
				, /** @scrutinizer ignore-call */ trailingslashit( WP_CONTENT_DIR )
Loading history...
Bug introduced by
The constant WP_CONTENT_DIR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
2009
				, $_source
2010
			);
2011
2012
			if ( is_dir( $working_directory ) ) {
2013
2014
				$files = glob( $working_directory . '*.php' );
2015
2016
				if ( is_array( $files ) ) {
2017
2018
					// Check if the folder contains a module.
2019
					foreach ( $files as $file ) {
2020
2021
						$info = wordpoints_get_module_data( $file, false, false );
2022
2023
						if ( ! empty( $info['name'] ) ) {
2024
							$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...
2025
								'wordpoints_module_archive_not_plugin'
2026
								, $source->get_error_message()
2027
								, __( '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

2027
								, /** @scrutinizer ignore-call */ __( 'This appears to be a WordPoints extension archive. Try installing it on the WordPoints extension install screen instead.', 'wordpoints' )
Loading history...
2028
							);
2029
2030
							break;
2031
						}
2032
					}
2033
				}
2034
			}
2035
		}
2036
2037
		unset( $_source );
2038
2039
	} // End if ( ! isset( $_source ) ) else.
2040
2041
	return $source;
2042
}
2043
2044
/**
2045
 * Add a sidebar to the general settings page.
2046
 *
2047
 * @since 1.1.0
2048
 *
2049
 * @WordPress\action wordpoints_admin_settings_bottom 5 Before other items are added.
2050
 */
2051
function wordpoints_admin_settings_screen_sidebar() {
2052
2053
	?>
2054
2055
	<div class="notice notice-info inline" style="height: 120px; margin-top: 50px;">
2056
		<div style="width:48%;float:left;">
2057
			<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

2057
			<h3><?php /** @scrutinizer ignore-call */ esc_html_e( 'Like this plugin?', 'wordpoints' ); ?></h3>
Loading history...
2058
			<p>
2059
				<?php
2060
2061
				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

2061
				echo /** @scrutinizer ignore-call */ wp_kses(
Loading history...
2062
					sprintf(
2063
						// translators: URL for leaving a review of WordPoints on WordPress.org.
2064
						__( '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

2064
						/** @scrutinizer ignore-call */ 
2065
      __( 'If you think WordPoints is great, let everyone know by giving it a <a href="%s">5 star rating</a>.', 'wordpoints' )
Loading history...
2065
						, 'https://wordpress.org/support/view/plugin-reviews/wordpoints?rate=5#postform'
2066
					)
2067
					, array( 'a' => array( 'href' => true ) )
2068
				);
2069
2070
				?>
2071
			</p>
2072
			<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>
2073
		</div>
2074
		<div style="width:48%;float:left;">
2075
			<h3><?php esc_html_e( 'Need help?', 'wordpoints' ); ?></h3>
2076
			<p>
2077
				<?php
2078
2079
				echo wp_kses(
2080
					sprintf(
2081
						// translators: URL of WordPoints plugin support forums WordPress.org.
2082
						__( 'Post your feature request or support question in the <a href="%s">support forums</a>', 'wordpoints' )
2083
						, 'https://wordpress.org/support/plugin/wordpoints'
2084
					)
2085
					, array( 'a' => array( 'href' => true ) )
2086
				);
2087
2088
				?>
2089
			</p>
2090
			<p><em><?php esc_html_e( 'Thank you for using WordPoints!', 'wordpoints' ); ?></em></p>
2091
		</div>
2092
	</div>
2093
2094
	<?php
2095
}
2096
2097
/**
2098
 * Display notices to the user on the administration panels.
2099
 *
2100
 * @since 1.8.0
2101
 *
2102
 * @WordPress\action admin_notices
2103
 */
2104
function wordpoints_admin_notices() {
2105
2106
	wordpoints_delete_admin_notice_option();
2107
2108
	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

2108
	if ( /** @scrutinizer ignore-call */ current_user_can( 'activate_wordpoints_extensions' ) ) {
Loading history...
2109
2110
		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

2110
		if ( /** @scrutinizer ignore-call */ is_network_admin() ) {
Loading history...
2111
2112
			$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

2112
			$deactivated_modules = /** @scrutinizer ignore-call */ get_site_option( 'wordpoints_breaking_deactivated_modules' );
Loading history...
2113
2114 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...
2115
				wordpoints_show_admin_error(
2116
					sprintf(
2117
						// translators: 1. Plugin version; 2. List of extensions.
2118
						__( '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

2118
						/** @scrutinizer ignore-call */ 
2119
      __( 'WordPoints has deactivated the following extensions because of incompatibilities with WordPoints %1$s: %2$s', 'wordpoints' )
Loading history...
2119
						, WORDPOINTS_VERSION
2120
						, implode( ', ', $deactivated_modules )
2121
					)
2122
					, array(
2123
						'dismissible' => true,
2124
						'option'      => 'wordpoints_breaking_deactivated_modules',
2125
					)
2126
				);
2127
			}
2128
2129
			$incompatible_modules = get_site_option( 'wordpoints_incompatible_modules' );
2130
2131 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...
2132
				wordpoints_show_admin_error(
2133
					sprintf(
2134
						// translators: 1. Plugin version; 2. List of extensions.
2135
						__( 'WordPoints has deactivated the following network-active extensions because of incompatibilities with WordPoints %1$s: %2$s', 'wordpoints' )
2136
						, WORDPOINTS_VERSION
2137
						, implode( ', ', $incompatible_modules )
2138
					)
2139
					, array(
2140
						'dismissible' => true,
2141
						'option'      => 'wordpoints_incompatible_modules',
2142
					)
2143
				);
2144
			}
2145
2146 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...
2147
2148
			$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

2148
			$incompatible_modules = /** @scrutinizer ignore-call */ get_option( 'wordpoints_incompatible_modules' );
Loading history...
2149
2150
			if ( is_array( $incompatible_modules ) ) {
2151
				wordpoints_show_admin_error(
2152
					sprintf(
2153
						// translators: 1. Plugin version; 2. List of extensions.
2154
						__( 'WordPoints has deactivated the following extensions on this site because of incompatibilities with WordPoints %1$s: %2$s', 'wordpoints' )
2155
						, WORDPOINTS_VERSION
2156
						, implode( ', ', $incompatible_modules )
2157
					)
2158
					, array(
2159
						'dismissible' => true,
2160
						'option'      => 'wordpoints_incompatible_modules',
2161
					)
2162
				);
2163
			}
2164
2165
		} // End if ( is_network_admin() ) else.
2166
2167
	} // End if ( user can activate modules ).
2168
2169
	if (
2170
		current_user_can( 'delete_wordpoints_extensions' )
2171
		&& (
2172
			! isset( $_REQUEST['action'] ) // WPCS: CSRF OK.
2173
			|| 'delete-selected' !== $_REQUEST['action'] // WPCS: CSRF OK.
2174
		)
2175
	) {
2176
2177
		$merged_extensions = get_site_option( 'wordpoints_merged_extensions' );
2178
2179
		if ( is_array( $merged_extensions ) && ! empty( $merged_extensions ) ) {
2180
2181
			foreach ( $merged_extensions as $i => $extension ) {
2182
				if ( true !== wordpoints_validate_module( $extension ) ) {
2183
					unset( $merged_extensions[ $i ] );
2184
				}
2185
			}
2186
2187
			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

2187
			/** @scrutinizer ignore-call */ 
2188
   update_site_option( 'wordpoints_merged_extensions', $merged_extensions );
Loading history...
2188
2189
			if ( ! empty( $merged_extensions ) ) {
2190
2191
				$message = sprintf(
2192
					// translators: 1. Plugin version; 2. List of extensions.
2193
					__( 'WordPoints has deactivated the following extensions because their features have now been merged into WordPoints %1$s: %2$s.', 'wordpoints' )
2194
					, WORDPOINTS_VERSION
2195
					, implode( ', ', $merged_extensions )
2196
				);
2197
2198
				$message .= ' ';
2199
				$message .= __( 'You can now safely delete these extensions.', 'wordpoints' );
2200
				$message .= ' ';
2201
2202
				$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

2202
				$url = /** @scrutinizer ignore-call */ admin_url(
Loading history...
2203
					'admin.php?page=wordpoints_extensions&action=delete-selected'
2204
				);
2205
2206
				foreach ( $merged_extensions as $extension ) {
2207
					$url .= '&checked[]=' . rawurlencode( $extension );
2208
				}
2209
2210
				$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

2210
				$url = /** @scrutinizer ignore-call */ wp_nonce_url( $url, 'bulk-modules' );
Loading history...
2211
2212
				$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

2212
				$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

2212
				$message .= '<a href="' . esc_url( $url ) . '">' . /** @scrutinizer ignore-call */ esc_html__( 'Delete Unneeded Extensions', 'wordpoints' ) . '</a>';
Loading history...
2213
2214
				wordpoints_show_admin_message(
2215
					$message
2216
					, 'warning'
2217
					, array(
2218
						'dismissible' => true,
2219
						'option'      => 'wordpoints_merged_extensions',
2220
					)
2221
				);
2222
			}
2223
2224
		} // End if ( merged extensions ).
2225
2226
	} // End if ( user can delete and aren't deleting ).
2227
2228
	if ( is_wordpoints_network_active() ) {
2229
		wordpoints_admin_show_update_skipped_notices( 'install' );
2230
		wordpoints_admin_show_update_skipped_notices( 'update' );
2231
	}
2232
}
2233
2234
/**
2235
 * Handle a request to delete an option tied to an admin notice.
2236
 *
2237
 * @since 2.1.0
2238
 *
2239
 * @WordPress\action wp_ajax_wordpoints-delete-admin-notice-option
2240
 */
2241
function wordpoints_delete_admin_notice_option() {
2242
2243
	// Check if any notices have been dismissed.
2244
	$is_notice_dismissed = wordpoints_verify_nonce(
2245
		'_wpnonce'
2246
		, 'wordpoints_dismiss_notice-%s'
2247
		, array( 'wordpoints_notice' )
2248
		, 'post'
2249
	);
2250
2251
	if ( $is_notice_dismissed && isset( $_POST['wordpoints_notice'] ) ) {
2252
2253
		$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

2253
		$option = /** @scrutinizer ignore-call */ sanitize_key( $_POST['wordpoints_notice'] );
Loading history...
2254
2255
		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

2255
		if ( ! /** @scrutinizer ignore-call */ is_network_admin() && 'wordpoints_incompatible_modules' === $option ) {
Loading history...
2256
			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

2256
			/** @scrutinizer ignore-call */ 
2257
   delete_option( $option );
Loading history...
2257
		} else {
2258
			wordpoints_delete_maybe_network_option( $option );
2259
		}
2260
	}
2261
2262
	if ( wp_doing_ajax() ) {
0 ignored issues
show
Bug introduced by
The function wp_doing_ajax 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

2262
	if ( /** @scrutinizer ignore-call */ wp_doing_ajax() ) {
Loading history...
2263
		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

2263
		/** @scrutinizer ignore-call */ 
2264
  wp_die( '', 200 );
Loading history...
2264
	}
2265
}
2266
2267
/**
2268
 * Save the screen options.
2269
 *
2270
 * @since 2.0.0
2271
 *
2272
 * @WordPress\action set-screen-option
2273
 *
2274
 * @param mixed  $sanitized The sanitized option value, or false if not sanitized.
2275
 * @param string $option    The option being saved.
2276
 * @param mixed  $value     The raw value supplied by the user.
2277
 *
2278
 * @return mixed The option value, sanitized if it is for one of the plugin's screens.
2279
 */
2280
function wordpoints_admin_set_screen_option( $sanitized, $option, $value ) {
2281
2282
	switch ( $option ) {
2283
2284
		case 'wordpoints_page_wordpoints_extensions_per_page':
2285
		case 'wordpoints_page_wordpoints_extensions_network_per_page':
2286
		case 'toplevel_page_wordpoints_extensions_per_page':
2287
			$sanitized = wordpoints_posint( $value );
2288
			break;
2289
	}
2290
2291
	return $sanitized;
2292
}
2293
2294
/**
2295
 * Ajax callback to load the modules admin screen when running module compat checks.
2296
 *
2297
 * We run this Ajax action to check module compatibility before loading modules
2298
 * after WordPoints is updated to a new major version. This avoids breaking the site
2299
 * if some modules aren't compatible with the backward-incompatible changes that are
2300
 * present in a major version.
2301
 *
2302
 * @since 2.0.0
2303
 *
2304
 * @WordPress\action wp_ajax_nopriv_wordpoints_breaking_module_check
2305
 */
2306
function wordpoints_admin_ajax_breaking_module_check() {
2307
2308
	if ( ! isset( $_GET['wordpoints_module_check'] ) ) { // WPCS: CSRF OK.
2309
		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

2309
		/** @scrutinizer ignore-call */ 
2310
  wp_die( '', 400 );
Loading history...
2310
	}
2311
2312
	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

2312
	if ( /** @scrutinizer ignore-call */ is_network_admin() ) {
Loading history...
2313
		$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

2313
		$nonce = /** @scrutinizer ignore-call */ get_site_option( 'wordpoints_module_check_nonce' );
Loading history...
2314
	} else {
2315
		$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

2315
		$nonce = /** @scrutinizer ignore-call */ get_option( 'wordpoints_module_check_nonce' );
Loading history...
2316
	}
2317
2318
	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

2318
	if ( ! $nonce || ! hash_equals( $nonce, /** @scrutinizer ignore-call */ sanitize_key( $_GET['wordpoints_module_check'] ) ) ) { // WPCS: CSRF OK.
Loading history...
2319
		wp_die( '', 403 );
2320
	}
2321
2322
	// The list table constructor calls WP_Screen::get(), which expects this.
2323
	$GLOBALS['hook_suffix'] = null;
2324
2325
	wordpoints_admin_screen_modules();
2326
2327
	wp_die( '', 200 );
2328
}
2329
2330
/**
2331
 * Initialize the Ajax actions.
2332
 *
2333
 * @since 2.1.0
2334
 *
2335
 * @WordPress\action admin_init
2336
 */
2337
function wordpoints_hooks_admin_ajax() {
2338
2339
	if ( wp_doing_ajax() ) {
0 ignored issues
show
Bug introduced by
The function wp_doing_ajax 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

2339
	if ( /** @scrutinizer ignore-call */ wp_doing_ajax() ) {
Loading history...
2340
		new WordPoints_Admin_Ajax_Hooks();
2341
	}
2342
}
2343
2344
/**
2345
 * Get the PHP version required for an update for the plugin.
2346
 *
2347
 * @since 2.3.0
2348
 *
2349
 * @return string|false The PHP version number, or false if no requirement could be
2350
 *                      determined. The version may be in x.y or x.y.z format.
2351
 */
2352
function wordpoints_admin_get_php_version_required_for_update() {
2353
2354
	$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

2354
	$plugin_basename = /** @scrutinizer ignore-call */ plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
Loading history...
2355
2356
	// We store this as a special field on the update plugins transient. That way it
2357
	// is cached, and we don't need to worry about keeping the cache in sync with
2358
	// this transient.
2359
	$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

2359
	$updates = /** @scrutinizer ignore-call */ get_site_transient( 'update_plugins' );
Loading history...
2360
2361
	if ( ! isset( $updates->response[ $plugin_basename ] ) ) {
2362
		return false;
2363
	}
2364
2365
	if ( ! isset( $updates->response[ $plugin_basename ]->wordpoints_required_php ) ) {
2366
2367
		/**
2368
		 * The plugin install functions.
2369
		 *
2370
		 * @since 2.3.0
2371
		 */
2372
		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...
2373
2374
		$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

2374
		$info = /** @scrutinizer ignore-call */ plugins_api(
Loading history...
2375
			'plugin_information'
2376
			, array(
2377
				'slug'   => 'wordpoints',
2378
				// We need to use the default locale in case the pattern we need to
2379
				// search for would have gotten lost in translation.
2380
				'locale' => 'en_US',
2381
			)
2382
		);
2383
2384
		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

2384
		if ( /** @scrutinizer ignore-call */ is_wp_error( $info ) ) {
Loading history...
2385
			return false;
2386
		}
2387
2388
		preg_match(
2389
			'/requires php (\d+\.\d+(?:\.\d)?)/i'
2390
			, $info->sections['description']
2391
			, $matches
2392
		);
2393
2394
		$version = false;
2395
2396
		if ( ! empty( $matches[1] ) ) {
2397
			$version = $matches[1];
2398
		}
2399
2400
		$updates->response[ $plugin_basename ]->wordpoints_required_php = $version;
2401
2402
		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

2402
		/** @scrutinizer ignore-call */ 
2403
  set_site_transient( 'update_plugins', $updates );
Loading history...
2403
2404
	} // End if ( PHP requirements not in cache ).
2405
2406
	return $updates->response[ $plugin_basename ]->wordpoints_required_php;
2407
}
2408
2409
/**
2410
 * Checks if the PHP version meets the requirements of the next WordPoints update.
2411
 *
2412
 * @since 2.3.0
2413
 *
2414
 * @return bool Whether the PHP version meets the requirements of the next update.
2415
 */
2416
function wordpoints_admin_is_running_php_version_required_for_update() {
2417
2418
	$required_version = wordpoints_admin_get_php_version_required_for_update();
2419
2420
	// If there is no required version, then the requirement is met.
2421
	if ( ! $required_version ) {
2422
		return true;
2423
	}
2424
2425
	return version_compare( PHP_VERSION, $required_version, '>=' );
2426
}
2427
2428
/**
2429
 * Replaces the update notice with an error message when PHP requirements aren't met.
2430
 *
2431
 * Normally WordPress displays an update notice row in the plugins list table on the
2432
 * Plugins screen. However, if the next version of WordPoints requires a greater PHP
2433
 * version than is currently in use, we replace that row with an error message
2434
 * informing the user of the situation instead.
2435
 *
2436
 * @since 2.3.0
2437
 *
2438
 * @WordPress\action load-plugins.php
2439
 */
2440
function wordpoints_admin_maybe_disable_update_row_for_php_version_requirement() {
2441
2442
	if ( wordpoints_admin_is_running_php_version_required_for_update() ) {
2443
		return;
2444
	}
2445
2446
	$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

2446
	$plugin_basename = /** @scrutinizer ignore-call */ plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
Loading history...
2447
2448
	// Remove the default update row function.
2449
	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

2449
	/** @scrutinizer ignore-call */ 
2450
 remove_action( "after_plugin_row_{$plugin_basename}", 'wp_plugin_update_row', 10 );
Loading history...
2450
2451
	// And add a custom function of our own to output an error message.
2452
	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

2452
	/** @scrutinizer ignore-call */ 
2453
 add_action(
Loading history...
2453
		"after_plugin_row_{$plugin_basename}"
2454
		, 'wordpoints_admin_not_running_php_version_required_for_update_plugin_row'
2455
		, 10
2456
		, 2
2457
	);
2458
}
2459
2460
/**
2461
 * Outputs an error row for an update requiring a greater PHP version than is in use.
2462
 *
2463
 * This is used to replace the default update notice row that WordPress displays in
2464
 * the plugins table if an update for WordPoints requires a greater version of PHP
2465
 * than the site is currently running. This prevents the user from being able to
2466
 * update, and informs them of the situation so that they can take action to update
2467
 * their version of PHP.
2468
 *
2469
 * @since 2.3.0
2470
 *
2471
 * @WordPress\action after_plugin_row_wordpoints/wordpoints.php
2472
 *
2473
 * @param string $file        Plugin basename.
2474
 * @param array  $plugin_data Plugin data, as returned by the plugins API.
2475
 */
2476
function wordpoints_admin_not_running_php_version_required_for_update_plugin_row(
2477
	$file,
2478
	$plugin_data
0 ignored issues
show
Unused Code introduced by
The parameter $plugin_data 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

2478
	/** @scrutinizer ignore-unused */ $plugin_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...
2479
) {
2480
2481
	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

2481
	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

2481
	if ( /** @scrutinizer ignore-call */ is_multisite() && ! is_network_admin() ) {
Loading history...
2482
		return;
2483
	}
2484
2485
	// First check that there is actually an update available.
2486
	$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

2486
	$updates = /** @scrutinizer ignore-call */ get_site_transient( 'update_plugins' );
Loading history...
2487
2488
	if ( ! isset( $updates->response[ $file ] ) ) {
2489
		return;
2490
	}
2491
2492
	$response = $updates->response[ $file ];
2493
2494
	$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

2494
	$wp_list_table = /** @scrutinizer ignore-call */ _get_list_table( 'WP_Plugins_List_Table' );
Loading history...
2495
2496
	if ( is_network_admin() ) {
2497
		$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

2497
		$active_class = /** @scrutinizer ignore-call */ is_plugin_active_for_network( $file ) ? ' active' : '';
Loading history...
2498
	} else {
2499
		$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

2499
		$active_class = /** @scrutinizer ignore-call */ is_plugin_active( $file ) ? ' active' : '';
Loading history...
2500
	}
2501
2502
	?>
2503
2504
	<tr
2505
		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

2505
		class="plugin-update-tr <?php echo /** @scrutinizer ignore-call */ esc_attr( $active_class ); ?>"
Loading history...
2506
		id="<?php echo esc_attr( $response->slug . '-update' ); ?>"
2507
		data-slug="<?php echo esc_attr( $response->slug ); ?>"
2508
		data-plugin="<?php echo esc_attr( $file ); ?>"
2509
	>
2510
		<td
2511
			colspan="<?php echo esc_attr( $wp_list_table->get_column_count() ); ?>"
2512
			class="plugin-update colspanchange"
2513
		>
2514
			<div class="update-message inline notice notice-error notice-alt">
2515
				<p>
2516
					<?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

2516
					<?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...
2517
					<?php
2518
2519
					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

2519
					echo /** @scrutinizer ignore-call */ wp_kses(
Loading history...
2520
						sprintf(
2521
							// translators: URL of WordPoints PHP Compatibility docs.
2522
							__( '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

2522
							/** @scrutinizer ignore-call */ 
2523
       __( 'See <a href="%s">the WordPoints user guide</a> for more information.', 'wordpoints' )
Loading history...
2523
							, 'https://wordpoints.org/user-guide/php-compatibility/'
2524
						)
2525
						, array( 'a' => array( 'href' => true ) )
2526
					);
2527
2528
					?>
2529
				</p>
2530
			</div>
2531
		</td>
2532
	</tr>
2533
2534
	<?php
2535
}
2536
2537
/**
2538
 * Prevents updates when they require a greater PHP version than is in use.
2539
 *
2540
 * @since 2.5.0
2541
 *
2542
 * @WordPress\filter upgrader_pre_install
2543
 *
2544
 * @param WP_Error|true $result     Whether or not to install the package.
2545
 * @param array         $hook_extra Information about the package being installed.
2546
 *
2547
 * @return WP_Error|true Whether or not to install the package.
2548
 */
2549
function wordpoints_admin_maybe_prevent_plugin_updates( $result, $hook_extra ) {
2550
2551
	$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

2551
	$plugin_basename = /** @scrutinizer ignore-call */ plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
Loading history...
2552
2553
	if (
2554
		isset( $hook_extra['plugin'] )
2555
		&& $plugin_basename === $hook_extra['plugin']
2556
		&& ! wordpoints_admin_is_running_php_version_required_for_update()
2557
	) {
2558
2559
		$message  = esc_html__( 'Your system is not compatible with this WordPoints update because it is running an outdated version of PHP.', '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

2559
		$message  = /** @scrutinizer ignore-call */ esc_html__( 'Your system is not compatible with this WordPoints update because it is running an outdated version of PHP.', 'wordpoints' );
Loading history...
2560
		$message .= ' ';
2561
		$message .= sprintf(
2562
			// translators: URL of WordPoints PHP Compatibility docs.
2563
			__( 'See the WordPoints user guide for more information: %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

2563
			/** @scrutinizer ignore-call */ 
2564
   __( 'See the WordPoints user guide for more information: %s', 'wordpoints' )
Loading history...
2564
			, 'https://wordpoints.org/user-guide/php-compatibility/'
2565
		);
2566
2567
		$result = new WP_Error(
2568
			'wordpoints_php_version_incompatible'
2569
			, $message
2570
		);
2571
	}
2572
2573
	return $result;
2574
}
2575
2576
/**
2577
 * Hides the plugin on the Updates screen if the PHP version requirements aren't met.
2578
 *
2579
 * On the Dashboard » Updates screen, WordPress displays a table of the available
2580
 * plugin updates. This function will prevent an update for WordPoints form being
2581
 * displayed in that table, if the PHP version requirements for that update are not
2582
 * met by the site.
2583
 *
2584
 * It is also used to hide the "Install Update Now" button in the plugin information
2585
 * dialog.
2586
 *
2587
 * @since 2.3.0
2588
 *
2589
 * @WordPress\action load-update-core.php
2590
 * @WordPress\action install_plugins_pre_plugin-information
2591
 */
2592
function wordpoints_admin_maybe_remove_from_updates_screen() {
2593
2594
	if ( wordpoints_admin_is_running_php_version_required_for_update() ) {
2595
		return;
2596
	}
2597
2598
	// Add filter to remove WordPoints from the update plugins list.
2599
	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

2599
	/** @scrutinizer ignore-call */ 
2600
 add_filter(
Loading history...
2600
		'site_transient_update_plugins'
2601
		, 'wordpoints_admin_remove_wordpoints_from_update_plugins_transient'
2602
	);
2603
}
2604
2605
/**
2606
 * Filter callback to remove WordPoints from the update plugins list.
2607
 *
2608
 * @since 2.3.0
2609
 *
2610
 * @WordPress\filter site_transient_update_plugins
2611
 *                   Added by wordpoints_admin_maybe_remove_from_updates_screen().
2612
 *
2613
 * @param object $data Object of plugin update data.
2614
 *
2615
 * @return object The filtered object.
2616
 */
2617
function wordpoints_admin_remove_wordpoints_from_update_plugins_transient( $data ) {
2618
2619
	$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

2619
	$plugin_basename = /** @scrutinizer ignore-call */ plugin_basename( WORDPOINTS_DIR . '/wordpoints.php' );
Loading history...
2620
2621
	if ( isset( $data->response[ $plugin_basename ] ) ) {
2622
		unset( $data->response[ $plugin_basename ] );
2623
	}
2624
2625
	return $data;
2626
}
2627
2628
/**
2629
 * Displays notices to admins when extension licenses are invalid, expired, etc.
2630
 *
2631
 * @since 2.4.0
2632
 *
2633
 * @WordPress\action admin_notices
2634
 */
2635
function wordpoints_admin_show_extension_license_notices() {
2636
2637
	// Don't show them on the extensions screen, because they would be shown before
2638
	// license activation notices, etc.
2639
	if ( isset( $_GET['page'] ) && 'wordpoints_extensions' === $_GET['page'] ) { // WPCS: CSRF OK.
2640
		return;
2641
	}
2642
2643
	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

2643
	if ( ! /** @scrutinizer ignore-call */ current_user_can( 'update_wordpoints_extensions' ) ) {
Loading history...
2644
		return;
2645
	}
2646
2647
	foreach ( wordpoints_get_modules() as $extension ) {
2648
2649
		if ( empty( $extension['ID'] ) ) {
2650
			continue;
2651
		}
2652
2653
		$server = wordpoints_get_server_for_extension( $extension );
2654
2655
		if ( ! $server ) {
2656
			continue;
2657
		}
2658
2659
		$api = $server->get_api();
2660
2661
		if ( ! $api instanceof WordPoints_Extension_Server_API_LicensesI ) {
2662
			continue;
2663
		}
2664
2665
		$extension_data = new WordPoints_Extension_Server_API_Extension_Data(
2666
			$extension['ID']
2667
			, $server
2668
		);
2669
2670
		if ( ! $api->extension_requires_license( $extension_data ) ) {
2671
			continue;
2672
		}
2673
2674
		$license_key = $extension_data->get( 'license_key' );
2675
2676 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...
2677
2678
			wordpoints_show_admin_error(
2679
				sprintf(
2680
					// translators: Extension name.
2681
					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

2681
					/** @scrutinizer ignore-call */ 
2682
     esc_html__( 'Please fill in your license key for the %s extension for WordPoints, so that you can receive updates.', 'wordpoints' )
Loading history...
2682
					, $extension['name']
2683
				)
2684
				. ' <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

2684
				. ' <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

2684
				. ' <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...
2685
			);
2686
2687
			continue;
2688
		}
2689
2690
		$license = $api->get_extension_license_object( $extension_data, $license_key );
2691
2692
		if ( ! $license->is_valid() ) {
2693
2694
			wordpoints_show_admin_error(
2695
				sprintf(
2696
					// translators: Extension name.
2697
					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' )
2698
					, $extension['name']
2699
				)
2700
				. ' <a href="' . esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ) . '">' . esc_html__( 'WordPoints Extensions screen &raquo;', 'wordpoints' ) . '</a>'
2701
			);
2702
2703
		} elseif ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ExpirableI && $license->is_expired() ) {
2704
2705
			if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_RenewableI && $license->is_renewable() ) {
2706
2707
				if ( $license instanceof WordPoints_Extension_Server_API_Extension_License_Renewable_URLI ) {
2708
2709
					wordpoints_show_admin_error(
2710
						sprintf(
2711
							// translators: Extension name.
2712
							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' )
2713
							, $extension['name']
2714
						)
2715
						. ' <a href="' . esc_url( $license->get_renewal_url() ) . '">' . esc_html__( 'Renew License', 'wordpoints' ) . '</a>'
2716
					);
2717
2718
				} else {
2719
2720
					wordpoints_show_admin_error(
2721
						sprintf(
2722
							// translators: Extension name.
2723
							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' )
2724
							, $extension['name']
2725
						)
2726
						. ' <a href="' . esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ) . '">' . esc_html__( 'WordPoints Extensions screen &raquo;', 'wordpoints' ) . '</a>'
2727
					);
2728
				}
2729
2730
			} else {
2731
2732
				wordpoints_show_admin_error(
2733
					sprintf(
2734
						// translators: Extension name.
2735
						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' )
2736
						, $extension['name']
2737
					)
2738
					. ' <a href="' . esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ) . '">' . esc_html__( 'WordPoints Extensions screen &raquo;', 'wordpoints' ) . '</a>'
2739
				);
2740
			}
2741
2742
		} elseif ( $license instanceof WordPoints_Extension_Server_API_Extension_License_ActivatableI && $license->is_activatable() && ! $license->is_active() ) {
2743
2744
			$extension_id = $extension['ID'];
2745
			$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

2745
			$server_url   = /** @scrutinizer ignore-call */ sanitize_title_with_dashes( $server->get_slug() );
Loading history...
2746
2747
			// translators: Extension name.
2748
			$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

2748
			$aria_label = /** @scrutinizer ignore-call */ __( 'Activate License for %s WordPoints Extension', 'wordpoints' );
Loading history...
2749
2750
			?>
2751
			<div class="notice notice-error">
2752
				<p>
2753
					<?php
2754
2755
					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

2755
					echo /** @scrutinizer ignore-call */ esc_html(
Loading history...
2756
						sprintf(
2757
							// translators: Extension name.
2758
							__( 'Your license key for the %s extension for WordPoints is not active. Please activate it so that you can receive updates.', 'wordpoints' )
2759
							, $extension['name']
2760
						)
2761
					);
2762
2763
					?>
2764
				</p>
2765
				<form method="post" action="<?php echo esc_url( self_admin_url( 'admin.php?page=wordpoints_extensions' ) ); ?>">
2766
					<input
2767
						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

2767
						id="license_key-<?php echo /** @scrutinizer ignore-call */ esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>"
Loading history...
2768
						name="license_key-<?php echo esc_attr( $server_url ); ?>-<?php echo esc_attr( $extension_id ); ?>"
2769
						type="hidden"
2770
						class="regular-text"
2771
						autocomplete="off"
2772
						value="<?php echo esc_attr( $license_key ); ?>"
2773
					/>
2774
					<?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

2774
					<?php /** @scrutinizer ignore-call */ wp_nonce_field( "wordpoints_activate_license_key-{$extension_id}", "wordpoints_activate_license_key-{$extension_id}" ); ?>
Loading history...
2775
					<p>
2776
						<input
2777
							type="submit"
2778
							name="activate-license-<?php echo esc_attr( $extension_id ); ?>"
2779
							class="button"
2780
							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

2780
							value="<?php /** @scrutinizer ignore-call */ esc_attr_e( 'Activate License', 'wordpoints' ); ?>"
Loading history...
2781
							aria-label="<?php echo esc_attr( sprintf( $aria_label, $extension_data['name'] ) ); ?>"
2782
						/>
2783
					</p>
2784
				</form>
2785
			</div>
2786
			<?php
2787
		}
2788
	}
2789
}
2790
2791
/**
2792
 * Shows the admin a notice if the update/install for an installable was skipped.
2793
 *
2794
 * @since 2.4.0
2795
 *
2796
 * @param string $notice_type The type of notices to display, 'update', or 'install'.
2797
 */
2798
function wordpoints_admin_show_update_skipped_notices( $notice_type = 'update' ) {
2799
2800
	$all_skipped = array_filter(
2801
		wordpoints_get_array_option( "wordpoints_network_{$notice_type}_skipped", 'site' )
2802
	);
2803
2804
	if ( empty( $all_skipped ) ) {
2805
		return;
2806
	}
2807
2808
	$messages = array();
2809
2810
	if ( 'install' === $notice_type ) {
2811
		// translators: 1. Extension/plugin name; 2. "extension", "plugin", or "component".
2812
		$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

2812
		$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...
2813
	} else {
2814
		// translators: 1. Extension/plugin name; 2. "extension", "plugin", or "component"; 3. Version number.
2815
		$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' );
2816
	}
2817
2818
	foreach ( $all_skipped as $type => $skipped ) {
2819
2820
		switch ( $type ) {
2821
2822
			case 'module':
2823
				$capability = 'wordpoints_manage_network_modules';
2824
			break;
2825
2826
			default:
2827
				$capability = 'manage_network_plugins';
2828
		}
2829
2830
		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

2830
		if ( ! /** @scrutinizer ignore-call */ current_user_can( $capability ) ) {
Loading history...
2831
			continue;
2832
		}
2833
2834
		switch ( $type ) {
2835
2836
			case 'module':
2837
				$type_name = __( '(extension)', 'wordpoints' );
2838
			break;
2839
2840
			case 'component':
2841
				$type_name = __( '(component)', 'wordpoints' );
2842
			break;
2843
2844
			default:
2845
				$type_name = __( '(plugin)', 'wordpoints' );
2846
		}
2847
2848
		foreach ( $skipped as $slug => $version ) {
2849
2850
			// Normally we might have used the installable's fancy name instead
2851
			// of the slug, but this is such an edge case to start with that I
2852
			// decided not to. Also of note: the version is only used in the
2853
			// update message.
2854
			$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

2854
			$messages[] = /** @scrutinizer ignore-call */ esc_html(
Loading history...
2855
				sprintf(
2856
					$message_template
2857
					, $slug
2858
					, $type_name
2859
					, $version
2860
				)
2861
			);
2862
		}
2863
2864
	} // End foreach ( $all_skipped ).
2865
2866
	if ( ! empty( $messages ) ) {
2867
2868
		$message  = '<p>' . implode( '</p><p>', $messages ) . '</p>';
2869
		$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

2869
		$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...
2870
		$message .= ' <a href="https://wordpoints.org/user-guide/multisite/">' . esc_html__( 'Learn more.', 'wordpoints' ) . '</a></p>';
2871
2872
		$args = array(
2873
			'dismissible' => true,
2874
			'option'      => "wordpoints_network_{$notice_type}_skipped",
2875
		);
2876
2877
		wordpoints_show_admin_error( $message, $args );
2878
	}
2879
}
2880
2881
// EOF
2882