Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.05 KB | None | 0 0
  1. <?php
  2.  
  3. namespace WPS\WPS_Hide_Login;
  4.  
  5.  
  6. class Plugin {
  7.  
  8. use Singleton;
  9.  
  10. private $wp_login_php;
  11.  
  12. protected function init() {
  13. global $wp_version;
  14.  
  15. if ( version_compare( $wp_version, '4.0-RC1-src', '<' ) ) {
  16. add_action( 'admin_notices', array( $this, 'admin_notices_incompatible' ) );
  17. add_action( 'network_admin_notices', array( $this, 'admin_notices_incompatible' ) );
  18.  
  19. return;
  20. }
  21.  
  22.  
  23. if ( is_multisite() && ! function_exists( 'is_plugin_active_for_network' ) || ! function_exists( 'is_plugin_active' ) ) {
  24. require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
  25.  
  26. }
  27.  
  28. if ( is_plugin_active_for_network( 'rename-wp-login/rename-wp-login.php' ) ) {
  29. deactivate_plugins( WPS_HIDE_LOGIN_BASENAME );
  30. add_action( 'network_admin_notices', array( $this, 'admin_notices_plugin_conflict' ) );
  31. if ( isset( $_GET['activate'] ) ) {
  32. unset( $_GET['activate'] );
  33. }
  34.  
  35. return;
  36. }
  37.  
  38. if ( is_plugin_active( 'rename-wp-login/rename-wp-login.php' ) ) {
  39. deactivate_plugins( WPS_HIDE_LOGIN_BASENAME );
  40. add_action( 'admin_notices', array( $this, 'admin_notices_plugin_conflict' ) );
  41. if ( isset( $_GET['activate'] ) ) {
  42. unset( $_GET['activate'] );
  43. }
  44.  
  45. return;
  46. }
  47.  
  48. if ( is_multisite() && is_plugin_active_for_network( WPS_HIDE_LOGIN_BASENAME ) ) {
  49. add_action( 'wpmu_options', array( $this, 'wpmu_options' ) );
  50. add_action( 'update_wpmu_options', array( $this, 'update_wpmu_options' ) );
  51.  
  52. // add_filter( 'network_admin_plugin_action_links_' . WPS_HIDE_LOGIN_BASENAME, array(
  53. // $this,
  54. // 'plugin_action_links'
  55. // ) );
  56. }
  57.  
  58. add_action( 'admin_init', array( $this, 'admin_init' ) );
  59. add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ), 9999 );
  60. add_action( 'admin_notices', array( $this, 'admin_notices' ) );
  61. add_action( 'network_admin_notices', array( $this, 'admin_notices' ) );
  62. add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
  63. add_action( 'setup_theme', array( $this, 'setup_theme' ), 1 );
  64.  
  65. // add_filter( 'plugin_action_links_' . WPS_HIDE_LOGIN_BASENAME, array( $this, 'plugin_action_links' ) );
  66. add_filter( 'site_url', array( $this, 'site_url' ), 10, 4 );
  67. add_filter( 'network_site_url', array( $this, 'network_site_url' ), 10, 3 );
  68. add_filter( 'wp_redirect', array( $this, 'wp_redirect' ), 10, 2 );
  69. add_filter( 'site_option_welcome_email', array( $this, 'welcome_email' ) );
  70.  
  71. remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
  72. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
  73.  
  74. add_action( 'admin_menu', array( $this, 'wps_hide_login_menu_page' ) );
  75. add_action( 'admin_init', array( $this, 'whl_template_redirect' ) );
  76.  
  77. add_action( 'template_redirect', array( $this, 'wps_hide_login_redirect_page_email_notif_woocommerce' ) );
  78. add_filter( 'login_url', array( $this, 'login_url' ), 10, 3 );
  79.  
  80. add_filter( 'user_request_action_email_content', array( $this, 'user_request_action_email_content' ), 999, 2 );
  81. }
  82.  
  83. public function user_request_action_email_content( $email_text, $email_data ) {
  84. $email_text = str_replace( '###CONFIRM_URL###', esc_url_raw( str_replace( $this->new_login_slug() . '/', 'wp-login.php', $email_data['confirm_url'] ) ), $email_text );
  85.  
  86. return $email_text;
  87. }
  88.  
  89. private function use_trailing_slashes() {
  90.  
  91. return ( '/' === substr( get_option( 'permalink_structure' ), - 1, 1 ) );
  92.  
  93. }
  94.  
  95. private function user_trailingslashit( $string ) {
  96.  
  97. return $this->use_trailing_slashes() ? trailingslashit( $string ) : untrailingslashit( $string );
  98.  
  99. }
  100.  
  101. private function wp_template_loader() {
  102.  
  103. global $pagenow;
  104.  
  105. $pagenow = 'index.php';
  106.  
  107. if ( ! defined( 'WP_USE_THEMES' ) ) {
  108.  
  109. define( 'WP_USE_THEMES', true );
  110.  
  111. }
  112.  
  113. wp();
  114.  
  115. if ( $_SERVER['REQUEST_URI'] === $this->user_trailingslashit( str_repeat( '-/', 10 ) ) ) {
  116.  
  117. $_SERVER['REQUEST_URI'] = $this->user_trailingslashit( '/wp-login-php/' );
  118.  
  119. }
  120.  
  121. require_once( ABSPATH . WPINC . '/template-loader.php' );
  122.  
  123. die;
  124.  
  125. }
  126.  
  127. private function new_login_slug() {
  128. if ( $slug = get_option( 'whl_page' ) ) {
  129. return $slug;
  130. } else if ( ( is_multisite() && is_plugin_active_for_network( WPS_HIDE_LOGIN_BASENAME ) && ( $slug = get_site_option( 'whl_page', 'login' ) ) ) ) {
  131. return $slug;
  132. } else if ( $slug = 'login' ) {
  133. return $slug;
  134. }
  135. }
  136.  
  137. private function new_redirect_slug() {
  138. if ( $slug = get_option( 'whl_redirect_admin' ) ) {
  139. return $slug;
  140. } else if ( ( is_multisite() && is_plugin_active_for_network( WPS_HIDE_LOGIN_BASENAME ) && ( $slug = get_site_option( 'whl_redirect_admin', '404' ) ) ) ) {
  141. return $slug;
  142. } else if ( $slug = '404' ) {
  143. return $slug;
  144. }
  145. }
  146.  
  147. public function new_login_url( $scheme = null ) {
  148.  
  149. if ( get_option( 'permalink_structure' ) ) {
  150.  
  151. return $this->user_trailingslashit( home_url( '/', $scheme ) . $this->new_login_slug() );
  152.  
  153. } else {
  154.  
  155. return home_url( '/', $scheme ) . '?' . $this->new_login_slug();
  156.  
  157. }
  158.  
  159. }
  160.  
  161. public function new_redirect_url( $scheme = null ) {
  162.  
  163. if ( get_option( 'permalink_structure' ) ) {
  164.  
  165. return $this->user_trailingslashit( home_url( '/', $scheme ) . $this->new_redirect_slug() );
  166.  
  167. } else {
  168.  
  169. return home_url( '/', $scheme ) . '?' . $this->new_redirect_slug();
  170.  
  171. }
  172.  
  173. }
  174.  
  175. public function admin_notices_incompatible() {
  176.  
  177. echo '<div class="error notice is-dismissible"><p>' . __( 'Please upgrade to the latest version of WordPress to activate', 'wpserveur-hide-login' ) . ' <strong>' . __( 'Url Login Admin', 'wpserveur-hide-login' ) . '</strong>.</p></div>';
  178.  
  179. }
  180.  
  181. public function admin_notices_plugin_conflict() {
  182.  
  183. echo '<div class="error notice is-dismissible"><p>' . __( 'Url Login Admin could not be activated because you already have Rename wp-login.php active. Please uninstall rename wp-login.php to use Url Login Admin', 'wpserveur-hide-login' ) . '</p></div>';
  184.  
  185. }
  186.  
  187. /**
  188. * Plugin activation
  189. */
  190. public static function activate() {
  191. //add_option( 'whl_redirect', '1' );
  192.  
  193. do_action( 'wps_hide_login_activate' );
  194. }
  195.  
  196. public function wpmu_options() {
  197.  
  198. $out = '';
  199.  
  200. $out .= '<h3>' . __( 'Url Login Admin', 'wpserveur-hide-login' ) . '</h3>';
  201. //$out .= '<p>' . __( 'This option allows you to set a networkwide default, which can be overridden by individual sites. Simply go to to the site’s permalink settings to change the url.', 'wpserveur-hide-login' ) . '</p>';
  202. //$out .= '<p>' . sprintf( __( 'Need help? Try the <a href="%1$s" target="_blank">support forum</a>. This plugin is kindly brought to you by <a href="%2$s" target="_blank">WPServeur</a>', 'wpserveur-hide-login' ), 'http://wordpress.org/support/plugin/wps-hide-login/', 'https://www.wpserveur.net/?refwps=14&campaign=wpshidelogin' ) . '</p>';
  203. $out .= '<table class="form-table">';
  204. $out .= '<tr valign="top">';
  205. $out .= '<th scope="row"><label for="whl_page">' . __( 'Networkwide default', 'wpserveur-hide-login' ) . '</label></th>';
  206. $out .= '<td><input id="whl_page" type="text" name="whl_page" value="' . esc_attr( get_site_option( 'whl_page', 'login' ) ) . '"></td>';
  207. $out .= '<th scope="row"><label for="whl_redirect_admin">' . __( 'Redirection url default', 'wpserveur-hide-login' ) . '</label></th>';
  208. $out .= '<td><input id="whl_redirect_admin" type="text" name="whl_redirect_admin" value="' . esc_attr( get_site_option( 'whl_redirect_admin', '404' ) ) . '"></td>';
  209. $out .= '</tr>';
  210. $out .= '</table>';
  211.  
  212. echo $out;
  213.  
  214. }
  215.  
  216. public function update_wpmu_options() {
  217. if ( check_admin_referer( 'siteoptions' ) ) {
  218. if ( ( $whl_page = sanitize_title_with_dashes( $_POST['whl_page'] ) )
  219. && strpos( $whl_page, 'wp-login' ) === false
  220. && ! in_array( $whl_page, $this->forbidden_slugs() ) ) {
  221.  
  222. update_site_option( 'whl_page', $whl_page );
  223.  
  224. }
  225. if ( ( $whl_redirect_admin = sanitize_title_with_dashes( $_POST['whl_redirect_admin'] ) )
  226. && strpos( $whl_redirect_admin, '404' ) === false ) {
  227.  
  228. update_site_option( 'whl_redirect_admin', $whl_redirect_admin );
  229.  
  230. }
  231. }
  232. }
  233.  
  234. public function admin_init() {
  235.  
  236. global $pagenow;
  237.  
  238. add_settings_section(
  239. 'wps-hide-login-section',
  240. 'Url Login Admin',
  241. array( $this, 'whl_section_desc' ),
  242. 'general'
  243. );
  244.  
  245. add_settings_field(
  246. 'whl_page',
  247. '<label for="whl_page">' . __( 'Login url', 'wpserveur-hide-login' ) . '</label>',
  248. array( $this, 'whl_page_input' ),
  249. 'general',
  250. 'wps-hide-login-section'
  251. );
  252.  
  253. add_settings_field(
  254. 'whl_redirect_admin',
  255. '<label for="whl_redirect_admin">' . __( 'Redirection url', 'wpserveur-hide-login' ) . '</label>',
  256. array( $this, 'whl_redirect_admin_input' ),
  257. 'general',
  258. 'wps-hide-login-section'
  259. );
  260.  
  261. register_setting( 'general', 'whl_page', 'sanitize_title_with_dashes' );
  262. register_setting( 'general', 'whl_redirect_admin', 'sanitize_title_with_dashes' );
  263.  
  264. if ( get_option( 'whl_redirect' ) ) {
  265.  
  266. delete_option( 'whl_redirect' );
  267.  
  268. if ( is_multisite()
  269. && is_super_admin()
  270. && is_plugin_active_for_network( WPS_HIDE_LOGIN_BASENAME ) ) {
  271.  
  272. $redirect = network_admin_url( 'settings.php#whl_settings' );
  273.  
  274. } else {
  275.  
  276. $redirect = admin_url( 'options-general.php#whl_settings' );
  277.  
  278. }
  279.  
  280. wp_safe_redirect( $redirect );
  281. die();
  282.  
  283. }
  284.  
  285. }
  286.  
  287. public function whl_section_desc() {
  288.  
  289. $out = '';
  290.  
  291. if ( ! is_multisite()
  292. || is_super_admin() ) {
  293.  
  294. $details_url_wpsbidouille = add_query_arg(
  295. array(
  296. 'tab' => 'plugin-information',
  297. 'plugin' => 'wps-bidouille',
  298. 'TB_iframe' => true,
  299. 'width' => 722,
  300. 'height' => 949,
  301. ),
  302. admin_url( 'plugin-install.php' )
  303. );
  304.  
  305. $details_url_wpscleaner = add_query_arg(
  306. array(
  307. 'tab' => 'plugin-information',
  308. 'plugin' => 'wps-cleaner',
  309. 'TB_iframe' => true,
  310. 'width' => 722,
  311. 'height' => 949,
  312. ),
  313. admin_url( 'plugin-install.php' )
  314. );
  315.  
  316. $details_url_wpslimitlogin = add_query_arg(
  317. array(
  318. 'tab' => 'plugin-information',
  319. 'plugin' => 'wps-limit-login',
  320. 'TB_iframe' => true,
  321. 'width' => 722,
  322. 'height' => 949,
  323. ),
  324. admin_url( 'plugin-install.php' )
  325. );
  326.  
  327. $out .= '<div id="whl_settings">';
  328. //$out .= sprintf( __( 'Need help? Try the <a href="%1$s" target="_blank">support forum</a>. This plugin is kindly brought to you by <a href="%2$s" target="_blank">WPServeur</a>', 'wpserveur-hide-login' ), 'http://wordpress.org/support/plugin/wps-hide-login/', 'https://www.wpserveur.net/?refwps=14&campaign=wpshidelogin' ) . ' (' . __( 'WordPress specialized hosting', 'wpserveur-hide-login' ) . ')';
  329. //$out .= '<br>' . __( 'Discover our other plugins:', 'wpserveur-hide-login' ) . ' ';
  330. //$out .= __( 'the plugin', 'wpserveur-hide-login' ) . ' <a href="' . $details_url_wpsbidouille . '" class="thickbox open-plugin-details-modal">' . __( 'WPS Bidouille', 'wpserveur-hide-login' ) . '</a>';
  331. //$out .= ', ' . __( 'the plugin', 'wpserveur-hide-login' ) . ' <a href="' . $details_url_wpscleaner . '" class="thickbox open-plugin-details-modal">' . __( 'WPS Cleaner', 'wpserveur-hide-login' ) . '</a>';
  332. //$out .= ' ' . __( 'and', 'wpserveur-hide-login' ) . ' <a href="' . $details_url_wpslimitlogin . '" class="thickbox open-plugin-details-modal">' . __( 'WPS Limit Login', 'wpserveur-hide-login' ) . '</a>';
  333. $out .= '</div>';
  334.  
  335. }
  336.  
  337. if ( is_multisite()
  338. && is_super_admin()
  339. && is_plugin_active_for_network( WPS_HIDE_LOGIN_BASENAME ) ) {
  340.  
  341. $out .= '<p>' . sprintf( __( 'To set a networkwide default, go to <a href="%s">Network Settings</a>.', 'wpserveur-hide-login' ), network_admin_url( 'settings.php#whl_settings' ) ) . '</p>';
  342.  
  343. }
  344.  
  345. echo $out;
  346.  
  347. }
  348.  
  349. public function whl_page_input() {
  350.  
  351. if ( get_option( 'permalink_structure' ) ) {
  352.  
  353. echo '<code>' . trailingslashit( home_url() ) . '</code> <input id="whl_page" type="text" name="whl_page" value="' . $this->new_login_slug() . '">' . ( $this->use_trailing_slashes() ? ' <code>/</code>' : '' );
  354.  
  355. } else {
  356.  
  357. echo '<code>' . trailingslashit( home_url() ) . '?</code> <input id="whl_page" type="text" name="whl_page" value="' . $this->new_login_slug() . '">';
  358.  
  359. }
  360.  
  361. echo '<p class="description">' . __( 'Proteja seu site alterando o URL de login e impedindo o acesso à página wp-login.php e ao diretório wp-admin a pessoas não conectadas.', 'wpserveur-hide-login' ) . '</p>';
  362.  
  363. }
  364.  
  365. public function whl_redirect_admin_input() {
  366. if ( get_option( 'permalink_structure' ) ) {
  367.  
  368. echo '<code>' . trailingslashit( home_url() ) . '</code> <input id="whl_redirect_admin" type="text" name="whl_redirect_admin" value="' . $this->new_redirect_slug() . '">' . ( $this->use_trailing_slashes() ? ' <code>/</code>' : '' );
  369.  
  370. } else {
  371.  
  372. echo '<code>' . trailingslashit( home_url() ) . '?</code> <input id="whl_redirect_admin" type="text" name="whl_redirect_admin" value="' . $this->new_redirect_slug() . '">';
  373.  
  374. }
  375.  
  376. echo '<p class="description">' . __( 'Redirecionar URL quando alguém tentar acessar a página wp-login.php e o diretório wp-admin enquanto não estiver logado.', 'wpserveur-hide-login' ) . '</p>';
  377. }
  378.  
  379. public function admin_notices() {
  380.  
  381. global $pagenow;
  382.  
  383. $out = '';
  384.  
  385. if ( ! is_network_admin()
  386. && $pagenow === 'options-general.php'
  387. && isset( $_GET['settings-updated'] )
  388. && ! isset( $_GET['page'] ) ) {
  389.  
  390. echo '<div class="updated notice is-dismissible"><p>' . sprintf( __( 'Your login page is now here: <strong><a href="%1$s">%2$s</a></strong>. Bookmark this page!', 'wpserveur-hide-login' ), $this->new_login_url(), $this->new_login_url() ) . '</p></div>';
  391.  
  392. }
  393.  
  394. }
  395.  
  396. // public function plugin_action_links( $links ) {
  397. //
  398. // if ( is_network_admin()
  399. // && is_plugin_active_for_network( WPS_HIDE_LOGIN_BASENAME ) ) {
  400. //
  401. // array_unshift( $links, '<a href="' . network_admin_url( 'settings.php#whl_settings' ) . '">' . __( 'Settings', 'wpserveur-hide-login' ) . '</a>' );
  402. //
  403. // } elseif ( ! is_network_admin() ) {
  404. //
  405. // array_unshift( $links, '<a href="' . admin_url( 'options-general.php#whl_settings' ) . '">' . __( 'Settings', 'wpserveur-hide-login' ) . '</a>' );
  406. //
  407. // }
  408. //
  409. // return $links;
  410. //
  411. // }
  412.  
  413. public function plugins_loaded() {
  414.  
  415. global $pagenow;
  416.  
  417. if ( ! is_multisite()
  418. && ( strpos( $_SERVER['REQUEST_URI'], 'wp-signup' ) !== false
  419. || strpos( $_SERVER['REQUEST_URI'], 'wp-activate' ) !== false ) && apply_filters( 'wps_hide_login_signup_enable', false ) === false ) {
  420.  
  421. wp_die( __( 'This feature is not enabled.', 'wpserveur-hide-login' ) );
  422.  
  423. }
  424.  
  425. $request = parse_url( $_SERVER['REQUEST_URI'] );
  426.  
  427. if ( isset( $request['query'] ) && strpos( $request['query'], 'action=confirmaction' ) !== false ) {
  428. @require_once ABSPATH . 'wp-login.php';
  429.  
  430. $pagenow = 'index.php';
  431. } elseif ( ( strpos( rawurldecode( $_SERVER['REQUEST_URI'] ), 'wp-login.php' ) !== false
  432. || untrailingslashit( $request['path'] ) === site_url( 'wp-login', 'relative' ) )
  433. && ! is_admin() ) {
  434.  
  435. $this->wp_login_php = true;
  436.  
  437. $_SERVER['REQUEST_URI'] = $this->user_trailingslashit( '/' . str_repeat( '-/', 10 ) );
  438.  
  439. $pagenow = 'index.php';
  440.  
  441. } elseif ( untrailingslashit( $request['path'] ) === home_url( $this->new_login_slug(), 'relative' )
  442. || ( ! get_option( 'permalink_structure' )
  443. && isset( $_GET[ $this->new_login_slug() ] )
  444. && empty( $_GET[ $this->new_login_slug() ] ) ) ) {
  445.  
  446. $pagenow = 'wp-login.php';
  447.  
  448. } elseif ( ( strpos( rawurldecode( $_SERVER['REQUEST_URI'] ), 'wp-register.php' ) !== false
  449. || untrailingslashit( $request['path'] ) === site_url( 'wp-register', 'relative' ) )
  450. && ! is_admin() ) {
  451.  
  452. $this->wp_login_php = true;
  453.  
  454. $_SERVER['REQUEST_URI'] = $this->user_trailingslashit( '/' . str_repeat( '-/', 10 ) );
  455.  
  456. $pagenow = 'index.php';
  457. }
  458.  
  459. }
  460.  
  461. public function setup_theme() {
  462. global $pagenow;
  463.  
  464. if ( ! is_user_logged_in() && 'customize.php' === $pagenow ) {
  465. wp_die( __( 'This has been disabled', 'wpserveur-hide-login' ), 403 );
  466. }
  467. }
  468.  
  469. public function wp_loaded() {
  470.  
  471. global $pagenow;
  472.  
  473. $request = parse_url( $_SERVER['REQUEST_URI'] );
  474.  
  475. if ( ! isset( $_POST['post_password'] ) ) {
  476.  
  477. if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' && ( isset( $_GET ) && empty( $_GET['adminhash'] ) && $request['path'] !== '/wp-admin/options.php' ) ) {
  478. wp_safe_redirect( $this->new_redirect_url() );
  479. die();
  480. }
  481.  
  482. if ( $pagenow === 'wp-login.php'
  483. && $request['path'] !== $this->user_trailingslashit( $request['path'] )
  484. && get_option( 'permalink_structure' ) ) {
  485.  
  486. wp_safe_redirect( $this->user_trailingslashit( $this->new_login_url() )
  487. . ( ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '' ) );
  488.  
  489. die;
  490.  
  491. } elseif ( $this->wp_login_php ) {
  492.  
  493. if ( ( $referer = wp_get_referer() )
  494. && strpos( $referer, 'wp-activate.php' ) !== false
  495. && ( $referer = parse_url( $referer ) )
  496. && ! empty( $referer['query'] ) ) {
  497.  
  498. parse_str( $referer['query'], $referer );
  499.  
  500. if ( ! empty( $referer['key'] )
  501. && ( $result = wpmu_activate_signup( $referer['key'] ) )
  502. && is_wp_error( $result )
  503. && ( $result->get_error_code() === 'already_active'
  504. || $result->get_error_code() === 'blog_taken' ) ) {
  505.  
  506. wp_safe_redirect( $this->new_login_url()
  507. . ( ! empty( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '' ) );
  508.  
  509. die;
  510.  
  511. }
  512.  
  513. }
  514.  
  515. $this->wp_template_loader();
  516.  
  517. } elseif ( $pagenow === 'wp-login.php' ) {
  518. global $error, $interim_login, $action, $user_login;
  519.  
  520. if ( is_user_logged_in() && ! isset( $_REQUEST['action'] ) ) {
  521. wp_safe_redirect( admin_url() );
  522. die();
  523. }
  524.  
  525. @require_once ABSPATH . 'wp-login.php';
  526.  
  527. die;
  528.  
  529. }
  530.  
  531. }
  532.  
  533. }
  534.  
  535. public function site_url( $url, $path, $scheme, $blog_id ) {
  536.  
  537. return $this->filter_wp_login_php( $url, $scheme );
  538.  
  539. }
  540.  
  541. public function network_site_url( $url, $path, $scheme ) {
  542.  
  543. return $this->filter_wp_login_php( $url, $scheme );
  544.  
  545. }
  546.  
  547. public function wp_redirect( $location, $status ) {
  548.  
  549. if ( strpos( $location, 'https://wordpress.com/wp-login.php' ) !== false ) {
  550. return $location;
  551. }
  552.  
  553. return $this->filter_wp_login_php( $location );
  554.  
  555. }
  556.  
  557. public function filter_wp_login_php( $url, $scheme = null ) {
  558.  
  559. if ( strpos( $url, 'wp-login.php?action=postpass' ) !== false ) {
  560. return $url;
  561. }
  562.  
  563. if ( strpos( $url, 'wp-login.php' ) !== false ) {
  564.  
  565. if ( is_ssl() ) {
  566.  
  567. $scheme = 'https';
  568.  
  569. }
  570.  
  571. $args = explode( '?', $url );
  572.  
  573. if ( isset( $args[1] ) ) {
  574.  
  575. parse_str( $args[1], $args );
  576.  
  577. if ( isset( $args['login'] ) ) {
  578. $args['login'] = rawurlencode( $args['login'] );
  579. }
  580.  
  581. $url = add_query_arg( $args, $this->new_login_url( $scheme ) );
  582.  
  583. } else {
  584.  
  585. $url = $this->new_login_url( $scheme );
  586.  
  587. }
  588.  
  589. }
  590.  
  591. return $url;
  592.  
  593. }
  594.  
  595. public function welcome_email( $value ) {
  596.  
  597. return $value = str_replace( 'wp-login.php', trailingslashit( get_site_option( 'whl_page', 'login' ) ), $value );
  598.  
  599. }
  600.  
  601. public function forbidden_slugs() {
  602.  
  603. $wp = new \WP;
  604.  
  605. return array_merge( $wp->public_query_vars, $wp->private_query_vars );
  606.  
  607. }
  608.  
  609. /**
  610. * Load scripts
  611. */
  612. public function admin_enqueue_scripts( $hook ) {
  613. if ( 'options-general.php' != $hook ) {
  614. return false;
  615. }
  616.  
  617. wp_enqueue_style( 'plugin-install' );
  618.  
  619. wp_enqueue_script( 'plugin-install' );
  620. wp_enqueue_script( 'updates' );
  621. add_thickbox();
  622. }
  623.  
  624. public function wps_hide_login_menu_page() {
  625. //$title = __( 'Url Login Admin' );
  626.  
  627. // add_options_page( $title, $title, 'manage_options', 'whl_settings', array(
  628. // $this,
  629. // 'settings_page'
  630. // ) );
  631. }
  632.  
  633. public function settings_page() {
  634. _e( 'Url Login Admin' );
  635. }
  636.  
  637. public function whl_template_redirect() {
  638. if ( ! empty( $_GET ) && isset( $_GET['page'] ) && 'whl_settings' === $_GET['page'] ) {
  639. wp_redirect( admin_url( 'options-general.php#whl_settings' ) );
  640. exit();
  641. }
  642. }
  643.  
  644. /**
  645. * Update redirect for Woocommerce email notification
  646. */
  647. public function wps_hide_login_redirect_page_email_notif_woocommerce() {
  648.  
  649. if ( ! class_exists( 'WC_Form_Handler' ) ) {
  650. return false;
  651. }
  652.  
  653. if ( ! empty( $_GET ) && isset( $_GET['action'] ) && 'rp' === $_GET['action'] && isset( $_GET['key'] ) && isset( $_GET['login'] ) ) {
  654. wp_redirect( $this->new_login_url() );
  655. exit();
  656. }
  657. }
  658.  
  659. /**
  660. *
  661. * Update url redirect : wp-admin/options.php
  662. *
  663. * @param $login_url
  664. * @param $redirect
  665. * @param $force_reauth
  666. *
  667. * @return string
  668. */
  669. public function login_url( $login_url, $redirect, $force_reauth ) {
  670. if ( is_404() ) {
  671. return '#';
  672. }
  673.  
  674. if ( $force_reauth === false ) {
  675. return $login_url;
  676. }
  677.  
  678. if ( empty( $redirect ) ) {
  679. return $login_url;
  680. }
  681.  
  682. $redirect = explode( '?', $redirect );
  683.  
  684. if ( $redirect[0] === admin_url( 'options.php' ) ) {
  685. $login_url = admin_url();
  686. }
  687.  
  688. return $login_url;
  689. }
  690.  
  691. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement