Plugin Directory

Changeset 3089036


Ignore:
Timestamp:
05/19/2024 04:58:53 PM (20 months ago)
Author:
Hakik
Message:

v1.0.2: Fix- text domain, headers already sent error after deleting a link, pot file added, temporary user can't delete another user

Location:
create-temporary-login
Files:
24 added
5 edited

Legend:

Unmodified
Added
Removed
  • create-temporary-login/trunk/create-temporary-login.php

    r3083509 r3089036  
    11<?php
    22/*
    3 Plugin Name:        WP Bifröst - Create Passwordless Temporary Login Links
     3Plugin Name:        Bifröst WP - Create Passwordless Temporary Login Links
    44Plugin URI:         https://wordpress.org/plugins/create-temporary-login
    55Description:        Create passwordless temporary login links to easily give access to your site's dashboard.
    6 Version:            1.0.1
     6Version:            1.0.2
    77Author:             Hakik Zaman
    88Author URI:         https://profiles.wordpress.org/users/hakik 
     
    2121 */
    2222if ( ! defined( 'CTLAZ_TEMP_LOGIN_VERSION' ) ) {
    23     define( 'CTLAZ_TEMP_LOGIN_VERSION', '1.0.1' );
     23    define( 'CTLAZ_TEMP_LOGIN_VERSION', '1.0.2' );
    2424}
    2525
  • create-temporary-login/trunk/includes/class-admin.php

    r3083509 r3089036  
    4343        // Disallow direct login access for Temp Users
    4444        add_filter( 'wp_authenticate_user', array( $this, 'disallow_temporary_user_login' ) );
     45        // Set redirect before the plugin render the plugin settings page
     46        add_action( 'admin_init', array( $this,'set_header_redirect' ) );
    4547    }
    4648
     
    7173    }
    7274
    73     /**
    74      * Create Temporary Login Interface
    75      */
    76     public function create_temporary_login(){
     75   
     76    /**
     77     * Sets the header redirect.
     78     */
     79    public function set_header_redirect(){
    7780        // If found a user_id as a get delete the user
    7881        if ( isset($_GET['ctl_delete_link_nonce']) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['ctl_delete_link_nonce'] ) ), 'ctl_delete_link') ){
     
    9093            }
    9194        }
    92 
    93         echo "<h1>".esc_html__( 'Create Temporary Login Settings', 'create-temporary-login' )."</h1>";
     95    }
     96
     97    /**
     98     * Create Temporary Login Interface
     99     */
     100    public function create_temporary_login(){
     101
     102        echo "<h1>".esc_html__( 'Bifröst WP - Settings (Create Passwordless Temporary Login Links)', 'create-temporary-login' )."</h1>";
    94103        $other_attributes = array( 'tabindex' => '1' );
    95104        submit_button( __( 'Generate a link', 'create-temporary-login' ), 'secondary ctl_generate_link', '', true, $other_attributes );
     
    136145                    esc_html__( 'Copied', 'create-temporary-login' ),
    137146                    // Human readable time to show how many days are remaining
    138                     ctlaz_create_temporary_login()->get_option()->human_readable_duration( $user->ID ),
     147                    ctlaz_create_temporary_login()->get_option()->get_human_readable_link_duration( $user->ID ),
    139148                    // Text of the Extend Button
    140149                    esc_html__( 'Extend 3 days', 'create-temporary-login' ),
     
    182191       
    183192                echo absint( $user_id );
    184                     wp_die();
     193                wp_die();
    185194               
    186195            }
  • create-temporary-login/trunk/includes/class-create-temporary-login.php

    r3083509 r3089036  
    4949        $this->get_option();
    5050        $this->get_admin();
     51        $this->set_hooks();
    5152    }
     53
     54    /**
     55     * Sets the hooks.
     56     */
     57    public function set_hooks(){
     58        add_action( 'plugins_loaded', array( $this, 'load_textdomain' ), 10 );
     59    }
     60
     61    /**
     62     * Loads a textdomain.
     63     */
     64    public function load_textdomain() {
     65        load_plugin_textdomain( 'create-temporary-login', false, basename( dirname( CTLAZ_TEMP_LOGIN_FILE ) )."/languages" );
     66    }
    5267
    5368    /**
  • create-temporary-login/trunk/includes/class-option.php

    r3083509 r3089036  
    2222    public function __construct(){
    2323        // Firing Hooks
    24         // $this->hooks();
     24        $this->set_hooks();
    2525    }
    2626
     27    /**
     28     * Sets the hooks.
     29     */
     30    public function set_hooks(){
     31        add_action( 'admin_init', array( $this, 'set_temporary_logged_in_user_permission' ), 10 );
     32    }
     33
     34    /**
     35     * Determines whether the specified user id is temporary user.
     36     *
     37     * @param      int  $user_ID  The user id
     38     *
     39     * @return     bool    True if the specified user id is temporary user, False otherwise.
     40     */
    2741    public function is_temporary_user( $user_ID ) : bool {
    2842        return (bool) get_user_meta( $user_ID, 'ctl_user', true );
    2943    }
    3044
     45    /**
     46     * Gets the maximum expired time.
     47     *
     48     * @return     int   The maximum expired time.
     49     */
    3150    public function get_max_expired_time(): int {
    3251        return current_time( 'timestamp' ) + WEEK_IN_SECONDS;
    3352    }
    3453
     54    /**
     55     * Determines whether the specified user id is user expired.
     56     *
     57     * @param      int  $user_ID  The user id
     58     *
     59     * @return     bool    True if the specified user id is user expired, False otherwise.
     60     */
    3561    public function is_user_expired( $user_ID ): bool {
    3662        $expiration = $this->get_expiration( $user_ID );
     
    4369    }
    4470
     71    /**
     72     * Gets the expiration.
     73     *
     74     * @param      int  $user_ID  The user id
     75     *
     76     * @return     int | bool  Meta ID if the key didn’t exist, true on successful update, false on failure or if the value passed to the function is the same as the one that is already in the database.
     77     */
    4578    public function get_expiration( $user_ID ) {
    4679        return get_user_meta( $user_ID, 'ctl_expiration', true );
    4780    }
    4881
    49     public function human_readable_duration( $user_ID ){
     82   
     83   
     84    /**
     85     * Gets the human readable link duration.
     86     *
     87     * @param      int  $user_ID  The user id
     88     *
     89     * @return     mixed  The human readable link duration.
     90     */
     91    public function get_human_readable_link_duration( $user_ID ){
    5092        if( $this->is_user_expired( $user_ID ) ){
    5193            return esc_html__( 'Expired', 'create-temporary-login' );
     
    5395        return sprintf(
    5496            /* translators: %s: How many days remaining */
    55              esc_html__( 'Will be expired after:&nbsp;%s', 'plugin-slug' ),
     97             esc_html__( 'Will be expired after:&nbsp;%s', 'create-temporary-login' ),
    5698             wp_kses_post( human_time_diff( $this->get_expiration( $user_ID ), current_time('U') ) )
    5799         );
    58100    }
    59101
     102    /**
     103     * Extends the expiration.
     104     *
     105     * @param      <int>  $user_ID  The user id
     106     *
     107     * @return     int | bool    Meta ID if the key didn’t exist, true on successful update, false on failure or if the value passed to the function is the same as the one that is already in the database.
     108     */
    60109    public function extend_expiration( $user_ID ) {
    61110        $expiration = $this->get_expiration( $user_ID );
     
    76125    }
    77126
     127   
     128    /**
     129     * Sets the temporary logged in user permission.
     130     */
     131    public function set_temporary_logged_in_user_permission(){
     132
     133        if( $this->is_temporary_user( get_current_user_id() ) ){
     134
     135            // Remove a capability from a specific user.
     136            $user = new WP_User( get_current_user_id() );
     137            /**
     138             * @note `list_users` to revoke entire access of the user menus
     139             *
     140             * To print the available capabilities for this current user- `print_r($user->get_role_caps());`
     141             */
     142            $user->add_cap( 'delete_users', false );
     143            /**
     144             * @note for future use
     145             * Remove the User menu for temporary users
     146             * remove_menu_page( 'users.php' );
     147             */
     148        }
     149       
     150       
     151
     152    }
     153
    78154}
  • create-temporary-login/trunk/readme.txt

    r3084138 r3089036  
    1 === WP Bifröst - Create Passwordless Temporary Login Links ===
     1=== Bifröst WP - Create Passwordless Temporary Login Links ===
    22Contributors: Hakik
    33Tags: temporary login, passwordless login, temporary access, login
     
    55Requires at least: 6.2
    66Tested up to: 6.5
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    1818
    1919[youtube https://www.youtube.com/watch?v=jMTwoAtKlUk]
    20 
    2120
    2221How often do you need to allow someone access to your WordPress site? There are many cases when you need to allow people access to your site, including support engineers.
     
    4544== Changelog ==
    4645
     46= 1.0.2 =
     47* Add: Disallow the temporary user to delete an user of the site.
     48* Add: POT file added.
     49* Fix: Text domain for a method.
     50* Fix: Headers already sent warning after deleting a link.
     51
    4752= 1.0.1 =
    4853* Fix: Plugin file header, sanitize for wp_nonce, prefix related issue, internationalization issues.
Note: See TracChangeset for help on using the changeset viewer.