| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
/* |
| 6 |
Code taken from: Custom List Table Example (plugin) |
| 7 |
Author: Matt Van Andel |
| 8 |
Author URI: http://www.mattvanandel.com |
| 9 |
*/ |
| 10 |
|
| 11 |
/*************************** LOAD THE BASE CLASS ******************************* |
| 12 |
******************************************************************************* |
| 13 |
* The PB_WP_List_Table class isn't automatically available to plugins, so we need |
| 14 |
* to check if it's available and load it if necessary. |
| 15 |
*/ |
| 16 |
if( !class_exists( 'PB_WP_List_Table' ) ){ |
| 17 |
require_once( WPPB_PLUGIN_DIR.'/assets/lib/class-list-table.php' ); |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
/************************** CREATE A PACKAGE CLASS ***************************** |
| 24 |
******************************************************************************* |
| 25 |
* Create a new list table package that extends the core PB_WP_List_Table class. |
| 26 |
* PB_WP_List_Table contains most of the framework for generating the table, but we |
| 27 |
* need to define and override some methods so that our data can be displayed |
| 28 |
* exactly the way we need it to be. |
| 29 |
* |
| 30 |
* To display this example on a page, you will first need to instantiate the class, |
| 31 |
* then call $yourInstance->prepare_items() to handle any data manipulation, then |
| 32 |
* finally call $yourInstance->display() to render the table to the page. |
| 33 |
* |
| 34 |
*/ |
| 35 |
class wpp_list_unfonfirmed_email_table extends PB_WP_List_Table { |
| 36 |
|
| 37 |
/** ************************************************************************ |
| 38 |
* REQUIRED. Set up a constructor that references the parent constructor. We |
| 39 |
* use the parent reference to set some default configs. |
| 40 |
***************************************************************************/ |
| 41 |
function __construct(){ |
| 42 |
global $status, $page; |
| 43 |
global $wpdb; |
| 44 |
|
| 45 |
//Set parent defaults |
| 46 |
parent::__construct( array( |
| 47 |
'singular' => 'user', //singular name of the listed records |
| 48 |
'plural' => 'users', //plural name of the listed records |
| 49 |
'ajax' => false //does this table support ajax? |
| 50 |
) ); |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
/** ************************************************************************ |
| 56 |
* Recommended. This method is called when the parent class can't find a method |
| 57 |
* specifically build for a given column. Generally, it's recommended to include |
| 58 |
* one method for each column you want to render, keeping your package class |
| 59 |
* neat and organized. For example, if the class needs to process a column |
| 60 |
* named 'username', it would first see if a method named $this->column_title() |
| 61 |
* exists - if it does, that method will be used. If it doesn't, this one will |
| 62 |
* be used. Generally, you should try to use custom column methods as much as |
| 63 |
* possible. |
| 64 |
* |
| 65 |
* Since we have defined a column_title() method later on, this method doesn't |
| 66 |
* need to concern itself with any column with a name of 'username'. Instead, it |
| 67 |
* needs to handle everything else. |
| 68 |
* |
| 69 |
* For more detailed insight into how columns are handled, take a look at |
| 70 |
* PB_WP_List_Table::single_row_columns() |
| 71 |
* |
| 72 |
* @param array $item A singular item (one full row's worth of data) |
| 73 |
* @param array $column_name The name/slug of the column to be processed |
| 74 |
* @return string Text or HTML to be placed inside the column <td> |
| 75 |
**************************************************************************/ |
| 76 |
function column_default($item, $column_name){ |
| 77 |
switch($column_name){ |
| 78 |
case 'email': |
| 79 |
return esc_html( $item[$column_name] ); |
| 80 |
case 'registered': |
| 81 |
return date_i18n( "Y-m-d G:i:s", wppb_add_gmt_offset( strtotime( $item[$column_name] ) ) ); |
| 82 |
case 'user-meta': |
| 83 |
global $wpdb; |
| 84 |
$sql_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->base_prefix . "signups WHERE user_email = %s", $item['email'] ), ARRAY_A ); |
| 85 |
$user_meta = $sql_result['meta']; |
| 86 |
$user_meta_lines = array(); |
| 87 |
if ( ! empty( $user_meta ) ) { |
| 88 |
foreach ( maybe_unserialize( $user_meta ) as $key => $value ) { |
| 89 |
if ( 'user_pass' === $key ) { |
| 90 |
continue; |
| 91 |
} |
| 92 |
if ( is_array( $value ) ) { |
| 93 |
$value = implode( ',', $value ); |
| 94 |
} |
| 95 |
$user_meta_lines[] = esc_html( (string) $key ) . ':' . esc_html( (string) $value ); |
| 96 |
} |
| 97 |
} |
| 98 |
$user_meta_html = '<div><pre>' . implode( "\n", $user_meta_lines ) . '</pre></div>'; |
| 99 |
$dialog_js = 'jQuery(\'' . esc_js( $user_meta_html ) . '\').dialog({title:\'' . esc_js( __( 'User Meta', 'profile-builder' ) ) . '\', width: 500 }); return false;'; |
| 100 |
return '<a href="#" data-email="' . esc_attr( $item['email'] ) . '" onclick="' . esc_attr( $dialog_js ) . '">' . esc_html__( 'show', 'profile-builder' ) . '</a>'; |
| 101 |
default: |
| 102 |
return print_r($item,true); //Show the whole array for troubleshooting purposes |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
/** |
| 108 |
* Unconfirmed-user row action. Args live on data attributes so the email is never interpolated into JavaScript. |
| 109 |
*/ |
| 110 |
function wppb_ec_action_link( $url, $todo, $email, $confirm_message, $label ) { |
| 111 |
return sprintf( |
| 112 |
'<a href="#" class="wppb-ec-action" data-url="%1$s" data-todo="%2$s" data-email="%3$s" data-message="%4$s">%5$s</a>', |
| 113 |
esc_url( $url ), |
| 114 |
esc_attr( $todo ), |
| 115 |
esc_attr( $email ), |
| 116 |
esc_attr( $confirm_message ), |
| 117 |
esc_html( $label ) |
| 118 |
); |
| 119 |
} |
| 120 |
|
| 121 |
/** ************************************************************************ |
| 122 |
* Recommended. This is a custom column method and is responsible for what |
| 123 |
* is rendered in any column with a name/slug of 'username'. Every time the class |
| 124 |
* needs to render a column, it first looks for a method named |
| 125 |
* column_{$column_title} - if it exists, that method is run. If it doesn't |
| 126 |
* exist, column_default() is called instead. |
| 127 |
* |
| 128 |
* This example also illustrates how to implement rollover actions. Actions |
| 129 |
* should be an associative array formatted as 'slug'=>'link html' - and you |
| 130 |
* will need to generate the URLs yourself. You could even ensure the links |
| 131 |
* |
| 132 |
* |
| 133 |
* @see PB_WP_List_Table::::single_row_columns() |
| 134 |
* @param array $item A singular item (one full row's worth of data) |
| 135 |
* @return string Text to be placed inside the column <td> |
| 136 |
**************************************************************************/ |
| 137 |
function column_username( $item ) { |
| 138 |
|
| 139 |
$GRavatar = get_avatar( $item['email'], 32, '' ); |
| 140 |
$current_url = wppb_curpageurl(); |
| 141 |
$email = $item['ID']; |
| 142 |
|
| 143 |
$actions = array( |
| 144 |
'delete' => $this->wppb_ec_action_link( $current_url, 'delete', $email, __( 'delete this user from the _signups table?', 'profile-builder' ), __( 'Delete', 'profile-builder' ) ), |
| 145 |
'confirm' => $this->wppb_ec_action_link( $current_url, 'confirm', $email, __( 'confirm this email yourself?', 'profile-builder' ), __( 'Confirm Email', 'profile-builder' ) ), |
| 146 |
'resend' => $this->wppb_ec_action_link( $current_url, 'resend', $email, __( 'resend the activation link?', 'profile-builder' ), __( 'Resend Activation Email', 'profile-builder' ) ), |
| 147 |
); |
| 148 |
|
| 149 |
//Return the user row |
| 150 |
return sprintf('%1$s <strong>%2$s</strong> %3$s', |
| 151 |
/*$1%s*/ $GRavatar, |
| 152 |
/*$2%s*/ esc_html( $item['username'] ), |
| 153 |
/*$3%s*/ $this->row_actions($actions) |
| 154 |
); |
| 155 |
} |
| 156 |
|
| 157 |
/** ************************************************************************ |
| 158 |
* REQUIRED if displaying checkboxes or using bulk actions! The 'cb' column |
| 159 |
* is given special treatment when columns are processed. It ALWAYS needs to |
| 160 |
* have it's own method. |
| 161 |
* |
| 162 |
* @see PB_WP_List_Table::::single_row_columns() |
| 163 |
* @param array $item A singular item (one full row's worth of data) |
| 164 |
* @return string Text to be placed inside the column <td> |
| 165 |
**************************************************************************/ |
| 166 |
function column_cb($item){ |
| 167 |
return sprintf( |
| 168 |
'<input type="checkbox" name="%1$s[]" value="%2$s" />', |
| 169 |
/*$1%s*/ esc_attr( $this->_args['singular'] ), |
| 170 |
/*$2%s*/ esc_attr( $item['ID'] ) |
| 171 |
); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
/** ************************************************************************ |
| 176 |
* REQUIRED! This method dictates the table's columns and titles. This should |
| 177 |
* return an array where the key is the column slug (and class) and the value |
| 178 |
* is the column's title text. If you need a checkbox for bulk actions, refer |
| 179 |
* to the $columns array below. |
| 180 |
* |
| 181 |
* The 'cb' column is treated differently than the rest. If including a checkbox |
| 182 |
* column in your table you must create a column_cb() method. If you don't need |
| 183 |
* bulk actions or checkboxes, simply leave the 'cb' entry out of your array. |
| 184 |
* |
| 185 |
* @see PB_WP_List_Table::::single_row_columns() |
| 186 |
* @return array An associative array containing column information: 'slugs'=>'Visible Titles' |
| 187 |
**************************************************************************/ |
| 188 |
function get_columns(){ |
| 189 |
$columns = array( |
| 190 |
'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
| 191 |
'username' => __( 'Username', 'profile-builder' ), |
| 192 |
'email' => __( 'Email', 'profile-builder' ), |
| 193 |
'registered' => __( 'Registered', 'profile-builder' ), |
| 194 |
'user-meta' => __( 'User Meta', 'profile-builder' ) |
| 195 |
); |
| 196 |
|
| 197 |
return $columns; |
| 198 |
} |
| 199 |
|
| 200 |
/** ************************************************************************ |
| 201 |
* Optional. If you want one or more columns to be sortable (ASC/DESC toggle), |
| 202 |
* you will need to register it here. This should return an array where the |
| 203 |
* key is the column that needs to be sortable, and the value is db column to |
| 204 |
* sort by. Often, the key and value will be the same, but this is not always |
| 205 |
* the case (as the value is a column name from the database, not the list table). |
| 206 |
* |
| 207 |
* This method merely defines which columns should be sortable and makes them |
| 208 |
* clickable - it does not handle the actual sorting. You still need to detect |
| 209 |
* the ORDERBY and ORDER querystring variables within prepare_items() and sort |
| 210 |
* your data accordingly (usually by modifying your query). |
| 211 |
* |
| 212 |
* @return array An associative array containing all the columns that should be sortable: 'slugs'=>array('data_values',bool) |
| 213 |
**************************************************************************/ |
| 214 |
function get_sortable_columns() { |
| 215 |
$sortable_columns = array( |
| 216 |
'username' => array('username',false), //true means it's already sorted |
| 217 |
'email' => array('email',false), |
| 218 |
'registered' => array('registered',false) |
| 219 |
); |
| 220 |
|
| 221 |
return $sortable_columns; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
/** ************************************************************************ |
| 226 |
* Optional. If you need to include bulk actions in your list table, this is |
| 227 |
* the place to define them. Bulk actions are an associative array in the format |
| 228 |
* 'slug'=>'Visible Title' |
| 229 |
* |
| 230 |
* If this method returns an empty value, no bulk action will be rendered. If |
| 231 |
* you specify any bulk actions, the bulk actions box will be rendered with |
| 232 |
* the table automatically on display(). |
| 233 |
* |
| 234 |
* Also note that list tables are not automatically wrapped in <form> elements, |
| 235 |
* so you will need to create those manually in order for bulk actions to function. |
| 236 |
* |
| 237 |
* @return array An associative array containing all the bulk actions: 'slugs'=>'Visible Titles' |
| 238 |
**************************************************************************/ |
| 239 |
function get_bulk_actions() { |
| 240 |
$actions = array( |
| 241 |
'delete' => __( 'Delete', 'profile-builder' ), |
| 242 |
'confirm' => __( 'Confirm Email', 'profile-builder' ), |
| 243 |
'resend' => __( 'Resend Activation Email', 'profile-builder' ) |
| 244 |
); |
| 245 |
|
| 246 |
return $actions; |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
/** ************************************************************************ |
| 251 |
* Optional. You can handle your bulk actions anywhere or anyhow you prefer. |
| 252 |
* For this example package, we will handle it in the class to keep things |
| 253 |
* clean and organized. |
| 254 |
* |
| 255 |
* @see $this->prepare_items() |
| 256 |
**************************************************************************/ |
| 257 |
|
| 258 |
function wppb_process_bulk_action_message( $message, $url ){ |
| 259 |
|
| 260 |
echo '<script type=\'text/javascript\'>confirmECActionBulk( "'.esc_js( $url ).'", "'.esc_js( $message ).'" )</script>'; |
| 261 |
} |
| 262 |
|
| 263 |
function wppb_process_bulk_action() { |
| 264 |
global $current_user; |
| 265 |
global $wpdb; |
| 266 |
|
| 267 |
// Only verify and process when a bulk action is actually being submitted through the list-table form. |
| 268 |
if ( false === $this->current_action() ) |
| 269 |
return; |
| 270 |
|
| 271 |
// CSRF protection: the bulk-action form rendered by display() already outputs a 'bulk-{plural}' nonce, verify it here. |
| 272 |
check_admin_referer( 'bulk-' . $this->_args['plural'] ); |
| 273 |
|
| 274 |
if ( current_user_can( apply_filters( 'wppb_email_confirmation_user_capability', 'manage_options' ) ) ){ |
| 275 |
if( 'delete' === $this->current_action() ) { |
| 276 |
if( !empty( $_GET['user'] ) && is_array( $_GET['user'] ) ) { |
| 277 |
foreach ( array_map( 'sanitize_email', $_GET['user'] ) as $user) { |
| 278 |
$sql_result = $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->base_prefix . "signups WHERE user_email = %s", $user)); |
| 279 |
|
| 280 |
if (!$sql_result) |
| 281 |
$this->wppb_process_bulk_action_message(sprintf(__("%s couldn't be deleted", "profile-builder"), $user), get_bloginfo('url') . '/wp-admin/users.php?page=unconfirmed_emails'); |
| 282 |
|
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
$this->wppb_process_bulk_action_message( __( 'All users have been successfully deleted', 'profile-builder' ), get_bloginfo('url').'/wp-admin/users.php?page=unconfirmed_emails' ); |
| 287 |
|
| 288 |
}elseif( 'confirm' === $this->current_action() ) { |
| 289 |
if( !empty( $_GET['user'] ) && is_array( $_GET['user'] ) ) { |
| 290 |
foreach ( array_map( 'sanitize_email', $_GET['user'] ) as $user) { |
| 291 |
$sql_result = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->base_prefix . "signups WHERE user_email = %s", $user), ARRAY_A); |
| 292 |
|
| 293 |
if ($sql_result) |
| 294 |
wppb_manual_activate_signup($sql_result['activation_key']); |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
$this->wppb_process_bulk_action_message( __( 'The selected users have been activated', 'profile-builder' ), get_bloginfo('url').'/wp-admin/users.php?page=unconfirmed_emails' ); |
| 299 |
|
| 300 |
}elseif( 'resend' === $this->current_action() ) { |
| 301 |
if( !empty( $_GET['user'] ) && is_array( $_GET['user'] ) ) { |
| 302 |
foreach ( array_map( 'sanitize_email', $_GET['user'] ) as $user ) { |
| 303 |
$sql_result = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->base_prefix . "signups WHERE user_email = %s", $user), ARRAY_A); |
| 304 |
|
| 305 |
if ($sql_result) |
| 306 |
wppb_signup_user_notification(esc_sql($sql_result['user_login']), esc_sql($sql_result['user_email']), $sql_result['activation_key'], $sql_result['meta']); |
| 307 |
|
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
$this->wppb_process_bulk_action_message( __( 'The selected users have had their activation emails resent', 'profile-builder' ), get_bloginfo('url').'/wp-admin/users.php?page=unconfirmed_emails' ); |
| 312 |
} |
| 313 |
|
| 314 |
}else |
| 315 |
$this->wppb_process_bulk_action_message( __( "Sorry, but you don't have permission to do that!", "profile-builder" ), get_bloginfo('url').'/wp-admin/' ); |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
/** ************************************************************************ |
| 320 |
* REQUIRED! This is where you prepare your data for display. This method will |
| 321 |
* usually be used to query the database, sort and filter the data, and generally |
| 322 |
* get it ready to be displayed. At a minimum, we should set $this->items and |
| 323 |
* $this->set_pagination_args(), although the following properties and methods |
| 324 |
* are frequently interacted with here... |
| 325 |
* |
| 326 |
* @global WPDB $wpdb |
| 327 |
* @uses $this->_column_headers |
| 328 |
* @uses $this->items |
| 329 |
* @uses $this->get_columns() |
| 330 |
* @uses $this->get_sortable_columns() |
| 331 |
* @uses $this->get_pagenum() |
| 332 |
* @uses $this->set_pagination_args() |
| 333 |
**************************************************************************/ |
| 334 |
function prepare_items() { |
| 335 |
global $wpdb; |
| 336 |
|
| 337 |
$this->dataArray = array(); |
| 338 |
|
| 339 |
/** |
| 340 |
* First, lets decide how many records per page to show |
| 341 |
*/ |
| 342 |
$per_page = get_user_meta( get_current_user_id(), 'users_per_page', true ); |
| 343 |
if( !empty($per_page) ) |
| 344 |
$per_page = apply_filters('wppb_email_confirmation_user_per_page_number', $per_page); |
| 345 |
else |
| 346 |
$per_page = apply_filters('wppb_email_confirmation_user_per_page_number', 20); |
| 347 |
|
| 348 |
/* determine offset */ |
| 349 |
if( !empty( $_REQUEST['paged'] ) ){ |
| 350 |
$offset = ( sanitize_text_field( $_REQUEST['paged'] ) -1 ) * $per_page; |
| 351 |
} |
| 352 |
else |
| 353 |
$offset = 0; |
| 354 |
|
| 355 |
/* handle order and orderby attr */ |
| 356 |
if( !empty( $_REQUEST['orderby'] ) ){ |
| 357 |
|
| 358 |
$orderby = sanitize_sql_orderby( $_REQUEST['orderby'] ); |
| 359 |
|
| 360 |
if( $orderby == 'username' ) |
| 361 |
$orderby = 'user_login'; |
| 362 |
elseif ( $orderby == 'email' ) |
| 363 |
$orderby = 'user_email'; |
| 364 |
|
| 365 |
} else |
| 366 |
$orderby = 'user_login'; |
| 367 |
|
| 368 |
if( !empty( $_REQUEST['order'] ) && sanitize_text_field( $_REQUEST['order'] ) === 'desc' ) |
| 369 |
$order = "DESC"; |
| 370 |
else |
| 371 |
$order = 'ASC'; |
| 372 |
|
| 373 |
/* handle the WHERE clause */ |
| 374 |
$where = "active = 0"; |
| 375 |
if( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) ){ |
| 376 |
$where .= $wpdb->prepare( " AND ( user_login LIKE %s OR user_email LIKE %s OR registered LIKE %s )", '%' . sanitize_text_field( $_REQUEST['s'] ) . '%', '%' . sanitize_text_field( $_REQUEST['s'] ) . '%' , '%' . sanitize_text_field( $_REQUEST['s'] ) . '%' ); |
| 377 |
} |
| 378 |
/* since version 2.0.7 for multisite we add a 'registered_for_blog_id' meta in the registration process |
| 379 |
so we can display only the users registered on that blog. Also for backwards compatibility we display the users that don't have that meta at all */ |
| 380 |
if( is_multisite() ){ |
| 381 |
$where .= $wpdb->prepare( " AND ( meta NOT LIKE '%\"registered_for_blog_id\"%' OR meta LIKE '%s' )", '%\"registered_for_blog_id\";i:'.get_current_blog_id().'%' ); |
| 382 |
} |
| 383 |
|
| 384 |
$results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM ".$wpdb->base_prefix."signups WHERE $where ORDER BY $orderby $order LIMIT %d, %d", $offset, $per_page ) ); |
| 385 |
|
| 386 |
foreach ($results as $result){ |
| 387 |
$tempArray = array('ID' => $result->user_email, 'username' => $result->user_login, 'email' => $result->user_email, 'registered' => $result->registered); |
| 388 |
array_push($this->dataArray, $tempArray); |
| 389 |
} |
| 390 |
|
| 391 |
/** |
| 392 |
* REQUIRED for pagination. Let's check how many items are in our data array. |
| 393 |
* In real-world use, this would be the total number of items in your database, |
| 394 |
* without filtering. We'll need this later, so you should always include it |
| 395 |
* in your own package classes. |
| 396 |
*/ |
| 397 |
$total_items = $wpdb->get_var( "SELECT COUNT(*) FROM ".$wpdb->base_prefix."signups WHERE $where" ); |
| 398 |
|
| 399 |
/** |
| 400 |
* REQUIRED. Now we need to define our column headers. This includes a complete |
| 401 |
* array of columns to be displayed (slugs & titles), a list of columns |
| 402 |
* to keep hidden, and a list of columns that are sortable. Each of these |
| 403 |
* can be defined in another method (as we've done here) before being |
| 404 |
* used to build the value for our _column_headers property. |
| 405 |
*/ |
| 406 |
$columns = $this->get_columns(); |
| 407 |
$hidden = array(); |
| 408 |
$sortable = $this->get_sortable_columns(); |
| 409 |
|
| 410 |
|
| 411 |
/** |
| 412 |
* REQUIRED. Finally, we build an array to be used by the class for column |
| 413 |
* headers. The $this->_column_headers property takes an array which contains |
| 414 |
* 3 other arrays. One for all columns, one for hidden columns, and one |
| 415 |
* for sortable columns. |
| 416 |
*/ |
| 417 |
$this->_column_headers = array($columns, $hidden, $sortable); |
| 418 |
|
| 419 |
|
| 420 |
/** |
| 421 |
* Optional. You can handle your bulk actions however you see fit. In this |
| 422 |
* case, we'll handle them within our package just to keep things clean. |
| 423 |
*/ |
| 424 |
$this->wppb_process_bulk_action(); |
| 425 |
|
| 426 |
|
| 427 |
/** |
| 428 |
* Instead of querying a database, we're going to fetch the example data |
| 429 |
* property we created for use in this plugin. This makes this example |
| 430 |
* package slightly different than one you might build on your own. In |
| 431 |
* this example, we'll be using array manipulation to sort and paginate |
| 432 |
* our data. In a real-world implementation, you will probably want to |
| 433 |
* use sort and pagination data to build a custom query instead, as you'll |
| 434 |
* be able to use your precisely-queried data immediately. |
| 435 |
*/ |
| 436 |
$data = $this->dataArray; |
| 437 |
|
| 438 |
/** |
| 439 |
* REQUIRED. Now we can add our *sorted* data to the items property, where |
| 440 |
* it can be used by the rest of the class. |
| 441 |
*/ |
| 442 |
$this->items = $data; |
| 443 |
|
| 444 |
|
| 445 |
/** |
| 446 |
* REQUIRED. We also have to register our pagination options & calculations. |
| 447 |
*/ |
| 448 |
$this->set_pagination_args( array( |
| 449 |
'total_items' => $total_items, //WE have to calculate the total number of items |
| 450 |
'per_page' => $per_page, //WE have to determine how many items to show on a page |
| 451 |
'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages |
| 452 |
) ); |
| 453 |
} |
| 454 |
|
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
/** ************************ REGISTER THE PAGE **************************** |
| 462 |
******************************************************************************* |
| 463 |
* Now we just need to define an admin page. |
| 464 |
*/ |
| 465 |
function wppb_add_ec_submenu_page() { |
| 466 |
$wppb_generalSettings = get_option('wppb_general_settings', 'not_found'); |
| 467 |
if($wppb_generalSettings != 'not_found') { |
| 468 |
if( !empty($wppb_generalSettings['emailConfirmation']) && ($wppb_generalSettings['emailConfirmation'] == 'yes') ){ |
| 469 |
$hook = add_submenu_page('users.php', 'Unconfirmed Email Address', 'Unconfirmed Email Address', 'manage_options', 'unconfirmed_emails', 'wppb_unconfirmed_email_address_custom_menu_page'); |
| 470 |
add_action( "load-$hook", 'wppb_ec_screen_options' ); //add screen options to Unconfirmed Email Users page |
| 471 |
//remove_submenu_page('users.php', 'unconfirmed_emails'); //hide the page in the admin menu |
| 472 |
} |
| 473 |
} |
| 474 |
} |
| 475 |
add_action('admin_menu', 'wppb_add_ec_submenu_page'); |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
/***************************** RENDER PAGE ******************************** |
| 480 |
******************************************************************************* |
| 481 |
* This function renders the admin page. Although it's |
| 482 |
* possible to call prepare_items() and display() from the constructor, there |
| 483 |
* are often times where you may need to include logic here between those steps, |
| 484 |
* so we've instead called those methods explicitly. It keeps things flexible, and |
| 485 |
* it's the way the list tables are used in the WordPress core. |
| 486 |
*/ |
| 487 |
function wppb_unconfirmed_email_address_custom_menu_page(){ |
| 488 |
|
| 489 |
//Create an instance of our package class... |
| 490 |
$listTable = new wpp_list_unfonfirmed_email_table(); |
| 491 |
//Fetch, prepare, sort, and filter our data... |
| 492 |
$listTable->prepare_items(); |
| 493 |
|
| 494 |
?> |
| 495 |
<div class="wrap"> |
| 496 |
|
| 497 |
<div class="wrap"><div id="icon-users" class="icon32"></div><h2><?php esc_html_e('Users with Unconfirmed Email Address', 'profile-builder');?></h2></div> |
| 498 |
|
| 499 |
<ul class="subsubsub"> |
| 500 |
<li class="all"><a href="users.php"><?php esc_html_e('All Users', 'profile-builder');?></a></li> |
| 501 |
</ul> |
| 502 |
|
| 503 |
<!-- Forms are NOT created automatically, so you need to wrap the table in one to use features like bulk actions --> |
| 504 |
<form id="movies-filter" method="get"> |
| 505 |
<!-- For plugins, we also need to ensure that the form posts back to our current page --> |
| 506 |
<?php $listTable->search_box( __( 'Search Users', 'profile-builder' ), 'user' ); ?> |
| 507 |
<input type="hidden" name="page" value="<?php echo isset( $_REQUEST['page'] ) ? esc_attr( sanitize_text_field( $_REQUEST['page'] ) ) : ''; ?>" /> |
| 508 |
<!-- Now we can render the completed list table --> |
| 509 |
<?php $listTable->display() ?> |
| 510 |
</form> |
| 511 |
|
| 512 |
</div> |
| 513 |
<?php |
| 514 |
} |
| 515 |
|
| 516 |
/** |
| 517 |
* Function that handles the screen options on Unconfirmed Email Users page |
| 518 |
*/ |
| 519 |
function wppb_ec_screen_options(){ |
| 520 |
$option = 'per_page'; |
| 521 |
|
| 522 |
$args = array( |
| 523 |
'label' => __( 'Number of items per page:' , 'profile-builder' ),//use the default wordpress domain |
| 524 |
'default' => 20, |
| 525 |
'option' => 'users_per_page' //this is the same option as the one on the normal User screen |
| 526 |
); |
| 527 |
|
| 528 |
add_screen_option( $option, $args ); |
| 529 |
} |
| 530 |
|
| 531 |
/** |
| 532 |
* Fix the page title of the admin page, since using remove_sumbenu_page() breaks the page title |
| 533 |
*/ |
| 534 |
add_filter('admin_title', 'wppb_ec_admin_title', 10 ); |
| 535 |
function wppb_ec_admin_title($admin_title){ |
| 536 |
if( isset( $_GET['page'] ) && sanitize_text_field( $_GET['page'] ) === 'unconfirmed_emails' ) { |
| 537 |
$admin_title = __('Users with Unconfirmed Email Address', 'profile-builder') . $admin_title; |
| 538 |
} |
| 539 |
|
| 540 |
return $admin_title; |
| 541 |
} |