Plugin Directory

Changeset 2579465


Ignore:
Timestamp:
08/06/2021 05:24:08 PM (5 years ago)
Author:
wpsecuredcom
Message:

Adding first version of my plugin

Location:
secured-wp
Files:
11 edited
7 copied

Legend:

Unmodified
Added
Removed
  • secured-wp/tags/1.5/classes/Controllers/User.php

    r2578505 r2579465  
    300300
    301301        /**
    302          * Unlocks the user
     302         * Unlocks the user and clears the login attempts
    303303         *
    304304         * @since 1.0.0
     
    314314                self::getLockedTransientPrefix() . self::$user->ID
    315315            );
     316
     317            LoginAttempts::clearLoginAttempts( $user );
    316318        }
    317319
  • secured-wp/tags/1.5/classes/Helpers/AjaxRequests.php

    r2576070 r2579465  
    1313
    1414use WPSEC\Controllers\User;
     15use WPSEC\Validators\Validator;
    1516
    1617defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
     
    3536            \add_action( 'wp_ajax_logged_device_delete', [ __CLASS__, 'deleteRememberMeDevice' ] );
    3637
    37             // delete all logged in device for user.
    38             \add_action( 'wp_ajax_nopriv_all_logged_device_delete', [ __CLASS__, 'deleteAllRememberMeDevice' ] );
    39             \add_action( 'wp_ajax_all_logged_device_delete', [ __CLASS__, 'deleteAllRememberMeDevice' ] );
     38            // delete all logged in devices for user.
     39            \add_action( 'wp_ajax_nopriv_all_logged_device_delete', [ __CLASS__, 'deleteAllRememberMeDevices' ] );
     40            \add_action( 'wp_ajax_all_logged_device_delete', [ __CLASS__, 'deleteAllRememberMeDevices' ] );
    4041
     42            // delete all logged in devices for user.
     43            \add_action( 'wp_ajax_nopriv_wps_delete_qr', [ __CLASS__, 'deleteQRCodeForUser' ] );
     44            \add_action( 'wp_ajax_wps_delete_qr', [ __CLASS__, 'deleteQRCodeForUser' ] );
    4145        }
    4246
     
    6367            }
    6468
    65             if ( empty( $device ) ) {
    66                 $device = base64_decode( $_POST['device'] );
     69            if ( empty( $device ) && isset( $_POST['device'] ) && ! empty( $_POST['device'] ) ) {
     70                $device = base64_decode( \sanitize_text_field( \wp_unslash( $_POST['device'] ) ) );
    6771            }
    68             if ( User::deleteLoggedInDevice( $device, $user ) ) {
    69                 echo \json_encode( [ 'result' => 'success' ] );
    70             } else {
    71                 echo \json_encode( [ 'result' => 'failed' ] );
     72
     73            if ( ! isset( $_POST['user'] ) || empty( $_POST['user'] ) ) {
     74                die();
     75            }
     76            if ( Validator::filterValidate( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ), 'int' ) ) {
     77
     78                if ( User::deleteLoggedInDevice( $device, \sanitize_text_field( \wp_unslash( $_POST['user'] ) ) ) ) {
     79                    echo \json_encode( [ 'result' => 'success' ] );
     80                } else {
     81                    echo \json_encode( [ 'result' => 'failed' ] );
     82                }
    7283            }
    7384
     
    8293         *
    8394         * ! WP do_action sends first empty parameter if there are no parameters
    84          * @param [type] $user - WP user for which remember me device must be deleted.
     95         * TODO: extend this and the method above so it can recieves parameters as well
     96         * @param mixed $user - WP user for which remember me device must be deleted.
    8597         *
    8698         * @return void
     
    89101         * @SuppressWarnings(PHPMD.Superglobals)
    90102         */
    91         public static function deleteAllRememberMeDevice( $user = null ) {
     103        public static function deleteAllRememberMeDevices( $user = null ) {
    92104            if ( ! isset( $_POST['nonce'] ) ||
    93105                empty( $_POST['nonce'] ) ||
     
    96108            }
    97109
    98             if ( User::deleteAllLoggedInDevices( $user ) ) {
    99                 echo \json_encode( [ 'result' => 'success' ] );
    100             } else {
    101                 echo \json_encode( [ 'result' => 'failed' ] );
     110            if ( ! isset( $_POST['user'] ) || empty( $_POST['user'] ) ) {
     111                die();
     112            }
     113            if ( Validator::filterValidate( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ), 'int' ) ) {
     114                if ( User::deleteAllLoggedInDevices( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ) ) ) {
     115                    echo \json_encode( [ 'result' => 'success' ] ); // @codingStandardsIgnoreLine
     116                } else {
     117                    echo \json_encode( [ 'result' => 'failed' ] ); // @codingStandardsIgnoreLine
     118                }
    102119            }
    103120
     
    105122        }
    106123
     124        /**
     125         * Deletes QR code for the given user
     126         *
     127         * @return void
     128         *
     129         * @since 1.5
     130         *
     131         * @SuppressWarnings(PHPMD.ExitExpressions)
     132         * @SuppressWarnings(PHPMD.Superglobals)
     133         */
     134        public static function deleteQRCodeForUser() {
     135            if ( ! isset( $_POST['nonce'] ) ||
     136                empty( $_POST['nonce'] ) ||
     137                ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['nonce'] ) ), 'wp-secured-wps_delete_qr-ajax-nonce' ) ) {
     138                die();
     139            }
     140
     141            if ( ! isset( $_POST['user'] ) || empty( $_POST['user'] ) ) {
     142                die();
     143            }
     144            if ( Validator::filterValidate( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ), 'int' ) ) {
     145                User::deleteUserTotp( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ) );
     146                echo \json_encode( [ 'result' => 'success' ] );
     147            }
     148
     149            die();
     150        }
    107151    }
    108152}
  • secured-wp/tags/1.5/classes/Helpers/NotifyAdmin.php

    r2577925 r2579465  
    4040
    4141            $message = \sprintf(
    42                 /*
    43                  translators: %1$s: Name of the user */
    44                 /*
    45                  translators: %2$s: Url of the site */
    46                 /* translators: %3$s: Number of the login attempts */
     42                /* translators: %1$s: Name of the user, %2$s: Url of the site, %3$s: Number of the login attempts */
    4743                __( 'User %1$s has tried to log in with an unsuitable password too many times to your site %2$s.\nThe system has identified %3$s unsuccessful login attempts.', 'ws-secured' ),
    4844                $user->display_name,
  • secured-wp/tags/1.5/classes/Helpers/OutOfBondEmail.php

    r2576070 r2579465  
    108108
    109109            $message = \sprintf(
    110                 /*
    111                  translators: %1$s: Name of the user */
    112                 /*
    113                  translators: %2$s: Url of the site */
    114                 /* translators: %3$s: Number of the login attempts */
     110                /* translators: %1$s: Name of the user, %2$s: Url of the site, %3$s: Number of the login attempts */
    115111                __( 'Hello %1$s,<br>Use the following link to login to site %2$s.<br>If not you who is trying to login, please contact the administrator immediately.<br>Click on the following link to login: %3$s', 'ws-secured' ),
    116112                User::getUser( $userId )->display_name,
  • secured-wp/tags/1.5/classes/Secured.php

    r2577925 r2579465  
    8989                <?php
    9090                echo \sprintf(
    91                     /* translators: %1$s: PHP version */
     91                /* translators: %1$s: PHP version */
    9292                    \esc_html__( 'You need to update your PHP version to %1s.', 'secured-wp' ),
    9393                    WPSEC_REQUIRED_PHP_VERSION // @codingStandardsIgnoreLine - that is defined constatnt no need to escape it
     
    110110                <?php
    111111                echo \sprintf(
    112                     /* translators: %1$s: WP version */
     112                /* translators: %1$s: WP version */
    113113                    \esc_html__( 'You need to update your WP version to %1s.', 'secured-wp' ),
    114                     WPSEC_REQUIRED_WP_VERSION // @codingStandardsIgnoreLine - that is defined constatnt no need to escape it
     114                WPSEC_REQUIRED_WP_VERSION // @codingStandardsIgnoreLine - that is defined constatnt no need to escape it
    115115                );
    116116                ?>
     
    151151                    'renderPluginSettingsPage',
    152152                ],
    153                 'data:image/svg+xml;base64,' . \base64_encode( \file_get_contents( WPSEC_PLUGIN_SECURED_PATH . 'assets/images/the-logo.svg' ) ), // @codingStandardsIgnoreLine - :) well that one is necessary
     153            'data:image/svg+xml;base64,' . \base64_encode( \file_get_contents( WPSEC_PLUGIN_SECURED_PATH . 'assets/images/the-logo.svg' ) ), // @codingStandardsIgnoreLine - :) well that one is necessary
    154154                81
    155155            );
     
    305305                }
    306306            }
     307
     308            /**
     309             * If user is logged in and there is woocommerce installed and the method is enabled,
     310             * we gona need the AJAX methods available.
     311             */
     312            if ( User::isCurrentlyLogged() ) {
     313                if ( class_exists( 'WooCommerce' ) ) {
     314                    if ( ! (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() ) {
     315                        // AJAX request for the user - do we need this globally for the Admin Part of the WP ?.
     316                        AjaxRequests::initAdmin();
     317                    }
     318                }
     319            }
    307320        }
    308321
  • secured-wp/tags/1.5/classes/Views/UserProfile.php

    r2577925 r2579465  
    189189                <?php
    190190
    191                 \submit_button(
    192                     __( 'Regenerate QR code', 'secured-wp' ),
    193                     'delete',
    194                     'regenerate-qr-code',
    195                     false
    196                 );
     191                if ( function_exists( 'submit_button' ) ) {
     192                    \submit_button(
     193                        \__( 'Regenerate QR code', 'secured-wp' ),
     194                        'delete',
     195                        'regenerate-qr-code',
     196                        false
     197                    );
     198                } else {
     199                    ?>
     200                <input type="submit" name="regenerate-qr-code" id="regenerate-qr-code" class="button delete" value="Regenerate QR code">
     201                    <?php
     202                    self::deleteQRCodeJS();
     203                }
    197204                ?>
    198205                </div>
     
    214221            if ( \current_user_can( 'edit_user', $userId ) ) {
    215222                if ( isset( $_POST['qr-nonce'] ) &&
    216                     \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['qr-nonce'] ) ), self::$qrNoncePrefix . $userId ) &&
    217                     isset( $_POST['regenerate-qr-code'] ) ) {
    218 
    219                         User::deleteUserTotp( $userId );
     223                \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['qr-nonce'] ) ), self::$qrNoncePrefix . $userId ) &&
     224                isset( $_POST['regenerate-qr-code'] ) ) {
     225
     226                    User::deleteUserTotp( $userId );
    220227                }
    221228            }
     
    238245                        'action': 'logged_device_delete',
    239246                        'nonce': '<?php echo \esc_attr( \wp_create_nonce( 'wp-secured-delete_device-ajax-nonce' ) ); ?>',
     247                        'user': '<?php echo \esc_attr( User::getUser()->ID ); ?>',
    240248                        'device': jQuery(this).data('device')      // We pass php values differently!
    241249                    };
     
    275283                    var deleteData = {
    276284                        'action': 'all_logged_device_delete',
     285                        'user': '<?php echo \esc_attr( User::getUser()->ID ); ?>',
    277286                        'nonce': '<?php echo \esc_attr( \wp_create_nonce( 'wp-secured-delete_all_device-ajax-nonce' ) ); ?>',
    278287                    };
     
    296305            <?php
    297306        }
     307
     308        /**
     309         * Javascript for qr code deletion
     310         *
     311         * @since 1.0.0
     312         *
     313         * @return void
     314         */
     315        private static function deleteQRCodeJS() {
     316            ?>
     317        <script>
     318            ( function( jQuery ) {
     319                jQuery('.alignleft').on('click', '#regenerate-qr-code', function(e) {
     320                    e.preventDefault();
     321                    var ajaxurl = "<?php echo \esc_url( admin_url( 'admin-ajax.php' ) ); ?>"
     322                    var deleteData = {
     323                        'action': 'wps_delete_qr',
     324                        'user': '<?php echo \esc_attr( User::getUser()->ID ); ?>',
     325                        'nonce': '<?php echo \esc_attr( \wp_create_nonce( 'wp-secured-wps_delete_qr-ajax-nonce' ) ); ?>',
     326                    };
     327
     328                    let that = this;
     329
     330                    jQuery.ajax({
     331                        type: "post",
     332                        dataType: "json",
     333                        url: ajaxurl,
     334                        data: deleteData,
     335                        success: function( msg ) {
     336                            if ( 'success' == msg['result'] ) {
     337                                location.reload(); ;
     338                            }
     339                        }
     340                    });
     341                });
     342            }( jQuery ) );
     343        </script>
     344            <?php
     345        }
    298346    }
    299347}
  • secured-wp/trunk/classes/Controllers/User.php

    r2578505 r2579465  
    300300
    301301        /**
    302          * Unlocks the user
     302         * Unlocks the user and clears the login attempts
    303303         *
    304304         * @since 1.0.0
     
    314314                self::getLockedTransientPrefix() . self::$user->ID
    315315            );
     316
     317            LoginAttempts::clearLoginAttempts( $user );
    316318        }
    317319
  • secured-wp/trunk/classes/Helpers/AjaxRequests.php

    r2576070 r2579465  
    1313
    1414use WPSEC\Controllers\User;
     15use WPSEC\Validators\Validator;
    1516
    1617defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
     
    3536            \add_action( 'wp_ajax_logged_device_delete', [ __CLASS__, 'deleteRememberMeDevice' ] );
    3637
    37             // delete all logged in device for user.
    38             \add_action( 'wp_ajax_nopriv_all_logged_device_delete', [ __CLASS__, 'deleteAllRememberMeDevice' ] );
    39             \add_action( 'wp_ajax_all_logged_device_delete', [ __CLASS__, 'deleteAllRememberMeDevice' ] );
     38            // delete all logged in devices for user.
     39            \add_action( 'wp_ajax_nopriv_all_logged_device_delete', [ __CLASS__, 'deleteAllRememberMeDevices' ] );
     40            \add_action( 'wp_ajax_all_logged_device_delete', [ __CLASS__, 'deleteAllRememberMeDevices' ] );
    4041
     42            // delete all logged in devices for user.
     43            \add_action( 'wp_ajax_nopriv_wps_delete_qr', [ __CLASS__, 'deleteQRCodeForUser' ] );
     44            \add_action( 'wp_ajax_wps_delete_qr', [ __CLASS__, 'deleteQRCodeForUser' ] );
    4145        }
    4246
     
    6367            }
    6468
    65             if ( empty( $device ) ) {
    66                 $device = base64_decode( $_POST['device'] );
     69            if ( empty( $device ) && isset( $_POST['device'] ) && ! empty( $_POST['device'] ) ) {
     70                $device = base64_decode( \sanitize_text_field( \wp_unslash( $_POST['device'] ) ) );
    6771            }
    68             if ( User::deleteLoggedInDevice( $device, $user ) ) {
    69                 echo \json_encode( [ 'result' => 'success' ] );
    70             } else {
    71                 echo \json_encode( [ 'result' => 'failed' ] );
     72
     73            if ( ! isset( $_POST['user'] ) || empty( $_POST['user'] ) ) {
     74                die();
     75            }
     76            if ( Validator::filterValidate( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ), 'int' ) ) {
     77
     78                if ( User::deleteLoggedInDevice( $device, \sanitize_text_field( \wp_unslash( $_POST['user'] ) ) ) ) {
     79                    echo \json_encode( [ 'result' => 'success' ] );
     80                } else {
     81                    echo \json_encode( [ 'result' => 'failed' ] );
     82                }
    7283            }
    7384
     
    8293         *
    8394         * ! WP do_action sends first empty parameter if there are no parameters
    84          * @param [type] $user - WP user for which remember me device must be deleted.
     95         * TODO: extend this and the method above so it can recieves parameters as well
     96         * @param mixed $user - WP user for which remember me device must be deleted.
    8597         *
    8698         * @return void
     
    89101         * @SuppressWarnings(PHPMD.Superglobals)
    90102         */
    91         public static function deleteAllRememberMeDevice( $user = null ) {
     103        public static function deleteAllRememberMeDevices( $user = null ) {
    92104            if ( ! isset( $_POST['nonce'] ) ||
    93105                empty( $_POST['nonce'] ) ||
     
    96108            }
    97109
    98             if ( User::deleteAllLoggedInDevices( $user ) ) {
    99                 echo \json_encode( [ 'result' => 'success' ] );
    100             } else {
    101                 echo \json_encode( [ 'result' => 'failed' ] );
     110            if ( ! isset( $_POST['user'] ) || empty( $_POST['user'] ) ) {
     111                die();
     112            }
     113            if ( Validator::filterValidate( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ), 'int' ) ) {
     114                if ( User::deleteAllLoggedInDevices( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ) ) ) {
     115                    echo \json_encode( [ 'result' => 'success' ] ); // @codingStandardsIgnoreLine
     116                } else {
     117                    echo \json_encode( [ 'result' => 'failed' ] ); // @codingStandardsIgnoreLine
     118                }
    102119            }
    103120
     
    105122        }
    106123
     124        /**
     125         * Deletes QR code for the given user
     126         *
     127         * @return void
     128         *
     129         * @since 1.5
     130         *
     131         * @SuppressWarnings(PHPMD.ExitExpressions)
     132         * @SuppressWarnings(PHPMD.Superglobals)
     133         */
     134        public static function deleteQRCodeForUser() {
     135            if ( ! isset( $_POST['nonce'] ) ||
     136                empty( $_POST['nonce'] ) ||
     137                ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['nonce'] ) ), 'wp-secured-wps_delete_qr-ajax-nonce' ) ) {
     138                die();
     139            }
     140
     141            if ( ! isset( $_POST['user'] ) || empty( $_POST['user'] ) ) {
     142                die();
     143            }
     144            if ( Validator::filterValidate( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ), 'int' ) ) {
     145                User::deleteUserTotp( \sanitize_text_field( \wp_unslash( $_POST['user'] ) ) );
     146                echo \json_encode( [ 'result' => 'success' ] );
     147            }
     148
     149            die();
     150        }
    107151    }
    108152}
  • secured-wp/trunk/classes/Helpers/NotifyAdmin.php

    r2577925 r2579465  
    4040
    4141            $message = \sprintf(
    42                 /*
    43                  translators: %1$s: Name of the user */
    44                 /*
    45                  translators: %2$s: Url of the site */
    46                 /* translators: %3$s: Number of the login attempts */
     42                /* translators: %1$s: Name of the user, %2$s: Url of the site, %3$s: Number of the login attempts */
    4743                __( 'User %1$s has tried to log in with an unsuitable password too many times to your site %2$s.\nThe system has identified %3$s unsuccessful login attempts.', 'ws-secured' ),
    4844                $user->display_name,
  • secured-wp/trunk/classes/Helpers/OutOfBondEmail.php

    r2576070 r2579465  
    108108
    109109            $message = \sprintf(
    110                 /*
    111                  translators: %1$s: Name of the user */
    112                 /*
    113                  translators: %2$s: Url of the site */
    114                 /* translators: %3$s: Number of the login attempts */
     110                /* translators: %1$s: Name of the user, %2$s: Url of the site, %3$s: Number of the login attempts */
    115111                __( 'Hello %1$s,<br>Use the following link to login to site %2$s.<br>If not you who is trying to login, please contact the administrator immediately.<br>Click on the following link to login: %3$s', 'ws-secured' ),
    116112                User::getUser( $userId )->display_name,
  • secured-wp/trunk/classes/Secured.php

    r2577925 r2579465  
    8989                <?php
    9090                echo \sprintf(
    91                     /* translators: %1$s: PHP version */
     91                /* translators: %1$s: PHP version */
    9292                    \esc_html__( 'You need to update your PHP version to %1s.', 'secured-wp' ),
    9393                    WPSEC_REQUIRED_PHP_VERSION // @codingStandardsIgnoreLine - that is defined constatnt no need to escape it
     
    110110                <?php
    111111                echo \sprintf(
    112                     /* translators: %1$s: WP version */
     112                /* translators: %1$s: WP version */
    113113                    \esc_html__( 'You need to update your WP version to %1s.', 'secured-wp' ),
    114                     WPSEC_REQUIRED_WP_VERSION // @codingStandardsIgnoreLine - that is defined constatnt no need to escape it
     114                WPSEC_REQUIRED_WP_VERSION // @codingStandardsIgnoreLine - that is defined constatnt no need to escape it
    115115                );
    116116                ?>
     
    151151                    'renderPluginSettingsPage',
    152152                ],
    153                 'data:image/svg+xml;base64,' . \base64_encode( \file_get_contents( WPSEC_PLUGIN_SECURED_PATH . 'assets/images/the-logo.svg' ) ), // @codingStandardsIgnoreLine - :) well that one is necessary
     153            'data:image/svg+xml;base64,' . \base64_encode( \file_get_contents( WPSEC_PLUGIN_SECURED_PATH . 'assets/images/the-logo.svg' ) ), // @codingStandardsIgnoreLine - :) well that one is necessary
    154154                81
    155155            );
     
    305305                }
    306306            }
     307
     308            /**
     309             * If user is logged in and there is woocommerce installed and the method is enabled,
     310             * we gona need the AJAX methods available.
     311             */
     312            if ( User::isCurrentlyLogged() ) {
     313                if ( class_exists( 'WooCommerce' ) ) {
     314                    if ( ! (bool) \WPSEC\Controllers\Modules\TwoFASettings::getGlobalSettingsValue() ) {
     315                        // AJAX request for the user - do we need this globally for the Admin Part of the WP ?.
     316                        AjaxRequests::initAdmin();
     317                    }
     318                }
     319            }
    307320        }
    308321
  • secured-wp/trunk/classes/Views/UserProfile.php

    r2577925 r2579465  
    189189                <?php
    190190
    191                 \submit_button(
    192                     __( 'Regenerate QR code', 'secured-wp' ),
    193                     'delete',
    194                     'regenerate-qr-code',
    195                     false
    196                 );
     191                if ( function_exists( 'submit_button' ) ) {
     192                    \submit_button(
     193                        \__( 'Regenerate QR code', 'secured-wp' ),
     194                        'delete',
     195                        'regenerate-qr-code',
     196                        false
     197                    );
     198                } else {
     199                    ?>
     200                <input type="submit" name="regenerate-qr-code" id="regenerate-qr-code" class="button delete" value="Regenerate QR code">
     201                    <?php
     202                    self::deleteQRCodeJS();
     203                }
    197204                ?>
    198205                </div>
     
    214221            if ( \current_user_can( 'edit_user', $userId ) ) {
    215222                if ( isset( $_POST['qr-nonce'] ) &&
    216                     \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['qr-nonce'] ) ), self::$qrNoncePrefix . $userId ) &&
    217                     isset( $_POST['regenerate-qr-code'] ) ) {
    218 
    219                         User::deleteUserTotp( $userId );
     223                \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['qr-nonce'] ) ), self::$qrNoncePrefix . $userId ) &&
     224                isset( $_POST['regenerate-qr-code'] ) ) {
     225
     226                    User::deleteUserTotp( $userId );
    220227                }
    221228            }
     
    238245                        'action': 'logged_device_delete',
    239246                        'nonce': '<?php echo \esc_attr( \wp_create_nonce( 'wp-secured-delete_device-ajax-nonce' ) ); ?>',
     247                        'user': '<?php echo \esc_attr( User::getUser()->ID ); ?>',
    240248                        'device': jQuery(this).data('device')      // We pass php values differently!
    241249                    };
     
    275283                    var deleteData = {
    276284                        'action': 'all_logged_device_delete',
     285                        'user': '<?php echo \esc_attr( User::getUser()->ID ); ?>',
    277286                        'nonce': '<?php echo \esc_attr( \wp_create_nonce( 'wp-secured-delete_all_device-ajax-nonce' ) ); ?>',
    278287                    };
     
    296305            <?php
    297306        }
     307
     308        /**
     309         * Javascript for qr code deletion
     310         *
     311         * @since 1.0.0
     312         *
     313         * @return void
     314         */
     315        private static function deleteQRCodeJS() {
     316            ?>
     317        <script>
     318            ( function( jQuery ) {
     319                jQuery('.alignleft').on('click', '#regenerate-qr-code', function(e) {
     320                    e.preventDefault();
     321                    var ajaxurl = "<?php echo \esc_url( admin_url( 'admin-ajax.php' ) ); ?>"
     322                    var deleteData = {
     323                        'action': 'wps_delete_qr',
     324                        'user': '<?php echo \esc_attr( User::getUser()->ID ); ?>',
     325                        'nonce': '<?php echo \esc_attr( \wp_create_nonce( 'wp-secured-wps_delete_qr-ajax-nonce' ) ); ?>',
     326                    };
     327
     328                    let that = this;
     329
     330                    jQuery.ajax({
     331                        type: "post",
     332                        dataType: "json",
     333                        url: ajaxurl,
     334                        data: deleteData,
     335                        success: function( msg ) {
     336                            if ( 'success' == msg['result'] ) {
     337                                location.reload(); ;
     338                            }
     339                        }
     340                    });
     341                });
     342            }( jQuery ) );
     343        </script>
     344            <?php
     345        }
    298346    }
    299347}
Note: See TracChangeset for help on using the changeset viewer.