Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build tools #28

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
1 change: 1 addition & 0 deletions .eslintrc
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ wp-content/uploads/
wp-content/wp-cache-config.php
.idea
.DS_Store
node_modules

/vendor/
vendor
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "dev-lib"]
path = dev-lib
url = https://github.com/xwp/wp-dev-lib.git
branch = master
1 change: 1 addition & 0 deletions .jscsrc
1 change: 1 addition & 0 deletions .jshintrc
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
sudo: false
dist: precise

notifications:
email:
on_success: never
on_failure: change

cache:
directories:
- node_modules
- vendor
- $HOME/phpunit-bin

language:
- php
- node_js

php:
- 7.0
- 7.1
- 7.2

env:
- WP_VERSION=latest WP_MULTISITE=0
- WP_VERSION=latest WP_MULTISITE=1
- WP_VERSION=trunk WP_MULTISITE=0
- WP_VERSION=trunk WP_MULTISITE=1

install:
- nvm install 6 && nvm use 6
- export DEV_LIB_PATH=dev-lib
- if [ ! -e "$DEV_LIB_PATH" ] && [ -L .travis.yml ]; then export DEV_LIB_PATH=$( dirname $( readlink .travis.yml ) ); fi
- if [ ! -e "$DEV_LIB_PATH" ]; then git clone https://github.com/xwp/wp-dev-lib.git $DEV_LIB_PATH; fi
- source $DEV_LIB_PATH/travis.install.sh

script:
- source $DEV_LIB_PATH/travis.script.sh

