PluginProbe
Authorizer / 3.6.0
Authorizer v3.6.0
3.16.0 3.15.3 3.15.2 3.15.1 3.15.0 3.14.3 3.14.4 3.14.2 3.14.1 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.10 2.9.11 2.9.12 2.9.13 2.9.2 2.9.3 All 127 releases
← All changes | src/authorizer/class-helper.php +58 -27 2.9.63.6.0 View file →
@@ -68,15 +68,8 @@
68 68 'strong' => array(),
69 69 );
70 70
71 71 /**
72 - * Generate a unique cookie to add to nonces to prevent CSRF.
73 - *
74 - * @var string
75 - */
76 - protected static $cookie_value = null;
77 -
78 - /**
79 72 * Encryption key (not secret!).
80 73 *
81 74 * @var string
82 75 */
@@ -110,25 +103,8 @@
110 103 }
111 104
112 105
113 106 /**
114 - * Retrieve the unique login cookie.
115 - *
116 - * @return string Login cookie value.
117 - */
118 - public static function get_cookie_value() {
119 - if ( ! self::$cookie_value ) {
120 - if ( isset( $_COOKIE['login_unique'] ) ) {
121 - self::$cookie_value = sanitize_key( wp_unslash( $_COOKIE['login_unique'] ) );
122 - } else {
123 - self::$cookie_value = md5( wp_rand() );
124 - }
125 - }
126 - return self::$cookie_value;
127 - }
128 -
129 -
130 - /**
131 107 * Helper function to generate an HTML class name for an option (used in
132 108 * Authorizer Settings in the Approved User list).
133 109 *
134 110 * @param string $suffix Unique part of class name.
@@ -343,8 +319,29 @@
343 319 }
344 320
345 321
346 322 /**
323 + * Helper function to discover the email addresses in a value in a
324 + * multidimensional array.
325 + *
326 + * @param array $haystack Multidimensional array, possibly containing an email.
327 + * @param array $emails Array of email addresses found.
328 + * @return array Array of Discovered emails, or empty array.
329 + */
330 + public static function find_emails_in_multi_array( $haystack, &$emails = array() ) {
331 + if ( is_array( $haystack ) ) {
332 + foreach ( $haystack as $key => $value ) {
333 + self::find_emails_in_multi_array( $value, $emails );
334 + }
335 + } elseif ( filter_var( $haystack, FILTER_VALIDATE_EMAIL ) ) {
336 + $emails[] = $haystack;
337 + }
338 +
339 + return $emails;
340 + }
341 +
342 +
343 + /**
347 344 * Helper function to determine if an URL is accessible.
348 345 *
349 346 * @param string $url URL that should be publicly reachable.
350 347 * @return boolean Whether the URL is publicly reachable.
@@ -385,9 +382,9 @@
385 382 * Helper function to get a single user info array from one of the access
386 383 * control lists (pending, approved, or blocked).
387 384 *
388 385 * @param string $email Email address to retrieve info for.
389 - * @param string $list List to get info from.
386 + * @param array $list List to get info from.
390 387 * @return mixed false if not found, otherwise: array(
391 388 * 'email' => '',
392 389 * 'role' => '',
393 390 * 'date_added' => '',
@@ -452,12 +449,32 @@
452 449 }
453 450
454 451
455 452 /**
453 + * Helper function to show a number as an ordinal (e.g., 5 as 5th).
454 + *
455 + * @see: https://stackoverflow.com/questions/3109978/display-numbers-with-ordinal-suffix-in-php
456 + *
457 + * @param int $number Number to show as an ordinal.
458 + * @return string Number as an ordinal string.
459 + */
460 + public static function ordinal( $number = 0 ) {
461 + $ends = array( 'th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th' );
462 + if ( $number % 100 >= 11 && $number % 100 <= 13 ) {
463 + return $number . 'th';
464 + } else {
465 + return $number . $ends[ $number % 10 ];
466 + }
467 + }
468 +
469 +
470 + /**
456 471 * Generate CAS authentication URL (wp-login.php URL with reauth=1 removed
457 472 * and external=cas added).
473 + *
474 + * @param string $provider External service provider type.
458 475 */
459 - public static function modify_current_url_for_cas_login() {
476 + public static function modify_current_url_for_external_login( $provider = 'cas' ) {
460 477 // Construct the URL of the current page (wp-login.php).
461 478 $url = '';
462 479 if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
463 480 $url = set_url_scheme( esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
@@ -462,8 +479,22 @@
462 479 if ( isset( $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ) ) {
463 480 $url = set_url_scheme( esc_url_raw( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
464 481 }
465 482
483 + // If we have a login form embedded elsewhere than wp-login.php, alter the
484 + // URL to point to wp-login.php with a redirect to the current page. This
485 + // will happen if the [authorizer_login_form] shortcode is used.
486 + if ( false === strpos( $url, 'wp-login.php' ) ) {
487 + $url = wp_login_url( $url );
488 + }
489 +
490 + // Edge case: If the WPS Hide Login plugin is installed, redirect to home
491 + // page after logging in instead of the plugin's login endpoint, which will
492 + // redirect to /wp-admin.
493 + if ( class_exists( '\WPS\WPS_Hide_Login\Plugin' ) ) {
494 + $url = wp_login_url( home_url() );
495 + }
496 +
466 497 // Parse the URL into its components.
467 498 $parsed_url = wp_parse_url( $url );
468 499
469 500 // Fix up the querystring values (remove reauth, make sure external=cas).
@@ -471,9 +502,9 @@
471 502 if ( array_key_exists( 'query', $parsed_url ) ) {
472 503 parse_str( $parsed_url['query'], $querystring );
473 504 }
474 505 unset( $querystring['reauth'] );
475 - $querystring['external'] = 'cas';
506 + $querystring['external'] = $provider;
476 507 $parsed_url['query'] = http_build_query( $querystring );
477 508
478 509 // Return the URL as a string.
479 510 return self::unparse_url( $parsed_url );