Passed
Push — master ( ec16eb...0357f3 )
by Stephanie
03:05
created

FrmListHelper::get_param()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
if ( ! defined('ABSPATH') ) {
3
	die( 'You are not allowed to call this page directly.' );
4
}
5
6
class FrmListHelper {
7
	/**
8
	 * The current list of items
9
	 *
10
	 * @since 2.0.18
11
	 * @var array
12
	 * @access public
13
	 */
14
	public $items;
15
16
	/**
17
	 * Various information about the current table
18
	 *
19
	 * @since 2.0.18
20
	 * @var array
21
	 * @access protected
22
	 */
23
	protected $_args;
24
25
	/**
26
	 * Various information needed for displaying the pagination
27
	 *
28
	 * @since 2.0.18
29
	 * @var array
30
	 */
31
	protected $_pagination_args = array();
32
33
	/**
34
	 * The current screen
35
	 *
36
	 * @since 2.0.18
37
	 * @var object
38
	 * @access protected
39
	 */
40
	protected $screen;
41
42
	/**
43
	 * Cached bulk actions
44
	 *
45
	 * @since 2.0.18
46
	 * @var array
47
	 * @access private
48
	 */
49
	private $_actions;
50
51
	/**
52
	 * Cached pagination output
53
	 *
54
	 * @since 2.0.18
55
	 * @var string
56
	 * @access private
57
	 */
58
	private $_pagination;
59
60
	/**
61
	 * The view switcher modes.
62
	 *
63
	 * @since 2.0.18
64
	 * @var array
65
	 * @access protected
66
	 */
67
	protected $modes = array();
68
69
	/**
70
	*
71
	* @var array
72
	*/
73
    protected $params;
74
75
	/**
76
	 * Stores the value returned by ->get_column_info()
77
	 *
78
	 * @var array
79
	 */
80
	protected $_column_headers;
81
82
	protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
83
84
	protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions', 'row_actions', 'view_switcher', 'get_items_per_page', 'pagination', 'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav', 'single_row_columns' );
85
86
	/**
87
	* Construct the table object
88
	*/
89
	public function __construct( $args ) {
90
	    $args = wp_parse_args( $args, array(
0 ignored issues
show
Bug introduced by
The function wp_parse_args was not found. Maybe you did not declare it correctly or list all 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
	    $args = /** @scrutinizer ignore-call */ wp_parse_args( $args, array(
Loading history...
91
			'params' => array(),
92
			'plural' => '',
93
			'singular' => '',
94
			'ajax' => false,
95
			'screen' => null,
96
		) );
97
98
		$this->params = $args['params'];
99
100
		$this->screen = convert_to_screen( $args['screen'] );
0 ignored issues
show
Bug introduced by
The function convert_to_screen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

100
		$this->screen = /** @scrutinizer ignore-call */ convert_to_screen( $args['screen'] );
Loading history...
101
102
		add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
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

102
		/** @scrutinizer ignore-call */ 
103
  add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
Loading history...
103
104
		if ( ! $args['plural'] ) {
105
			$args['plural'] = $this->screen->base;
106
		}
107
108
		$args['plural'] = sanitize_key( $args['plural'] );
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

108
		$args['plural'] = /** @scrutinizer ignore-call */ sanitize_key( $args['plural'] );
Loading history...
109
		$args['singular'] = sanitize_key( $args['singular'] );
110
111
		$this->_args = $args;
112
113
		if ( $args['ajax'] ) {
114
			// wp_enqueue_script( 'list-table' );
115
			add_action( 'admin_footer', array( $this, '_js_vars' ) );
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

115
			/** @scrutinizer ignore-call */ 
116
   add_action( 'admin_footer', array( $this, '_js_vars' ) );
Loading history...
116
		}
117
118
		if ( empty( $this->modes ) ) {
119
			$this->modes = array(
120
				'list'    => __( 'List View' ),
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

120
				'list'    => /** @scrutinizer ignore-call */ __( 'List View' ),
Loading history...
121
				'excerpt' => __( 'Excerpt View' ),
122
			);
123
		}
124
	}
125
126
	public function ajax_user_can() {
127
		return current_user_can( 'administrator' );
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

127
		return /** @scrutinizer ignore-call */ current_user_can( 'administrator' );
Loading history...
128
	}
129
130
	public function get_columns() {
131
		return array();
132
	}
133
134
	public function display_rows() {
135
		foreach ( $this->items as $item ) {
136
			echo "\n\t", $this->single_row( $item );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->single_row($item) targeting FrmListHelper::single_row() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
137
		}
138
	}
139
140
	/**
141
	 * Prepares the list of items for displaying.
142
	 * @uses FrmListHelper::set_pagination_args()
143
	 *
144
	 * @since 2.0.18
145
	 * @access public
146
	 * @abstract
147
	 */
148
	public function prepare_items() {
149
		die( 'function FrmListHelper::prepare_items() must be over-ridden in a sub-class.' );
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...
150
	}
151
152
	/**
153
	 * @since 3.0
154
	 */
155
	protected function get_param( $args ) {
156
		return FrmAppHelper::get_simple_request( array(
157
			'param'    => $args['param'],
158
			'default'  => isset( $args['default'] ) ? $args['default'] : '',
159
			'sanitize' => isset( $args['sanitize'] ) ? $args['sanitize'] : 'sanitize_title',
160
			'type'     => 'request',
161
		) );
162
	}
163
164
	/**
165
	 * An internal method that sets all the necessary pagination arguments
166
	 *
167
	 * @param array $args An associative array with information about the pagination
168
	 * @access protected
169
	 *
170
	 * @param array|string $args
171
	 */
172
	protected function set_pagination_args( $args ) {
173
		$args = wp_parse_args( $args, array(
0 ignored issues
show
Bug introduced by
The function wp_parse_args was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

173
		$args = /** @scrutinizer ignore-call */ wp_parse_args( $args, array(
Loading history...
174
			'total_items' => 0,
175
			'total_pages' => 0,
176
			'per_page' => 0,
177
		) );
178
179
		if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
180
			$args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
181
		}
182
183
		// Redirect if page number is invalid and headers are not already sent.
184
		if ( ! headers_sent() && ! FrmAppHelper::wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
185
			wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
0 ignored issues
show
Bug introduced by
The function wp_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

185
			/** @scrutinizer ignore-call */ 
186
   wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
Loading history...
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

185
			wp_redirect( /** @scrutinizer ignore-call */ add_query_arg( 'paged', $args['total_pages'] ) );
Loading history...
186
			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...
187
		}
188
189
		$this->_pagination_args = $args;
190
	}
191
192
	/**
193
	 * Access the pagination args.
194
	 *
195
	 * @since 2.0.18
196
	 * @access public
197
	 *
198
	 * @param string $key Pagination argument to retrieve. Common values include 'total_items',
199
	 *                    'total_pages', 'per_page', or 'infinite_scroll'.
200
	 * @return int Number of items that correspond to the given pagination argument.
201
	 */
202
	public function get_pagination_arg( $key ) {
203
		if ( 'page' == $key ) {
204
			return $this->get_pagenum();
205
		}
206
207
		if ( isset( $this->_pagination_args[ $key ] ) ) {
208
			return $this->_pagination_args[ $key ];
209
		}
210
	}
211
212
	/**
213
	 * Whether the table has items to display or not
214
	 *
215
	 * @since 2.0.18
216
	 * @access public
217
	 *
218
	 * @return bool
219
	 */
220
	public function has_items() {
221
		return ! empty( $this->items );
222
	}
223
224
	/**
225
	 * Message to be displayed when there are no items
226
	 *
227
	 * @since 2.0.18
228
	 * @access public
229
	 */
230
	public function no_items() {
231
		_e( 'No items found.' );
0 ignored issues
show
Bug introduced by
The function _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

231
		/** @scrutinizer ignore-call */ 
232
  _e( 'No items found.' );
Loading history...
232
	}
233
234
	/**
235
	 * Display the search box.
236
	 *
237
	 * @since 2.0.18
238
	 * @access public
239
	 *
240
	 * @param string $text The search button text
241
	 * @param string $input_id The search input id
242
	 */
243
	public function search_box( $text, $input_id ) {
244
		if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
245
			return;
246
		}
247
248
		$input_id = $input_id . '-search-input';
249
250
		foreach ( array( 'orderby', 'order' ) as $search_params ) {
251
			$this->hidden_search_inputs( $search_params );
252
		}
253
?>
254
<p class="search-box">
255
	<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ) ?>"><?php echo wp_kses( $text, array() ); ?>:</label>
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

255
	<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ) ?>"><?php echo /** @scrutinizer ignore-call */ wp_kses( $text, array() ); ?>:</label>
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

255
	<label class="screen-reader-text" for="<?php echo /** @scrutinizer ignore-call */ esc_attr( $input_id ) ?>"><?php echo wp_kses( $text, array() ); ?>:</label>
Loading history...
256
	<input type="search" id="<?php echo esc_attr( $input_id ) ?>" name="s" value="<?php _admin_search_query(); ?>" />
0 ignored issues
show
Bug introduced by
The function _admin_search_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

256
	<input type="search" id="<?php echo esc_attr( $input_id ) ?>" name="s" value="<?php /** @scrutinizer ignore-call */ _admin_search_query(); ?>" />
Loading history...
257
	<?php submit_button( $text, 'button', '', false, array( 'id' => 'search-submit' ) ); ?>
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

257
	<?php /** @scrutinizer ignore-call */ submit_button( $text, 'button', '', false, array( 'id' => 'search-submit' ) ); ?>
Loading history...
258
</p>
259
<?php
260
	}
261
262
	private function hidden_search_inputs( $param_name ) {
263
		if ( ! empty( $_REQUEST[ $param_name ] ) ) {
264
			echo '<input type="hidden" name="' . esc_attr( $param_name ) . '" value="' . esc_attr( $_REQUEST[ $param_name ] ) . '" />';
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

264
			echo '<input type="hidden" name="' . /** @scrutinizer ignore-call */ esc_attr( $param_name ) . '" value="' . esc_attr( $_REQUEST[ $param_name ] ) . '" />';
Loading history...
265
		}
266
	}
267
268
	/**
269
	 * Get an associative array ( id => link ) with the list
270
	 * of views available on this table.
271
	 *
272
	 * @since 2.0.18
273
	 * @access protected
274
	 *
275
	 * @return array
276
	 */
277
	protected function get_views() {
278
		return array();
279
	}
280
281
	/**
282
	 * Display the list of views available on this table.
283
	 *
284
	 * @since 2.0.18
285
	 * @access public
286
	 */
287
	public function views() {
288
		$views = $this->get_views();
289
		/**
290
		 * Filter the list of available list table views.
291
		 *
292
		 * The dynamic portion of the hook name, `$this->screen->id`, refers
293
		 * to the ID of the current screen, usually a string.
294
		 *
295
		 * @since 3.5.0
296
		 *
297
		 * @param array $views An array of available list table views.
298
		 */
299
		$views = apply_filters( 'views_' . $this->screen->id, $views );
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

299
		$views = /** @scrutinizer ignore-call */ apply_filters( 'views_' . $this->screen->id, $views );
Loading history...
300
301
		if ( empty( $views ) ) {
302
			return;
303
		}
304
305
		echo "<ul class='subsubsub'>\n";
306
		foreach ( $views as $class => $view ) {
307
			$views[ $class ] = "\t<li class='$class'>$view";
308
		}
309
		echo implode( " |</li>\n", $views ) . "</li>\n";
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'implode'
Loading history...
310
		echo '</ul>';
311
	}
312
313
	/**
314
	 * Get an associative array ( option_name => option_title ) with the list
315
	 * of bulk actions available on this table.
316
	 *
317
	 * @since 2.0.18
318
	 * @access protected
319
	 *
320
	 * @return array
321
	 */
322
	protected function get_bulk_actions() {
323
		return array();
324
	}
325
326
	/**
327
	 * Display the bulk actions dropdown.
328
	 *
329
	 * @since 2.0.18
330
	 * @access protected
331
	 *
332
	 * @param string $which The location of the bulk actions: 'top' or 'bottom'.
333
	 *                      This is designated as optional for backwards-compatibility.
334
	 */
335
	protected function bulk_actions( $which = '' ) {
336
		if ( is_null( $this->_actions ) ) {
0 ignored issues
show
introduced by
The condition is_null($this->_actions) can never be true.
Loading history...
337
			$no_new_actions = $this->get_bulk_actions();
338
			$this->_actions = $no_new_actions;
339
340
			/**
341
			 * Filter the list table Bulk Actions drop-down.
342
			 *
343
			 * The dynamic portion of the hook name, `$this->screen->id`, refers
344
			 * to the ID of the current screen, usually a string.
345
			 *
346
			 * This filter can currently only be used to remove bulk actions.
347
			 *
348
			 * @since 3.5.0
349
			 *
350
			 * @param array $actions An array of the available bulk actions.
351
			 */
352
			$this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
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

352
			$this->_actions = /** @scrutinizer ignore-call */ apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
Loading history...
353
			$this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
354
			$two = '';
355
		} else {
356
			$two = '2';
357
		}
358
359
		if ( empty( $this->_actions ) ) {
360
			return;
361
		}
362
363
		echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . esc_attr__( 'Select bulk action' ) . '</label>';
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

363
		echo "<label for='bulk-action-selector-" . /** @scrutinizer ignore-call */ esc_attr( $which ) . "' class='screen-reader-text'>" . esc_attr__( 'Select bulk action' ) . '</label>';
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

363
		echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . /** @scrutinizer ignore-call */ esc_attr__( 'Select bulk action' ) . '</label>';
Loading history...
364
		echo "<select name='action" . esc_attr( $two ) . "' id='bulk-action-selector-" . esc_attr( $which ) . "'>\n";
365
		echo "<option value='-1' selected='selected'>" . esc_attr__( 'Bulk Actions' ) . "</option>\n";
366
367
		foreach ( $this->_actions as $name => $title ) {
368
			$class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
369
370
			echo "\t<option value='" . esc_attr( $name ) . "'$class>$title</option>\n";
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"'$class>$title</option>\n"'
Loading history...
371
		}
372
373
		echo "</select>\n";
374
375
		submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
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

375
		/** @scrutinizer ignore-call */ 
376
  submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
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

375
		submit_button( /** @scrutinizer ignore-call */ __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
Loading history...
376
		echo "\n";
377
	}
378
379
	/**
380
	 * Get the current action selected from the bulk actions dropdown.
381
	 *
382
	 * @since 2.0.18
383
	 * @access public
384
	 *
385
	 * @return string|false The action name or False if no action was selected
386
	 */
387
	public function current_action() {
388
		if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
389
			return false;
390
		}
391
392
		$action = $this->get_bulk_action( 'action' );
393
		if ( $action === false ) {
394
			$action = $this->get_bulk_action( 'action2' );
395
		}
396
397
		return $action;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $action also could return the type array which is incompatible with the documented return type false|string.
Loading history...
398
	}
399
400
	private static function get_bulk_action( $action_name ) {
401
		$action = false;
402
		$action_param = self::get_param( array(
0 ignored issues
show
Bug Best Practice introduced by
The method FrmListHelper::get_param() is not static, but was called statically. ( Ignorable by Annotation )

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

402
		/** @scrutinizer ignore-call */ 
403
  $action_param = self::get_param( array(
Loading history...
403
			'param' => $action_name,
404
			'sanitize' => 'sanitize_text_field',
405
		) );
406
		if ( $action_param && -1 != $action_param ) {
407
			$action = $action_param;
408
		}
409
		return $action;
410
	}
411
412
	/**
413
	 * Generate row actions div
414
	 *
415
	 * @since 2.0.18
416
	 * @access protected
417
	 *
418
	 * @param array $actions The list of actions
419
	 * @param bool $always_visible Whether the actions should be always visible
420
	 * @return string
421
	 */
422
	protected function row_actions( $actions, $always_visible = false ) {
423
		$action_count = count( $actions );
424
		$i = 0;
425
426
		if ( ! $action_count ) {
427
			return '';
428
		}
429
430
		$out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
431
		foreach ( $actions as $action => $link ) {
432
			++$i;
433
			( $i == $action_count ) ? $sep = '' : $sep = ' | ';
434
			$out .= "<span class='$action'>$link$sep</span>";
435
		}
436
		$out .= '</div>';
437
438
		$out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
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

438
		$out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . /** @scrutinizer ignore-call */ __( 'Show more details' ) . '</span></button>';
Loading history...
439
440
		return $out;
441
	}
442
443
	/**
444
	 * Display a view switcher
445
	 *
446
	 * @since 2.0.18
447
	 * @access protected
448
	 *
449
	 * @param string $current_mode
450
	 */
451
	protected function view_switcher( $current_mode ) {
452
?>
453
		<input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
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

453
		<input type="hidden" name="mode" value="<?php echo /** @scrutinizer ignore-call */ esc_attr( $current_mode ); ?>" />
Loading history...
454
		<div class="view-switch">
455
<?php
456
			foreach ( $this->modes as $mode => $title ) {
457
				$classes = array( 'view-' . $mode );
458
				if ( $current_mode == $mode ) {
459
					$classes[] = 'current';
460
				}
461
462
				printf(
463
					"<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
464
					esc_url( add_query_arg( 'mode', $mode ) ),
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

464
					/** @scrutinizer ignore-call */ 
465
     esc_url( add_query_arg( 'mode', $mode ) ),
Loading history...
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

464
					esc_url( /** @scrutinizer ignore-call */ add_query_arg( 'mode', $mode ) ),
Loading history...
465
					implode( ' ', $classes ),
466
					$title
467
				);
468
			}
469
		?>
470
		</div>
471
<?php
472
	}
473
474
	/**
475
	 * Get the current page number
476
	 *
477
	 * @since 2.0.18
478
	 * @access public
479
	 *
480
	 * @return int
481
	 */
482
	public function get_pagenum() {
483
		$pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
0 ignored issues
show
Bug introduced by
The function absint was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

483
		$pagenum = isset( $_REQUEST['paged'] ) ? /** @scrutinizer ignore-call */ absint( $_REQUEST['paged'] ) : 0;
Loading history...
484
485
		if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) {
486
			$pagenum = $this->_pagination_args['total_pages'];
487
		}
488
489
		return max( 1, $pagenum );
490
	}
491
492
	/**
493
	 * Get number of items to display on a single page
494
	 *
495
	 * @since 2.0.18
496
	 * @access protected
497
	 *
498
	 * @param string $option
499
	 * @param int    $default
500
	 * @return int
501
	 */
502
	protected function get_items_per_page( $option, $default = 20 ) {
503
		$per_page = (int) get_user_option( $option );
0 ignored issues
show
Bug introduced by
The function get_user_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

503
		$per_page = (int) /** @scrutinizer ignore-call */ get_user_option( $option );
Loading history...
504
		if ( empty( $per_page ) || $per_page < 1 ) {
505
			$per_page = $default;
506
		}
507
508
		/**
509
		 * Filter the number of items to be displayed on each page of the list table.
510
		 *
511
		 * The dynamic hook name, $option, refers to the `per_page` option depending
512
		 * on the type of list table in use. Possible values include: 'edit_comments_per_page',
513
		 * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
514
		 * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
515
		 * 'edit_{$post_type}_per_page', etc.
516
		 *
517
		 * @since 2.9.0
518
		 *
519
		 * @param int $per_page Number of items to be displayed. Default 20.
520
		 */
521
		return (int) apply_filters( $option, $per_page );
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

521
		return (int) /** @scrutinizer ignore-call */ apply_filters( $option, $per_page );
Loading history...
522
	}
523
524
	/**
525
	 * Display the pagination.
526
	 *
527
	 * @since 2.0.18
528
	 * @access protected
529
	 *
530
	 * @param string $which
531
	 */
532
	protected function pagination( $which ) {
533
		if ( empty( $this->_pagination_args ) ) {
534
			return;
535
		}
536
537
		$total_items = $this->_pagination_args['total_items'];
538
		$total_pages = $this->_pagination_args['total_pages'];
539
		$infinite_scroll = false;
540
		if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
541
			$infinite_scroll = $this->_pagination_args['infinite_scroll'];
542
		}
543
544
		$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
0 ignored issues
show
Bug introduced by
The function _n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

544
		$output = '<span class="displaying-num">' . sprintf( /** @scrutinizer ignore-call */ _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
Loading history...
Bug introduced by
The function number_format_i18n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

544
		$output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), /** @scrutinizer ignore-call */ number_format_i18n( $total_items ) ) . '</span>';
Loading history...
545
546
		$current = $this->get_pagenum();
547
548
		$page_links = array();
549
550
		$total_pages_before = '<span class="paging-input">';
551
		$total_pages_after  = '</span>';
552
553
		$disable = $this->disabled_pages( $total_pages );
554
555
		$page_links[] = $this->add_page_link( array(
556
			'page'     => 'first',
557
			'arrow'    => '&laquo;',
558
			'number'   => '',
559
			'disabled' => $disable['first'],
560
		) );
561
562
		$page_links[] = $this->add_page_link( array(
563
			'page'     => 'prev',
564
			'arrow'    => '&lsaquo;',
565
			'number'   => max( 1, $current - 1 ),
566
			'disabled' => $disable['prev'],
567
		) );
568
569
		if ( 'bottom' == $which ) {
570
			$html_current_page  = $current;
571
			$total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input">';
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

571
			$total_pages_before = '<span class="screen-reader-text">' . /** @scrutinizer ignore-call */ __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input">';
Loading history...
572
		} else {
573
			$html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />",
574
				'<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
575
				$current,
576
				strlen( $total_pages )
577
			);
578
		}
579
		$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
580
		$page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$total_pages_after'
Loading history...
Bug introduced by
The function _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

580
		$page_links[] = $total_pages_before . sprintf( /** @scrutinizer ignore-call */ _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
Loading history...
581
582
		$page_links[] = $this->add_page_link( array(
583
			'page'     => 'next',
584
			'arrow'    => '&rsaquo;',
585
			'number'   => min( $total_pages, $current + 1 ),
586
			'disabled' => $disable['next'],
587
		) );
588
589
		$page_links[] = $this->add_page_link( array(
590
			'page'     => 'last',
591
			'arrow'    => '&raquo;',
592
			'number'   => $total_pages,
593
			'disabled' => $disable['last'],
594
		) );
595
596
		$pagination_links_class = 'pagination-links';
597
		if ( ! empty( $infinite_scroll ) ) {
0 ignored issues
show
introduced by
The condition ! empty($infinite_scroll) can never be true.
Loading history...
598
			$pagination_links_class = ' hide-if-js';
599
		}
600
		$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
601
602
		if ( $total_pages ) {
603
			$page_class = $total_pages < 2 ? ' one-page' : '';
604
		} else {
605
			$page_class = ' no-pages';
606
		}
607
		$this->_pagination = "<div class='tablenav-pages" . esc_attr( $page_class ) . "'>$output</div>";
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

607
		$this->_pagination = "<div class='tablenav-pages" . /** @scrutinizer ignore-call */ esc_attr( $page_class ) . "'>$output</div>";
Loading history...
608
609
		echo $this->_pagination;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
610
	}