after_script:
- source $DEV_LIB_PATH/travis.after_script.sh
104 changes: 55 additions & 49 deletions admin/class-wcemails-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Admin WooCommerce Custom Emails Class
*
* @class WCE_Admin
* @version 0.1
* @version 0.1
*/
class WCEmails_Admin {

Expand Down Expand Up @@ -81,13 +81,13 @@ function wcemails_settings_callback() {
$type = $_REQUEST['type'];
}
$all_types = array( 'add-email', 'view-email' );
if ( ! in_array( $type, $all_types ) ) {
if ( ! in_array( $type, $all_types, true ) ) {
$type = 'add-email';
}
?>
<ul class="subsubsub">
<li class="today"><a class ="<?php echo ( 'add-email' == $type ) ? 'current' : ''; ?>" href="<?php echo add_query_arg( array( 'type' => 'add-email' ), admin_url( 'admin.php?page=wcemails-settings' ) ); ?>"><?php _e( 'Add Custom Emails', 'woo-custom-emails' ); ?></a> |</li>
<li class="today"><a class ="<?php echo ( 'view-email' == $type ) ? 'current' : ''; ?>" href="<?php echo add_query_arg( array( 'type' => 'view-email' ), admin_url( 'admin.php?page=wcemails-settings' ) ); ?>"><?php _e( 'View Your Custom Emails', 'woo-custom-emails' ); ?></a></li>
<li class="today"><a class ="<?php echo ( 'add-email' === $type ) ? 'current' : ''; ?>" href="<?php echo add_query_arg( array( 'type' => 'add-email' ), admin_url( 'admin.php?page=wcemails-settings' ) ); ?>"><?php _e( 'Add Custom Emails', 'woo-custom-emails' ); ?></a> |</li>
<li class="today"><a class ="<?php echo ( 'view-email' === $type ) ? 'current' : ''; ?>" href="<?php echo add_query_arg( array( 'type' => 'view-email' ), admin_url( 'admin.php?page=wcemails-settings' ) ); ?>"><?php _e( 'View Your Custom Emails', 'woo-custom-emails' ); ?></a></li>
</ul>
<?php $this->wcemails_render_sections( $type ); ?>
</div>
Expand All @@ -97,9 +97,9 @@ function wcemails_settings_callback() {

function wcemails_render_sections( $type ) {

if ( 'add-email' == $type ) {
if ( 'add-email' === $type ) {
$this->wcemails_render_add_email_section();
} else if ( 'view-email' == $type ) {
} elseif ( 'view-email' === $type ) {
$this->wcemails_render_view_email_section();
} else {
$this->wcemails_render_add_email_section();
Expand All @@ -114,8 +114,8 @@ function wcemails_render_add_email_section() {
$wcemails_email_details = get_option( 'wcemails_email_details', array() );
if ( ! empty( $wcemails_email_details ) ) {
foreach ( $wcemails_email_details as $key => $details ) {
if ( $_REQUEST['wcemails_edit'] == $key ) {
$wcemails_detail = $details;
if ( $_REQUEST['wcemails_edit'] === $key ) {
$wcemails_detail = $details;
$wcemails_detail['template'] = stripslashes( $wcemails_detail['template'] );
}
}
Expand All @@ -125,7 +125,7 @@ function wcemails_render_add_email_section() {
$wc_statuses = wc_get_order_statuses();
if ( ! empty( $wc_statuses ) ) {
foreach ( $wc_statuses as $k => $status ) {
$key = ( 'wc-' === substr( $k, 0, 3 ) ) ? substr( $k, 3 ) : $k;
$key = ( 'wc-' === substr( $k, 0, 3 ) ) ? substr( $k, 3 ) : $k;
$wc_statuses[ $key ] = $status;
unset( $wc_statuses[ $k ] );
}
Expand Down Expand Up @@ -190,7 +190,7 @@ function wcemails_render_add_email_section() {
</span>
</th>
<td>
<input name="wcemails_send_customer" id="wcemails_send_customer" type="checkbox" <?php echo ( isset( $wcemails_detail['send_customer'] ) && 'on' == $wcemails_detail['send_customer'] ) ? 'checked="checked"' : ''; ?> />
<input name="wcemails_send_customer" id="wcemails_send_customer" type="checkbox" <?php echo ( isset( $wcemails_detail['send_customer'] ) && 'on' === $wcemails_detail['send_customer'] ) ? 'checked="checked"' : ''; ?> />
</td>
</tr>
<tr>
Expand Down Expand Up @@ -225,7 +225,7 @@ function wcemails_render_add_email_section() {
$status_options = '';
foreach ( $wc_statuses as $k => $wc_status ) {
$selected = '';
if ( $k == $status ) {
if ( $k === $status ) {
$selected = 'selected="selected"';
}
$status_options .= '<option value="' . $k . '" ' . $selected . '>' . $wc_status . '</option>';
Expand All @@ -239,16 +239,16 @@ function wcemails_render_add_email_section() {
$status_options = '';
foreach ( $wc_statuses as $k => $wc_status ) {
$selected = '';
if ( $k == $wcemails_detail['to_status'][ $key ] ) {
if ( $k === $wcemails_detail['to_status'][ $key ] ) {
$selected = 'selected="selected"';
}
$status_options .= '<option value="' . $k . '" ' . $selected . '>' . $wc_status . '</option>';
}
echo $status_options;
?>
</select>
<a href="#" class="clone" title="<?php _e( 'Add Another', 'woo-custom-emails' ) ?>">+</a>
<a href="#" class="delete" title="<?php _e( 'Delete', 'woo-custom-emails' ) ?>">-</a>
<a href="#" class="clone" title="<?php _e( 'Add Another', 'woo-custom-emails' ); ?>">+</a>
<a href="#" class="delete" title="<?php _e( 'Delete', 'woo-custom-emails' ); ?>">-</a>
</div>
<?php
}
Expand All @@ -267,8 +267,8 @@ function wcemails_render_add_email_section() {
<option value=""><?php _e( 'Select To Status', 'woo-custom-emails' ); ?></option>
<?php echo $status_options; ?>
</select>
<a href="#" class="clone" title="<?php _e( 'Add Another', 'woo-custom-emails' ) ?>">+</a>
<a href="#" class="delete" title="<?php _e( 'Delete', 'woo-custom-emails' ) ?>">-</a>
<a href="#" class="clone" title="<?php _e( 'Add Another', 'woo-custom-emails' ); ?>">+</a>
<a href="#" class="delete" title="<?php _e( 'Delete', 'woo-custom-emails' ); ?>">-</a>
</div>
<?php
}
Expand All @@ -281,7 +281,9 @@ function wcemails_render_add_email_section() {
<th scope="row">
<?php _e( 'Template', 'woo-custom-emails' ); ?>
<span style="display: block; font-size: 12px; font-weight: 300;">
<?php _e( '( Use these tags to to print them in email. - ', 'woo-custom-emails' ) ?><br/>
<?php
_e(
'( Use these tags to to print them in email. - <br/>
<i>{order_date},
{order_number},
{woocommerce_email_order_meta},
Expand All @@ -290,15 +292,17 @@ function wcemails_render_add_email_section() {
{email_order_total_footer},
{order_billing_email},
{order_billing_phone},
{email_addresses}</i> )
{email_addresses}</i> )'
);
?>
</span>
</th>
<td>
<?php
$settings = array(
'textarea_name' => 'wcemails_template',
);
wp_editor( html_entity_decode( isset( $wcemails_detail['template'] ) ? $wcemails_detail['template'] : '' ), 'ezway_custom_email_new_order', $settings );
wp_editor( html_entity_decode( isset( $wcemails_detail['template'] ) ? $wcemails_detail['template'] : '' ), 'ezway_custom_email_new_order', $settings ); // phpcs:ignore PHPCompatibility.ParameterValues.NewHTMLEntitiesEncodingDefault.NotSet
?>
</td>
</tr>
Expand All @@ -310,7 +314,7 @@ function wcemails_render_add_email_section() {
</span>
</th>
<td>
<input name="wcemails_order_action" id="wcemails_order_action" type="checkbox" <?php echo ( isset( $wcemails_detail['order_action'] ) && 'on' == $wcemails_detail['order_action'] ) ? 'checked="checked"' : ''; ?> />
<input name="wcemails_order_action" id="wcemails_order_action" type="checkbox" <?php echo ( isset( $wcemails_detail['order_action'] ) && 'on' === $wcemails_detail['order_action'] ) ? 'checked="checked"' : ''; ?> />
</td>
</tr>
<tr>
Expand All @@ -321,7 +325,7 @@ function wcemails_render_add_email_section() {
</span>
</th>
<td>
<input name="wcemails_enable" id="wcemails_enable" type="checkbox" <?php echo ( isset( $wcemails_detail['enable'] ) && 'on' == $wcemails_detail['enable'] ) ? 'checked="checked"' : ''; ?> />
<input name="wcemails_enable" id="wcemails_enable" type="checkbox" <?php echo ( isset( $wcemails_detail['enable'] ) && 'on' === $wcemails_detail['enable'] ) ? 'checked="checked"' : ''; ?> />
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -389,31 +393,31 @@ function wcemails_email_actions_details() {
if ( isset( $_POST['wcemails_update'] ) ) {
if ( ! empty( $wcemails_email_details ) ) {
foreach ( $wcemails_email_details as $key => $details ) {
if ( $key == $_POST['wcemails_update'] ) {
$data['id'] = $details['id'];
if ( $key === $_POST['wcemails_update'] ) {
$data['id'] = $details['id'];
$wcemails_email_details[ $key ] = $data;
}
}
}
} else {
$id = uniqid( 'wcemails' );
$id = uniqid( 'wcemails' );
$data['id'] = $id;
array_push( $wcemails_email_details, $data );
}

update_option( 'wcemails_email_details', $wcemails_email_details );

add_settings_error( 'wcemails-settings', 'error_code', $title.' is saved and if you have enabled it then you can see it in Woocommerce Email Settings Now', 'success' );
add_settings_error( 'wcemails-settings', 'error_code', $title . ' is saved and if you have enabled it then you can see it in Woocommerce Email Settings Now', 'success' );

} else if ( isset( $_REQUEST['wcemails_delete'] ) ) {
} elseif ( isset( $_REQUEST['wcemails_delete'] ) ) {

$wcemails_email_details = get_option( 'wcemails_email_details', array() );

$delete_key = $_REQUEST['wcemails_delete'];

if ( ! empty( $wcemails_email_details ) ) {
foreach ( $wcemails_email_details as $key => $details ) {
if ( $key == $delete_key ) {
if ( $key === $delete_key ) {
unset( $wcemails_email_details[ $key ] );
}
}
Expand Down Expand Up @@ -446,7 +450,7 @@ function wcemails_custom_woocommerce_emails( $email_classes ) {

$enable = $details['enable'];

if ( 'on' == $enable ) {
if ( 'on' === $enable ) {

$title = isset( $details['title'] ) ? $details['title'] : '';
$id = isset( $details['id'] ) ? $details['id'] : '';
Expand All @@ -457,11 +461,11 @@ function wcemails_custom_woocommerce_emails( $email_classes ) {
$from_status = isset( $details['from_status'] ) ? $details['from_status'] : array();
$to_status = isset( $details['to_status'] ) ? $details['to_status'] : array();
$send_customer = isset( $details['send_customer'] ) ? $details['send_customer'] : array();
$template = stripslashes( html_entity_decode( isset( $details['template'] ) ? $details['template'] : '' ) );
$template = stripslashes( html_entity_decode( isset( $details['template'] ) ? $details['template'] : '' ) ); // phpcs:ignore PHPCompatibility.ParameterValues.NewHTMLEntitiesEncodingDefault.NotSet

$wcemails_instance = new WCEmails_Instance( $id, $title, $description, $subject, $recipients, $heading, $from_status, $to_status, $send_customer, $template );

$email_classes[ 'WCustom_Emails_'.$id.'_Email' ] = $wcemails_instance;
$email_classes[ 'WCustom_Emails_' . $id . '_Email' ] = $wcemails_instance;

}
}
Expand All @@ -486,15 +490,16 @@ function wcemails_change_action_emails( $emails ) {

foreach ( $wcemails_email_details as $key => $details ) {

$enable = $details['enable'];
$enable = $details['enable'];
$order_action = $details['order_action'];

if ( 'on' == $enable && 'on' == $order_action ) {
if ( 'on' === $enable && 'on' === $order_action ) {

$id = $details['id'];
$title = isset( $details['title'] ) ? $details['title'] : '';
$id = $details['id'];
$title = isset( $details['title'] ) ? $details['title'] : '';

$emails[$id] = __( 'Resend ' . $title, 'woo-custom-emails' );
// translators: Resent email title
$emails[ $id ] = sprintf( __( 'Resend %s', 'woo-custom-emails' ), $title );

}
}
Expand All @@ -509,7 +514,9 @@ function wcemails_change_action_emails( $emails ) {
*/
function wcemails_woocommerce_check() {
if ( ! class_exists( 'WooCommerce' ) ) {
?><h2><?php _e( 'WooCommerce is not activated!', 'woo-custom-emails' );?></h2><?php
?>
<h2><?php _e( 'WooCommerce is not activated!', 'woo-custom-emails' ); ?></h2>
<?php
die();
}
}
Expand All @@ -531,20 +538,19 @@ function wcemails_filter_actions( $actions ) {

$enable = $details['enable'];

if ( 'on' == $enable ) {
if ( 'on' === $enable ) {

$from_status = isset( $details['from_status'] ) ? $details['from_status'] : array();
$to_status = isset( $details['to_status'] ) ? $details['to_status'] : array();
$from_status = isset( $details['from_status'] ) ? $details['from_status'] : array();
$to_status = isset( $details['to_status'] ) ? $details['to_status'] : array();

if ( ! empty( $from_status ) && ! empty( $to_status ) ) {
foreach ( $from_status as $k => $status ) {
$hook = 'woocommerce_order_status_' . $status . '_to_' . $to_status[ $k ];
if ( ! in_array( $hook, $actions ) ) {
if ( ! in_array( $hook, $actions, true ) ) {
$actions[] = 'woocommerce_order_status_' . $status . '_to_' . $to_status[ $k ];
}
}
}

}
}
}
Expand All @@ -563,21 +569,21 @@ function do_email_actions( $post_id, $post ) {
$wcemails_email_details = get_option( 'wcemails_email_details', array() );
if ( ! empty( $wcemails_email_details ) ) {
foreach ( $wcemails_email_details as $key => $details ) {
$enable = $details['enable'];
$enable = $details['enable'];
$order_action = $details['order_action'];
if ( 'on' == $enable && 'on' == $order_action ) {
$id = $details['id'];
if ( $id == $action ) {
if ( 'on' === $enable && 'on' === $order_action ) {
$id = $details['id'];
if ( $id === $action ) {
WC()->payment_gateways();
WC()->shipping();
WC()->mailer()->emails['WCustom_Emails_'.$id.'_Email']->trigger( $order->get_id(), $order );
}
WC()->mailer()->emails[ 'WCustom_Emails_' . $id . '_Email' ]->trigger( $order->get_id(), $order );
}
}
}
}
}
}

}
}

}

Expand Down
Loading