/opt/drweb/drwebd.real 'description' => array( __('Disable the customized Admin Url redirect to Login page', 'wp-hide-security-enhancer') ), 'help' => array( 'title' => __( 'Help', 'wp-hide-security-enhancer') . ' - ' . __('Block default Admin Url', 'wp-hide-security-enhancer'), 'description' => __( "The option provides the ability to control the redirection behavior of the customized URL to the login page.", 'wp-hide-security-enhancer') . "
" . __( "By default, when a non-logged-in user attempts to access the WordPress admin area via the customized URL, they are automatically redirected to the login page for authentication.", 'wp-hide-security-enhancer') . "
" . __( "Instead it will be redirected to homepage.", 'wp-hide-security-enhancer') . "

" . __('The option might interfere with specific plugins that use redirects when calling the admin URL.', 'wp-hide-security-enhancer') . '', 'option_documentation_url' => 'https://wp-hide.com/documentation/admin-change-wp-admin/' ), 'input_type' => 'radio', 'options' => array( 'no' => __('No', 'wp-hide-security-enhancer'), 'yes' => __('Yes', 'wp-hide-security-enhancer'), ), 'default_value' => 'no', 'sanitize_type' => array('sanitize_title', 'strtolower'), 'processing_order' => 65 ); $this->module_settings[] = array( 'id' => 'block_default_admin_url', 'label' => __('Block default Admin Url', 'wp-hide-security-enhancer'), 'description' => array( __('Block default admin url and files from being accesible.', 'wp-hide-security-enhancer') ), 'help' => array( 'title' => __('Help', 'wp-hide-security-enhancer') . ' - ' . __('Block default Admin Url', 'wp-hide-security-enhancer'), 'description' => __("If set to Yes, the old admin url will be blocked and a default theme 404 error page will be returned.", 'wp-hide-security-enhancer') . "

" . __('Ensure the New Admin Url option works correctly on your server before activate this.', 'wp-hide-security-enhancer') . '', 'input_value_extension' => 'php', 'option_documentation_url' => 'https://wp-hide.com/documentation/admin-change-wp-admin/' ), 'advanced_option' => array( 'description' => '' . __('This is an advanced option !', 'wp-hide-security-enhancer') . '
' . __('This can break the layour of dashboard admin if server not supporting the feature. Ensure `New Admin Url` option works fine before activate this.
If not working, use the recovery link to revert.', 'wp-hide-security-enhancer') ), 'input_type' => 'radio', 'options' => array( 'no' => __('No', 'wp-hide-security-enhancer'), 'yes' => __('Yes', 'wp-hide-security-enhancer'), ), 'default_value' => 'no', 'sanitize_type' => array('sanitize_title', 'strtolower'), 'processing_order' => 65 ); return $this->module_settings; } function _init_admin_url($saved_field_data) { if(empty($saved_field_data)) return FALSE; remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 ); $this->wph->functions->add_replacement( trailingslashit( site_url() ) . 'wp-admin' , trailingslashit( home_url() ) . $saved_field_data ); add_action('set_auth_cookie', array($this,'set_auth_cookie'), 999, 5); add_action('wp_logout', array($this,'wp_logout'), 999, 5); //make sure the admin url redirect url is updated when updating WordPress Core add_filter('user_admin_url', array($this, 'wp_core_update_user_admin_url'), 999, 2); add_filter('admin_url', array($this, 'wp_core_update_admin_url'), 999, 3); //ensure admin_url() return correct url add_filter('admin_url', array($this, 'update_admin_url'), 999, 3); } function _callback_saved_admin_url($saved_field_data) { $processing_response = array(); //check if the field is noe empty if(empty($saved_field_data)) return $processing_response; $wp_admin = untrailingslashit ( $this->wph->functions->get_url_path( trailingslashit( site_url() ) . 'wp-admin' ) ); $new_admin = untrailingslashit ( $this->wph->functions->get_url_path( trailingslashit( home_url() ) . $saved_field_data ) ); $rewrite_base = $saved_field_data; $rewrite_to = $this->wph->functions->get_rewrite_to_base( $wp_admin, TRUE, FALSE ); $rewrite_to_new_admin = $new_admin; $text = ''; if($this->wph->server_htaccess_config === TRUE) { $text = "\nRewriteCond %{REQUEST_URI} ". $rewrite_to_new_admin ."$"; $text .= "\nRewriteRule ^(.*)$ ". $rewrite_to_new_admin ."/ [R=301,L]"; $text .= "\nRewriteRule ^" . $rewrite_base . '/(.*) '. $rewrite_to .'/$1 [L,QSA]'; } if($this->wph->server_web_config === TRUE) $text = ' '; $processing_response['rewrite'] = $text; return $processing_response; } function admin_url($url, $path, $blog_id) { if($this->wph->uninstall === TRUE) return $url; $new_admin_url = $this->wph->functions->get_module_item_setting('admin_url'); $admin_dir_uri = trailingslashit( site_url() ) . trim($new_admin_url, "/"); $new_url = trailingslashit( $admin_dir_uri ) . $path; //add replacement $this->wph->functions->add_replacement($url, $new_url); return $new_url; } function set_auth_cookie( $auth_cookie, $expire, $expiration, $user_id, $scheme ) { $new_admin_url = $this->wph->functions->get_module_item_setting('admin_url'); if ( $scheme == 'secure_auth' ) { $auth_cookie_name = SECURE_AUTH_COOKIE; $secure = TRUE; } else { $auth_cookie_name = AUTH_COOKIE; $secure = FALSE; } $sitecookiepath = empty ( $this->wph->default_variables['wordpress_directory'] ) ? SITECOOKIEPATH : rtrim ( SITECOOKIEPATH, trailingslashit ( $this->wph->default_variables['wordpress_directory'] ) ); if (empty ($sitecookiepath)) $sitecookiepath = '/'; setcookie ( $auth_cookie_name, $auth_cookie, $expire, $sitecookiepath . $new_admin_url, COOKIE_DOMAIN, $secure, true ); } function wp_logout() { $new_admin_url = $this->wph->functions->get_module_item_setting( 'admin_url' ); $sitecookiepath = empty($this->wph->default_variables['wordpress_directory']) ? SITECOOKIEPATH : rtrim(SITECOOKIEPATH, trailingslashit($this->wph->default_variables['wordpress_directory'])); if (empty ($sitecookiepath)) $sitecookiepath = '/'; setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, $sitecookiepath . $new_admin_url, COOKIE_DOMAIN ); setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, $sitecookiepath . $new_admin_url, COOKIE_DOMAIN ); } function _init_block_default_admin_url($saved_field_data) { if(empty($saved_field_data) || $saved_field_data == 'no') return FALSE; } function _callback_saved_block_default_admin_url($saved_field_data) { $processing_response = array(); //check if the field is noe empty if(empty($saved_field_data) || $saved_field_data == 'no') return $processing_response; //prevent from blocking if the admin_url is empty $admin_url = $this->wph->functions->get_module_item_setting('admin_url'); if (empty( $admin_url )) return FALSE; $rewrite_base = $this->wph->functions->get_rewrite_base( '', FALSE); $rewrite_to = $this->wph->functions->get_rewrite_to_base( 'index.php', TRUE, FALSE, 'site_path' ); $text = ''; if($this->wph->server_htaccess_config === TRUE) { $text .= "RewriteCond %{ENV:REDIRECT_STATUS} ^$\n"; $text .= "RewriteRule ^".$rewrite_base."wp-admin(.+) ". $rewrite_to ."?wph-throw-404 [L]\n"; } if($this->wph->server_web_config === TRUE) { $text .= ' '; } $processing_response['rewrite'] = $text; return $processing_response; } /** * Replace any dots in the slug, as it will confuse the server uppon being an actual file * * @param mixed $value */ function sanitize_path_name( $value ) { $value = str_replace(".","-", $value); return $value; } function wp_core_update_user_admin_url( $url, $path ) { if( strpos( $_SERVER['REQUEST_URI'], "/update-core.php") === FALSE ) return $url; //replace the wp-admin with custom slug $admin_url = $this->wph->functions->get_module_item_setting('admin_url'); $url = str_replace('/wp-admin', '/' . $admin_url, $url); return $url; } function wp_core_update_admin_url( $url, $path, $blog_id ) { if( strpos( $_SERVER['REQUEST_URI'], "/update-core.php") === FALSE && strpos( $_SERVER['REQUEST_URI'], "/update.php") === FALSE) return $url; //replace the wp-admin with custom slug $admin_url = $this->wph->functions->get_module_item_setting('admin_url'); $url = str_replace('/wp-admin', '/' . $admin_url, $url); return $url; } function update_admin_url( $url, $path, $blog_id ) { //replace the wp-admin with custom slug $admin_url = $this->wph->functions->get_module_item_setting('admin_url'); if ( ! empty ( $this->wph->default_variables['wordpress_directory'] ) ) $url = str_replace( $this->wph->default_variables['wordpress_directory'] . '/wp-admin', '/' . $admin_url, $url); else $url = str_replace( '/wp-admin', '/' . $admin_url, $url); return $url; } } ?>