Skip to content

Instantly share code, notes, and snippets.

@marklchaves
Last active March 19, 2025 12:31
Show Gist options
  • Save marklchaves/985d6b20dab73646ca7f2d946bf4b3e0 to your computer and use it in GitHub Desktop.
Save marklchaves/985d6b20dab73646ca7f2d946bf4b3e0 to your computer and use it in GitHub Desktop.
Force a popup to save when you toggle the Enabled button on the All Popups page.
<?php // Ignore this first line when copying to your child theme's functions.php file.
// Test utility
add_action('admin_notices', function() {
// Only show on popup edit screen after saving.
if (!isset($_GET['post']) || get_post_type($_GET['post']) !== 'popup') {
return;
}
// Display the last saved time from a transient.
$last_saved = get_transient('pum_last_save_' . $_GET['post']);
if ($last_saved) {
echo '<div class="notice notice-success is-dismissible">';
echo '<p>Whoo hoo! You saved this popup at: ' . $last_saved . '</p>';
echo '</div>';
}
});
// Test utility
add_action('pum_save_popup', function($post_id) {
// Set a transient with the current time
set_transient('pum_last_save_' . $post_id, current_time('mysql'), 60);
pum_log_message( "Hello from my pum_save_popup test stub!" ); // Log to Popup Maker > Tools > Error Log. Remove for production.
} );
/**
* Hook into wp_ajax_pum_save_enabled_state to call pum_save_popup when you toggle the enabled button
* on the popups list page.
*/
add_action('wp_ajax_pum_save_enabled_state', function() {
// Get the popup ID from the original Popup Maker request.
$popup_id = isset($_REQUEST['popupID']) ? intval($_REQUEST['popupID']) : 0;
pum_log_message( "You toggled the enabled button for popup ID " . $popup_id . "." ); // Log to Popup Maker > Tools > Error Log. Remove for production.
if ($popup_id) {
do_action('pum_save_popup', $popup_id); // Force a call to save the popup.
pum_log_message( "Yay! I forced a save for popup ID " . $popup_id . "." ); // Log to Popup Maker > Tools > Error Log. Remove for production.
}
} );
/**
* You can add the PHP code snippet to your child theme's functions.php file
* or with third-party plugins such as My Custom Functions and Code Snippets.
*
* Learn more:
* - https://wppopupmaker.com/docs/getting-started-with-custom-code/getting-started-with-custom-php/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment