2 if ( !class_exists(
'WP_List_Table' ) ) {
3 require_once( ABSPATH .
'wp-admin/includes/class-wp-list-table.php' );
109 parent::__construct(
$args );
112 $this->
id = sanitize_key(
$id );
115 $this->getStatusID = self::GET_STATUS;
119 $this->viewController->view->class[] =
'wpdk-list-table-box';
210 if ( isset( $_REQUEST[
'action'] ) && -1 != $_REQUEST[
'action'] ) {
211 return $_REQUEST[
'action'];
214 if ( isset( $_REQUEST[
'action2'] ) && -1 != $_REQUEST[
'action2'] ) {
215 return $_REQUEST[
'action2'];
248 private function _defaultStatus()
250 $default_status =
'';
252 foreach ( $statuses as $status ) {
253 if ( is_array( $status ) &&
true === $status[1] ) {
254 $default_status = $status[0];
257 elseif ( empty( $default_status ) ) {
258 $default_status = $status;
262 return $default_status;
272 private function _defaultSortableColumn()
274 $sortable_columns = $this->get_sortable_columns();
275 if ( !empty( $sortable_columns ) ) {
276 foreach ( $sortable_columns as $column_name => $value ) {
277 if (
true === $value[1] ) {
292 private function _currentViewStatus()
294 $current_status = isset( $_REQUEST[$this->getStatusID] ) ? $_REQUEST[
$this->getStatusID] : $this->_defaultStatus();
295 return $current_status;
311 private function _SQLDefaultOrder( $default_order =
'ASC' )
313 $column_name = $this->_defaultSortableColumn();
314 $order_by = isset( $_GET[
'order_by'] ) ? $_GET[
'order_by'] : $column_name;
315 $order = isset( $_GET[
'order'] ) ? $_GET[
'order'] : $default_order;
316 return sprintf(
'%s %s', $order_by, $order );
326 private function _SQLStatus()
329 $current_status = $this->_currentViewStatus();
331 return sprintf(
' AND %s = "%s"', $status_field, $current_status );
407 if ( !$this->prepare_items() ) :
410 <form
id=
"<?php echo $this->id ?>" class=
"wpdk-list-table-form" method=
"get" action=
"">
412 <?php
if ( isset( $_REQUEST[
'page'] ) ) : ?>
413 <input type=
"hidden" name=
"page" value=
"<?php echo $_REQUEST['page'] ?>" />
416 <?php
if ( isset( $_REQUEST[
'post_type'] ) ) : ?>
417 <input type=
"hidden" name=
"post_type" value=
"<?php echo $_REQUEST['post_type'] ?>" />
420 <?php
if ( isset( $_REQUEST[
'orderby'] ) ) : ?>
421 <input type=
"hidden" name=
"orderby" value=
"<?php echo $_REQUEST['orderby'] ?>" />
424 <?php
if ( isset( $_REQUEST[
'order'] ) ) : ?>
425 <input type=
"hidden" name=
"order" value=
"<?php echo $_REQUEST['order'] ?>" />
428 <?php do_action(
'wpdk_list_table_form', $this ); ?>
429 <?php unset( $_REQUEST[
'action'] ); ?>
430 <?php $_SERVER[
'REQUEST_URI'] = remove_query_arg( array(
'action',
'_wp_http_referer',
'_wp_nonce' ), $_SERVER[
'REQUEST_URI']); ?>
432 <?php parent::display() ?>
437 $content = ob_get_contents();
440 $this->viewController->viewHead->content = $content;
442 add_action(
'wpdk_header_view_title_did_appear', array( $this,
'wpdk_header_view_title_did_appear' ) );
444 return $this->viewController->html();
456 if (
'new' != $this->current_action() ) {
457 $add_new = sprintf(
'<a class="wpdk-add-new button button-primary" href="%s">%s</a>', $this->
urlAddNew(), __(
'Add New', WPDK_TEXTDOMAIN ) );
458 $add_new = apply_filters(
'wpdk_listtable_viewcontroller_add_new', $add_new, $this );
459 if ( !empty( $add_new ) ) {
479 printf( __(
'No %s found.', WPDK_TEXTDOMAIN ), $this->title );
484 _e(
'Please, check again your search parameters.', WPDK_TEXTDOMAIN );
514 $filter_status = isset( $_GET[$get_status_id] ) ? $_GET[$get_status_id] : $this->_defaultStatus();
517 $uri = ( isset( $_SERVER[
'HTTP_REFERER'] ) &&
wpdk_is_ajax() ) ? $_SERVER[
'HTTP_REFERER'] :
false;
522 $status = is_array( $status ) ? $status[0] : $status;
526 if ( !empty( $count ) ) {
528 $current = ( $filter_status == $key ) ?
'class="current"' :
'';
533 $this->_args[
'singular'] =>
false
535 $href = add_query_arg(
$args, $uri );
537 $views[$key] = sprintf(
'<a %s href="%s">%s <span class="count">(%s)</span></a>', $current, $href, $status, $count );
563 public function prepare_items()
574 $id_user = get_current_user_id();
579 $screen = get_current_screen();
581 $option = $screen->get_option(
'per_page',
'option' );
582 if( !empty( $option ) ) {
583 $per_page = get_user_meta( $id_user, $option,
true );
586 if ( empty ( $per_page ) || $per_page < 1 ) {
587 $per_page = $screen->get_option(
'per_page',
'default' );
588 if( empty( $per_page ) ) {
594 $this->column_headers = $this->get_column_info();
597 $remove = array(
'action' );
598 $_SERVER[
'REQUEST_URI'] = remove_query_arg( $remove, stripslashes( $_SERVER[
'REQUEST_URI'] ) );
601 $data = $this->
data();
608 $current_page = $this->get_pagenum();
616 $total_items = apply_filters(
'wpdk_listtable_total_items_' . $this->
id, count( $data ) );
623 $slice_data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
629 $this->items = apply_filters(
'wpdk_listtable_items_' . $this->
id, $slice_data, $data );
635 'total_items' => $total_items,
636 'per_page' => $per_page,
637 'total_pages' => ceil( $total_items / $per_page )
639 $this->set_pagination_args(
$args );
656 if( !empty( $this->model ) && method_exists( $this->model,
'select' ) ) {
657 return $this->model->select( $_REQUEST );
676 switch ( $column_name ) {
678 return print_r( $item,
true );
698 public function actions_column( $item, $column_name =
'description', $item_status =
'', $custom_content =
'' )
701 $status = $this->_currentViewStatus();
703 if ( !empty( $item_status ) ) {
704 $status = $item_status;
709 if ( !empty( $action ) ) {
712 $this->args[
'singular'] => $item[$this->args[
'singular']]
714 $href = apply_filters(
'wpdk_listtable_action_' . $action, add_query_arg(
$args ),
$args );
715 $stack[$action] = sprintf(
'<a href="%s">%s</a>', $href, $label );
719 $description = empty( $custom_content ) ? sprintf(
'<strong>%s</strong>', $item[$column_name] ) : $custom_content;
720 return sprintf(
'%s %s', $description, $this->row_actions( $stack ) );
736 $name = $this->args[
'singular'];
737 $value = $item[$name];
738 return sprintf(
'<input type="checkbox" name="%s[]" value="%s" />', $name, $value );
751 $current_status = isset( $_REQUEST[$this->getStatusID] ) ? $_REQUEST[
$this->getStatusID] : $this->_defaultStatus();
770 die( __METHOD__ .
' must be over-ridden in a sub-class.' );
796 foreach (
$args[
'actions'] as $key => $label ) {
801 $href = add_query_arg(
$args );
802 $actions[$key] = sprintf(
'<a href="%s">%s</a>', $href, $label );
805 if ( empty( $status ) || $status !=
'trash' ) {
806 unset( $actions[
'untrash'] );
807 unset( $actions[
'delete'] );
809 else if ( $status ==
'trash' ) {
810 unset( $actions[
'edit'] );
811 unset( $actions[
'trash'] );
832 $this->_args[
'singular']
834 $url = remove_query_arg( $remove, stripslashes( $_SERVER[
'REQUEST_URI'] ) );
850 $this->_args[
'singular']
852 $url = remove_query_arg( $remove, stripslashes( $_SERVER[
'REQUEST_URI'] ) );
867 'page' => $_REQUEST[
'page']
918 die( __METHOD__ .
' must be override in your subclass' );