| 1 |
<?php |
| 2 |
/** |
| 3 |
* Login endpoint. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Login_Endpoint |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.5.0 |
| 10 |
* @version 1.6.37 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Login_Endpoint' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Charitable_Login_Endpoint |
| 21 |
* |
| 22 |
* @since 1.5.0 |
| 23 |
*/ |
| 24 |
class Charitable_Login_Endpoint extends Charitable_Endpoint { |
| 25 |
|
| 26 |
/** Endpoint ID. */ |
| 27 |
const ID = 'login'; |
| 28 |
|
| 29 |
/** The endpoint's priority in terms of when it should be loaded. */ |
| 30 |
const PRIORITY = 20; |
| 31 |
|
| 32 |
/** |
| 33 |
* Object instantiation. |
| 34 |
* |
| 35 |
* @since 1.5.4 |
| 36 |
*/ |
| 37 |
public function __construct() { |
| 38 |
$this->cacheable = false; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Return the endpoint ID. |
| 43 |
* |
| 44 |
* @since 1.5.0 |
| 45 |
* |
| 46 |
* @return string |
| 47 |
*/ |
| 48 |
public static function get_endpoint_id() { |
| 49 |
return self::ID; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Add rewrite rules for the endpoint. |
| 54 |
* |
| 55 |
* @since 1.5.0 |
| 56 |
*/ |
| 57 |
public function setup_rewrite_rules() {} |
| 58 |
|
| 59 |
/** |
| 60 |
* Return the endpoint URL. |
| 61 |
* |
| 62 |
* @since 1.5.0 |
| 63 |
* |
| 64 |
* @global WP_Rewrite $wp_rewrite |
| 65 |
* @param array $args Mixed arguments. |
| 66 |
* @return string |
| 67 |
*/ |
| 68 |
public function get_page_url( $args = array() ) { |
| 69 |
$page = charitable_get_option( 'login_page', 'wp' ); |
| 70 |
|
| 71 |
return 'wp' == $page ? wp_login_url() : get_permalink( $page ); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Return whether we are currently viewing the endpoint. |
| 76 |
* |
| 77 |
* @since 1.5.0 |
| 78 |
* |
| 79 |
* @global WP_Post $post |
| 80 |
* @param array $args Mixed arguments. |
| 81 |
* @return boolean |
| 82 |
*/ |
| 83 |
public function is_page( $args = array() ) { |
| 84 |
global $post, $wp_query; |
| 85 |
|
| 86 |
$page = charitable_get_option( 'login_page', 'wp' ); |
| 87 |
$strict = ! array_key_exists( 'strict', $args ) || $args['strict']; |
| 88 |
|
| 89 |
if ( 'wp' == $page ) { |
| 90 |
return $strict ? false : wp_login_url() == charitable_get_current_url(); |
| 91 |
} |
| 92 |
|
| 93 |
if ( is_object( $post ) ) { |
| 94 |
return $page == $post->ID; |
| 95 |
} |
| 96 |
|
| 97 |
return false; |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Get the nav menu object. |
| 102 |
* |
| 103 |
* @since 1.6.29 |
| 104 |
* |
| 105 |
* @return object |
| 106 |
*/ |
| 107 |
public function nav_menu_object() { |
| 108 |
return $this->get_nav_menu_object( __( 'Log In', 'charitable' ) ); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
endif; |
| 113 |
|