611
612
	private function disabled_pages( $total_pages ) {
613
		$current = $this->get_pagenum();
614
		$disable = array(
615
			'first' => false,
616
			'last'  => false,
617
			'prev'  => false,
618
			'next'  => false,
619
		);
620
621
 		if ( $current == 1 ) {
622
			$disable['first'] = true;
623
			$disable['prev']  = true;
624
 		} elseif ( $current == 2 ) {
625
			$disable['first'] = true;
626
		}
627
628
 		if ( $current == $total_pages ) {
629
			$disable['last'] = true;
630
			$disable['next'] = true;
631
 		} elseif ( $current == $total_pages - 1 ) {
632
			$disable['last'] = true;
633
		}
634
635
		return $disable;
636
	}
637
638
	private function link_label( $link ) {
639
		$labels = array(
640
			'first' => __( 'First page' ),
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

640
			'first' => /** @scrutinizer ignore-call */ __( 'First page' ),
Loading history...
641
			'last'  => __( 'Last page' ),
642
			'prev'  => __( 'Previous page' ),
643
			'next'  => __( 'Next page' ),
644
		);
645
		return $labels[ $link ];
646
	}
647
648
	private function current_url() {
649
		$current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
0 ignored issues
show
Bug introduced by
The function set_url_scheme was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

649
		$current_url = /** @scrutinizer ignore-call */ set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
Loading history...
650
651
		return remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
0 ignored issues
show
Bug introduced by
The function remove_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

651
		return /** @scrutinizer ignore-call */ remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
Loading history...
652
	}
