esc_html__( 'Forbidden.', 'advance-wp-redirect' ) ) ); } check_ajax_referer( 'xsawrlite_admin', 'nonce' ); } /** * Admin menu. */ public function xsawrlite_admin_menu() { add_menu_page( esc_html__( 'Advance WP Redirect', 'advance-wp-redirect' ), esc_html__( 'Advance WP Redirect', 'advance-wp-redirect' ), 'manage_options', 'xsawrlite_page', 'xsawrlite_page', 'dashicons-external', 40 ); add_submenu_page( 'xsawrlite_page', esc_html__( 'Support', 'advance-wp-redirect' ), esc_html__( 'Support', 'advance-wp-redirect' ), 'manage_options', 'xsawrlite_support', 'xsawrlite_support' ); } /** * Enqueue admin CSS/JS (no external stylesheets). */ public function xsawrlite_load_css_js() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only admin page slug. $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( 'xsawrlite_page' !== $page && 'xsawrlite_support' !== $page ) { return; } $ver = XSAWRLITE_VERSION; $url = $this->xsawrlite_assets_url(); wp_register_style( 'xsawrlite-material', $url . 'assets/css/xsawrlite.material.min.css', array(), $ver ); wp_register_style( 'xsawrlite-custom', $url . 'assets/css/xsawrlite.custom.css', array( 'xsawrlite-material' ), $ver ); wp_register_script( 'xsawrlite-material', $url . 'assets/js/xsawrlite.material.min.js', array( 'jquery' ), $ver, true ); wp_register_script( 'xsawrlite-custom', $url . 'assets/js/xsawrlite.custom.js', array( 'jquery', 'xsawrlite-material' ), $ver, true ); wp_enqueue_style( 'xsawrlite-material' ); wp_enqueue_style( 'xsawrlite-custom' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'xsawrlite-material' ); wp_enqueue_script( 'xsawrlite-custom' ); wp_localize_script( 'xsawrlite-custom', 'xsawrliteAdmin', array( 'nonce' => wp_create_nonce( 'xsawrlite_admin' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), ) ); } /** * Front-end script for link attributes. */ public function xsawrlite_forntend_load_js() { wp_enqueue_script( 'xsawrlite-frontend', $this->xsawrlite_assets_url() . 'assets/js/xsawrlite.frontend.js', array( 'jquery' ), XSAWRLITE_VERSION, true ); wp_localize_script( 'xsawrlite-frontend', 'frontend_ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), ) ); } /** * Register settings with sanitization. */ public function xsawrlite_register_settings() { register_setting( 'xsawrlite_options', 'xsawrlite-masteroptions', array( 'type' => 'array', 'sanitize_callback' => 'xsawrlite_sanitize_master_options', ) ); } /** * Add/update redirects (AJAX). */ public function xsawrlite_add_redirects() { $this->xsawrlite_verify_ajax_admin(); // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verified in xsawrlite_verify_ajax_admin(). $datajson = array(); $redirects = get_option( 'xsawrlite_easy_redirect', array() ); if ( ! is_array( $redirects ) ) { $redirects = array(); } if ( empty( $redirects ) ) { $index = 0; } else { end( $redirects ); $index = key( $redirects ); } if ( empty( $_POST['redirect_data'] ) ) { $datajson['error'] = esc_html__( 'Invalid request.', 'advance-wp-redirect' ); wp_send_json( $datajson ); } // Do not use sanitize_textarea_field() on the serialized string: WordPress _sanitize_text_fields() // strips all %XX sequences, which breaks bracketed field names and decodes URLs (e.g. %2F, %3A). $xsawrlite_redirect = array(); parse_str( wp_unslash( $_POST['redirect_data'] ), $xsawrlite_redirect ); if ( empty( $xsawrlite_redirect['xsawrlite_easy_redirect'] ) || ! is_array( $xsawrlite_redirect['xsawrlite_easy_redirect'] ) ) { $datajson['error'] = esc_html__( 'Invalid redirect data.', 'advance-wp-redirect' ); wp_send_json( $datajson ); } $row =& $xsawrlite_redirect['xsawrlite_easy_redirect']; $http = isset( $_SERVER['HTTP_ORIGIN'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_ORIGIN'] ) ) : ''; $server_name = isset( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : ''; $order = array_filter( array( $http, '/' . $server_name, $server_name ) ); $rurl_raw = isset( $row['rurl'] ) ? $row['rurl'] : ''; $rurl = $rurl_raw; foreach ( $order as $strip ) { if ( $strip !== '' ) { $rurl = str_replace( $strip, '', $rurl ); } } $row['rurl'] = $rurl; if ( ! isset( $row['rurl'] ) || '' === trim( (string) $row['rurl'] ) ) { $datajson['error'] = esc_html__( 'Please Enter Request URL', 'advance-wp-redirect' ); } $slash = substr( (string) $row['rurl'], 0, 1 ); if ( '/' !== $slash ) { $row['rurl'] = '/' . $rurl; } else { $row['rurl'] = $rurl; } if ( ! isset( $row['nw'] ) ) { if ( isset( $row['nf'] ) ) { $temp1 = $row['nf']; unset( $row['nf'] ); $row['nw'] = '0'; $row['nf'] = $temp1; } else { $row['nw'] = '0'; } } if ( ! isset( $row['nf'] ) ) { $row['nf'] = '0'; } if ( ! isset( $_POST['redirect_id'] ) ) { $rurls = array_column( $redirects, 'rurl' ); if ( in_array( $row['rurl'], $rurls, true ) ) { $datajson['error'] = esc_html__( 'Request URL Already Exist', 'advance-wp-redirect' ); } else { $redirects[ $index + 1 ] = $row; $datajson['success'] = esc_html__( 'Added Redirect Successfully', 'advance-wp-redirect' ); } } else { $xsawr_id = sanitize_text_field( wp_unslash( $_POST['redirect_id'] ) ); if ( ! isset( $redirects[ $xsawr_id ] ) ) { $datajson['error'] = esc_html__( 'Redirect not found.', 'advance-wp-redirect' ); wp_send_json( $datajson ); } $redirects[ $xsawr_id ] = $row; $datajson['updated'] = esc_html__( 'Updated Redirect Successfully', 'advance-wp-redirect' ); } if ( ! isset( $row['durl'] ) || '' === trim( (string) $row['durl'] ) ) { $datajson['error'] = esc_html__( 'Please Enter Target URL', 'advance-wp-redirect' ); } if ( ! isset( $datajson['error'] ) ) { $redirects = array_map( 'xsawrlite_sanitize_redirect_entry', $redirects ); update_option( 'xsawrlite_easy_redirect', $redirects ); $datajson['output'] = $this->xsawrlite_redirect_table_rows_html(); } // phpcs:enable WordPress.Security.NonceVerification.Missing wp_send_json( $datajson ); } /** * Build tbody rows HTML for redirect table. * * @return string */ private function xsawrlite_redirect_table_rows_html() { $output = ''; $xsawrlite_eredirect = get_option( 'xsawrlite_easy_redirect', array() ); if ( ! is_array( $xsawrlite_eredirect ) ) { return $output; } foreach ( $xsawrlite_eredirect as $xsawrlite_key => $val ) { if ( ! is_array( $val ) ) { continue; } $xsawrlite_key_attr = esc_attr( (string) $xsawrlite_key ); $xsawrlite_key_html = esc_html( (string) $xsawrlite_key ); $output .= '
| User Name | ' . esc_html( $name ) . ' |
|---|---|
| User email | ' . esc_html( $email ) . ' |
| Plugin Name | ' . esc_html( $data['plugin_name'] ) . ' |
| Version | ' . esc_html( $data['version'] ) . ' |
| Website | ' . esc_html( $data['website'] ) . ' |
| Message | ' . esc_html( $message ) . ' |