Skip to content

Passwort vergessen, Zurück link unterbinden #8

@bueltge

Description

@bueltge

Optionales ausblenden der Links

<?php
/**
 * Plugin Name: Password Reset Removed
 * Description: Removes the ability for non admin users to change/reset their passwords.
 * Version:     1.0.0
 * Author:      Frank Bültge
 * Author URI:  http://bueltge.de
 * License:     GPLv3
 */

! defined( 'ABSPATH' ) and exit;

class Fb_Password_Reset_Removed {

    protected static $instance = NULL;

    public function __construct() {

        add_filter( 'show_password_fields',  array( $this, 'disable' ) );
        add_filter( 'allow_password_reset',  array( $this, 'disable' ) );
        add_filter( 'gettext',               array( $this, 'remove' ) );
        add_action( 'login_enqueue_scripts', array( $this, 'add_script' ) );
        add_action( 'login_footer',          array( $this, 'remove_via_js' ) );
    }

    /**
     * Access this plugin’s working instance
     *
     * @wp-hook plugins_loaded
     * @return  object of this class
     */
    public static function get_instance() {

        NULL === self::$instance and self::$instance = new self();

        return self::$instance;
    }

    function disable() {

        if ( is_admin() ) {
            $userdata = wp_get_current_user();
            $user = new WP_User($userdata->ID);
            if ( !empty( $user->roles ) && is_array( $user->roles ) && $user->roles[0] == 'administrator' )
            return TRUE;
        }

        return FALSE;
    }

    function remove($text) {

        return str_replace( array( 'Passwort vergessen', 'Lost your password?', 'Lost your password' ), '', trim($text, '?') ); 
    }

    function add_script() {

        wp_enqueue_script( 'jquery' );
    }

    function remove_via_js() {
        ?>
        <script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready( function($) {
            $( '#backtoblog, #nav' ).remove();
        });
        //]]>
        </script>
        <?php
    }
}
add_action( 'plugins_loaded', array( 'Fb_Password_Reset_Removed', 'get_instance' ) );

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions