Plugin Directory

Changeset 2756866


Ignore:
Timestamp:
07/15/2022 11:12:39 AM (4 years ago)
Author:
dweijer
Message:

Version 1.1.0 release!! :)

Location:
e-customer-emails
Files:
12 added
4 edited

Legend:

Unmodified
Added
Removed
  • e-customer-emails/trunk/ECustomerEmails.php

    r2756845 r2756866  
    44 * Plugin URI:       
    55 * Description:       Send an email easily to a client via the orders menu of WooCommerce
    6  * Version:           1.0.0
     6 * Version:           1.1.0
    77 * Requires at least: 5.9
    88 * Requires PHP:      7.4
     
    8383
    8484/**
     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 */
     90add_action( 'add_meta_boxes', 'ECE_add_meta_boxes_variables' );
     91if ( ! 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/**
    85105 * Function to create the content of the Email metabox
    86106 *
     
    105125        ob_start();
    106126        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 */
     137if ( ! 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' );
    107141        echo ob_get_clean();
    108142    }
     
    141175    $first_name = wp_kses_post( $order->get_billing_first_name() );
    142176    $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    }
    143188
    144189    $gottenSubject = wp_kses_post( $_REQUEST['subject'] );
     
    181226        $headers .= 'From: '. esc_html( $current_user->display_name ) .' <'. sanitize_email( $current_user->user_email ) .'>' . "\r\n";
    182227        $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        }
    183236
    184237        // Send the email and check if it was sent successfully
     
    209262
    210263/**
     264 * Function to handle the AJAX Request when 'Insert Signature' button is clicked
     265 *
     266 * @since   1.1.0
     267 * @author  Dennis Weijer
     268 */
     269add_action( "wp_ajax_ece_insert_signature", "ece_insert_signature" );
     270function 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( "&nbsp;", "<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
     323add_action( 'init', 'ECE_create_signatures_post_type', 0 );
     324if ( ! 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/**
    211381 * Function to enqueue all the scripts
    212382 *
     
    219389    // Register JS files with a unique handle, file location, and an array of dependencies
    220390    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') );
    221392   
    222393    // Localize scripts to the domain name, so that we can reference the url to admin-ajax.php file easily
    223394    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' ) ) );
    224396
    225397    // Enqueue jQuery library and all the scripts above
    226398    wp_enqueue_script( 'jquery' );
    227399    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  
    3333        subject = $( "#ece-subject" ).val();
    3434        message = tinyMCE.get( 'ece-message' ).getContent();
     35        cc = $( '#ece-cc' ).val();
     36        bcc = $( '#ece-bcc' ).val();
    3537
    3638        // 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
    3941        // Make an AJAX request
    40         $.post( ECE_Ajax.ajaxurl, data, function(response) {
     42        $.post( ECE_Ajax.ajaxurl, data, function( response ) {
    4143
    4244            // Decode the JSON code gotten from the response
     
    4749                // Set the fields to empty
    4850                $( "#ece-subject" ).val( '' );
     51                $( "#ece-cc" ).val( '' );
     52                $( "#ece-bcc" ).val( '' );
    4953                tinyMCE.get( 'ece-message' ).setContent( '' );
    5054
    51                 // Show an success message
     55                // Show a success message
    5256                $( '#ece-response-text-success' ).html( response.msg );
    5357            }
    5458            // If there is one or more errors
    5559            else {
    56                 // Show the errors
     60                // Show the error(s)
    5761                $.each( response.msg, function( index, value ) {
    5862                    $( '#ece-response-text-error' ).append( '<li>' + value + '</li>' );
     
    6064            }
    6165
    62             // reset the disabled states and deactivate the spinner
     66            // Reset the disabled states and deactivate the spinner
    6367            $( '.ece-spinner' ).removeClass( 'is-active' );
    6468            $( '.ece_send_email_button' ).attr( "disabled", false );
  • e-customer-emails/trunk/readme.txt

    r2756845 r2756866  
    44Requires at least: 5.7
    55Tested up to: 6.0
    6 Stable tag: 1.0.0
     6Stable tag: 1.1.0
    77Requires PHP: 7.4
    88License: GPLv2 or later
     
    3232== Screenshots ==
    3333
     341. Blank email field in the WooCommerce order screen.
     352. Filled in example of an email.
     36
    3437== 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.
    3543
    3644= 1.0.0 =
  • e-customer-emails/trunk/templates/ece-email-form.php

    r2756845 r2756866  
    1010     * @author  Dennis Weijer
    1111     */
     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 );
    1219?>
    1320
    1421<div class="ece-form">
    1522    <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>
    1724        <input type="email" disabled="disabled" value="<?php echo esc_attr( sanitize_email( $billing_email ) ); ?>">
    1825    </div>
    1926    <br />
    2027    <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>
    2229        <input type="text" id="ece-subject" minlength="10" maxlength="75">
    2330    </div>
    2431    <br />
    2532    <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>
    2761        <?php wp_editor( '', 'ece-message', [ 'wpautop' => false ] ); ?>
    2862        <br />
    29         <span class="description">
    30             <?php esc_html_e( "Type the following in your message:", "e-customer-emails" ); ?>
    31             <ul>
    32                 <li>&emsp;&emsp;<strong>[first_name]</strong> - <?php esc_html_e( "To insert the first name of the client.", "e-customer-emails" ); ?></li>
    33                 <li>&emsp;&emsp;<strong>[last_name]</strong> - <?php esc_html_e( "To insert the last name of the client.", "e-customer-emails" ); ?></li>
    34                 <li>&emsp;&emsp;<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        ?>
    3768    </div>
    3869    <br />
Note: See TracChangeset for help on using the changeset viewer.