Created
March 4, 2019 15:16
-
-
Save Garconis/09ab024fa7661a01dc2bf5c152beb88f to your computer and use it in GitHub Desktop.
Theme My Login | Shortcodes to spit out a custom Logout anchor and Helpers to force-change the Lost Password URL for certain pages/forms.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* shortcode that will output the Logout URL with Kiosk URL redirect, as anchor and text */ | |
// [fs_kiosk_logout_url_anchor class="whatever-it-is you-want"]Log Out[/fs_kiosk_logout_url_anchor] | |
add_shortcode( 'fs_kiosk_logout_url_anchor', 'fs_sc_kiosk_logout_url_anchor' ); | |
function fs_sc_kiosk_logout_url_anchor( $atts, $content = null ) { | |
// define attributes and their defaults | |
$a = shortcode_atts( array( | |
'class' => 'kiosk-logout-url-anchor' | |
), $atts ); | |
// redirect to Kiosk page with logout param | |
$kiosk_logout_url = wp_logout_url(home_url('/kiosk/')); | |
// set the anchor | |
$anchor = '<a href="' . $kiosk_logout_url . '" class="' . esc_attr($a['class']) . '">' . $content . '</a>'; | |
// return the anchor | |
return $anchor; | |
} | |
/* shortcode that will output the Logout URL with Kiosk URL redirect, as URL only */ | |
// [fs_kiosk_logout_url] | |
add_shortcode( 'fs_kiosk_logout_url', 'fs_sc_kiosk_logout_url' ); | |
function fs_sc_kiosk_logout_url() { | |
// redirect to Kiosk page with logout param | |
//echo add_query_arg( '_wpnonce', wp_create_nonce( 'action' ), $url ); | |
$kiosk_logout_url = wp_logout_url(home_url('/kiosk/')); | |
$actionurl = str_replace( '&', '&', $kiosk_logout_url ); | |
// return the anchor | |
return $actionurl; | |
} | |
/* help the Kiosk's TML lostpassword shortcode display errors on the proper Kiosk page (instead of the overall Lost Passworrd page) */ | |
// tell TML to get the action type of the "current" form | |
function add_action_to_each_tml_form() { | |
foreach ( tml_get_actions() as $action ) { | |
tml_add_form_field( $action->get_name(), 'action', array( | |
'type' => 'hidden', | |
'value' => $action->get_name(), | |
) ); | |
} | |
} | |
add_action( 'init', 'add_action_to_each_tml_form' ); | |
// if the TML is trying to do Lost Password and it on a Kiosk page, then force a URL for the page errors and form submission action to occur on the custom Kiosk Lost Password page | |
function filter_tml_action_url( $url, $action ) { | |
if ( strpos( $_SERVER['REQUEST_URI'], '/kiosk/' ) === false ) { | |
return $url; | |
} | |
if ( 'lostpassword' == $action ) { | |
$url = home_url( '/kiosk/password/' ); | |
} | |
return $url; | |
} | |
add_filter( 'tml_get_action_url', 'filter_tml_action_url', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment