Last active
January 15, 2018 06:44
-
-
Save bryanwillis/be99eab2a298bb32b8a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| return ChangeAdminUrlPlugin::bootstrap(); | |
| class ChangeAdminUrlPlugin { | |
| private $renameFrom = 'wp-admin'; | |
| private $renameTo = 'dashboard'; | |
| static $instance; | |
| static public function bootstrap() { | |
| null === self::$instance | |
| && self::$instance = new self() | |
| ; | |
| return self::$instance; | |
| } | |
| private function setCookiePath() { | |
| defined('SITECOOKIEPATH') || define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) ); | |
| defined('ADMIN_COOKIE_PATH') || define('ADMIN_COOKIE_PATH', SITECOOKIEPATH . $this->renameTo); | |
| } | |
| public function __construct() { | |
| $this->setCookiePath(); | |
| add_action('init', array($this, 'init')) ; | |
| } | |
| public function init() { | |
| add_filter('admin_url', array($this, 'admin_url'), 10, 3); | |
| add_filter('network_admin_url', array($this, 'network_admin_url'), 10, 3);//Added by Mark Figueredo, <http://gruvii.com/> | |
| } | |
| // OLD WAY DIDN'T CHECK FOR RELATIVE URLS | |
| /* | |
| public function admin_url($url, $path, $blog_id) { | |
| $renameFrom = $this->renameFrom; | |
| $renameTo = $this->renameTo; | |
| $scheme = 'admin'; | |
| $find = get_site_url($blog_id, $renameFrom.'/', $scheme); | |
| $replace = get_site_url($blog_id, $renameTo.'/', $scheme); | |
| (0 === strpos($url, $find)) | |
| && $url = $replace.substr($url, strlen($find)) | |
| ; | |
| return $url; | |
| } | |
| // */ | |
| public function admin_url($url, $path, $blog_id) { | |
| $renameFrom = $this->renameFrom; | |
| $renameTo = $this->renameTo; | |
| $scheme = (0 === strpos($url, '/')) ? 'relative' : 'admin'; | |
| $find = get_site_url($blog_id, $renameFrom.'/', $scheme); | |
| $replace = get_site_url($blog_id, $renameFrom.'/', $scheme); | |
| (0 === strpos($url, $find)) | |
| && $url = $replace . substr($url, strlen($find)) | |
| ; | |
| return $url; | |
| } | |
| public function network_admin_url($url, $path) { | |
| $renameFrom = $this->renameFrom; | |
| $renameTo = $this->renameTo; | |
| $scheme = 'admin'; | |
| $find = network_site_url($renameFrom.'/', $scheme); | |
| $replace = network_site_url($renameTo.'/', $scheme); | |
| (0 === strpos($url, $find)) | |
| && $url = $replace.substr($url, strlen($find)) | |
| ; | |
| return $url; | |
| } | |
| } | |
| #EOF; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| define('WP_ADMIN_DIR', 'admin'); | |
| defined('SITECOOKIEPATH') || define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) ); | |
| define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR); | |
| add_filter('site_url', 'wpadmin_filter', 10, 3); | |
| function wpadmin_filter( $url, $path, $orig_scheme ) { | |
| $old = array( "/(wp-admin)/"); | |
| $admin_dir = WP_ADMIN_DIR; | |
| $new = array($admin_dir); | |
| return preg_replace( $old, $new, $url, 1); | |
| } | |
| function redirect_wp_admin(){ | |
| $redirect_to = $_SERVER['REQUEST_URI']; | |
| if(count($_REQUEST)> 0 && array_key_exists('redirect_to', $_REQUEST)){ | |
| $redirect_to = $_REQUEST['redirect_to']; | |
| $check_wp_admin = stristr($redirect_to, 'wp-admin'); | |
| if($check_wp_admin){ | |
| wp_safe_redirect( '404.php' ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment