*/ class Active_User_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $active_user The ID of this plugin. */ private $active_user; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $active_user The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $active_user, $version ) { $this->active_user = $active_user; $this->version = $version; add_action( 'wp_loaded', array($this, 'process_deletions' )); add_action( 'shutdown', array($this, 'process_messages' )); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { wp_enqueue_style( $this->active_user, plugin_dir_url( __FILE__ ) . 'css/active-user-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { // wp_enqueue_script( $this->active_user, plugin_dir_url( __FILE__ ) . 'js/active_user-admin.js', array( 'jquery' ), $this->version, false ); } /** * Set up the admin page menu link. * * @since 1.0.0 */ public function add_menu_page() { $icon_svg = 'data:image/svg+xml;base64,' . base64_encode(''); add_menu_page( __( 'Active User Settings', 'active-user' ), __( 'Active User', 'active-user' ), 'manage_options', 'active-user', array( $this, 'display_menu_page' ), $icon_svg ); add_submenu_page( 'active-user', __( 'Settings', 'active-user' ), __( 'Settings', 'active-user' ), 'manage_options', 'active-user', array( $this, 'display_settings_page' ) ); add_submenu_page( 'active-user', __( 'Active User Table', 'active-user' ), __( 'Active User Table', 'active-user' ), 'manage_options', 'active-user-table', array( $this, 'display_last_activity_page' ) ); add_submenu_page( 'active-user', __( 'Deletion Queue', 'active-user' ), __( 'Deletion Queue', 'active-user' ), 'manage_options', 'active-user-queue', array( $this, 'display_deletion_queue' ) ); } /** * Display the admin page. * * @since 1.0.0 */ public function display_menu_page() { } /** * Display the admin page. * * @since 1.0.0 */ public function display_settings_page() { ?>
here.
get_inactive_users_not_grace(); if ( empty($inactive_users) ) { echo '' . __( "There are no inactive users who meet the criteria.", 'active-user' ) . '
'; } else { ?> '; } } /** * Process the deletions. * * @since 1.0.0 */ public function process_deletions() { if( !empty( $_REQUEST['delete_option']) ) { require_once(ABSPATH.'wp-admin/includes/user.php'); if ( is_multisite() ) { wp_die( __( 'User deletion is not allowed from this screen.' ), 400 ); } check_admin_referer( 'delete-users' ); $redirect = 'admin.php?page=active-user-table'; $userids = array_map( 'intval', (array) $_REQUEST['users'] ); if ( ! current_user_can( 'delete_users' ) ) { wp_die( __( 'Sorry, you are not allowed to delete users.' ), 403 ); } $nonce = wp_unslash( $_REQUEST['_wpnonce'] ); if ( ! wp_verify_nonce( $nonce, 'delete-users' ) ) { wp_die( __( "Sorry, you can't do that right now, hacker dude" ), 403 ); } else { $updated = 'del'; $delete_count = 0; foreach ( $userids as $id ) { if ( ! current_user_can( 'delete_user', $id ) ) { wp_die( __( 'Sorry, you are not allowed to delete that user.' ), 403 ); } if ( $id == $current_user->ID ) { $updated = 'err_admin_del'; continue; } switch ( $_REQUEST['delete_option'] ) { case 'delete': wp_delete_user( $id ); break; case 'reassign': wp_delete_user( $id, $_REQUEST['reassign_user'] ); break; } ++$delete_count; } $redirect = add_query_arg( array( 'delete_count' => $delete_count, 'update' => $updated ), $redirect ); wp_redirect( $redirect ); exit(); } } } /** * Process the admin messages. * * @since 1.0.0 */ public function process_messages() { $messages = array(); if ( !empty( $_REQUEST['update'] ) ) : switch ( $_REQUEST['update'] ) { case 'del': case 'del_many': $delete_count = isset( $_REQUEST['delete_count'] ) ? (int) $_REQUEST['delete_count'] : 0; if ( 1 == $delete_count ) { $message = __( 'User deleted.' ); } else { $message = _n( '%s user deleted.', '%s users deleted.', $delete_count ); } $messages[] = '' . sprintf( $message, number_format_i18n( $delete_count ) ) . '
' . __( 'You can’t delete the current user.' ) . '
' . __( 'Other users have been deleted.' ) . '
' . __('Enter the number of days, months, or years after which a user is considered inactive', 'active_user') . '
'; echo $html; } /** * Render the Purge grace period interval length * * @since 1.0.0 */ public function wpau_purge_grace_interval_length_cb() { $options = get_option('purge_section'); $arg = isset( $options['wpau_purge_grace_interval_length'] ) ? $options['wpau_purge_grace_interval_length'] : ''; echo ''; } /** * Render the Purge grace period interval unit * * @since 1.0.0 */ public function wpau_purge_grace_interval_unit_cb() { $options = get_option( 'purge_section' ); $options['wpau_purge_grace_interval_unit'] = !empty( $options['wpau_purge_grace_interval_unit'] ) ? $options['wpau_purge_grace_interval_unit'] : 'M'; $html = ''; $html .= '' . __('Enter the number of days, months, or years the grace period should last', 'active_user') . '
'; echo $html; } /** * Render the email member toggle checkbox * * @since 1.0.0 */ public function wpau_purge_email_member_toggle_cb() { $options = get_option('purge_section'); $toggle = isset( $options['wpau_purge_email_member_toggle'] ) ? $options['wpau_purge_email_member_toggle'] : '0'; echo ''; echo '' . __('Tick to send an email to the user when they become inactive', 'active_user') . '
'; } /** * Render the email member body * * @since 1.0.0 */ public function wpau_purge_email_member_body_cb() { $options = get_option('purge_section'); $placeholder = "You have not been active on the site recently. Please login as soon as you can to prevent your account from being deleted."; $arg = !empty( $options['wpau_purge_email_member_body'] ) ? $options['wpau_purge_email_member_body'] : $placeholder; echo ''; echo '' . __('You can change the content of the above email here', 'active_user') . '
'; } /** * Render the email admin toggle checkbox * * @since 1.0.0 */ public function wpau_purge_email_admin_toggle_cb() { $options = get_option('purge_section'); $toggle = isset( $options['wpau_purge_email_admin_toggle'] ) ? $options['wpau_purge_email_admin_toggle'] : '0'; echo ''; echo '' . __('Email the site administrator when there are inactive members', 'active_user') . '
'; } /** * Validate our code. Keep everyone safe and happy. * * @since 1.0.0 */ public function wpau_validate( $input ) { // Create our array for storing the validated options $output = array(); // Loop through each of the incoming options foreach( $input as $key => $value ) { // Check to see if the current option has a value. If so, process it. if( isset( $input[$key] ) ) { // Strip all HTML and PHP tags and properly handle quoted strings $output[$key] = strip_tags( stripslashes( $input[ $key ] ) ); } // end if } // end foreach // Return the array processing any additional functions filtered by this action return apply_filters( 'wpau_validate', $output, $input ); } }