Plugin Directory

Changeset 2944363


Ignore:
Timestamp:
07/27/2023 07:59:43 PM (3 years ago)
Author:
anderly
Message:

Release 1.3.4, see readme.txt for the changelog.

Location:
disable-user-login
Files:
4 added
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • disable-user-login/tags/1.3.4/disable-user-login.php

    r2823022 r2944363  
    44 * Plugin URI:  http://wordpress.org/plugins/disable-user-login
    55 * Description: Provides the ability to disable user accounts and prevent them from logging in.
    6  * Version:     1.3.3
     6 * Version:     1.3.4
    77 *
    88 * Author:      Saint Systems
  • disable-user-login/tags/1.3.4/includes/class-ss-disable-user-login-plugin.php

    r2823022 r2944363  
    1616     * @var string
    1717     */
    18     private static $version = '1.3.3';
     18    private static $version = '1.3.4';
    1919
    2020    /**
     
    6060
    6161            self::$instance = new SS_Disable_User_Login_Plugin();
     62            self::$instance->define_constants();
    6263            self::$instance->load_plugin_textdomain();
    6364            self::$instance->add_hooks();
     
    8081
    8182    /**
     83     * Define Plugin Constants.
     84     */
     85    private function define_constants() {
     86
     87        // Plugin version.
     88        $this->define( 'SS_DISABLE_USER_LOGIN_VERSION', self::version() );
     89
     90        // Plugin Folder Path.
     91        $this->define( 'SS_DISABLE_USER_LOGIN_DIR', plugin_dir_path( SS_DISABLE_USER_LOGIN_FILE ) );
     92
     93        // Plugin Folder URL.
     94        $this->define( 'SS_DISABLE_USER_LOGIN_URL', plugin_dir_url( SS_DISABLE_USER_LOGIN_FILE ) );
     95
     96    } //function define_constants
     97
     98    /**
     99     * Define constant if not already set.
     100     *
     101     * @param  string      $name  Constant name.
     102     * @param  string|bool $value Constant value.
     103     * @return void
     104     */
     105    private function define( $name, $value ) {
     106        if ( ! defined( $name ) ) {
     107            define( $name, $value );
     108        }
     109    } //function define
     110
     111    /**
    82112     * Setup the plugin action hooks and filters
    83113     */
    84114    private function add_hooks() {
    85115
    86         // Actions
    87         add_action( 'edit_user_profile',          array( $this, 'add_disabled_field'          )        );
    88         add_action( 'personal_options_update',    array( $this, 'save_disabled_field'         )        );
    89         add_action( 'edit_user_profile_update',   array( $this, 'save_disabled_field'         )        );
    90         add_filter( 'manage_users_custom_column', array( $this, 'manage_users_column_content' ), 10, 3 );
    91         add_action( 'admin_footer-users.php',     array( $this, 'manage_users_css'            )        );
    92         add_action( 'admin_notices',              array( $this, 'bulk_disable_user_notices'   )        );
     116        if ( is_admin() ) {
     117            // Actions
     118            add_action( 'edit_user_profile',          array( $this, 'add_disabled_field'          )        );
     119            add_action( 'personal_options_update',    array( $this, 'save_disabled_field'         )        );
     120            add_action( 'edit_user_profile_update',   array( $this, 'save_disabled_field'         )        );
     121            add_filter( 'manage_users_custom_column', array( $this, 'manage_users_column_content' ), 10, 3 );
     122            add_action( 'admin_footer-users.php',     array( $this, 'manage_users_css'            )        );
     123            add_action( 'admin_notices',              array( $this, 'bulk_disable_user_notices'   )        );
     124            add_action( 'admin_enqueue_scripts',      array( $this, 'enqueue_scripts'             )        );
     125            add_action( 'wp_ajax_ssdul_enable_disable_user', array( $this, 'enable_disable_user'  )        );
     126        }
    93127
    94128        // Disabled hook
     
    101135        add_filter( 'bulk_actions-users',         array( $this, 'bulk_action_disable_users'   )        );
    102136        add_filter( 'handle_bulk_actions-users',  array( $this, 'handle_bulk_disable_users'   ), 10, 3 );
     137        add_filter( 'user_row_actions',           array( $this, 'add_quick_links'             ), 10, 2 );
    103138
    104139    } //end function add_hooks
     140
     141    /**
     142     * Adds a quick 'enable/disable' link to the user row actions based on the current user status.
     143     *
     144     * @param [type] $actions
     145     * @param [type] $user_object
     146     * @return void
     147     */
     148    function add_quick_links( $actions, $user_object ) {
     149
     150        if ( $user_object->ID !== get_current_user_id() ) {
     151            $action = 'disable';
     152            $label = __( 'Disable', 'disable-user-login' );
     153
     154            if ( $this->is_user_disabled( $user_object->ID ) ) {
     155                $action = 'enable';
     156                $label = __( 'Enable', 'disable-user-login' );
     157            }
     158            $actions[ 'disable_user_login' ] = "<a class='dul-quick-links' href='#' data-dul-action='$action' data-dul-user-id='$user_object->ID'>" . $label . '</a>';
     159        }
     160        return $actions;
     161    }
    105162
    106163    /**
     
    235292
    236293    /**
     294     * Enable/Disable users from user row actions quick links.
     295     */
     296    public function enable_disable_user() {
     297
     298        check_ajax_referer( 'ssdul_quick_links', 'nonce' );
     299
     300        if ( empty( $_POST['data'] ) ) return;
     301
     302        $data = $_POST['data'];
     303
     304        $user_id = $data['user_id'];
     305
     306        $action = $data['action'];
     307
     308        if ( ! $this->can_disable( $user_id ) ) {
     309            $response = array(
     310                'error' => sprintf( esc_html__( 'User %s cannot disable user $s.', 'disable-user-login' ), get_current_user_id(), $user_id )
     311            );
     312            wp_send_json( $response);
     313            return;
     314        }
     315
     316        $disabled = $action == 'disable' ? 1 : 0;
     317
     318        // Store disabled status before update
     319        $originally_disabled = $this->is_user_disabled( $user_id );
     320
     321        // Update the user's disabled status
     322        update_user_meta( $user_id, self::$user_meta_key, $disabled );
     323
     324        $this->maybe_trigger_enabled_disabled_actions( $user_id, $originally_disabled, $disabled );
     325
     326        $response = array(
     327            'status_code' => 200,
     328            'message'     => sprintf( esc_html__( 'Success: user %s %s', 'disable-user-login' ), $user_id, ($disabled ? 'disabled' : 'enabled' ) ),
     329        );
     330        wp_send_json( $response, '200' );
     331    }
     332
     333    /**
    237334     * After login check to see if user account is disabled
    238335     *
     
    455552    } //end function force_logout
    456553
     554    /**
     555     * Enqueue plugin settings scripts.
     556     *
     557     * @since 1.3.4
     558     *
     559     * @access public
     560     * @return array $scripts
     561     */
     562    public function enqueue_scripts() {
     563
     564        // Plugin scripts
     565        wp_register_script( 'disable-user-login-admin', SS_DISABLE_USER_LOGIN_URL . 'assets/js/admin.js', array( 'jquery' ), time() ) ;//self::version() );
     566
     567        $nonces = array(
     568            'quick_links'         => wp_create_nonce( 'ssdul_quick_links' ),
     569        );
     570
     571        $ssdul = array(
     572            //'messages' => $translations,
     573            'nonces'   => $nonces,
     574        );
     575
     576        wp_localize_script( 'disable-user-login-admin', 'SSDUL', $ssdul );
     577
     578        // Scripts.
     579        wp_enqueue_script( 'disable-user-login-admin' );
     580
     581    } //end function scripts
     582
    457583} //end class SS_Disable_User_Login_Plugin
  • disable-user-login/tags/1.3.4/readme.txt

    r2823022 r2944363  
    66Tested up to: 6.1.1
    77Requires PHP: 5.6
    8 Stable tag: 1.3.3
     8Stable tag: 1.3.4
    99License: GPLv3
    1010
     
    4949== Changelog ==
    5050
     51= 1.3.4 =
     52* Add user enable/disable quick links.
     53
    5154= 1.3.3 =
    5255* Bump WP tested version.
  • disable-user-login/trunk/disable-user-login.php

    r2823022 r2944363  
    44 * Plugin URI:  http://wordpress.org/plugins/disable-user-login
    55 * Description: Provides the ability to disable user accounts and prevent them from logging in.
    6  * Version:     1.3.3
     6 * Version:     1.3.4
    77 *
    88 * Author:      Saint Systems
  • disable-user-login/trunk/includes/class-ss-disable-user-login-plugin.php

    r2823022 r2944363  
    1616     * @var string
    1717     */
    18     private static $version = '1.3.3';
     18    private static $version = '1.3.4';
    1919
    2020    /**
     
    6060
    6161            self::$instance = new SS_Disable_User_Login_Plugin();
     62            self::$instance->define_constants();
    6263            self::$instance->load_plugin_textdomain();
    6364            self::$instance->add_hooks();
     
    8081
    8182    /**
     83     * Define Plugin Constants.
     84     */
     85    private function define_constants() {
     86
     87        // Plugin version.
     88        $this->define( 'SS_DISABLE_USER_LOGIN_VERSION', self::version() );
     89
     90        // Plugin Folder Path.
     91        $this->define( 'SS_DISABLE_USER_LOGIN_DIR', plugin_dir_path( SS_DISABLE_USER_LOGIN_FILE ) );
     92
     93        // Plugin Folder URL.
     94        $this->define( 'SS_DISABLE_USER_LOGIN_URL', plugin_dir_url( SS_DISABLE_USER_LOGIN_FILE ) );
     95
     96    } //function define_constants
     97
     98    /**
     99     * Define constant if not already set.
     100     *
     101     * @param  string      $name  Constant name.
     102     * @param  string|bool $value Constant value.
     103     * @return void
     104     */
     105    private function define( $name, $value ) {
     106        if ( ! defined( $name ) ) {
     107            define( $name, $value );
     108        }
     109    } //function define
     110
     111    /**
    82112     * Setup the plugin action hooks and filters
    83113     */
    84114    private function add_hooks() {
    85115
    86         // Actions
    87         add_action( 'edit_user_profile',          array( $this, 'add_disabled_field'          )        );
    88         add_action( 'personal_options_update',    array( $this, 'save_disabled_field'         )        );
    89         add_action( 'edit_user_profile_update',   array( $this, 'save_disabled_field'         )        );
    90         add_filter( 'manage_users_custom_column', array( $this, 'manage_users_column_content' ), 10, 3 );
    91         add_action( 'admin_footer-users.php',     array( $this, 'manage_users_css'            )        );
    92         add_action( 'admin_notices',              array( $this, 'bulk_disable_user_notices'   )        );
     116        if ( is_admin() ) {
     117            // Actions
     118            add_action( 'edit_user_profile',          array( $this, 'add_disabled_field'          )        );
     119            add_action( 'personal_options_update',    array( $this, 'save_disabled_field'         )        );
     120            add_action( 'edit_user_profile_update',   array( $this, 'save_disabled_field'         )        );
     121            add_filter( 'manage_users_custom_column', array( $this, 'manage_users_column_content' ), 10, 3 );
     122            add_action( 'admin_footer-users.php',     array( $this, 'manage_users_css'            )        );
     123            add_action( 'admin_notices',              array( $this, 'bulk_disable_user_notices'   )        );
     124            add_action( 'admin_enqueue_scripts',      array( $this, 'enqueue_scripts'             )        );
     125            add_action( 'wp_ajax_ssdul_enable_disable_user', array( $this, 'enable_disable_user'  )        );
     126        }
    93127
    94128        // Disabled hook
     
    101135        add_filter( 'bulk_actions-users',         array( $this, 'bulk_action_disable_users'   )        );
    102136        add_filter( 'handle_bulk_actions-users',  array( $this, 'handle_bulk_disable_users'   ), 10, 3 );
     137        add_filter( 'user_row_actions',           array( $this, 'add_quick_links'             ), 10, 2 );
    103138
    104139    } //end function add_hooks
     140
     141    /**
     142     * Adds a quick 'enable/disable' link to the user row actions based on the current user status.
     143     *
     144     * @param [type] $actions
     145     * @param [type] $user_object
     146     * @return void
     147     */
     148    function add_quick_links( $actions, $user_object ) {
     149
     150        if ( $user_object->ID !== get_current_user_id() ) {
     151            $action = 'disable';
     152            $label = __( 'Disable', 'disable-user-login' );
     153
     154            if ( $this->is_user_disabled( $user_object->ID ) ) {
     155                $action = 'enable';
     156                $label = __( 'Enable', 'disable-user-login' );
     157            }
     158            $actions[ 'disable_user_login' ] = "<a class='dul-quick-links' href='#' data-dul-action='$action' data-dul-user-id='$user_object->ID'>" . $label . '</a>';
     159        }
     160        return $actions;
     161    }
    105162
    106163    /**
     
    235292
    236293    /**
     294     * Enable/Disable users from user row actions quick links.
     295     */
     296    public function enable_disable_user() {
     297
     298        check_ajax_referer( 'ssdul_quick_links', 'nonce' );
     299
     300        if ( empty( $_POST['data'] ) ) return;
     301
     302        $data = $_POST['data'];
     303
     304        $user_id = $data['user_id'];
     305
     306        $action = $data['action'];
     307
     308        if ( ! $this->can_disable( $user_id ) ) {
     309            $response = array(
     310                'error' => sprintf( esc_html__( 'User %s cannot disable user $s.', 'disable-user-login' ), get_current_user_id(), $user_id )
     311            );
     312            wp_send_json( $response);
     313            return;
     314        }
     315
     316        $disabled = $action == 'disable' ? 1 : 0;
     317
     318        // Store disabled status before update
     319        $originally_disabled = $this->is_user_disabled( $user_id );
     320
     321        // Update the user's disabled status
     322        update_user_meta( $user_id, self::$user_meta_key, $disabled );
     323
     324        $this->maybe_trigger_enabled_disabled_actions( $user_id, $originally_disabled, $disabled );
     325
     326        $response = array(
     327            'status_code' => 200,
     328            'message'     => sprintf( esc_html__( 'Success: user %s %s', 'disable-user-login' ), $user_id, ($disabled ? 'disabled' : 'enabled' ) ),
     329        );
     330        wp_send_json( $response, '200' );
     331    }
     332
     333    /**
    237334     * After login check to see if user account is disabled
    238335     *
     
    455552    } //end function force_logout
    456553
     554    /**
     555     * Enqueue plugin settings scripts.
     556     *
     557     * @since 1.3.4
     558     *
     559     * @access public
     560     * @return array $scripts
     561     */
     562    public function enqueue_scripts() {
     563
     564        // Plugin scripts
     565        wp_register_script( 'disable-user-login-admin', SS_DISABLE_USER_LOGIN_URL . 'assets/js/admin.js', array( 'jquery' ), time() ) ;//self::version() );
     566
     567        $nonces = array(
     568            'quick_links'         => wp_create_nonce( 'ssdul_quick_links' ),
     569        );
     570
     571        $ssdul = array(
     572            //'messages' => $translations,
     573            'nonces'   => $nonces,
     574        );
     575
     576        wp_localize_script( 'disable-user-login-admin', 'SSDUL', $ssdul );
     577
     578        // Scripts.
     579        wp_enqueue_script( 'disable-user-login-admin' );
     580
     581    } //end function scripts
     582
    457583} //end class SS_Disable_User_Login_Plugin
  • disable-user-login/trunk/readme.txt

    r2823022 r2944363  
    66Tested up to: 6.1.1
    77Requires PHP: 5.6
    8 Stable tag: 1.3.3
     8Stable tag: 1.3.4
    99License: GPLv3
    1010
     
    4949== Changelog ==
    5050
     51= 1.3.4 =
     52* Add user enable/disable quick links.
     53
    5154= 1.3.3 =
    5255* Bump WP tested version.
Note: See TracChangeset for help on using the changeset viewer.