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

Issues/1718 #1719

Merged
merged 5 commits into from
May 22, 2017
Merged
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
42 changes: 23 additions & 19 deletions includes/admin/emails/abstract-email-notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,26 @@ abstract class Give_Email_Notification {
* @var array
*/
public $config = array(
'id' => '',
'label' => '',
'description' => '',
'has_recipient_field' => false,
'recipient_group_name' => '',
'notification_status' => 'disabled',
'notification_status_editable' => true,
'notices' => array(),
'content_type_editable' => true,
'has_preview' => true,
'has_preview_header' => true,
'preview_email_tags_values' => array(),
'email_tag_context' => 'all',
'form_metabox_setting' => true,
'content_type' => '',
'email_template' => '',
'default_email_subject' => '',
'default_email_message' => '',
'id' => '',
'label' => '',
'description' => '',
'has_recipient_field' => false,
'recipient_group_name' => '',
'notification_status' => 'disabled',
'notification_status_editable' => true,
'notices' => array(),
'content_type_editable' => true,
'has_preview' => true,
'has_preview_header' => true,
'preview_email_tags_values' => array(),
'email_tag_context' => 'all',
'form_metabox_setting' => true,
'content_type' => '',
'email_template' => '',
'default_email_subject' => '',
'default_email_message' => '',
// This setting page will appear under core setting.
'show_on_emails_setting_page' => true,
);

/**
Expand Down Expand Up @@ -185,7 +187,9 @@ private function setup_filters() {
}

// Setup setting fields.
add_filter( 'give_get_settings_emails', array( $this, 'add_setting_fields' ), 10, 2 );
if( $this->config['show_on_emails_setting_page'] ) {
add_filter( 'give_get_settings_emails', array( $this, 'add_setting_fields' ), 10, 2 );
}

if ( $this->config['form_metabox_setting'] ) {
add_filter(
Expand Down
13 changes: 10 additions & 3 deletions includes/admin/emails/class-email-notification-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,20 @@ public function prepare_items() {
// Set columns.
$columns = $this->get_columns();
$hidden = array();
$email_notifications = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable, $this->get_primary_column_name() );

// Set email notifications.
$email_notifications = $this->email_notifications->get_email_notifications();
$totalItems = count( $email_notifications );
$this->items = $email_notifications;
/* @var Give_Email_Notification $email_notification */
foreach ( $this->email_notifications->get_email_notifications() as $email_notification ) {
if ( Give_Email_Notification_Util::is_show_on_emails_setting_page( $email_notification ) ) {
$email_notifications[] = $email_notification;
}
}

$totalItems = count( $email_notifications );
$this->items = $email_notifications;
$this->set_pagination_args( array(
'total_items' => $totalItems,
'per_page' => $this->per_page,
Expand Down
14 changes: 14 additions & 0 deletions includes/admin/emails/class-email-notification-util.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ public static function is_email_preview( Give_Email_Notification $email ) {
return $email->config['has_preview'];
}

/**
* Check if email notification setting appear on emails setting page or not.
*
* @since 2.0
* @access public
*
* @param Give_Email_Notification $email
*
* @return bool
*/
public static function is_show_on_emails_setting_page( Give_Email_Notification $email ){
return $email->config['show_on_emails_setting_page'];
}


/**
* Check email active or not.
Expand Down
19 changes: 10 additions & 9 deletions includes/admin/emails/class-email-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ public function init() {

/* @var Give_Email_Notification $email */
foreach ( $this->get_email_notifications() as $email ) {
// Add section.
add_filter( 'give_get_sections_emails', array( $email, 'add_section' ) );
add_filter( "give_hide_section_{$email->config['id']}_on_emails_page", array( $email, 'hide_section' ) );

if ( ! Give_Email_Notification_Util::is_email_preview_has_header( $email ) ) {
continue;
// Setup email section.
if( Give_Email_Notification_Util::is_show_on_emails_setting_page( $email ) ) {
add_filter( 'give_get_sections_emails', array( $email, 'add_section' ) );
add_filter( "give_hide_section_{$email->config['id']}_on_emails_page", array( $email, 'hide_section' ) );
}

add_action( "give_{$email->config['id']}_email_preview", array( $this, 'email_preview_header' ) );
add_filter( "give_{$email->config['id']}_email_preview_data", array( $this, 'email_preview_data' ) );
add_filter( "give_{$email->config['id']}_email_preview_message", array( $this, 'email_preview_message' ), 1, 2 );
// Setup email preview.
if ( Give_Email_Notification_Util::is_email_preview_has_header( $email ) ) {
add_action( "give_{$email->config['id']}_email_preview", array( $this, 'email_preview_header' ) );
add_filter( "give_{$email->config['id']}_email_preview_data", array( $this, 'email_preview_data' ) );
add_filter( "give_{$email->config['id']}_email_preview_message", array( $this, 'email_preview_message' ), 1, 2 );
}
}
}

Expand Down