PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 1.7.0
WP 2FA – Two-factor authentication for WordPress v1.7.0
4.1.0 4.0.0 1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / Admin / Controllers / Settings.php
wp-2fa / includes / classes / Admin / Controllers Last commit date
Settings.php 5 years ago
Settings.php
111 lines
1 <?php
2
3 namespace WP2FA\Admin\Controllers;
4
5 use WP2FA\WP2FA;
6
7 defined( 'ABSPATH' ) || exit; // Exit if accessed directly
8
9 /**
10 * WP2FA Settings controller
11 */
12 class Settings {
13
14 /**
15 * The name of the WP2FA WP admin settings page
16 *
17 * @var string
18 */
19 private static $settingsPageName = 'wp-2fa-settings';
20
21 /**
22 * The link to the WP admin settings page
23 *
24 * @var string
25 */
26 private static $settingsPageLink = '';
27
28 /**
29 * The name of the WP2FA WP admin setup page
30 *
31 * @var string
32 */
33 private static $setupPageName = 'wp-2fa-setup';
34
35 /**
36 * The link to the WP admin setup page
37 *
38 * @var string
39 */
40 private static $setupPageLink = '';
41
42 /**
43 * The link to the custom settings page (if one is presented)
44 *
45 * @var string
46 */
47 private static $customSetupPageLink = null;
48
49 /**
50 * Returns the link to the WP admin settings page, based on the current WP install
51 *
52 * @return string
53 */
54 public static function getSettingsPageLink() {
55 if ( '' === self::$settingsPageLink ) {
56 if ( WP2FA::is_this_multisite() ) {
57 self::$settingsPageLink = add_query_arg( 'page', self::$settingsPageName, network_admin_url( 'settings.php' ) );
58 } else {
59 self::$settingsPageLink = add_query_arg( 'page', self::$settingsPageName, admin_url( 'options-general.php' ) );
60 }
61 }
62
63 return self::$settingsPageLink;
64 }
65
66 /**
67 * Returns the link to the WP admin settings page, based on the current WP install
68 *
69 * @return string
70 */
71 public static function getSetupPageLink() {
72 if ( '' === self::$setupPageLink ) {
73 if ( WP2FA::is_this_multisite() ) {
74 self::$setupPageLink = add_query_arg( 'show', self::$setupPageName, network_admin_url( 'profile.php' ) );
75 } else {
76 self::$setupPageLink = add_query_arg( 'show', self::$setupPageName, admin_url( 'profile.php' ) );
77 }
78 }
79
80 return self::$setupPageLink;
81 }
82
83 /**
84 * Extracts the custom settings page URL
85 *
86 * @return string
87 */
88 public static function getCustomPageLink(): string {
89 if ( null === self::$customSetupPageLink ) {
90 self::$customSetupPageLink = WP2FA::get_wp2fa_setting( 'custom-user-page-id' );
91
92 if ( ! empty( self::$customSetupPageLink ) ) {
93 $customSlug = '';
94 if ( WP2FA::is_this_multisite() ) {
95 switch_to_blog( get_main_site_id() );
96
97 $customSlug = get_post_field( 'post_name', get_post( self::$customSetupPageLink ) );
98 self::$customSetupPageLink = trailingslashit( get_site_url() ) . $customSlug;
99
100 restore_current_blog();
101 } else {
102 $customSlug = get_post_field( 'post_name', get_post( self::$customSetupPageLink ) );
103 self::$customSetupPageLink = trailingslashit( get_site_url() ) . $customSlug;
104 }
105 }
106 }
107
108 return self::$customSetupPageLink;
109 }
110 }
111