Skip to content

Instantly share code, notes, and snippets.

@danieliser
Created December 8, 2016 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieliser/146c01820053c71ca7423c40ef42deea to your computer and use it in GitHub Desktop.
Save danieliser/146c01820053c71ca7423c40ef42deea to your computer and use it in GitHub Desktop.
Allows customizing redirect url after successful login with Popup Maker AJAX Login Modals. This example checks for a specific class on the trigger which is used to change the redirect.
<?php
/**
* Copy the following to your themes functions.php file and customize as needed.
*
* This example specifically checks for a specific class `type1` on the clicked trigger.
* If present then the hidden field is updated and a different redirect url is sent back.
*
* This example uses the following customizable information.
*
* Field Name: my_custom_field
* Popup ID: 123
* Class: type1
* Redirect: example.com
*/
add_action( 'wp_footer', '_custom_popup_scripts', 1000 );
function _custom_popup_scripts() {
?>
<script type="text/javascript">
(function ($) {
$('#pum-123').on('pumAfterOpen', function () {
var $popup = PUM.getPopup(this),
$field = $popup.find('[name="my_custom_field"]'),
$trigger = $($.fn.popmake.last_open_trigger);
if ($trigger.hasClass('type1')) {
$field.val('1');
} else {
$field.val('2');
}
});
}(jQuery));
</script>
<?php
}
add_filter( 'pum_login_form_fields', '_custom_popup_login_fields', 10, 2 );
function _custom_popup_login_fields( $form_fields, $args ) {
$form_fields['my_custom_field'] = array(
'type' => 'hidden',
'std' => '2', // Default value for both JS & Here.
'priority' => 50,
);
return $form_fields;
}
add_filter( 'pum_alm_ajax_login_success_data', '_custom_popup_login_success_data', 10, 2 );
function _custom_popup_login_processing( $data, $values = array() ) {
if ( $values['my_custom_field'] == 1 ) {
$data['redirect'] = 'example.com';
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment