PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.7
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.7
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / shortcodes / class-charitable-login-shortcode.php

class-charitable-login-shortcode.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.6.7, at includes/shortcodes/class-charitable-login-shortcode.php

110 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Login shortcode class.
4 *
5 * @package Charitable/Shortcodes/Login
6 * @author Eric Daams
7 * @copyright Copyright (c) 2018, Studio 164a
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.0.0
10 * @version 1.5.7
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) { exit; }
15
16 if ( ! class_exists( 'Charitable_Login_Shortcode' ) ) :
17
18 /**
19 * Charitable_Login_Shortcode class.
20 *
21 * @since 1.0.0
22 */
23 class Charitable_Login_Shortcode {
24
25 /**
26 * The callback method for the campaigns shortcode.
27 *
28 * This receives the user-defined attributes and passes the logic off to the class.
29 *
30 * @since 1.0.0
31 *
32 * @param array $atts User-defined shortcode attributes.
33 * @return string
34 */
35 public static function display( $atts = array() ) {
36 $defaults = array(
37 'logged_in_message' => __( 'You are already logged in!', 'charitable' ),
38 'redirect' => esc_url( charitable_get_login_redirect_url() ),
39 'registration_link_text' => __( 'Register', 'charitable' ),
40 );
41
42 $args = shortcode_atts( $defaults, $atts, 'charitable_login' );
43 $args['login_form_args'] = self::get_login_form_args( $args );
44
45 if ( is_user_logged_in() ) {
46 ob_start();
47 charitable_template( 'shortcodes/logged-in.php', $args );
48 return ob_get_clean();
49 }
50
51 if ( false == $args['registration_link_text'] || 'false' == $args['registration_link_text'] ) {
52 $args['registration_link'] = false;
53 } else {
54 $registration_link = charitable_get_permalink( 'registration_page' );
55
56 if ( charitable_get_permalink( 'login_page' ) === $registration_link ) {
57 $args['registration_link'] = false;
58 } else {
59 $args['registration_link'] = add_query_arg( 'redirect_to', $args['redirect'], $registration_link );
60 }
61 }
62
63 ob_start();
64
65 charitable_template( 'shortcodes/login.php', $args );
66
67 return apply_filters( 'charitable_login_shortcode', ob_get_clean() );
68
69 }
70
71 /**
72 * Fingerprint the login form with our charitable=true hidden field.
73 *
74 * @since 1.4.0
75 *
76 * @param string $content
77 * @return string
78 */
79 public static function add_hidden_field_to_login_form( $content, $args ) {
80 if ( isset( $args['charitable'] ) && $args['charitable'] ) {
81 $content .= '<input type="hidden" name="charitable" value="1" />';
82 }
83
84 return $content;
85 }
86
87 /**
88 * Return donations to display with the shortcode.
89 *
90 * @since 1.0.0
91 *
92 * @param array $args
93 * @return mixed[] $args
94 */
95 protected static function get_login_form_args( $args ) {
96 $default = array(
97 'redirect' => $args['redirect'],
98 'charitable' => true,
99 );
100
101 if ( isset( $_GET['username'] ) ) {
102 $default['value_username'] = $_GET['username'];
103 }
104
105 return apply_filters( 'charitable_login_form_args', $default, $args );
106 }
107 }
108
109 endif;
110