Changeset 2756866
- Timestamp:
- 07/15/2022 11:12:39 AM (4 years ago)
- Location:
- e-customer-emails
- Files:
-
- 12 added
- 4 edited
-
tags/1.1.0 (added)
-
tags/1.1.0/ECustomerEmails.php (added)
-
tags/1.1.0/js (added)
-
tags/1.1.0/js/ece-insert-signature.js (added)
-
tags/1.1.0/js/ece-send-email.js (added)
-
tags/1.1.0/readme.txt (added)
-
tags/1.1.0/screenshot.png (added)
-
tags/1.1.0/templates (added)
-
tags/1.1.0/templates/ece-email-form.php (added)
-
tags/1.1.0/templates/ece-variables.php (added)
-
trunk/ECustomerEmails.php (modified) (7 diffs)
-
trunk/js/ece-insert-signature.js (added)
-
trunk/js/ece-send-email.js (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/templates/ece-email-form.php (modified) (1 diff)
-
trunk/templates/ece-variables.php (added)
Legend:
- Unmodified
- Added
- Removed
-
e-customer-emails/trunk/ECustomerEmails.php
r2756845 r2756866 4 4 * Plugin URI: 5 5 * Description: Send an email easily to a client via the orders menu of WooCommerce 6 * Version: 1. 0.06 * Version: 1.1.0 7 7 * Requires at least: 5.9 8 8 * Requires PHP: 7.4 … … 83 83 84 84 /** 85 * Function to create an Variables metabox into the E-Customer Singatures post type 86 * 87 * @since 1.1.0 88 * @author Dennis Weijer 89 */ 90 add_action( 'add_meta_boxes', 'ECE_add_meta_boxes_variables' ); 91 if ( ! function_exists( 'ECE_add_meta_boxes_variables' ) ) { 92 function ECE_add_meta_boxes_variables() { 93 add_meta_box( 94 'ECE_variables_field', 95 esc_html__( 'Variables', 'e-customer-emails' ), 96 'ECE_add_variables_field', 97 'ece_signatures', 98 'normal', 99 'default' 100 ); 101 } 102 } 103 104 /** 85 105 * Function to create the content of the Email metabox 86 106 * … … 105 125 ob_start(); 106 126 include( plugin_dir_path( __FILE__ ) . 'templates/ece-email-form.php' ); 127 echo ob_get_clean(); 128 } 129 } 130 131 /** 132 * Function to create the content of the Variables metabox 133 * 134 * @since 1.1.0 135 * @author Dennis Weijer 136 */ 137 if ( ! function_exists( 'ECE_add_variables_field' ) ) { 138 function ECE_add_variables_field() { 139 ob_start(); 140 include( plugin_dir_path( __FILE__ ) . 'templates/ece-variables.php' ); 107 141 echo ob_get_clean(); 108 142 } … … 141 175 $first_name = wp_kses_post( $order->get_billing_first_name() ); 142 176 $last_name = wp_kses_post( $order->get_billing_last_name() ); 177 178 $cc = sanitize_email( $_REQUEST['cc'] ); 179 $bcc = sanitize_email( $_REQUEST['bcc'] ); 180 181 if ( ! empty( $cc ) && is_email( $cc ) == false ) { 182 $errors[] = esc_html__( "CC email adress is not valid!", "e-customer-emails" ); 183 } 184 185 if( ! empty( $bcc ) && is_email( $bcc ) == false ) { 186 $errors[] = esc_html__( "BCC email adress is not valid!", "e-cutsomer-emails" ); 187 } 143 188 144 189 $gottenSubject = wp_kses_post( $_REQUEST['subject'] ); … … 181 226 $headers .= 'From: '. esc_html( $current_user->display_name ) .' <'. sanitize_email( $current_user->user_email ) .'>' . "\r\n"; 182 227 $headers .= 'To: '. $first_name . ' ' . $last_name .' <'. $billing_email .'>' . "\r\n"; 228 229 if ( ! empty( $cc ) ) { 230 $headers .= 'Cc: ' . $cc . "\r\n"; 231 } 232 233 if ( ! empty( $bcc ) ) { 234 $headers .= 'Bcc: ' . $bcc . "\r\n"; 235 } 183 236 184 237 // Send the email and check if it was sent successfully … … 209 262 210 263 /** 264 * Function to handle the AJAX Request when 'Insert Signature' button is clicked 265 * 266 * @since 1.1.0 267 * @author Dennis Weijer 268 */ 269 add_action( "wp_ajax_ece_insert_signature", "ece_insert_signature" ); 270 function ece_insert_signature() { 271 272 // Setting standard result, if no other result is given by this function 273 $result['type'] = "error"; 274 $result['msg'] = esc_html__( "Something went wrong!", "e-customer-emails" ); 275 276 // Getting all the values, sanitize them, replace strings (if neccesary), and generate errors if there are any 277 $errors = []; 278 279 $signature_id = sanitize_key( $_REQUEST[ 'signature_id' ] ); 280 281 if ( empty( $signature_id ) ) { 282 $errors[] = "Please select an valid signature!"; 283 } 284 285 // If there are no errors 286 if ( empty( $errors ) ) { 287 288 $signature_post = get_post( $signature_id ); 289 $signature_content = wp_kses_post( $signature_post->post_content ); 290 $signature_content = apply_filters( 'the_content', $signature_content ); 291 $signature_content = str_replace( '"', "'", $signature_content ); 292 $signature_content = str_replace( " ", "<br />", $signature_content ); 293 294 $result['type'] = "success"; 295 $result['msg'] = esc_html__( "Signature inserted successfully!", "e-customer-emails" ); 296 $result['signature'] = $signature_content; 297 298 } 299 // If there are errors 300 else { 301 $result['msg'] = $errors; 302 } 303 304 // Check if action was fired via Ajax call. If yes, JS code will be triggered. Else the user is redirected to the post page 305 if( ! empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) { 306 $result = json_encode( $result ); 307 echo wp_kses_post( $result ); 308 } else { 309 header( "Location: " . $_SERVER['HTTP_REFERER'] ); 310 } 311 312 // Don't forget to end your scripts with a die() function - very important 313 wp_die(); 314 } 315 316 /** 317 * Function to add the signatures post type 318 * 319 * @since 1.1.0 320 * @author Dennis weijer 321 */ 322 // Register Custom Post Type 323 add_action( 'init', 'ECE_create_signatures_post_type', 0 ); 324 if ( ! function_exists( 'ECE_create_signatures_post_type' ) ) { 325 function ECE_create_signatures_post_type() { 326 327 $labels = array( 328 'name' => _x( 'E-Customer Signatures', 'Post Type General Name', 'e-customer-emails' ), 329 'singular_name' => _x( 'E-Customer Signature', 'Post Type Singular Name', 'e-customer-emails' ), 330 'menu_name' => __( 'E-Customer Signatures', 'e-customer-emails' ), 331 'name_admin_bar' => __( 'Signatures', 'e-customer-emails' ), 332 'archives' => __( 'E-Customer Signature Archives', 'e-customer-emails' ), 333 'attributes' => __( 'E-Customer Signature Attributes', 'e-customer-emails' ), 334 'parent_item_colon' => __( 'Parent E-Customer Signature:', 'e-customer-emails' ), 335 'all_items' => __( 'All E-Customer Signatures', 'e-customer-emails' ), 336 'add_new_item' => __( 'Add New E-Customer Signature', 'e-customer-emails' ), 337 'add_new' => __( 'Add New', 'e-customer-emails' ), 338 'new_item' => __( 'New E-Customer Signature', 'e-customer-emails' ), 339 'edit_item' => __( 'Edit E-Customer Signature', 'e-customer-emails' ), 340 'update_item' => __( 'Update E-Customer Signature', 'e-customer-emails' ), 341 'view_item' => __( 'View E-Customer Signature', 'e-customer-emails' ), 342 'view_items' => __( 'View E-Customer Signature', 'e-customer-emails' ), 343 'search_items' => __( 'Search E-Customer Signature', 'e-customer-emails' ), 344 'not_found' => __( 'Not found', 'e-customer-emails' ), 345 'not_found_in_trash' => __( 'Not found in Trash', 'e-customer-emails' ), 346 'featured_image' => __( 'Featured Image', 'e-customer-emails' ), 347 'set_featured_image' => __( 'Set featured image', 'e-customer-emails' ), 348 'remove_featured_image' => __( 'Remove featured image', 'e-customer-emails' ), 349 'use_featured_image' => __( 'Use as featured image', 'e-customer-emails' ), 350 'insert_into_item' => __( 'Insert into E-Customer Signature', 'e-customer-emails' ), 351 'uploaded_to_this_item' => __( 'Uploaded to this E-Customer Signature', 'e-customer-emails' ), 352 'items_list' => __( 'E-Customer Signatures list', 'e-customer-emails' ), 353 'items_list_navigation' => __( 'E-Customer Signatures list navigation', 'e-customer-emails' ), 354 'filter_items_list' => __( 'Filter E-Customer Signatures list', 'e-customer-emails' ), 355 ); 356 $args = array( 357 'label' => __( 'E-Customer Signature', 'e-customer-emails' ), 358 'description' => __( 'Email signatures for the E-customer Emails plugin', 'e-customer-emails' ), 359 'labels' => $labels, 360 'supports' => array( 'title', 'editor' ), 361 'hierarchical' => false, 362 'public' => false, 363 'show_ui' => true, 364 'show_in_menu' => true, 365 'menu_position' => 54, 366 'menu_icon' => 'dashicons-email-alt2', 367 'show_in_admin_bar' => true, 368 'show_in_nav_menus' => false, 369 'can_export' => false, 370 'has_archive' => false, 371 'exclude_from_search' => true, 372 'publicly_queryable' => true, 373 'capability_type' => 'post', 374 ); 375 register_post_type( 'ece_signatures', $args ); 376 377 } 378 } 379 380 /** 211 381 * Function to enqueue all the scripts 212 382 * … … 219 389 // Register JS files with a unique handle, file location, and an array of dependencies 220 390 wp_register_script( "send_email_script", plugin_dir_url( __FILE__ ) . 'js/ece-send-email.js', array('jquery') ); 391 wp_register_script( "insert_signature_script", plugin_dir_url( __FILE__ ) . 'js/ece-insert-signature.js', array('jquery') ); 221 392 222 393 // Localize scripts to the domain name, so that we can reference the url to admin-ajax.php file easily 223 394 wp_localize_script( "send_email_script", 'ECE_Ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); 395 wp_localize_script( "insert_signature_script", 'ECE_Ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); 224 396 225 397 // Enqueue jQuery library and all the scripts above 226 398 wp_enqueue_script( 'jquery' ); 227 399 wp_enqueue_script( 'send_email_script' ); 228 } 400 wp_enqueue_script( 'insert_signature_script' ); 401 } -
e-customer-emails/trunk/js/ece-send-email.js
r2756845 r2756866 33 33 subject = $( "#ece-subject" ).val(); 34 34 message = tinyMCE.get( 'ece-message' ).getContent(); 35 cc = $( '#ece-cc' ).val(); 36 bcc = $( '#ece-bcc' ).val(); 35 37 36 38 // Store the data in a data variabled 37 data = { action: 'ece_send_email', post_id: post_id, subject: subject, message: message, nonce: nonce };38 39 data = { action: 'ece_send_email', post_id: post_id, subject: subject, message: message, cc: cc, bcc: bcc, nonce: nonce }; 40 39 41 // Make an AJAX request 40 $.post( ECE_Ajax.ajaxurl, data, function( response) {42 $.post( ECE_Ajax.ajaxurl, data, function( response ) { 41 43 42 44 // Decode the JSON code gotten from the response … … 47 49 // Set the fields to empty 48 50 $( "#ece-subject" ).val( '' ); 51 $( "#ece-cc" ).val( '' ); 52 $( "#ece-bcc" ).val( '' ); 49 53 tinyMCE.get( 'ece-message' ).setContent( '' ); 50 54 51 // Show a nsuccess message55 // Show a success message 52 56 $( '#ece-response-text-success' ).html( response.msg ); 53 57 } 54 58 // If there is one or more errors 55 59 else { 56 // Show the error s60 // Show the error(s) 57 61 $.each( response.msg, function( index, value ) { 58 62 $( '#ece-response-text-error' ).append( '<li>' + value + '</li>' ); … … 60 64 } 61 65 62 // reset the disabled states and deactivate the spinner66 // Reset the disabled states and deactivate the spinner 63 67 $( '.ece-spinner' ).removeClass( 'is-active' ); 64 68 $( '.ece_send_email_button' ).attr( "disabled", false ); -
e-customer-emails/trunk/readme.txt
r2756845 r2756866 4 4 Requires at least: 5.7 5 5 Tested up to: 6.0 6 Stable tag: 1. 0.06 Stable tag: 1.1.0 7 7 Requires PHP: 7.4 8 8 License: GPLv2 or later … … 32 32 == Screenshots == 33 33 34 1. Blank email field in the WooCommerce order screen. 35 2. Filled in example of an email. 36 34 37 == Changelog == 38 39 = 1.1.0 = 40 * Added the functionality to add an email address to CC. 41 * Added the functionality to add an email address to BCC. 42 * Added a signature functionality. You can now easily create a signature on the newly created tab and insert it as soon as you write an email. 35 43 36 44 = 1.0.0 = -
e-customer-emails/trunk/templates/ece-email-form.php
r2756845 r2756866 10 10 * @author Dennis Weijer 11 11 */ 12 13 // Get all the signatures 14 $args = array( 15 'post_type' => 'ece_signatures', 16 'posts_per_page' => -1 17 ); 18 $posts = new WP_Query( $args ); 12 19 ?> 13 20 14 21 <div class="ece-form"> 15 22 <div class="form-field form-field-wide"> 16 <label for=""><?php esc_html_e( "Customer Email:", "e-customer-emails" ); ?> </label>23 <label for=""><?php esc_html_e( "Customer Email:", "e-customer-emails" ); ?> <span style="color: red">*</span></label><br> 17 24 <input type="email" disabled="disabled" value="<?php echo esc_attr( sanitize_email( $billing_email ) ); ?>"> 18 25 </div> 19 26 <br /> 20 27 <div class="form-field form-field-wide"> 21 <label for=""><?php esc_html_e( "Email Subject:", "e-customer-emails" ); ?> </label>28 <label for=""><?php esc_html_e( "Email Subject:", "e-customer-emails" ); ?> <span style="color: red">*</span></label><br> 22 29 <input type="text" id="ece-subject" minlength="10" maxlength="75"> 23 30 </div> 24 31 <br /> 25 32 <div class="form-field form-field-wide"> 26 <label for=""><?php esc_html_e( "Message:", "e-customer-emails" ); ?></label> 33 <label for="">CC:</label><br> 34 <input type="text" id="ece-cc" placeholder="<?php esc_html_e( "Leave blank if you don't want to add a CC", "e-customer-emails" ); ?>"> 35 </div> 36 <br /> 37 <div class="form-field form-field-wide"> 38 <label for="">BCC:</label><br> 39 <input type="text" id="ece-bcc" placeholder="<?php esc_html_e( "Leave blank if you don't want to add a BCC", "e-customer-emails" ); ?>"> 40 </div> 41 <br /> 42 <div class="form-field form-field-wide"> 43 <label for=""><?php esc_html_e( "Insert Signature:", "e-customer-emails" ); ?></label><br> 44 <!-- Loop through the signatures --> 45 <select name="" id="ece-signature-select"> 46 <option value="">-- <?php esc_html_e( "Select a signature", "e-customer-emails" ); ?> --</option> 47 <?php if ( $posts->have_posts() ): ?> 48 <?php while ( $posts->have_posts() ): $posts->the_post(); ?> 49 <option value="<?php esc_attr( the_ID() ); ?>"><?php esc_html( the_title() ); ?></option> 50 <?php endwhile; ?> 51 <?php wp_reset_postdata(); endif; ?> 52 </select> 53 <a href="" class="ece_insert_signature_button button button-secondary"><?php esc_html_e( "Insert", "e-customer-emails" ); ?></a> 54 <span class="ece-spinner-signature spinner"></span> 55 <p class="ece-signature-success" style="color: green;"></p> 56 <ul class="ece-signature-error" style="color: red;"></p> 57 </div> 58 <br /> 59 <div class="form-field form-field-wide"> 60 <label for=""><?php esc_html_e( "Message:", "e-customer-emails" ); ?> <span style="color: red">*</span></label><br><br> 27 61 <?php wp_editor( '', 'ece-message', [ 'wpautop' => false ] ); ?> 28 62 <br /> 29 <span class="description"> 30 <?php esc_html_e( "Type the following in your message:", "e-customer-emails" ); ?> 31 <ul> 32 <li>  <strong>[first_name]</strong> - <?php esc_html_e( "To insert the first name of the client.", "e-customer-emails" ); ?></li> 33 <li>  <strong>[last_name]</strong> - <?php esc_html_e( "To insert the last name of the client.", "e-customer-emails" ); ?></li> 34 <li>  <strong>[full_name]</strong> - <?php esc_html_e( "To insert the full name of the client.", "e-customer-emails" ); ?></li> 35 </ul> 36 </span> 63 <?php 64 ob_start(); 65 include( plugin_dir_path( __FILE__ ) . 'ece-variables.php' ); 66 echo ob_get_clean(); 67 ?> 37 68 </div> 38 69 <br />
Note: See TracChangeset
for help on using the changeset viewer.