653
654
	private function add_page_link( $atts ) {
655
		if ( $atts['disabled'] ) {
656
			$link = $this->add_disabled_link( $atts['arrow'] );
657
		} else {
658
			$link = $this->add_active_link( $atts );
659
		}
660
		return $link;
661
	}
662
663
	private function add_disabled_link( $label ) {
664
		return '<span class="tablenav-pages-navspan" aria-hidden="true">' . $label . '</span>';
665
	}
666
667
	private function add_active_link( $atts ) {
668
		$url = esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) );
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

668
		$url = esc_url( /** @scrutinizer ignore-call */ add_query_arg( 'paged', $atts['number'], $this->current_url() ) );
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

668
		$url = /** @scrutinizer ignore-call */ esc_url( add_query_arg( 'paged', $atts['number'], $this->current_url() ) );
Loading history...
669
		$label = $this->link_label( $atts['page'] );
670
		return sprintf(
671
			"<a class='%s-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
672
			$atts['page'], $url, $label, $atts['arrow']
673
		);
674
	}
675
676
	/**
677
	 * Get a list of sortable columns. The format is:
678
	 * 'internal-name' => 'orderby'
679
	 * or
680
	 * 'internal-name' => array( 'orderby', true )
681
	 *
682
	 * The second format will make the initial sorting order be descending
683
	 *
684
	 * @since 2.0.18
685
	 * @access protected
686
	 *
687
	 * @return array
688
	 */
689
	protected function get_sortable_columns() {
690
		return array();
691
	}
692
693
	/**
694
	 * Gets the name of the default primary column.
695
	 *
696
	 * @since 4.3.0
697
	 * @access protected
698
	 *
699
	 * @return string Name of the default primary column, in this case, an empty string.
700
	 */
701
	protected function get_default_primary_column_name() {
702
		$columns = $this->get_columns();
703
		$column = '';
704
705
		// We need a primary defined so responsive views show something,
706
		// so let's fall back to the first non-checkbox column.
707
		foreach ( $columns as $col => $column_name ) {
708
			if ( 'cb' === $col ) {
709
				continue;
710
			}
711
712
			$column = $col;
713
			break;
714
		}
715
716
		return $column;
717
	}
718
719
	/**
720
	 * Gets the name of the primary column.
721
	 *
722
	 * @since 4.3.0
723
	 * @access protected
724
	 *
725
	 * @return string The name of the primary column.
726
	 */
727
	protected function get_primary_column_name() {
728
		$columns = $this->get_columns();
729
		$default = $this->get_default_primary_column_name();
730
731
		// If the primary column doesn't exist fall back to the
732
		// first non-checkbox column.
733
		if ( ! isset( $columns[ $default ] ) ) {
734
			$default = FrmListHelper::get_default_primary_column_name();
0 ignored issues
show
Bug Best Practice introduced by
The method FrmListHelper::get_default_primary_column_name() is not static, but was called statically. ( Ignorable by Annotation )

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

734
			/** @scrutinizer ignore-call */ 
735
   $default = FrmListHelper::get_default_primary_column_name();
Loading history...
735
		}
736
737
		/**
738
		 * Filter the name of the primary column for the current list table.
739
		 *
740
		 * @since 4.3.0
741
		 *
742
		 * @param string $default Column name default for the specific list table, e.g. 'name'.
743
		 * @param string $context Screen ID for specific list table, e.g. 'plugins'.
744
		 */
745
		$column  = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
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

745
		$column  = /** @scrutinizer ignore-call */ apply_filters( 'list_table_primary_column', $default, $this->screen->id );
Loading history...
746
747
		if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
748
			$column = $default;
749
		}
