__( 'You are already logged in!', 'charitable' ), 'redirect' => esc_url( charitable_get_login_redirect_url() ), 'registration_link_text' => __( 'Register', 'charitable' ), ); $args = shortcode_atts( $defaults, $atts, 'charitable_login' ); $args['login_form_args'] = self::get_login_form_args( $args ); if ( is_user_logged_in() ) { ob_start(); charitable_template( 'shortcodes/logged-in.php', $args ); return ob_get_clean(); } if ( false == $args['registration_link_text'] || 'false' == $args['registration_link_text'] ) { $args['registration_link'] = false; } else { $registration_link = charitable_get_permalink( 'registration_page' ); if ( charitable_get_permalink( 'login_page' ) === $registration_link ) { $args['registration_link'] = false; } else { $args['registration_link'] = add_query_arg( 'redirect_to', urlencode( urldecode( $args['redirect'] ) ), $registration_link ); } } ob_start(); charitable_template( 'shortcodes/login.php', $args ); /** * Filter the default output of the login shortcode. * * @since 1.0.0 * * @param string $content The default login shortcode output. */ return apply_filters( 'charitable_login_shortcode', ob_get_clean() ); } /** * Fingerprint the login form with our charitable=true hidden field. * * @see wp_login_form * * @since 1.4.0 * * @param string $content The default output. * @param array $args Arguments passed to wp_login_form. * @return string */ public static function add_hidden_field_to_login_form( $content, $args ) { if ( isset( $args['charitable'] ) && $args['charitable'] ) { $content .= ''; } return $content; } /** * Return donations to display with the shortcode. * * @see wp_login_form * * @since 1.0.0 * * @param array $args Arguments to pass to wp_login_form. * @return mixed[] $args */ protected static function get_login_form_args( $args ) { $default = array( 'redirect' => $args['redirect'], 'charitable' => true, ); if ( isset( $_GET['username'] ) ) { $default['value_username'] = str_replace( ' ', '+', $_GET['username'] ); } /** * Filter the arguments to pass to wp_login_form(). * * @since 1.0.0 * * @param array $default The default arguments. * @param array $args Passed in arguments. */ return apply_filters( 'charitable_login_form_args', $default, $args ); } } endif;