', '<', '&', '(c)', '(tm)', '(R)', '--', '-', '*', '£', 'EUR', // Euro sign. € ? '', // Unknown/unhandled entities ' ' // Runs of spaces, post-handling ); /** * Constructor * * @access public * @return void */ function __construct() { global $woocommerce; // Init settings $this->init_form_fields(); $this->init_settings(); // Save settings hook add_action( 'woocommerce_update_options_email_' . $this->id, array( $this, 'process_admin_options' ) ); // Default template base if not declared in child constructor if ( is_null( $this->template_base ) ) $this->template_base = $woocommerce->plugin_path() . '/templates/'; // Settings $this->heading = $this->get_option( 'heading', $this->heading ); $this->subject = $this->get_option( 'subject', $this->subject ); $this->email_type = $this->get_option( 'email_type' ); $this->enabled = $this->get_option( 'enabled' ); // Find/replace $this->find = array( '{blogname}', '{site_title}' ); $this->replace = array( $this->get_blogname(), $this->get_blogname() ); // For multipart messages add_filter( 'phpmailer_init', array( $this, 'handle_multipart' ) ); // For default inline styles add_filter( 'woocommerce_email_style_inline_tags', array( $this, 'style_inline_tags' ) ); add_filter( 'woocommerce_email_style_inline_h1_tag', array( $this, 'style_inline_h1_tag' ) ); add_filter( 'woocommerce_email_style_inline_h2_tag', array( $this, 'style_inline_h2_tag' ) ); add_filter( 'woocommerce_email_style_inline_h3_tag', array( $this, 'style_inline_h3_tag' ) ); add_filter( 'woocommerce_email_style_inline_a_tag', array( $this, 'style_inline_a_tag' ) ); add_filter( 'woocommerce_email_style_inline_img_tag', array( $this, 'style_inline_img_tag' ) ); } /** * handle_multipart function. * * @access public * @param mixed $mailer * @return void */ function handle_multipart( $mailer ) { if ( $this->sending && $this->get_email_type() == 'multipart' ) { $mailer->AltBody = wordwrap( preg_replace( $this->plain_search, $this->plain_replace, strip_tags( $this->get_content_plain() ) ) ); //$mailer->AltBody = wordwrap( html_entity_decode( strip_tags( $this->get_content_plain() ) ), 70 ); $this->sending = false; } return $mailer; } /** * format_string function. * * @access public * @param mixed $string * @return string */ function format_string( $string ) { return str_replace( $this->find, $this->replace, $string ); } /** * get_subject function. * * @access public * @return string */ function get_subject() { return apply_filters( 'woocommerce_email_subject_' . $this->id, $this->format_string( $this->subject ), $this->object ); } /** * get_heading function. * * @access public * @return string */ function get_heading() { return apply_filters( 'woocommerce_email_heading_' . $this->id, $this->format_string( $this->heading ), $this->object ); } /** * get_recipient function. * * @access public * @return string */ function get_recipient() { return apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object ); } /** * get_headers function. * * @access public * @return string */ function get_headers() { return apply_filters( 'woocommerce_email_headers', "Content-Type: " . $this->get_content_type() . "\r\n", $this->id, $this->object ); } /** * get_attachments function. * * @access public * @return string */ function get_attachments() { return apply_filters( 'woocommerce_email_attachments', '', $this->id, $this->object ); } /** * get_type function. * * @access public * @return string */ function get_email_type() { return $this->email_type ? $this->email_type : 'plain'; } /** * get_content_type function. * * @access public * @return void */ function get_content_type() { switch ( $this->get_email_type() ) { case "html" : return 'text/html'; case "multipart" : return 'multipart/alternative'; default : return 'text/plain'; } } /** * Proxy to parent's get_option and attempt to localize the result using gettext. * * @access public * @return string */ function get_option( $key, $empty_value = null ) { return __( parent::get_option( $key, $empty_value ) ); } /** * Checks if this email is enabled and will be sent. * * @access public * @return bool */ function is_enabled() { $enabled = $this->enabled == "yes" ? true : false; return apply_filters( 'woocommerce_email_enabled_' . $this->id, $enabled, $this->object ); } /** * get_blogname function. * * @access public * @return void */ function get_blogname() { return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); } /** * get_content function. * * @access public * @return string */ function get_content() { $this->sending = true; if ( $this->get_email_type() == 'plain' ) { $email_content = preg_replace( $this->plain_search, $this->plain_replace, strip_tags( $this->get_content_plain() ) ); } else { $email_content = $this->style_inline( $this->get_content_html() ); } return $email_content; } /** * style_inline_tags function. * * @access public * @return array */ function style_inline_tags($tags) { return array_unique( array_merge( $tags, array( 'h1', 'h2', 'h3', 'a', 'img' ) ) ); } /** * style_inline_h1_tag function. * * @access public * @return array */ function style_inline_h1_tag($styles) { $styles['color'] = get_option( 'woocommerce_email_text_color' ); $styles['display'] = 'block'; $styles['font-family'] = 'Arial'; $styles['font-size'] = '34px'; $styles['font-weight'] = 'bold'; $styles['margin-top'] = '10px'; $styles['margin-right'] = '0'; $styles['margin-bottom'] = '10px'; $styles['margin-left'] = '0'; $styles['text-align'] = 'left'; $styles['line-height'] = '150%'; return $styles; } /** * style_inline_h2_tag function. * * @access public * @return array */ function style_inline_h2_tag($styles) { $styles['color'] = get_option( 'woocommerce_email_text_color' ); $styles['display'] = 'block'; $styles['font-family'] = 'Arial'; $styles['font-size'] = '30px'; $styles['font-weight'] = 'bold'; $styles['margin-top'] = '10px'; $styles['margin-right'] = '0'; $styles['margin-bottom'] = '10px'; $styles['margin-left'] = '0'; $styles['text-align'] = 'left'; $styles['line-height'] = '150%'; return $styles; } /** * style_inline_h3_tag function. * * @access public * @return array */ function style_inline_h3_tag($styles) { $styles['color'] = get_option( 'woocommerce_email_text_color' ); $styles['display'] = 'block'; $styles['font-family'] = 'Arial'; $styles['font-size'] = '26px'; $styles['font-weight'] = 'bold'; $styles['margin-top'] = '10px'; $styles['margin-right'] = '0'; $styles['margin-bottom'] = '10px'; $styles['margin-left'] = '0'; $styles['text-align'] = 'left'; $styles['line-height'] = '150%'; return $styles; } function style_inline_a_tag($styles) { $styles['color'] = get_option( 'woocommerce_email_text_color' ); $styles['font-weight'] = 'normal'; $styles['text-decoration'] = 'underline'; return $styles; } /** * style_inline_img_tag function. * * @access public * @return array */ function style_inline_img_tag($styles) { $styles['display'] = 'inline'; $styles['border'] = 'none'; $styles['font-size'] = '14px'; $styles['font-weight'] = 'bold'; $styles['height'] = 'auto'; $styles['line-height'] = '100%'; $styles['outline'] = 'none'; $styles['text-decoration'] = 'none'; $styles['text-transform'] = 'capitalize'; return $styles; } /** * get_style_inline_tags function. * * @access public * @return array */ function get_style_inline_tags() { return apply_filters( 'woocommerce_email_style_inline_tags', array() ); } /** * get_style_inline_for_tag function. * * @access public * @return string */ function get_style_inline_for_tag($tag) { $styles = apply_filters( 'woocommerce_email_style_inline_' . $tag . '_tag', array() ); $css = array(); foreach( $styles as $property => $value ) { $css[] = $property . ':' . $value; } return implode('; ', $css); } /** * Apply inline styles to dynamic content. * * @access public * @param mixed $content * @return void */ function style_inline( $content ) { if ( ! class_exists( 'DOMDocument' ) ) return $content; $dom = new DOMDocument(); libxml_use_internal_errors( true ); @$dom->loadHTML( $content ); libxml_clear_errors(); foreach( $this->get_style_inline_tags() as $tag ) { $nodes = $dom->getElementsByTagName($tag); foreach( $nodes as $node ) { if ( ! $node->hasAttribute( 'style' ) ) $node->setAttribute( 'style', $this->get_style_inline_for_tag($tag) ); } } $content = $dom->saveHTML(); return $content; } /** * get_content_plain function. * * @access public * @return void */ function get_content_plain() {} /** * get_content_html function. * * @access public * @return void */ function get_content_html() {} /** * Get from name for email. * * @access public * @return string */ function get_from_name() { return wp_specialchars_decode( esc_html( get_option( 'woocommerce_email_from_name' ) ), ENT_QUOTES ); } /** * Get from email address. * * @access public * @return string */ function get_from_address() { return sanitize_email( get_option( 'woocommerce_email_from_address' ) ); } /** * Send the email. * * @access public * @param mixed $to * @param mixed $subject * @param mixed $message * @param string $headers * @param string $attachments * @return void */ function send( $to, $subject, $message, $headers, $attachments ) { add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); wp_mail( $to, $subject, $message, $headers, $attachments ); remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) ); remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) ); remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) ); } /** * Initialise Settings Form Fields - these are generic email options most will use. * * @access public * @return void */ function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'Enable this email notification', 'woocommerce' ), 'default' => 'yes' ), 'subject' => array( 'title' => __( 'Email subject', 'woocommerce' ), 'type' => 'text', 'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), $this->subject ), 'placeholder' => '', 'default' => '' ), 'heading' => array( 'title' => __( 'Email heading', 'woocommerce' ), 'type' => 'text', 'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), $this->heading ), 'placeholder' => '', 'default' => '' ), 'email_type' => array( 'title' => __( 'Email type', 'woocommerce' ), 'type' => 'select', 'description' => __( 'Choose which format of email to send.', 'woocommerce' ), 'default' => 'html', 'class' => 'email_type', 'options' => array( 'plain' => __( 'Plain text', 'woocommerce' ), 'html' => __( 'HTML', 'woocommerce' ), 'multipart' => __( 'Multipart', 'woocommerce' ), ) ) ); } /** * Admin Panel Options Processing * - Saves the options to the DB * * @since 1.0.0 * @access public * @return bool */ public function process_admin_options() { // Save regular options parent::process_admin_options(); // Save templates if ( ! empty( $_POST['template_html_code'] ) && ! empty( $this->template_html ) ) { $saved = false; $file = get_stylesheet_directory() . '/woocommerce/' . $this->template_html; $code = stripslashes( $_POST['template_html_code'] ); if ( is_writeable( $file ) ) { $f = fopen( $file, 'w+' ); if ( $f !== FALSE ) { fwrite( $f, $code ); fclose( $f ); $saved = true; } } if ( ! $saved ) { $redirect = add_query_arg( 'wc_error', urlencode( __( 'Could not write to template file.', 'woocommerce' ) ) ); wp_redirect( $redirect ); exit; } } if ( ! empty( $_POST['template_plain_code'] ) && ! empty( $this->template_plain ) ) { $saved = false; $file = get_stylesheet_directory() . '/woocommerce/' . $this->template_plain; $code = stripslashes( $_POST['template_plain_code'] ); if ( is_writeable( $file ) ) { $f = fopen( $file, 'w+' ); if ( $f !== FALSE ) { fwrite( $f, $code ); fclose( $f ); $saved = true; } } if ( ! $saved ) { $redirect = add_query_arg( 'wc_error', __( 'Could not write to template file.', 'woocommerce' ) ); wp_redirect( $redirect ); exit; } } } /** * Admin Options * * Setup the gateway settings screen. * Override this in your gateway. * * @since 1.0.0 * @access public * @return void */ function admin_options() { global $woocommerce; // Handle any actions if ( ! empty( $this->template_html ) || ! empty( $this->template_plain ) ) { if ( ! empty( $_GET['move_template'] ) && ( $template = esc_attr( basename( $_GET['move_template'] ) ) ) ) { if ( ! empty( $this->$template ) ) { if ( wp_mkdir_p( dirname( get_stylesheet_directory() . '/woocommerce/' . $this->$template ) ) && ! file_exists( get_stylesheet_directory() . '/woocommerce/' . $this->$template ) ) { // Locate template file $core_file = $this->template_base . $this->$template; $template_file = apply_filters( 'woocommerce_locate_core_template', $core_file, $this->$template, $this->template_base ); // Copy template file copy( $template_file, get_stylesheet_directory() . '/woocommerce/' . $this->$template ); echo '

' . __( 'Template file copied to theme.', 'woocommerce' ) . '

'; } } } if ( ! empty( $_GET['delete_template'] ) && ( $template = esc_attr( basename( $_GET['delete_template'] ) ) ) ) { if ( ! empty( $this->$template ) ) { if ( file_exists( get_stylesheet_directory() . '/woocommerce/' . $this->$template ) ) { unlink( get_stylesheet_directory() . '/woocommerce/' . $this->$template ); echo '

' . __( 'Template file deleted from theme.', 'woocommerce' ) . '

'; } } } } ?>

title ) ) ? $this->title : __( 'Settings','woocommerce' ) ; ?>

description ) ) ? wpautop( $this->description ) : ''; ?> generate_settings_html(); ?>
template_html ) || ! empty( $this->template_plain ) ) { ?>
__( 'HTML template', 'woocommerce' ), 'template_plain' => __( 'Plain text template', 'woocommerce' ) ); foreach ( $templates as $template => $title ) : if ( empty( $this->$template ) ) continue; $local_file = get_stylesheet_directory() . '/woocommerce/' . $this->$template; $core_file = $this->template_base . $this->$template; $template_file = apply_filters( 'woocommerce_locate_core_template', $core_file, $this->$template, $this->template_base ); ?>

%s.', 'woocommerce' ), 'yourtheme/woocommerce/' . $this->$template ); ?>

%s to your theme folder: %s.', 'woocommerce' ), plugin_basename( $template_file ) , 'yourtheme/woocommerce/' . $this->$template ); ?>