Created
December 5, 2021 14:59
-
-
Save adczk/d3137fc1ca02747cd2130302c6f5e49c to your computer and use it in GitHub Desktop.
Fix for specific/rare issue of {email} variable not saving in "automated mail" settings in some cases in Hustle
This file contains hidden or 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 | |
/************************************ | |
* | |
* HUSTLE - fix for {email-1} placeholder not being saved in "automated e-mail" settings | |
* | |
* This is a fix for a very specific issue only | |
* | |
* author: Prashant Singh/WPMU DEV | |
* | |
* Tested with Hustle 7.4.7 only! | |
* | |
* NOTE: EDIT line no. 69 to set your module/popup ID - this is important! | |
* | |
**************************************/ | |
add_action('admin_init', 'wpmudev_change_hustle_ajax_method'); | |
function wpmudev_change_hustle_ajax_method(){ | |
global $wp_filter; | |
$tag = 'wp_ajax_hustle_save_module'; | |
$hook_method = 'save_module'; | |
$hook_class = 'Hustle_Modules_Common_Admin_Ajax'; | |
if ( ! isset( $wp_filter[$tag] ) ) { | |
return; | |
} | |
foreach ( $wp_filter[$tag]->callbacks as $key => $callback_array ) { | |
foreach ( $callback_array as $c_key => $callback ) { | |
if ( substr_compare( $c_key, $hook_method, strlen( $c_key ) - strlen( $hook_method ), strlen( $hook_method ) ) === 0 ) { | |
if ( $callback['function'][0] instanceof $hook_class ){ | |
unset( $wp_filter[$tag]->callbacks[$key][$c_key] ); | |
} | |
} | |
} | |
} | |
add_action( 'wp_ajax_hustle_save_module', 'wpmudev_hustle_save_module' ); | |
} | |
function wpmudev_hustle_save_module() { | |
Opt_In_Utils::validate_ajax_call( 'hustle_save_module_wizard' ); | |
$module_id = filter_input( INPUT_POST, 'id', FILTER_VALIDATE_INT ); | |
Opt_In_Utils::is_user_allowed_ajax( 'hustle_edit_module', $module_id ); | |
$_post = stripslashes_deep( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
$error_array = array(); | |
try { | |
if ( empty( $module_id ) ) { | |
throw new Exception(); | |
} | |
$module = Hustle_Module_Collection::instance()->return_model_from_id( $module_id ); | |
if ( is_wp_error( $module ) ) { | |
throw new Exception(); | |
} | |
$_post = $module->sanitize_module( $_post ); | |
// replace the number below - example is 11 - with an ID of your Hustle module/popup | |
if( $module_id == 11 && $_post['emails']['recipient'] == '' ){ | |
$_post['emails']['recipient'] = '{email}'; | |
} | |
$validation = $module->validate_module( $_post ); | |
if ( true !== $validation ) { | |
$error_array = array( 'data' => $validation['error'] ); | |
throw new Exception(); | |
} | |
$updated = $module->update_module( $_post ); | |
if ( isset( $updated['success'] ) && false === $updated['success'] ) { | |
$error_array = array( 'data' => $updated['error'] ); | |
throw new Exception(); | |
} | |
if ( false === $updated ) { | |
$error_array = array( 'data' => $updated ); | |
throw new Exception(); | |
} | |
} catch ( Exception $e ) { | |
wp_send_json_error( $error_array ); | |
} | |
wp_send_json_success(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment