Plugin Directory

Changeset 3258796


Ignore:
Timestamp:
03/19/2025 09:03:25 PM (12 months ago)
Author:
wpmobo
Message:

1.1.2

Added CAPTCHA support for WP Registration Form
Added CAPTCHA support for Blog Post Comment Form
Added CAPTCHA support for WooCommerce Login Form
Added CAPTCHA support for WooCommerce Registration Form
Added CAPTCHA support for EDD Login Form
Added CAPTCHA support for EDD Registration Form
Added an enable/disable switch for CAPTCHA
Fixed an issue with Activity Logs errors

Location:
admintosh
Files:
75 added
6 edited

Legend:

Unmodified
Added
Removed
  • admintosh/trunk/admin/Admin.php

    r3248536 r3258796  
    111111                        'anc_class' => 'admintosh-tab',
    112112                        'data_attr' => 'login_recaptcha',
    113                         'title' => esc_html__( 'Login reCAPTCHA', 'admintosh' )
     113                        'title' => esc_html__( 'reCAPTCHA', 'admintosh' )
    114114                    ],
    115115                    'login_attempts' => [
     
    524524                            'condition'   => [ 'captcha_type' => ['google_captcha'] ]
    525525                        ]);
     526
     527                        $this->switcher_field([
     528                            'title' => esc_html__( 'Captcha for Login Form', 'admintosh' ),
     529                            'name' => 'captcha_wp_login',
     530                            'description' => esc_html__( 'Captcha will work on wp login, WooCommerce login & EDD login form.', 'admintosh' )
     531                        ]);
     532
     533                        $this->switcher_field([
     534                            'title' => esc_html__( 'Captcha on WP Registration Form', 'admintosh' ),
     535                            'name' => 'captcha_wp_registration',
     536                            'description' => esc_html__( 'Captcha will work on wp login, WooCommerce login & EDD login form.', 'admintosh' )
     537                        ]);
     538                       
     539                        $this->switcher_field([
     540                            'title' => esc_html__( 'Captcha on Blog Comment Form', 'admintosh' ),
     541                            'name' => 'captcha_blog_comment',
     542                            'description' => esc_html__( 'Captcha will work on blog comment form.', 'admintosh' )
     543                        ]);
     544
    526545                    ?>
    527546
  • admintosh/trunk/admintosh.php

    r3248536 r3258796  
    44Plugin URI:   http://wpmobo.com/admintosh
    55Description:  WordPress admin customization and security tools
    6 Version:      1.1.1
     6Version:      1.1.2
    77Author:       wpmobo
    88Author URI:   http://wpmobo.com
     
    5858        add_action( 'init', [ $this, 'client_insights' ] );
    5959        $this->include();
    60         $this->init();
     60        add_action( 'plugins_loaded', [ $this, 'init' ] );
    6161    }
    6262   
  • admintosh/trunk/inc/Admin_Activity_Logs.php

    r3248536 r3258796  
    1818       
    1919        add_action('wp_insert_post', [ $this, 'log_post_changes' ], 10, 3);
     20        add_action('wp_trash_post', [ $this, 'log_post_trash' ], 10, 2);
    2021        add_action('before_delete_post', [ $this, 'log_post_deletion' ]);
    21         add_action('set_user_role', [ $this, 'admintosh_log_user_role_change' ], 10, 3);
     22        add_action('set_user_role', [ $this, 'log_user_role_change' ], 10, 3);
    2223
    2324        add_action('activated_plugin', [ $this, 'log_plugin_status' ], 10, 2);
     
    2526        add_action('deactivated_plugin', [ $this, 'log_plugin_deactivation' ], 10, 2);
    2627
    27         add_action('switch_theme', [ $this, 'log_theme_change' ]);
     28        add_action('switch_theme', [ $this, 'log_theme_change' ], 10, 3 );
    2829
    2930        add_action('admin_menu', [ $this, 'add_activity_log_page' ] );
     
    5354                'ip_address'  => sanitize_text_field( $ip_address ),
    5455                'user_agent'  => sanitize_text_field( $user_agent['user_agent'] ?? '' ),
    55                 'timestamp'   => sanitize_text_field( current_time( 'mysql' ) )
     56                'timestamp'   => sanitize_text_field( current_time( 'timestamp' ) )
    5657            ],
    5758            ['%d', '%s', '%s', '%d', '%s', '%s', '%s', '%s']
     
    6061
    6162
     63    public function log_post_trash( $post_id, $previous_status ) {
     64
     65        if( !$post_id ) {
     66            return;
     67        }
     68
     69        $user_id = get_current_user_id();
     70        $title = get_the_title($post_id);
     71        $post_type = get_post_type($post_id);
     72        $action = 'trash';
     73        $message = "title: $title (ID: $post_id) move to $action.";
     74
     75        $this->admintosh_log_activity($user_id, $action, $post_type, $post_id, $message);
     76    }
     77
    6278    public function log_post_changes($post_id, $post, $update) {
    6379        if (wp_is_post_revision($post_id)) return;
     
    6581        $user_id = get_current_user_id();
    6682        $action = $update ? 'updated' : 'created';
    67         $message = "Post '{$post->post_title}' (ID: $post_id) was $action.";
    68 
    69         $this->admintosh_log_activity($user_id, $action, 'post', $post_id, $message);
     83        $post_type = get_post_type($post_id);
     84        $message = "title: {$post->post_title} (ID: $post_id) was $action.";
     85
     86        $this->admintosh_log_activity($user_id, $action, $post_type, $post_id, $message);
    7087    }
    7188   
     
    7390    public function log_post_deletion($post_id) {
    7491        $user_id = get_current_user_id();
    75         $message = "Post (ID: $post_id) was deleted.";
    76 
    77         $this->admintosh_log_activity($user_id, 'deleted', 'post', $post_id, $message);
     92        $post_type = get_post_type($post_id);
     93        $title = get_the_title($post_id);
     94        $message = "title: $title (ID: $post_id) was permanently deleted.";
     95
     96        $this->admintosh_log_activity($user_id, 'deleted', $post_type, $post_id, $message);
    7897    }
    7998   
    8099
    81100    public function log_user_role_change($user_id, $new_roles, $old_roles) {
    82         $message = "User (ID: $user_id) role changed from " . implode(', ', $old_roles) . " to " . implode(', ', $new_roles) . ".";
    83         $this->admintosh_log_activity(get_current_user_id(), 'role_change', 'user', $user_id, $message);
     101
     102        if( !empty( $old_roles ) ) {
     103            $message = "User (ID: $user_id) role changed from " . implode(', ', $old_roles) . " to " . $new_roles . ".";
     104            $this->admintosh_log_activity(get_current_user_id(), 'role_change', 'user', $user_id, $message);
     105        }
     106
    84107    }
    85108
     
    103126    }
    104127
    105     public function log_theme_change($new_theme) {
    106         $user_id = get_current_user_id();
    107         $message = "Theme changed to '{$new_theme->get('Name')}'.";
     128    public function log_theme_change( $new_name, $new_theme, $old_theme ) {
     129
     130        $user_id = get_current_user_id();
     131        $message = "Theme changed '{$old_theme->get('Name')}' to $new_name.";
    108132       
    109133        $this->admintosh_log_activity($user_id, 'theme_change', 'theme', 0, $message);
     
    127151        $table_name = $wpdb->prefix . 'ats_activity_logs';
    128152        $logs = $wpdb->get_results("SELECT * FROM $table_name ORDER BY timestamp DESC LIMIT 50");
     153        //
     154        $dateTimeFormat = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
    129155
    130156        ?>
     
    147173                            foreach ( $logs as $log ):
    148174                                $user = get_user_by('ID', $log->user_id);
     175
     176                                $display_name = !empty( $user->display_name ) ? $user->display_name : '';
    149177                        ?>
    150178                        <tr>
    151                             <td><?php echo esc_html( "{$user->display_name} (ID: {$log->user_id})" ); ?></td>
     179                            <td><?php echo esc_html( " $display_name (ID: {$log->user_id})" ); ?></td>
    152180                            <td><?php echo esc_html( $log->action_type ); ?></td>
    153181                            <td><?php echo esc_html( "{$log->object_type} (ID: {$log->object_id})" ); ?></td>
    154182                            <td><?php echo esc_html( $log->message ); ?></td>
    155183                            <td><?php echo esc_html( $log->ip_address ); ?></td>
    156                             <td><?php echo esc_html( $log->timestamp ); ?></td>
     184                            <td><?php echo esc_html( wp_date( $dateTimeFormat, $log->timestamp ) ); ?></td>
    157185                        </tr>
    158186                        <?php
     
    170198    }
    171199
    172     protected function create_database_table() {
     200    public function create_database_table() {
    173201        global $wpdb;
    174202        $table_name = $wpdb->prefix . 'ats_activity_logs';
     
    185213            ip_address VARCHAR(45) NOT NULL,
    186214            user_agent TEXT NOT NULL,
    187             timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
     215            timestamp TEXT DEFAULT CURRENT_TIMESTAMP
    188216        ) $charset_collate;";
    189217
  • admintosh/trunk/inc/Recaptcha.php

    r3152299 r3258796  
    1414    protected $options;
    1515
     16    protected $errorMsg;
     17
    1618    /**
    1719     * Start up
     
    2123        $this->options = get_option( ADMINTOSH_OPTION_NAME );
    2224
     25        $this->errorMsg = esc_html__( 'CAPTCHA verification failed. Please try again.', 'admintosh' );
     26
    2327        $get_options = $this->options;
    2428
    25         add_action('init', [ $this, 'init_session' ], 999 );
     29        add_action('init', [ $this, 'init_session' ], 1 );
    2630        if( !empty( $get_options['active_login_captcha'] ) ) {
    27             add_action('login_form', [ $this, 'login_form_captcha' ], 999 );
    28             add_filter('wp_authenticate_user',[ $this, 'validate_login_captcha' ],10,2);
     31
     32            // WP login
     33            if( !empty( $get_options['captcha_wp_login'] ) ) {
     34
     35                // wp login form
     36                add_action('login_form', [ $this, 'login_form_captcha' ], 999 );
     37
     38                // WooCommerce My account login
     39                if( adtosh_is_woo_active() ) {
     40                    add_action('woocommerce_login_form', [ $this, 'add_recaptcha' ]);
     41                }
     42               
     43                // Edd Login
     44                if( adtosh_is_edd_active() ) {
     45                    add_action('edd_login_fields_after', [ $this, 'add_recaptcha' ]);
     46                    add_action('edd_user_login', [ $this, 'edd_recaptcha_validate_login' ] );
     47                }
     48               
     49                add_filter('wp_authenticate_user',[ $this, 'validate_login_captcha' ],10,2);
     50            }
     51
     52
     53            // WP registration
     54            if( !empty( $get_options['captcha_wp_registration'] ) ) {
     55
     56                // wp reg
     57                add_action('register_form', [ $this, 'login_form_captcha' ]);
     58                add_filter('registration_errors', [ $this, 'validate_recaptcha_wp_registration' ], 10, 3);
     59
     60                // Edd register form
     61                if( adtosh_is_edd_active() ) {
     62                    add_action('edd_register_form_fields_before_submit', [ $this, 'add_recaptcha' ]);
     63                    add_action('edd_process_register_form', [ $this, 'edd_recaptcha_validate_registration' ], 10 );
     64                }
     65
     66                // WooCommerce Registration form
     67                if( adtosh_is_woo_active() ) {
     68                    add_action('woocommerce_register_form', [ $this, 'add_recaptcha' ] );
     69                    add_action('woocommerce_register_post', [ $this, 'validate_recaptcha_wc_registration' ], 10, 3);
     70                }
     71
     72            }
     73
     74            // blog comment
     75            if( !empty( $get_options['captcha_blog_comment'] ) ) {
     76                add_action('comment_form_submit_field', [ $this, 'add_comment_recaptcha' ] );
     77                add_filter('preprocess_comment', [ $this, 'verify_recaptcha_on_comment' ]);
     78            }           
     79           
     80
    2981        }
    3082       
     
    3284
    3385    public function init_session() {
     86
     87        //session_destroy();
    3488        if(!session_id()) {
    3589            session_start();
    3690        }
    37 
    3891    }
    3992
     
    86139
    87140    public function validate_login_captcha( $user, $password ) {
    88 
    89         $return_value = $user;
     141       
     142        if( !$this->is_validate_captch() ) {
     143            return new \WP_Error( 'loginCaptchaError', $this->errorMsg );
     144        }
     145       
     146        return $user;
     147    }
     148
     149    public function is_validate_captch () {
     150
    90151        $admintoshrev_options = $this->options;
     152
     153        $is_true = true;
    91154
    92155        // Check captcha type
     
    109172
    110173            if ($response->success != true) {
    111                 $return_value = new \WP_Error( 'loginCaptchaError', esc_html__( 'Captcha Error. Please try again.', 'admintosh' ) );
     174                $is_true = false;
    112175            }
    113176
     
    116179            if( !$this->check( sanitize_text_field( $_POST['adtosh_captcha_answer'] ) ) ) {
    117180                // if there is a mis-match
    118                 $return_value = new \WP_Error( 'loginCaptchaError', esc_html__( 'Captcha Error. Please try again. ', 'admintosh' ) );
    119 
    120             }
    121         }
    122 
    123        
    124         return $return_value;
     181                $is_true = false;
     182            }
     183        }
     184
     185        return $is_true;
     186
     187
    125188    }
    126189
     
    158221    }
    159222
     223    public function validate_recaptcha_wp_registration( $errors, $sanitized_user_login, $user_email ) {
     224
     225        if( !$this->is_validate_captch() ) {
     226
     227            $errors->add('recaptcha_failed', $this->errorMsg );
     228           
     229        }
     230
     231        return $errors;
     232
     233    }
     234
     235    public function edd_recaptcha_validate_registration() {
     236
     237        if( !$this->is_validate_captch() ) {
     238            edd_set_error('edd_recaptcha', $this->errorMsg );
     239            return false;
     240        }
     241
     242        return true;
     243
     244    }
     245
     246    public function validate_recaptcha_wc_registration( $username, $email, $errors ) {
     247
     248        if( !$this->is_validate_captch() ) {
     249            $errors->add('recaptcha_failed', $this->errorMsg );
     250        }
     251        return $errors;
     252
     253    }
     254
     255    public function verify_recaptcha_on_comment( $commentdata ) {
     256
     257        if( !$this->is_validate_captch() ) {
     258
     259            wp_die('<div class="wp-die-message"><p><strong>Error:</strong> '.esc_html( $this->errorMsg ).'</p></div><p><a href="javascript:history.back()">« Back</a></p>');
     260        }
     261        return $commentdata;
     262
     263    }
     264
     265    public function add_recaptcha() {
     266        $this->login_form_captcha();
     267    }
     268   
     269    public function add_comment_recaptcha( $submit_field ) {
     270
     271        ob_start();
     272        $this->login_form_captcha();
     273        $captch = ob_get_clean();
     274
     275        return $captch.$submit_field;
     276
     277    }
     278
     279    public function edd_recaptcha_validate_login($login_data) {
     280        if ( !$this->is_validate_captch() ) {
     281            edd_set_error('edd_recaptcha', esc_html( $this->errorMsg ) );
     282        }
     283    }
     284
     285
     286
    160287
    161288}
  • admintosh/trunk/inc/functions.php

    r3126611 r3258796  
    9494
    9595}
     96
     97function adtosh_is_woo_active() {
     98    return class_exists('WooCommerce');
     99}
     100
     101function adtosh_is_edd_active() {
     102    return class_exists('Easy_Digital_Downloads');
     103}
  • admintosh/trunk/readme.txt

    r3248536 r3258796  
    66Requires at least: 6.5
    77Tested up to: 6.7.1
    8 Stable tag: 1.1.1
    9 Version: 1.1.1
     8Stable tag: 1.1.2
     9Version: 1.1.2
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2626* **Customize Dashboard**: Customize the Dashboard and make it like your own brand all customization possibilities are here like background color, menu color, text color, link color, logo upload, etc.
    2727
    28 * **Captcha**: Add captch into login, registration, lost password, comments Form etc. The plugin offer 3 types of Captcha Google reCaptcha ( Version 2 ), Random number Captcha and Math Captcha so you could use any one of them's to protection from remote digital entry by making sure only a human being with the right password can access the account.
     28* **Captcha**: Add captch into login, registration, lost password, comments Form etc. It also supported **WooCommerce** & **EDD**. The plugin offer 3 types of Captcha Google reCaptcha ( Version 2 ), Random number Captcha and Math Captcha so you could use any one of them's to protection from remote digital entry by making sure only a human being with the right password can access the account.
    2929
    3030* **Limit Login Attempts**: After a preset number of attempts has been exceeded, this feature automatically stops any more attempts from a specific Internet Protocol (IP) address and/or username. This considerably reduces the potency of brute force attacks on your website.
     
    200200== Changelog ==
    201201
     202= 1.1.2 =
     203
     204- Added CAPTCHA support for WP Registration Form
     205- Added CAPTCHA support for Blog Post Comment Form
     206- Added CAPTCHA support for WooCommerce Login Form
     207- Added CAPTCHA support for WooCommerce Registration Form
     208- Added CAPTCHA support for EDD Login Form
     209- Added CAPTCHA support for EDD Registration Form
     210- Added an enable/disable switch for CAPTCHA
     211- Fixed an issue with Activity Logs errors
     212
    202213= 1.1.1 =
    203214
Note: See TracChangeset for help on using the changeset viewer.