Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../deprecat.../classes
File: notifications-table.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/*************************** LOAD THE BASE CLASS *******************************
[2] Fix | Delete
*******************************************************************************
[3] Fix | Delete
* The WP_List_Table class isn't automatically available to plugins, so we need
[4] Fix | Delete
* to check if it's available and load it if necessary. In this tutorial, we are
[5] Fix | Delete
* going to use the WP_List_Table class directly from WordPress core.
[6] Fix | Delete
*
[7] Fix | Delete
* IMPORTANT:
[8] Fix | Delete
* Please note that the WP_List_Table class technically isn't an official API,
[9] Fix | Delete
* and it could change at some point in the distant future. Should that happen,
[10] Fix | Delete
* I will update this plugin with the most current techniques for your reference
[11] Fix | Delete
* immediately.
[12] Fix | Delete
*
[13] Fix | Delete
* If you are really worried about future compatibility, you can make a copy of
[14] Fix | Delete
* the WP_List_Table class (file path is shown just below) to use and distribute
[15] Fix | Delete
* with your plugins. If you do that, just remember to change the name of the
[16] Fix | Delete
* class to avoid conflicts with core.
[17] Fix | Delete
*
[18] Fix | Delete
* Since I will be keeping this tutorial up-to-date for the foreseeable future,
[19] Fix | Delete
* I am going to work with the copy of the class provided in WordPress core.
[20] Fix | Delete
*/
[21] Fix | Delete
if( ! class_exists( 'WP_List_Table' ) ) {
[22] Fix | Delete
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/************************** CREATE A PACKAGE CLASS *****************************
[26] Fix | Delete
*******************************************************************************
[27] Fix | Delete
* Create a new list table package that extends the core WP_List_Table class.
[28] Fix | Delete
* WP_List_Table contains most of the framework for generating the table, but we
[29] Fix | Delete
* need to define and override some methods so that our data can be displayed
[30] Fix | Delete
* exactly the way we need it to be.
[31] Fix | Delete
*
[32] Fix | Delete
* To display this example on a page, you will first need to instantiate the class,
[33] Fix | Delete
* then call $yourInstance->prepare_items() to handle any data manipulation, then
[34] Fix | Delete
* finally call $yourInstance->display() to render the table to the page.
[35] Fix | Delete
*
[36] Fix | Delete
* Our theme for this list table is going to be movies.
[37] Fix | Delete
*/
[38] Fix | Delete
class NF_Notifications_List_Table extends WP_List_Table {
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* @var form_id
[42] Fix | Delete
*/
[43] Fix | Delete
var $form_id = '';
[44] Fix | Delete
[45] Fix | Delete
/** ************************************************************************
[46] Fix | Delete
* REQUIRED. Set up a constructor that references the parent constructor. We
[47] Fix | Delete
* use the parent reference to set some default configs.
[48] Fix | Delete
***************************************************************************/
[49] Fix | Delete
function __construct(){
[50] Fix | Delete
global $status, $page;
[51] Fix | Delete
[52] Fix | Delete
//Set parent defaults
[53] Fix | Delete
parent::__construct( array(
[54] Fix | Delete
'singular' => 'notification', //singular name of the listed records
[55] Fix | Delete
'plural' => 'notifications', //plural name of the listed records
[56] Fix | Delete
'ajax' => false //does this table support ajax?
[57] Fix | Delete
) );
[58] Fix | Delete
[59] Fix | Delete
$this->form_id = isset ( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : '';
[60] Fix | Delete
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/** ************************************************************************
[64] Fix | Delete
* Recommended. This method is called when the parent class can't find a method
[65] Fix | Delete
* specifically build for a given column. Generally, it's recommended to include
[66] Fix | Delete
* one method for each column you want to render, keeping your package class
[67] Fix | Delete
* neat and organized. For example, if the class needs to process a column
[68] Fix | Delete
* named 'title', it would first see if a method named $this->column_title()
[69] Fix | Delete
* exists - if it does, that method will be used. If it doesn't, this one will
[70] Fix | Delete
* be used. Generally, you should try to use custom column methods as much as
[71] Fix | Delete
* possible.
[72] Fix | Delete
*
[73] Fix | Delete
* Since we have defined a column_title() method later on, this method doesn't
[74] Fix | Delete
* need to concern itself with any column with a name of 'title'. Instead, it
[75] Fix | Delete
* needs to handle everything else.
[76] Fix | Delete
*
[77] Fix | Delete
* For more detailed insight into how columns are handled, take a look at
[78] Fix | Delete
* WP_List_Table::single_row_columns()
[79] Fix | Delete
*
[80] Fix | Delete
* @param array $item A singular item (one full row's worth of data)
[81] Fix | Delete
* @param array $column_name The name/slug of the column to be processed
[82] Fix | Delete
* @return string Text or HTML to be placed inside the column <td>
[83] Fix | Delete
**************************************************************************/
[84] Fix | Delete
public function column_default($item, $column_name){
[85] Fix | Delete
switch($column_name){
[86] Fix | Delete
case 'type':
[87] Fix | Delete
return Ninja_Forms()->notification( $item['id'] )->type_name();
[88] Fix | Delete
case 'date_updated':
[89] Fix | Delete
return $item[$column_name];
[90] Fix | Delete
default:
[91] Fix | Delete
return print_r($item,true); //Show the whole array for troubleshooting purposes
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/** ************************************************************************
[96] Fix | Delete
* Recommended. This is a custom column method and is responsible for what
[97] Fix | Delete
* is rendered in any column with a name/slug of 'title'. Every time the class
[98] Fix | Delete
* needs to render a column, it first looks for a method named
[99] Fix | Delete
* column_{$column_title} - if it exists, that method is run. If it doesn't
[100] Fix | Delete
* exist, column_default() is called instead.
[101] Fix | Delete
*
[102] Fix | Delete
* This example also illustrates how to implement rollover actions. Actions
[103] Fix | Delete
* should be an associative array formatted as 'slug'=>'link html' - and you
[104] Fix | Delete
* will need to generate the URLs yourself. You could even ensure the links
[105] Fix | Delete
*
[106] Fix | Delete
*
[107] Fix | Delete
* @see WP_List_Table::::single_row_columns()
[108] Fix | Delete
* @param array $item A singular item (one full row's worth of data)
[109] Fix | Delete
* @return string Text to be placed inside the column <td> (movie title only)
[110] Fix | Delete
**************************************************************************/
[111] Fix | Delete
public function column_name( $item ){
[112] Fix | Delete
[113] Fix | Delete
$base_url = esc_url_raw( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ) ) );
[114] Fix | Delete
[115] Fix | Delete
$activate_text = ( Ninja_Forms()->notification( $item['id'] )->active ) ? __( 'Deactivate', 'ninja-forms' ) : __( 'Activate', 'ninja-forms' );
[116] Fix | Delete
[117] Fix | Delete
$activate_action = ( Ninja_Forms()->notification( $item['id'] )->active ) ? 'deactivate' : 'activate';
[118] Fix | Delete
[119] Fix | Delete
$activate_url = esc_url( add_query_arg( array( 'notification-action' => $activate_action, 'id' => $item['id'] ), $base_url ) );
[120] Fix | Delete
$edit_url = esc_url( add_query_arg( array( 'notification-action' => 'edit', 'id' => $item['id'] ), $base_url ) );
[121] Fix | Delete
$delete_url = esc_url( add_query_arg( array( 'action' => 'delete' ), $base_url ) );
[122] Fix | Delete
$duplicate_url = esc_url( add_query_arg( array( 'notification-action' => 'duplicate', 'id' => $item['id'] ), $base_url ) );
[123] Fix | Delete
[124] Fix | Delete
//Build row actions
[125] Fix | Delete
$actions = array(
[126] Fix | Delete
'active' => '<a href="' . $activate_url . '" class="notification-activate" data-action="' . $activate_action . '" data-n_id="' . $item['id'] . '">' . $activate_text . '</a>',
[127] Fix | Delete
'edit' => '<a href="' . $edit_url . '">' . __( 'Edit', 'ninja-forms' ) . '</a>',
[128] Fix | Delete
'delete' => '<a href="' . $delete_url .'" class="notification-delete" data-n_id="' . $item['id'] . '">' . __( 'Delete', 'ninja-forms' ) . '</a>',
[129] Fix | Delete
'duplicate' => '<a href="' . $duplicate_url .'">' . __( 'Duplicate', 'ninja-forms' ) . '</a>',
[130] Fix | Delete
);
[131] Fix | Delete
[132] Fix | Delete
//Return the title contents
[133] Fix | Delete
return sprintf( '<a href="%1$s">%2$s</a> %3$s',
[134] Fix | Delete
/*$1%s*/ $edit_url,
[135] Fix | Delete
/*$2%s*/ $item['name'],
[136] Fix | Delete
/*$3%s*/ $this->row_actions($actions)
[137] Fix | Delete
);
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/** ************************************************************************
[141] Fix | Delete
* REQUIRED if displaying checkboxes or using bulk actions! The 'cb' column
[142] Fix | Delete
* is given special treatment when columns are processed. It ALWAYS needs to
[143] Fix | Delete
* have it's own method.
[144] Fix | Delete
*
[145] Fix | Delete
* @see WP_List_Table::::single_row_columns()
[146] Fix | Delete
* @param array $item A singular item (one full row's worth of data)
[147] Fix | Delete
* @return string Text to be placed inside the column <td> (movie title only)
[148] Fix | Delete
**************************************************************************/
[149] Fix | Delete
public function column_cb($item){
[150] Fix | Delete
return sprintf(
[151] Fix | Delete
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
[152] Fix | Delete
/*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
[153] Fix | Delete
/*$2%s*/ $item['id'] //The value of the checkbox should be the record's id
[154] Fix | Delete
);
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/** ************************************************************************
[158] Fix | Delete
* REQUIRED! This method dictates the table's columns and titles. This should
[159] Fix | Delete
* return an array where the key is the column slug (and class) and the value
[160] Fix | Delete
* is the column's title text. If you need a checkbox for bulk actions, refer
[161] Fix | Delete
* to the $columns array below.
[162] Fix | Delete
*
[163] Fix | Delete
* The 'cb' column is treated differently than the rest. If including a checkbox
[164] Fix | Delete
* column in your table you must create a column_cb() method. If you don't need
[165] Fix | Delete
* bulk actions or checkboxes, simply leave the 'cb' entry out of your array.
[166] Fix | Delete
*
[167] Fix | Delete
* @see WP_List_Table::::single_row_columns()
[168] Fix | Delete
* @return array An associative array containing column information: 'slugs'=>'Visible Titles'
[169] Fix | Delete
**************************************************************************/
[170] Fix | Delete
public function get_columns(){
[171] Fix | Delete
$columns = array(
[172] Fix | Delete
'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
[173] Fix | Delete
'name' => __( 'Name', 'ninja-forms' ),
[174] Fix | Delete
'type' => __( 'Type', 'ninja-forms' ),
[175] Fix | Delete
'date_updated' => __( 'Date Updated', 'ninja-forms' ),
[176] Fix | Delete
);
[177] Fix | Delete
return $columns;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
/** ************************************************************************
[181] Fix | Delete
* Optional. If you want one or more columns to be sortable (ASC/DESC toggle),
[182] Fix | Delete
* you will need to register it here. This should return an array where the
[183] Fix | Delete
* key is the column that needs to be sortable, and the value is db column to
[184] Fix | Delete
* sort by. Often, the key and value will be the same, but this is not always
[185] Fix | Delete
* the case (as the value is a column name from the database, not the list table).
[186] Fix | Delete
*
[187] Fix | Delete
* This method merely defines which columns should be sortable and makes them
[188] Fix | Delete
* clickable - it does not handle the actual sorting. You still need to detect
[189] Fix | Delete
* the ORDERBY and ORDER querystring variables within prepare_items() and sort
[190] Fix | Delete
* your data accordingly (usually by modifying your query).
[191] Fix | Delete
*
[192] Fix | Delete
* @return array An associative array containing all the columns that should be sortable: 'slugs'=>array('data_values',bool)
[193] Fix | Delete
**************************************************************************/
[194] Fix | Delete
public function get_sortable_columns() {
[195] Fix | Delete
$sortable_columns = array(
[196] Fix | Delete
'name' => array( 'name',false ), //true means it's already sorted
[197] Fix | Delete
'type' => array( 'type',false ),
[198] Fix | Delete
'date_updated' => array( 'date_updated',false )
[199] Fix | Delete
);
[200] Fix | Delete
return $sortable_columns;
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
/** ************************************************************************
[204] Fix | Delete
* Optional. If you need to include bulk actions in your list table, this is
[205] Fix | Delete
* the place to define them. Bulk actions are an associative array in the format
[206] Fix | Delete
* 'slug'=>'Visible Title'
[207] Fix | Delete
*
[208] Fix | Delete
* If this method returns an empty value, no bulk action will be rendered. If
[209] Fix | Delete
* you specify any bulk actions, the bulk actions box will be rendered with
[210] Fix | Delete
* the table automatically on display().
[211] Fix | Delete
*
[212] Fix | Delete
* Also note that list tables are not automatically wrapped in <form> elements,
[213] Fix | Delete
* so you will need to create those manually in order for bulk actions to function.
[214] Fix | Delete
*
[215] Fix | Delete
* @return array An associative array containing all the bulk actions: 'slugs'=>'Visible Titles'
[216] Fix | Delete
**************************************************************************/
[217] Fix | Delete
public function get_bulk_actions() {
[218] Fix | Delete
$actions = array(
[219] Fix | Delete
'activate' => __( 'Activate', 'ninja-forms' ),
[220] Fix | Delete
'deactivate' => __( 'Deactivate', 'ninja-forms' ),
[221] Fix | Delete
'delete' => __( 'Delete', 'ninja-forms' ),
[222] Fix | Delete
);
[223] Fix | Delete
return $actions;
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
public function extra_tablenav( $which ) {
[227] Fix | Delete
if ( $which == 'bottom' )
[228] Fix | Delete
return false;
[229] Fix | Delete
[230] Fix | Delete
if ( isset ( $_REQUEST['type'] ) ) {
[231] Fix | Delete
$type = esc_html( $_REQUEST['type'] );
[232] Fix | Delete
} else {
[233] Fix | Delete
$type = '';
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
?>
[237] Fix | Delete
<div class="alignleft actions">
[238] Fix | Delete
<select name="type" id="filter-type">
[239] Fix | Delete
<option value="" <?php selected( $type, '' ); ?>><?php _e( '- View All Types', 'ninja-forms' ); ?></option>
[240] Fix | Delete
<?php
[241] Fix | Delete
foreach ( Ninja_Forms()->notifications->get_types() as $slug => $nicename ) {
[242] Fix | Delete
?>
[243] Fix | Delete
<option value="<?php echo $slug; ?>" <?php selected( $type, $slug ); ?>><?php echo $nicename; ?></option>
[244] Fix | Delete
<?php
[245] Fix | Delete
}
[246] Fix | Delete
?>
[247] Fix | Delete
</select>
[248] Fix | Delete
<span class="nf-more-actions"><a href="<?php echo nf_aff_link( 'https://ninjaforms.com/extensions/?display=actions&utm_medium=plugin&utm_source=actions-table&utm_campaign=Ninja+Forms+Upsell&utm_content=Ninja+Forms+Actions' ); ?>" target="_blank"><?php _e( 'Get More Types', 'ninja-forms' ); ?> <span class="dashicons dashicons-external"></span></a></span>
[249] Fix | Delete
<span style="float:left;" class="spinner"></span>
[250] Fix | Delete
</div>
[251] Fix | Delete
<?php
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
/**
[255] Fix | Delete
* Generates content for a single row of the table
[256] Fix | Delete
*
[257] Fix | Delete
* @since 3.1.0
[258] Fix | Delete
* @access protected
[259] Fix | Delete
*
[260] Fix | Delete
* @param object $item The current item
[261] Fix | Delete
*/
[262] Fix | Delete
function single_row( $item ) {
[263] Fix | Delete
static $alternate = '';
[264] Fix | Delete
[265] Fix | Delete
$active = ( Ninja_Forms()->notification( $item['id'] )->active ) ? 'nf-notification-active ' : 'nf-notification-inactive';
[266] Fix | Delete
$alternate = ( $alternate == '' ? 'alternate' : '' );
[267] Fix | Delete
[268] Fix | Delete
echo '<tr class="' . $active . ' ' . $alternate . '" id="' . $item['id'] . '">';
[269] Fix | Delete
$this->single_row_columns( $item );
[270] Fix | Delete
echo '</tr>';
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/** ************************************************************************
[274] Fix | Delete
* REQUIRED! This is where you prepare your data for display. This method will
[275] Fix | Delete
* usually be used to query the database, sort and filter the data, and generally
[276] Fix | Delete
* get it ready to be displayed. At a minimum, we should set $this->items and
[277] Fix | Delete
* $this->set_pagination_args(), although the following properties and methods
[278] Fix | Delete
* are frequently interacted with here...
[279] Fix | Delete
*
[280] Fix | Delete
* @global WPDB $wpdb
[281] Fix | Delete
* @uses $this->_column_headers
[282] Fix | Delete
* @uses $this->items
[283] Fix | Delete
* @uses $this->get_columns()
[284] Fix | Delete
* @uses $this->get_sortable_columns()
[285] Fix | Delete
* @uses $this->get_pagenum()
[286] Fix | Delete
* @uses $this->set_pagination_args()
[287] Fix | Delete
**************************************************************************/
[288] Fix | Delete
public function prepare_items() {
[289] Fix | Delete
global $wpdb; //This is used only if making any database queries
[290] Fix | Delete
[291] Fix | Delete
/**
[292] Fix | Delete
* First, lets decide how many records per page to show
[293] Fix | Delete
*/
[294] Fix | Delete
$per_page = 99999;
[295] Fix | Delete
[296] Fix | Delete
[297] Fix | Delete
/**
[298] Fix | Delete
* REQUIRED. Now we need to define our column headers. This includes a complete
[299] Fix | Delete
* array of columns to be displayed (slugs & titles), a list of columns
[300] Fix | Delete
* to keep hidden, and a list of columns that are sortable. Each of these
[301] Fix | Delete
* can be defined in another method (as we've done here) before being
[302] Fix | Delete
* used to build the value for our _column_headers property.
[303] Fix | Delete
*/
[304] Fix | Delete
$columns = $this->get_columns();
[305] Fix | Delete
$hidden = array();
[306] Fix | Delete
$sortable = $this->get_sortable_columns();
[307] Fix | Delete
[308] Fix | Delete
[309] Fix | Delete
/**
[310] Fix | Delete
* REQUIRED. Finally, we build an array to be used by the class for column
[311] Fix | Delete
* headers. The $this->_column_headers property takes an array which contains
[312] Fix | Delete
* 3 other arrays. One for all columns, one for hidden columns, and one
[313] Fix | Delete
* for sortable columns.
[314] Fix | Delete
*/
[315] Fix | Delete
$this->_column_headers = array($columns, $hidden, $sortable);
[316] Fix | Delete
[317] Fix | Delete
[318] Fix | Delete
/**
[319] Fix | Delete
* Optional. You can handle your bulk actions however you see fit. In this
[320] Fix | Delete
* case, we'll handle them within our package just to keep things clean.
[321] Fix | Delete
*/
[322] Fix | Delete
//$this->process_bulk_action();
[323] Fix | Delete
[324] Fix | Delete
[325] Fix | Delete
/**
[326] Fix | Delete
* Instead of querying a database, we're going to fetch the example data
[327] Fix | Delete
* property we created for use in this plugin. This makes this example
[328] Fix | Delete
* package slightly different than one you might build on your own. In
[329] Fix | Delete
* this example, we'll be using array manipulation to sort and paginate
[330] Fix | Delete
* our data. In a real-world implementation, you will probably want to
[331] Fix | Delete
* use sort and pagination data to build a custom query instead, as you'll
[332] Fix | Delete
* be able to use your precisely-queried data immediately.
[333] Fix | Delete
*/
[334] Fix | Delete
$notifications = nf_get_notifications_by_form_id( $this->form_id );
[335] Fix | Delete
$data = array();
[336] Fix | Delete
[337] Fix | Delete
if ( is_array( $notifications ) ) {
[338] Fix | Delete
foreach ( $notifications as $id => $n ) {
[339] Fix | Delete
if ( isset ( $_REQUEST['type'] ) && ! empty( $_REQUEST['type'] ) ) {
[340] Fix | Delete
if ( nf_get_object_meta_value( $id, 'type' ) == esc_html( $_REQUEST['type'] ) ) {
[341] Fix | Delete
$n['id'] = $id;
[342] Fix | Delete
$data[] = $n;
[343] Fix | Delete
}
[344] Fix | Delete
} else {
[345] Fix | Delete
$n['id'] = $id;
[346] Fix | Delete
$data[] = $n;
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
}
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
/**
[353] Fix | Delete
* This checks for sorting input and sorts the data in our array accordingly.
[354] Fix | Delete
*
[355] Fix | Delete
* In a real-world situation involving a database, you would probably want
[356] Fix | Delete
* to handle sorting by passing the 'orderby' and 'order' values directly
[357] Fix | Delete
* to a custom query. The returned data will be pre-sorted, and this array
[358] Fix | Delete
* sorting technique would be unnecessary.
[359] Fix | Delete
*/
[360] Fix | Delete
function usort_reorder($a,$b){
[361] Fix | Delete
$orderby = (!empty($_REQUEST['orderby'])) ? esc_html( $_REQUEST['orderby'] ) : 'name'; //If no sort, default to title
[362] Fix | Delete
$order = (!empty($_REQUEST['order'])) ? esc_html( $_REQUEST['order'] ) : 'asc'; //If no order, default to asc
[363] Fix | Delete
$result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
[364] Fix | Delete
return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
[365] Fix | Delete
}
[366] Fix | Delete
usort($data, 'usort_reorder');
[367] Fix | Delete
[368] Fix | Delete
[369] Fix | Delete
/***********************************************************************
[370] Fix | Delete
* ---------------------------------------------------------------------
[371] Fix | Delete
* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
[372] Fix | Delete
*
[373] Fix | Delete
* In a real-world situation, this is where you would place your query.
[374] Fix | Delete
*
[375] Fix | Delete
* For information on making queries in WordPress, see this Codex entry:
[376] Fix | Delete
* http://codex.wordpress.org/Class_Reference/wpdb
[377] Fix | Delete
*
[378] Fix | Delete
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[379] Fix | Delete
* ---------------------------------------------------------------------
[380] Fix | Delete
**********************************************************************/
[381] Fix | Delete
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* REQUIRED for pagination. Let's figure out what page the user is currently
[385] Fix | Delete
* looking at. We'll need this later, so you should always include it in
[386] Fix | Delete
* your own package classes.
[387] Fix | Delete
*/
[388] Fix | Delete
$current_page = $this->get_pagenum();
[389] Fix | Delete
[390] Fix | Delete
/**
[391] Fix | Delete
* REQUIRED for pagination. Let's check how many items are in our data array.
[392] Fix | Delete
* In real-world use, this would be the total number of items in your database,
[393] Fix | Delete
* without filtering. We'll need this later, so you should always include it
[394] Fix | Delete
* in your own package classes.
[395] Fix | Delete
*/
[396] Fix | Delete
$total_items = count($data);
[397] Fix | Delete
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* The WP_List_Table class does not handle pagination for us, so we need
[401] Fix | Delete
* to ensure that the data is trimmed to only the current page. We can use
[402] Fix | Delete
* array_slice() to
[403] Fix | Delete
*/
[404] Fix | Delete
$data = array_slice($data,(($current_page-1)*$per_page),$per_page);
[405] Fix | Delete
[406] Fix | Delete
[407] Fix | Delete
[408] Fix | Delete
/**
[409] Fix | Delete
* REQUIRED. Now we can add our *sorted* data to the items property, where
[410] Fix | Delete
* it can be used by the rest of the class.
[411] Fix | Delete
*/
[412] Fix | Delete
$this->items = $data;
[413] Fix | Delete
[414] Fix | Delete
[415] Fix | Delete
/**
[416] Fix | Delete
* REQUIRED. We also have to register our pagination options & calculations.
[417] Fix | Delete
*/
[418] Fix | Delete
$this->set_pagination_args( array(
[419] Fix | Delete
'total_items' => $total_items, //WE have to calculate the total number of items
[420] Fix | Delete
'per_page' => $per_page, //WE have to determine how many items to show on a page
[421] Fix | Delete
'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages
[422] Fix | Delete
) );
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function