templates
4 years ago
dashboard.php
4 years ago
enqueue.php
4 years ago
functions.php
4 years ago
render.php
4 years ago
functions.php
162 lines
| 1 | <?php |
| 2 | |
| 3 | if ( isset( $_POST['wplra_login_redirect_filter_reset'] ) ) |
| 4 | { |
| 5 | if ( ! isset( $_POST['wplra_login_redirect_filters_fields_submit'] ) |
| 6 | || ! wp_verify_nonce( $_POST['wplra_login_redirect_filters_fields_submit'], 'wplra_login_redirect_filters_values_submit' ) |
| 7 | ) |
| 8 | { |
| 9 | function wplra_reset_nonce_error_message() |
| 10 | { |
| 11 | $class = 'notice notice-warning'; |
| 12 | |
| 13 | $message = __( 'Sorry, your nonce did not verify.', 'wplra' ); |
| 14 | |
| 15 | printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); |
| 16 | } |
| 17 | |
| 18 | add_action( 'admin_notices', 'wplra_reset_nonce_error_message' ); |
| 19 | |
| 20 | exit; |
| 21 | } |
| 22 | else |
| 23 | { |
| 24 | if( current_user_can( 'administrator' ) ) |
| 25 | { |
| 26 | delete_option( "wplra_login_redirect_filters" ); |
| 27 | |
| 28 | update_option( "wplra_login_redirect_enable", 'off' ); |
| 29 | |
| 30 | function wplra_reset_success_message() |
| 31 | { |
| 32 | $class = 'notice notice-success'; |
| 33 | |
| 34 | $message = __( 'Filters Reset Successfully', 'wplra' ); |
| 35 | |
| 36 | printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) ); |
| 37 | } |
| 38 | |
| 39 | add_action( 'admin_notices', 'wplra_reset_success_message' ); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | add_action( "admin_head", "wplra_redirect_url_suggestion" ); |
| 45 | |
| 46 | function wplra_redirect_url_suggestion() |
| 47 | { |
| 48 | $is_https = isset( $_SERVER['HTTPS'] ) && ( $_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1 ) |
| 49 | || isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'; |
| 50 | |
| 51 | $protocol = ( $is_https ) ? 'https://' : 'http://'; |
| 52 | |
| 53 | echo |
| 54 | |
| 55 | "<script> |
| 56 | |
| 57 | var wplra_all_posts_pages_sugestion = ["; |
| 58 | |
| 59 | $post_types = get_post_types( array('public' => true, '_builtin' => false ), 'names', 'or' ); |
| 60 | |
| 61 | $all_post_types = array(); |
| 62 | |
| 63 | foreach ( $post_types as $post_type ) |
| 64 | { |
| 65 | $all_post_types[] = $post_type; |
| 66 | } |
| 67 | |
| 68 | $args = array( |
| 69 | 'posts_per_page' => -1, |
| 70 | 'post_type' => $all_post_types, |
| 71 | ); |
| 72 | |
| 73 | foreach( get_posts( $args ) as $post ) |
| 74 | { |
| 75 | echo '"'. str_replace( $protocol, "", get_the_permalink( $post->ID ) ) .'",'; |
| 76 | } |
| 77 | |
| 78 | echo "];"; |
| 79 | |
| 80 | echo "var wplra_site_protocol = '$protocol';"; |
| 81 | |
| 82 | echo "</script>"; |
| 83 | } |
| 84 | |
| 85 | function wplra_add_login_filter_templates() |
| 86 | { |
| 87 | $files = array_slice( scandir( WPLRA_TEMPLATE_PATH ), 2 ); |
| 88 | |
| 89 | foreach ( $files as $file ) |
| 90 | { |
| 91 | require_once WPLRA_TEMPLATE_PATH . $file; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | add_action( "wp_ajax_wplra_login_redirect_filter_toggle_enable_disable", "wplra_login_redirect_filter_toggle_enable_disable" ); |
| 96 | |
| 97 | add_action( "wp_ajax_wplra_login_redirect_filter", "wplra_login_redirect_filter" ); |
| 98 | |
| 99 | function wplra_login_redirect_filter_toggle_enable_disable() |
| 100 | { |
| 101 | if ( ! isset( $_POST['wplra_login_redirect_filters_fields_submit'] ) |
| 102 | || ! wp_verify_nonce( $_POST['wplra_login_redirect_filters_fields_submit'], 'wplra_login_redirect_filters_values_submit' ) |
| 103 | ) |
| 104 | { |
| 105 | $responce = array('error'); |
| 106 | |
| 107 | $responce['message'] = 'Sorry, your nonce did not verify.'; |
| 108 | |
| 109 | wp_send_json( $response ); |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | if ( isset( $_POST['wplra_login_redirect_enable'] ) && !empty( $_POST['wplra_login_redirect_enable'] ) ) |
| 114 | { |
| 115 | if ( $_POST['wplra_login_redirect_enable'] == 'on' ) |
| 116 | { |
| 117 | if( current_user_can( 'administrator' ) ) |
| 118 | { |
| 119 | update_option( "wplra_login_redirect_enable", 'on' ); |
| 120 | |
| 121 | die(); |
| 122 | } |
| 123 | } |
| 124 | elseif ( $_POST['wplra_login_redirect_enable'] == 'off' ) |
| 125 | { |
| 126 | if( current_user_can( 'administrator' ) ) |
| 127 | { |
| 128 | update_option( "wplra_login_redirect_enable", 'off' ); |
| 129 | |
| 130 | die(); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | function wplra_login_redirect_filter() |
| 138 | { |
| 139 | if ( ! isset( $_POST['wplra_login_redirect_filters_fields_submit'] ) |
| 140 | || ! wp_verify_nonce( $_POST['wplra_login_redirect_filters_fields_submit'], 'wplra_login_redirect_filters_values_submit' ) |
| 141 | ) |
| 142 | { |
| 143 | $responce = array('error'); |
| 144 | |
| 145 | $responce['message'] = 'Sorry, your nonce did not verify.'; |
| 146 | |
| 147 | wp_send_json( $response ); |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | if (isset( $_POST['filters'] ) ) |
| 152 | { |
| 153 | if( current_user_can( 'administrator' ) ) |
| 154 | { |
| 155 | update_option( "wplra_login_redirect_filters", json_encode( $_POST['filters'] ) ); |
| 156 | |
| 157 | die(); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 |