| 1 |
<?php /** |
| 2 |
* @version 1.0 |
| 3 |
* @description Action for Template Setup pages |
| 4 |
* @category Setup Action |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site http://oplugins.com/ |
| 8 |
* @email info@oplugins.com |
| 9 |
* |
| 10 |
* @modified 2024-09-29 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
|
| 15 |
|
| 16 |
// ------------------------------------------------------------------------------------------------------------- |
| 17 |
// == Action - General Info == |
| 18 |
// ------------------------------------------------------------------------------------------------------------- |
| 19 |
/** |
| 20 |
* Template - General Info - Step 01 |
| 21 |
* |
| 22 |
* Help Tips: |
| 23 |
* |
| 24 |
* <script type="text/html" id="tmpl-template_name_a"> |
| 25 |
* Escaped: {{data.test_key}} |
| 26 |
* HTML: {{{data.test_key}}} |
| 27 |
* JS: <# if (true) { alert( 1 ); } #> |
| 28 |
* </script> |
| 29 |
* |
| 30 |
* var template__var = wp.template( 'template_name_a' ); |
| 31 |
* |
| 32 |
* jQuery( '.content' ).html( template__var( { 'test_key' => '<strong>Data</strong>' } ) ); |
| 33 |
* |
| 34 |
* @return void |
| 35 |
*/ |
| 36 |
|
| 37 |
|
| 38 |
function wpbc_template__general_info__action_validate_data( $post_data ){ |
| 39 |
|
| 40 |
$escaped_data = array( |
| 41 |
'wpbc_swp_industry' => '', |
| 42 |
'type' => '', // FixIn: 10.7.1.3. |
| 43 |
'days' => '', |
| 44 |
'version' => 'V: ' .wpbc_feedback_01_get_version(), |
| 45 |
'wpbc_swp_booking_who_setup' => '', |
| 46 |
'wpbc_swp_business_name' => '', |
| 47 |
'wpbc_swp_email' => '', |
| 48 |
'wpbc_swp_accept_send' => 'Off' |
| 49 |
); |
| 50 |
|
| 51 |
$how_old_info_arr = wpbc_get_info__about_how_old(); |
| 52 |
if ( ! empty( $how_old_info_arr ) ) { |
| 53 |
$escaped_data['days'] = 'Days: ' . $how_old_info_arr['days']; |
| 54 |
} |
| 55 |
|
| 56 |
$key = 'wpbc_swp_industry'; |
| 57 |
if ( ( isset( $post_data[ $key ] ) ) && ( ! empty( ( $post_data[ $key ] ) ) ) ) { |
| 58 |
$escaped_data[ $key ] = 'Industry: ' . wpbc_clean_text_value( $post_data[ $key ] ); |
| 59 |
} |
| 60 |
$key = 'wpbc_swp_booking_who_setup'; |
| 61 |
if ( ( isset( $post_data[ $key ] ) ) && ( ! empty( ( $post_data[ $key ] ) ) ) ) { |
| 62 |
$escaped_data[ $key ] = 'Who_setup: ' . wpbc_clean_text_value( $post_data[ $key ] ); |
| 63 |
} |
| 64 |
$key = 'wpbc_swp_business_name'; |
| 65 |
if ( ( isset( $post_data[ $key ] ) ) && ( ! empty( ( $post_data[ $key ] ) ) ) ) { |
| 66 |
$escaped_data[ $key ] = 'Business_name: ' . wpbc_clean_text_value( $post_data[ $key ] ); |
| 67 |
} |
| 68 |
$key = 'wpbc_swp_email'; |
| 69 |
if ( ( isset( $post_data[ $key ] ) ) && ( ! empty( ( $post_data[ $key ] ) ) ) ) { |
| 70 |
$escaped_data[ $key ] = 'Email: ' . wpbc_clean_text_value( $post_data[ $key ] ); |
| 71 |
} |
| 72 |
$key = 'wpbc_swp_accept_send'; |
| 73 |
if ( ( isset( $post_data[ $key ] ) ) && ( ! empty( ( $post_data[ $key ] ) ) ) ) { |
| 74 |
$escaped_data[ $key ] = wpbc_clean_text_value( $post_data[ $key ] ); |
| 75 |
} |
| 76 |
|
| 77 |
return $escaped_data; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
/** |
| 82 |
* Send email with Setup Feedback |
| 83 |
* |
| 84 |
* @param $feedback_description |
| 85 |
* |
| 86 |
* @return void |
| 87 |
*/ |
| 88 |
function wpbc_setup_feedback__send_email( $feedback_description_arr ) { |
| 89 |
|
| 90 |
|
| 91 |
$feedback_description = implode( "\n", $feedback_description_arr); |
| 92 |
|
| 93 |
$us_data = wp_get_current_user(); |
| 94 |
|
| 95 |
$fields_values = array(); |
| 96 |
$fields_values['from_email'] = get_option( 'admin_email' ); |
| 97 |
$fields_values['from_name'] = $us_data->display_name; |
| 98 |
$fields_values['from_name'] = wp_specialchars_decode( esc_html( stripslashes( $fields_values['from_name'] ) ), ENT_QUOTES ); |
| 99 |
$fields_values['from_email'] = sanitize_email( $fields_values['from_email'] ); |
| 100 |
|
| 101 |
$subject = 'WPBC - Initial Setup'; |
| 102 |
|
| 103 |
|
| 104 |
$message = '';// '=============================================' . "\n"; |
| 105 |
$message .= $feedback_description . "\n"; |
| 106 |
$message .= '=============================================' . "\n"; |
| 107 |
$message .="\n"; |
| 108 |
|
| 109 |
$message .= $fields_values['from_name'] . "\n"; |
| 110 |
$message .="\n"; |
| 111 |
$message .= '---------------------------------------------' . "\n"; |
| 112 |
|
| 113 |
$message .= 'Booking Calendar ' . wpbc_feedback_01_get_version() . "\n"; |
| 114 |
|
| 115 |
$how_old_info_arr = wpbc_get_info__about_how_old(); |
| 116 |
if ( ! empty( $how_old_info_arr ) ) { |
| 117 |
$message .= "\n"; |
| 118 |
$message .= 'From: ' . $how_old_info_arr['date_echo']; |
| 119 |
$message .= ' - ' . $how_old_info_arr['days'] . ' days ago.'; |
| 120 |
} |
| 121 |
|
| 122 |
$message .="\n"; |
| 123 |
$message .= '---------------------------------------------' . "\n"; |
| 124 |
$message .= '[' . date_i18n( get_bk_option( 'booking_date_format' ) ) . ' ' . date_i18n( get_bk_option( 'booking_time_format' ) ) . ']'. "\n"; |
| 125 |
$message .= home_url() ; |
| 126 |
|
| 127 |
$headers = ''; |
| 128 |
|
| 129 |
if ( ! empty( $fields_values['from_email'] ) ) { |
| 130 |
|
| 131 |
$headers .= 'From: ' . $fields_values['from_name'] . ' <' . $fields_values['from_email'] . '> ' . "\r\n"; |
| 132 |
} else { |
| 133 |
/* If we don't have an email from the input headers default to wordpress@$sitename |
| 134 |
* Some hosts will block outgoing mail from this address if it doesn't exist but |
| 135 |
* there's no easy alternative. Defaulting to admin_email might appear to be another |
| 136 |
* option but some hosts may refuse to relay mail from an unknown domain. See |
| 137 |
* https://core.trac.wordpress.org/ticket/5007. |
| 138 |
*/ |
| 139 |
} |
| 140 |
$headers .= 'Content-Type: ' . 'text/plain' . "\r\n" ; // 'text/html' |
| 141 |
|
| 142 |
$attachments = ''; |
| 143 |
|
| 144 |
|
| 145 |
$to = 'setup_feedback@wpbookingcalendar.com'; |
| 146 |
|
| 147 |
// debuge('In email', htmlentities($to), $subject, htmlentities($message), $headers, $attachments) ; |
| 148 |
// debuge( '$to, $subject, $message, $headers, $attachments',htmlspecialchars($to), htmlspecialchars($subject), htmlspecialchars($message), htmlspecialchars($headers), htmlspecialchars($attachments)); |
| 149 |
|
| 150 |
$return = @wp_mail( $to, $subject, $message, $headers, $attachments ); |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
/** |
| 155 |
* Update "General Data" like "Email" and "Title" |
| 156 |
* |
| 157 |
* @param $cleaned_data array( |
| 158 |
* 'wpbc_swp_business_name' => '', |
| 159 |
* 'wpbc_swp_booking_who_setup' => '', |
| 160 |
* 'wpbc_swp_industry' => '', |
| 161 |
* 'wpbc_swp_email' => '', |
| 162 |
* 'wpbc_swp_accept_send' => 'Off' |
| 163 |
* |
| 164 |
* ) |
| 165 |
* |
| 166 |
* @return void |
| 167 |
*/ |
| 168 |
function wpbc_setup__update__general_info( $cleaned_data ){ |
| 169 |
|
| 170 |
if ( ( ! empty( $cleaned_data['wpbc_swp_email'] ) ) && ( false !== is_email( $cleaned_data['wpbc_swp_email'] ) ) ) { |
| 171 |
|
| 172 |
//update_bk_option( 'wpbc_swp_email', $cleaned_data['wpbc_swp_email'] ); |
| 173 |
|
| 174 |
// ------------------------------------------------------------------------------------------------------------- |
| 175 |
// Update Emails |
| 176 |
// ------------------------------------------------------------------------------------------------------------- |
| 177 |
$email_option_names = array( WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_NEW_ADMIN_ID |
| 178 |
, WPBC_EMAIL_NEW_VISITOR_PREFIX . WPBC_EMAIL_NEW_VISITOR_ID |
| 179 |
, WPBC_EMAIL_APPROVED_PREFIX . WPBC_EMAIL_APPROVED_ID |
| 180 |
, WPBC_EMAIL_DENY_PREFIX . WPBC_EMAIL_DENY_ID |
| 181 |
, WPBC_EMAIL_TRASH_PREFIX . WPBC_EMAIL_TRASH_ID |
| 182 |
, WPBC_EMAIL_DELETED_PREFIX . WPBC_EMAIL_DELETED_ID |
| 183 |
); |
| 184 |
if ( class_exists( 'wpdev_bk_personal' ) ) { |
| 185 |
$email_option_names[] = WPBC_EMAIL_MODIFICATION_PREFIX . WPBC_EMAIL_MODIFICATION_ID; |
| 186 |
} |
| 187 |
if ( class_exists('wpdev_bk_biz_s')) { |
| 188 |
$email_option_names[] = WPBC_EMAIL_PAYMENT_REQUEST_PREFIX . WPBC_EMAIL_PAYMENT_REQUEST_ID; |
| 189 |
} |
| 190 |
foreach ( $email_option_names as $email_option_name ) { |
| 191 |
|
| 192 |
// Get Email Data |
| 193 |
$email_data = get_bk_option( $email_option_name ); |
| 194 |
|
| 195 |
$email_data['from'] = $cleaned_data['wpbc_swp_email']; |
| 196 |
|
| 197 |
if ( $email_option_name === WPBC_EMAIL_NEW_ADMIN_PREFIX . WPBC_EMAIL_NEW_ADMIN_ID ) { |
| 198 |
$email_data['to'] = $cleaned_data['wpbc_swp_email']; |
| 199 |
} else { |
| 200 |
$email_data['to'] = $cleaned_data['wpbc_swp_email']; |
| 201 |
} |
| 202 |
|
| 203 |
// Update Email Data |
| 204 |
update_bk_option( $email_option_name, $email_data ); |
| 205 |
} |
| 206 |
// ------------------------------------------------------------------------------------------------------------- |
| 207 |
} |
| 208 |
} |