750
751
		return $column;
752
	}
753
754
	/**
755
	 * Get a list of all, hidden and sortable columns, with filter applied
756
	 *
757
	 * @since 2.0.18
758
	 * @access protected
759
	 *
760
	 * @return array
761
	 */
762
	protected function get_column_info() {
763
		// $_column_headers is already set / cached
764
		if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
765
			// Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
766
			// In 4.3, we added a fourth argument for primary column.
767
			$column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
768
			foreach ( $this->_column_headers as $key => $value ) {
769
				$column_headers[ $key ] = $value;
770
			}
771
772
			return $column_headers;
773
		}
774
775
		$columns = get_column_headers( $this->screen );
0 ignored issues
show
Bug introduced by
The function get_column_headers was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

775
		$columns = /** @scrutinizer ignore-call */ get_column_headers( $this->screen );
Loading history...
776
		$hidden = get_hidden_columns( $this->screen );
0 ignored issues
show
Bug introduced by
The function get_hidden_columns was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

776
		$hidden = /** @scrutinizer ignore-call */ get_hidden_columns( $this->screen );
Loading history...
777
778
		$sortable_columns = $this->get_sortable_columns();
779
		/**
780
		 * Filter the list table sortable columns for a specific screen.
781
		 *
782
		 * The dynamic portion of the hook name, `$this->screen->id`, refers
783
		 * to the ID of the current screen, usually a string.
784
		 *
785
		 * @since 3.5.0
786
		 *
787
		 * @param array $sortable_columns An array of sortable columns.
788
		 */
789
		$_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
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

789
		$_sortable = /** @scrutinizer ignore-call */ apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
Loading history...
790
791
		$sortable = array();
792
		foreach ( $_sortable as $id => $data ) {
793
			if ( empty( $data ) ) {
794
				continue;
795
			}
796
797
			$data = (array) $data;
798
			if ( ! isset( $data[1] ) ) {
799
				$data[1] = false;
800
			}
801
802
			$sortable[ $id ] = $data;
803
		}
804
805
		$primary = $this->get_primary_column_name();
806
		$this->_column_headers = array( $columns, $hidden, $sortable, $primary );
807
808
		return $this->_column_headers;
809
	}
810
811
	/**
812
	 * Return number of visible columns
813
	 *
814
	 * @since 2.0.18
815
	 * @access public
816
	 *
817
	 * @return int
818
	 */
819
	public function get_column_count() {
820
		list ( $columns, $hidden ) = $this->get_column_info();
821
		$hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
822
		return count( $columns ) - count( $hidden );
823
	}
824
825
	/**
826
	 * Print column headers, accounting for hidden and sortable columns.
827
	 *
828
	 * @since 2.0.18
829
	 * @access public
830
	 *
831
	 * @staticvar int $cb_counter
832
	 *
833
	 * @param bool $with_id Whether to set the id attribute or not
834
	 */
835
	public function print_column_headers( $with_id = true ) {
836
		list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
837
838
		$current_url = set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
0 ignored issues
show
Bug introduced by
The function set_url_scheme was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

838
		$current_url = /** @scrutinizer ignore-call */ set_url_scheme( 'http://' . FrmAppHelper::get_server_value( 'HTTP_HOST' ) . FrmAppHelper::get_server_value( 'REQUEST_URI' ) );
Loading history...
839
		$current_url = remove_query_arg( 'paged', $current_url );
0 ignored issues
show
Bug introduced by
The function remove_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

839
		$current_url = /** @scrutinizer ignore-call */ remove_query_arg( 'paged', $current_url );
Loading history...
840
841
		if ( isset( $_GET['orderby'] ) ) {
842
			$current_orderby = sanitize_text_field( $_GET['orderby'] );
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

842
			$current_orderby = /** @scrutinizer ignore-call */ sanitize_text_field( $_GET['orderby'] );
Loading history...
843
		} else {
844
			$current_orderby = '';
845
		}
846
847
		if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) {
848
			$current_order = 'desc';
849
		} else {
850
			$current_order = 'asc';
851
		}
852
853
		if ( ! empty( $columns['cb'] ) ) {
854
			static $cb_counter = 1;
855
			$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
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

855
			$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . /** @scrutinizer ignore-call */ __( 'Select All' ) . '</label>'
Loading history...
856
				. '<input id="cb-select-all-' . esc_attr( $cb_counter ) . '" type="checkbox" />';
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

856
				. '<input id="cb-select-all-' . /** @scrutinizer ignore-call */ esc_attr( $cb_counter ) . '" type="checkbox" />';
Loading history...
857
			$cb_counter++;
858
		}
859
860
		foreach ( $columns as $column_key => $column_display_name ) {
861
			$class = array( 'manage-column', "column-$column_key" );
862
863
			if ( in_array( $column_key, $hidden ) ) {
864
				$class[] = 'hidden';
865
			}
866
867
			if ( 'cb' == $column_key ) {
868
				$class[] = 'check-column';
869
			} else if ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
870
				$class[] = 'num';
871
			}
872
873
			if ( $column_key === $primary ) {
874
				$class[] = 'column-primary';
875
			}
876
877
			if ( isset( $sortable[ $column_key ] ) ) {
878
				list( $orderby, $desc_first ) = $sortable[ $column_key ];
879
880
				if ( $current_orderby == $orderby ) {
881
					$order = 'asc' == $current_order ? 'desc' : 'asc';
882
					$class[] = 'sorted';
883
					$class[] = $current_order;
884
				} else {
885
					$order = $desc_first ? 'desc' : 'asc';
886
					$class[] = 'sortable';
887
					$class[] = $desc_first ? 'asc' : 'desc';
888
				}
889
890
				$column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
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

890
				$column_display_name = '<a href="' . esc_url( /** @scrutinizer ignore-call */ add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></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

890
				$column_display_name = '<a href="' . /** @scrutinizer ignore-call */ esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
Loading history...
891
			}
892
893
			$tag = ( 'cb' === $column_key ) ? 'td' : 'th';
894
			$scope = ( 'th' === $tag ) ? 'scope="col"' : '';
895
			$id = $with_id ? "id='" . esc_attr( $column_key ) . "'" : '';
896
897
			if ( ! empty( $class ) ) {
898
				$class = "class='" . join( ' ', $class ) . "'";
899
			}
900
901
			echo "<$tag $scope $id $class>$column_display_name</$tag>";
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"<$tag $scope $id $class>$column_display_name</$tag>"'
Loading history...
902
		}
903
	}
904
905
	/**
906
	 * Display the table
907
	 *
908
	 * @since 2.0.18
909
	 * @access public
910
	 */
911
	public function display() {
912
		$singular = $this->_args['singular'];
913
914
		$this->display_tablenav( 'top' );
915
?>
916
<table class="wp-list-table <?php echo esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>">
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

916
<table class="wp-list-table <?php echo /** @scrutinizer ignore-call */ esc_attr( implode( ' ', $this->get_table_classes() ) ); ?>">
Loading history...
917
	<thead>
918
	<tr>
919
		<?php $this->print_column_headers(); ?>
920
	</tr>
921
	</thead>
922
923
	<tbody id="the-list"<?php echo ( $singular ? " data-wp-lists='list:" . esc_attr( $singular ) . "'" : '' ); ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
924
		<?php $this->display_rows_or_placeholder(); ?>
925
	</tbody>
926
927
	<tfoot>
928
	<tr>
929
		<?php $this->print_column_headers( false ); ?>
930
	</tr>
931
	</tfoot>
932
933
</table>
934
<?php
935
		$this->display_tablenav( 'bottom' );
936
	}
937
938
	/**
939
	 * Get a list of CSS classes for the list table table tag.
940
	 *
941
	 * @since 2.0.18
942
	 * @access protected
943
	 *
944
	 * @return array List of CSS classes for the table tag.
945
	 */
946
	protected function get_table_classes() {
947
		return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
948
	}
949
950
	/**
951
	 * Generate the table navigation above or below the table
952
	 *
953
	 * @since 2.0.18
954
	 * @access protected
955
	 * @param string $which
956
	 */
957
	protected function display_tablenav( $which ) {
958
		if ( 'top' == $which ) {
959
			wp_nonce_field( 'bulk-' . $this->_args['plural'] );
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

959
			/** @scrutinizer ignore-call */ 
960
   wp_nonce_field( 'bulk-' . $this->_args['plural'] );
Loading history...
960
		}
961
?>
962
	<div class="tablenav <?php echo esc_attr( $which ); ?>">
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

962
	<div class="tablenav <?php echo /** @scrutinizer ignore-call */ esc_attr( $which ); ?>">
Loading history...
963
964
		<div class="alignleft actions bulkactions">
965
			<?php $this->bulk_actions( $which ); ?>
966
		</div>
967
<?php
968
		$this->extra_tablenav( $which );
969
		$this->pagination( $which );
970
?>
971
972
		<br class="clear" />
973
	</div>
974
<?php
975
	}
976
977
	/**
978
	 * Extra controls to be displayed between bulk actions and pagination
979
	 *
980
	 * @since 2.0.18
981
	 * @access protected
982
	 *
983
	 * @param string $which
984
	 */
985
	protected function extra_tablenav( $which ) {}
986
987
	/**
988
	 * Generate the tbody element for the list table.
989
	 *
990
	 * @since 2.0.18
991
	 * @access public
992
	 */
993
	public function display_rows_or_placeholder() {
994
		if ( $this->has_items() ) {
995
			$this->display_rows();
996
		} else {
997
			echo '<tr class="no-items"><td class="colspanchange" colspan="' . esc_attr( $this->get_column_count() ) . '">';
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

997
			echo '<tr class="no-items"><td class="colspanchange" colspan="' . /** @scrutinizer ignore-call */ esc_attr( $this->get_column_count() ) . '">';
Loading history...
998
			$this->no_items();
999
			echo '</td></tr>';
1000
		}
1001
	}
1002
1003
	/**
1004
	 * Generates content for a single row of the table
1005
	 *
1006
	 * @since 2.0.18
1007
	 * @access public
1008
	 *
1009
	 * @param object $item The current item
1010
	 */
1011
	public function single_row( $item ) {
1012
		echo '<tr>';
1013
		$this->single_row_columns( $item );
1014
		echo '</tr>';
1015
	}
1016
1017
	/**
1018
	 * Generates the columns for a single row of the table
1019
	 *
1020
	 * @since 2.0.18
1021
	 * @access protected
1022
	 *
1023
	 * @param object $item The current item
1024
	 */
1025
	protected function single_row_columns( $item ) {
1026
		list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1027
1028
		foreach ( $columns as $column_name => $column_display_name ) {
1029
			$classes = "$column_name column-$column_name";
1030
			if ( $primary === $column_name ) {
1031
				$classes .= ' has-row-actions column-primary';
1032
			}
1033
1034
			if ( in_array( $column_name, $hidden ) ) {
1035
				$classes .= ' hidden';
1036
			}
1037
1038
			// Comments column uses HTML in the display name with screen reader text.
1039
			// Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
1040
			$data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
0 ignored issues
show
Bug introduced by
The function wp_strip_all_tags was not found. Maybe you did not declare it correctly or list all 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
			$data = 'data-colname="' . /** @scrutinizer ignore-call */ wp_strip_all_tags( $column_display_name ) . '"';
Loading history...
1041
1042
			$attributes = "class='$classes' $data";
1043
1044
			if ( 'cb' == $column_name ) {
1045
				echo '<th scope="row" class="check-column"></th>';
1046
			} elseif ( method_exists( $this, '_column_' . $column_name ) ) {
1047
				echo call_user_func(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'call_user_func'
Loading history...
1048
					array( $this, '_column_' . $column_name ),
1049
					$item,
1050
					$classes,
1051
					$data,
1052
					$primary
1053
				);
1054
			} elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1055
				echo "<td $attributes>";
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"<td $attributes>"'
Loading history...
1056
				echo call_user_func( array( $this, 'column_' . $column_name ), $item );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'call_user_func'
Loading history...
1057
				echo $this->handle_row_actions( $item, $column_name, $primary );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
1058
				echo '</td>';
1059
			} else {
1060
				echo "<td $attributes>";
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"<td $attributes>"'
Loading history...
1061
				echo $this->handle_row_actions( $item, $column_name, $primary );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
1062
				echo '</td>';
1063
			}
1064
		}
1065
	}
1066
1067
	/**
1068
	 * Generates and display row actions links for the list table.
1069
	 *
1070
	 * @since 4.3.0
1071
	 * @access protected
1072
	 *
1073
	 * @param object $item        The item being acted upon.
1074
	 * @param string $column_name Current column name.
1075
	 * @param string $primary     Primary column name.
1076
	 * @return string The row actions output. In this case, an empty string.
1077
	 */
1078
	protected function handle_row_actions( $item, $column_name, $primary ) {
1079
		return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : '';
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

1079
		return $column_name == $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . /** @scrutinizer ignore-call */ __( 'Show more details' ) . '</span></button>' : '';
Loading history...
1080
 	}
1081
1082
	/**
1083
	 * Handle an incoming ajax request (called from admin-ajax.php)
1084
	 *
1085
	 * @since 2.0.18
1086
	 * @access public
1087
	 */
1088
	public function ajax_response() {
1089
		$this->prepare_items();
1090
1091
		ob_start();
1092
		if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1093
			$this->display_rows();
1094
		} else {
1095
			$this->display_rows_or_placeholder();
1096
		}
1097
1098
		$rows = ob_get_clean();
1099
1100
		$response = array( 'rows' => $rows );
1101
1102
		if ( isset( $this->_pagination_args['total_items'] ) ) {
1103
			$response['total_items_i18n'] = sprintf(
1104
				_n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
0 ignored issues
show
Bug introduced by
The function _n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

1104
				/** @scrutinizer ignore-call */ 
1105
    _n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
Loading history...
1105
				number_format_i18n( $this->_pagination_args['total_items'] )
0 ignored issues
show
Bug introduced by
The function number_format_i18n was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

1105
				/** @scrutinizer ignore-call */ 
1106
    number_format_i18n( $this->_pagination_args['total_items'] )
Loading history...
1106
			);
1107
		}
1108
		if ( isset( $this->_pagination_args['total_pages'] ) ) {
1109
			$response['total_pages'] = $this->_pagination_args['total_pages'];
1110
			$response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1111
		}
1112
1113
		die( wp_json_encode( $response ) );
0 ignored issues
show
Bug introduced by
The function wp_json_encode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

1113
		die( /** @scrutinizer ignore-call */ wp_json_encode( $response ) );
Loading history...
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...
1114
	}
1115
1116
	/**
1117
	 * Send required variables to JavaScript land
1118
	 *
1119
	 * @access public
1120
	 */
1121
	public function _js_vars() {
1122
		$args = array(
1123
			'class'  => get_class( $this ),
1124
			'screen' => array(
1125
				'id'   => $this->screen->id,
1126
				'base' => $this->screen->base,
1127
			),
1128
		);
1129
1130
		printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
0 ignored issues
show
Bug introduced by
The function wp_json_encode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

1130
		printf( "<script type='text/javascript'>list_args = %s;</script>\n", /** @scrutinizer ignore-call */ wp_json_encode( $args ) );
Loading history...
1131
	}
1132
}
1133