LinkUser 2. LINK_USER -> LINK_USER 3. link_user -> link_user 4. Check in api-emails.php 'db_prefix_option' => '...' option, have to be the same as WPBM_EMAIL_LINK_USER_PREFIX here 5. Configure Fields in init_settings_fields. */ if ( ! defined( 'WPBM_EMAIL_LINK_USER_PREFIX' ) ) define( 'WPBM_EMAIL_LINK_USER_PREFIX', 'wpbm_email_' ); // Its defined in api-emails.php file & its same for all emails, here its used only for easy coding... if ( ! defined( 'WPBM_EMAIL_LINK_USER_ID' ) ) define( 'WPBM_EMAIL_LINK_USER_ID', 'link_user' ); /* Define Name of Email Template. Note. Prefix "wpbm_email_" defined in api-emails.php file. Full name of option is - "wpbm_email_link_user" Other email templates names: - 'link_user' - send email with download link to user - 'link_admin' - send copy of email to admin with download link - 'download_admin' - send email about downloads happend */ require_once( WPBM_PLUGIN_DIR . '/core/any/api-emails.php' ); // API /** Email F i e l d s */ class WPBM_Emails_API_LinkUser extends WPBM_Emails_API { // O v e r r i d i n g "WPBM_Emails_API" ClASS /** Overrided functions - define Email Fields & Values */ public function init_settings_fields() { $this->fields = array(); $this->fields['enabled'] = array( 'type' => 'checkbox' , 'default' => 'On' , 'title' => __('Enable / Disable', 'booking-manager') , 'label' => __('Enable this email notification', 'booking-manager') , 'description' => '' , 'group' => 'general' ); $this->fields['copy_to_admin'] = array( 'type' => 'checkbox' , 'default' => 'On' , 'title' => __('Copy to admin', 'booking-manager') , 'label' => __('Enable / disable sending copy of this email notification to admin', 'booking-manager') , 'description' => '' , 'group' => 'general' ); $this->fields['enabled_hr'] = array( 'type' => 'hr' ); $user_info = array( 'name' => '' ); if ( is_user_logged_in() ) { $user_data = get_userdata( get_current_user_id() ); $user_info['name'] = ( $user_data ) ? $user_data->display_name : ''; } /* $this->fields['to_html_prefix'] = array( 'type' => 'pure_html' , 'group' => 'general' , 'html' => '
' . realpath( dirname(__FILE__) . '/../any/emails_tpl/' ) . '' )
)
, 'cols' => 2
, 'group' => 'style'
);
$this->fields['base_color'] = array(
'type' => 'color'
, 'default' => '#557da1'
, 'title' => __('Base Color', 'booking-manager')
, 'description' => __('The base color for email templates.', 'booking-manager')
. ' ' . __('Default color', 'booking-manager') .': #557da1.'
, 'group' => 'style'
, 'tr_class' => 'template_colors'
);
$this->fields['background_color'] = array(
'type' => 'color'
, 'default' => '#f5f5f5'
, 'title' => __('Background Color', 'booking-manager')
, 'description' => __('The background color for email templates.', 'booking-manager')
. ' ' . __('Default color', 'booking-manager') .': #f5f5f5.'
, 'group' => 'style'
, 'tr_class' => 'template_colors'
);
$this->fields['body_color'] = array(
'type' => 'color'
, 'default' => '#fdfdfd'
, 'title' => __('Email Body Background Color', 'booking-manager')
, 'description' => __('The main body background color for email templates.', 'booking-manager')
. ' ' . __('Default color', 'booking-manager') .': #fdfdfd.'
, 'group' => 'style'
, 'tr_class' => 'template_colors'
);
$this->fields['text_color'] = array(
'type' => 'color'
, 'default' => '#505050'
, 'title' => __('Email Body Text Colour', 'booking-manager')
, 'description' => __('The main body text color for email templates.', 'booking-manager')
. ' ' . __('Default color', 'booking-manager') .': #505050.'
, 'group' => 'style'
, 'tr_class' => 'template_colors'
);
////////////////////////////////////////////////////////////////////
// Email format: Plain, HTML, MultiPart
////////////////////////////////////////////////////////////////////
$this->fields['email_content_type'] = array(
'type' => 'select'
, 'default' => 'plain'
, 'title' => __('Email format', 'booking-manager')
, 'description' => __('Choose which format of email to send.', 'booking-manager')
, 'description_tag' => 'p'
, 'css' => 'width:100%;'
, 'options' => array(
'plain' => __('Plain text', 'booking-manager')
// , 'html' => __('HTML', 'booking-manager')
// , 'multipart' => __('Multipart', 'booking-manager')
)
, 'group' => 'email_content_type'
);
if ( class_exists( 'DOMDocument' ) ) {
$this->fields['email_content_type']['options']['html'] = __('HTML', 'booking-manager');
$this->fields['email_content_type']['options']['multipart'] = __('Multipart', 'booking-manager');
$this->fields['email_content_type']['default'] = 'html';
}
////////////////////////////////////////////////////////////////////
// Help
////////////////////////////////////////////////////////////////////
$this->fields['content_help'] = array(
'type' => 'help'
, 'value' => array()
, 'cols' => 2
, 'group' => 'help'
);
$skip_shortcodes = array(
'denyreason'
, 'paymentreason'
, 'visitorediturl'
, 'visitorcancelurl'
, 'visitorpayurl'
);
$email_example = sprintf(__('For example: "You have a new reservation %s on the following date(s): %s Contact information: %s You can approve or cancel this item at: %s Thank you, Reservation service."' , 'booking-manager'),'','[dates]<br/><br/>','<br/> [content]<br/><br/>', htmlentities( ' '.__('here' , 'booking-manager').' ') . '<br/><br/> ');
// $help_fields = wpbm_get_email_help_shortcodes( $skip_shortcodes, $email_example );
//
// foreach ( $help_fields as $help_fields_key => $help_fields_value ) {
// $this->fields['content_help']['value'][] = $help_fields_value;
// }
}
}
/** Settings Emails P a g e */
class WPBM_Settings_Page_Email_LinkUser extends WPBM_Page_Structure {
public $email_settings_api = false;
/** Define interface for Email API
*
* @param string $selected_email_name - name of Email template
* @param array $init_fields_values - array of init form fields data
* @return object Email API
*/
public function mail_api( $selected_email_name ='', $init_fields_values = array() ){
if ( $this->email_settings_api === false ) {
$this->email_settings_api = new WPBM_Emails_API_LinkUser( $selected_email_name , $init_fields_values );
}
return $this->email_settings_api;
}
public function in_page() { // P a g e t a g
return 'wpbm-settings';
}
public function tabs() { // T a b s A r r a y
$tabs = array();
$tabs[ 'email' ] = array(
'title' => __( 'Emails', 'booking-manager') // Title of TAB
, 'page_title'=> __( 'Emails Settings', 'booking-manager') // Title of Page
, 'hint' => __( 'Emails Settings', 'booking-manager') // Hint
//, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
//, 'position' => '' // 'left' || 'right' || ''
//, 'css_classes'=> '' // CSS class(es)
//, 'icon' => '' // Icon - link to the real PNG img
, 'font_icon' => 'glyphicon glyphicon-envelope' // CSS definition of forn Icon
//, 'default' => false // Is this tab activated by default or not: true || false.
//, 'disabled' => false // Is this tab disbaled: true || false.
//, 'hided' => false // Is this tab hided: true || false.
, 'subtabs' => array()
);
$subtabs = array();
$is_data_exist = get_wpbm_option( WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID ); // ''wpbm_email_' - defined in api-emails.php file.
if ( ( ! empty( $is_data_exist ) ) && ( isset( $is_data_exist['enabled'] ) ) && ( $is_data_exist['enabled'] == 'On' ) )
$icon = ' ';
else
$icon = ' ';
$subtabs['link-user'] = array(
'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
, 'title' => $icon . __('To User' , 'booking-manager') // Title of TAB
, 'page_title' => __('Emails Settings', 'booking-manager') // Title of Page
, 'hint' => __('Email with download link, which is sending to user' , 'booking-manager') // Hint
, 'link' => '' // link
, 'position' => '' // 'left' || 'right' || ''
, 'css_classes' => '' // CSS class(es)
//, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img
//, 'font_icon' => 'glyphicon glyphicon-envelope' // CSS definition of Font Icon
, 'default' => true // Is this sub tab activated by default or not: true || false.
, 'disabled' => false // Is this sub tab deactivated: true || false.
, 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' )
, 'content' => 'content' // Function to load as conten of this TAB
);
$tabs[ 'email' ]['subtabs'] = $subtabs;
return $tabs;
}
/** Show Content of Settings page */
public function content() {
//debuge( 'WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID, get_wpbm_option( WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID )', WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID, get_wpbm_option( WPBM_EMAIL_LINK_USER_PREFIX . WPBM_EMAIL_LINK_USER_ID ) );
$this->css();
////////////////////////////////////////////////////////////////////////
// Checking
////////////////////////////////////////////////////////////////////////
do_action( 'wpbm_hook_settings_page_header', array( 'page' => $this->in_page(), 'subpage' => 'emails_settings' ) ); // Define Notices Section and show some static messages, if needed.
////////////////////////////////////////////////////////////////////////
// Load Data
////////////////////////////////////////////////////////////////////////
/** Its will load DATA from DB, during creattion mail_api CLASS
* during initial activation of the API its try to get option from DB
* We need to define this API before checking POST, to know all available fields
* Define Email Name & define field values from DB, if not exist, then default values.
Array (
[wpbm_email_link_user] => Array
(
[enabled] => On
[to] => beta@oplugins.com
[to_name] => 'Some name'
[from] => admin@oplugins.com
[from_name] =>
[subject] => New item
[content] => You need to approve [shortcodetype] for: [dates]...
[header_content] =>
[footer_content] =>
[template_file] => plain
[base_color] => #557da1
[background_color] => #f5f5f5
[body_color] => #fdfdfd
[text_color] => #505050
[email_content_type] => html
)
)
// $mail_api->save_to_db( $fields_values );
*/
$init_fields_values = array();
$this->mail_api( WPBM_EMAIL_LINK_USER_ID, $init_fields_values );
////////////////////////////////////////////////////////////////////////
// S u b m i t Actions - S e n d
////////////////////////////////////////////////////////////////////////
$submit_form_name_action = 'wpbm_form_action'; // Define form name
if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name_action ] ) ) {
// Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
$nonce_gen_time = check_admin_referer( 'wpbm_settings_page_' . $submit_form_name_action ); // Its stop show anything on submiting, if its not refear to the original page
// Save Changes
$this->update_actions();
}
?>
mail_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields before submit.
if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) {
// Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. }
$nonce_gen_time = check_admin_referer( 'wpbm_settings_page_' . $submit_form_name ); // Its stop show anything on submiting, if its not refear to the original page
// Save Changes
$this->update();
}
////////////////////////////////////////////////////////////////////////
// JavaScript: Tooltips, Popover, Datepick (js & css)
////////////////////////////////////////////////////////////////////////
echo '';
wpbm_js_for_items_page();
echo '';
////////////////////////////////////////////////////////////////////////
// Content
////////////////////////////////////////////////////////////////////////
?>
enqueue_js();
}
/**
* Update form from Toolbar - create / delete/ load email templates
*
* @return boolean
*/
public function update_actions( ) {
if ( $_POST['form_action'] == 'test_send' ) { // Sending test email
/*
$this->email_settings_api = false;
$selected_email_name = 'standard';
$email_fields = get_wpbm_option( 'wpbm_email_' . $selected_email_name );
$this->mail_api( $selected_email_name, $email_fields );
*/
//$to = sanitize_email( $this->mail_api()->fields_values['to'] );
$replace = array();
$replace[ 'product_id' ] = '99';
$replace[ 'product_title' ] = 'Product ZZZ';
$replace[ 'product_version' ] = '1.0';
$replace[ 'product_description' ] = 'Product ZZZ Info';
$replace[ 'product_filename' ] = 'zzz_product.zip';
$replace[ 'product_link' ] = home_url();
$replace[ 'product_size' ] = '3 Mb';
$replace[ 'product_expire_after' ] = '1 day';
$replace[ 'product_expire_date' ] = date_i18n( get_wpbm_option( 'wpbm_date_format' ) . ' ' . get_wpbm_option( 'wpbm_time_format' ), strtotime( '+1 day' ) );
$replace[ 'product_summary' ] = '' . $replace[ 'product_filename' ] . ' (' . $replace[ 'product_size' ] . ') ~ expire in ' . $replace[ 'product_expire_after' ];
$replace[ 'link_sent_to' ] = $this->mail_api()->get_from__email_address();
$replace[ 'siteurl' ] = htmlspecialchars_decode( '' . home_url() . '' );
$replace[ 'remote_ip' ] = wpbm_get_user_ip(); // The IP address from which the user is viewing the current page.
$replace[ 'user_agent' ] = $_SERVER[ 'HTTP_USER_AGENT' ]; // Contents of the User-Agent: header from the current request, if there is one.
$replace[ 'request_url' ] = $_SERVER[ 'HTTP_REFERER' ]; // The address of the page (if any) where action was occured. Because we are sending it in Ajax request, we need to use the REFERER HTTP
$replace[ 'current_date' ] = date_i18n( get_wpbm_option( 'wpbm_date_format' ) );
$replace[ 'current_time' ] = date_i18n( get_wpbm_option( 'wpbm_time_format' ) );
$to = $this->mail_api()->get_from__email_address();
$to_name = $this->mail_api()->get_from__name();
$to = trim( $to_name ) . ' <' . $to . '> ';
$email_result = $this->mail_api()->send( $to , $replace );
if ( $email_result )
wpbm_show_message ( __('Email sent to ', 'booking-manager') . ' ' . $this->mail_api()->get_from__email_address() , 5 );
else
wpbm_show_message ( __('Email was not sent. An error occurred.', 'booking-manager'), 5 ,'error' );
}
/*
if ( $_POST['form_action'] == 'create' ) { // Create
$email_title = esc_attr( $_POST['create_email_template'] );
$email_name = wpbm_get_slug_format_4_option_name( $email_title );
$wpbm_email_tpl_names = get_wpbm_option( 'wpbm_email_tpl_names' );
if ( empty( $wpbm_email_tpl_names ) ) $wpbm_email_tpl_names = array();
if ( empty($email_name) || isset( $wpbm_email_tpl_names[ $email_name ] ) ) { // Error
wpbm_show_message ( __('Email template has not added.', 'booking-manager'), 5 , 'error' );
return false;
}
$wpbm_email_tpl_names[ $email_name ]= stripslashes( $email_title );
update_wpbm_option( 'wpbm_email_tpl_names', $wpbm_email_tpl_names );
wpbm_show_message ( __('Email template added successfully', 'booking-manager'), 5 ); // Show Save message
$redir = esc_url( add_query_arg( array('email_template' => $email_name ), html_entity_decode( $this->getUrl() ) ) );
wpbm_reload_page_by_js( $redir );
return true;
}
if ( $_POST['form_action'] == 'delete' ) { // Delete
$email_name = esc_attr( $_POST['select_email_template'] );
$wpbm_email_tpl_names = get_wpbm_option( 'wpbm_email_tpl_names' );
if ( empty( $wpbm_email_tpl_names ) ) $wpbm_email_tpl_names = array();
if ( ! isset( $wpbm_email_tpl_names[ $email_name ] ) ) { // Error
wpbm_show_message ( __('Email template does not exist.', 'booking-manager'), 5 , 'error' );
return false;
}
unset($wpbm_email_tpl_names[ $email_name ]); // Remove Email name from list of email names
update_wpbm_option( 'wpbm_email_tpl_names', $wpbm_email_tpl_names );
delete_wpbm_option( 'wpbm_email_' . $email_name ); // Delete Email Template
wpbm_show_message ( __('Email template deleted successfully', 'booking-manager'), 5 ); // Show Save message
$redir = esc_url( remove_query_arg( array( 'email_template' ), html_entity_decode( $this->getUrl() ) ) ); // Load standard email template
wpbm_reload_page_by_js( $redir );
return true;
}
if ( $_POST['form_action'] == 'load' ) { // Load
$email_name = $_POST['select_email_template'];
$wpbm_email_tpl_names = get_wpbm_option( 'wpbm_email_tpl_names' );
if ( empty( $wpbm_email_tpl_names ) ) $wpbm_email_tpl_names = array();
if ( ! isset( $wpbm_email_tpl_names[ $email_name ] ) ) { // Error
wpbm_show_message ( __('Email template does not exist.', 'booking-manager'), 5 , 'error' );
return false;
}
}
*/
}
/** Update Email template to DB */
public function update() {
// Get Validated Email fields
$validated_fields = $this->mail_api()->validate_post();
// Remove at begining and
at END of email template. if ( ( substr( $validated_fields['content'], 0, 3) === '' ) && ( substr( $validated_fields['content'], -4 ) === '
' ) ) { $validated_fields['content'] = substr ( $validated_fields['content'], 3, ( strlen ( $validated_fields['content'] ) - 7 ) ); } $this->mail_api()->save_to_db( $validated_fields ); wpbm_show_message ( __('Settings saved.', 'booking-manager'), 5 ); // Show Save message } //