diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php
index 8ddbd1fc..88b54289 100644
--- a/includes/admin/core/class-admin-settings.php
+++ b/includes/admin/core/class-admin-settings.php
@@ -54,8 +54,6 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
add_action( 'admin_init', array( &$this, 'um_download_install_info' ) );
- // wpml translations
- add_filter( 'um_admin_settings_email_section_fields', array( &$this, 'um_admin_settings_email_section_fields' ), 10, 2 );
}
@@ -2173,37 +2171,5 @@ Use Only Cookies: external_integrations()->is_wpml_active() ) {
- global $sitepress;
-
- $default_language_code = $sitepress->get_locale_from_language_code( $sitepress->get_default_language() );
- $current_language_code = $sitepress->get_locale_from_language_code( $sitepress->get_current_language() );
-
- $lang = '';
-
- if ( $default_language_code != $current_language_code ) {
- $lang = '_' . $current_language_code;
- }
-
- $value_default = UM()->options()->get( $email_key . '_sub' );
- $value = UM()->options()->get( $email_key . '_sub' . $lang );
-
- $section_fields[2]['id'] = $email_key . '_sub' . $lang;
- $section_fields[2]['value'] = ! empty( $value ) ? $value : $value_default;
- }
-
- return $section_fields;
- }
}
}
\ No newline at end of file
diff --git a/includes/admin/core/list-tables/emails-list-table.php b/includes/admin/core/list-tables/emails-list-table.php
index b1dff113..d0d2e350 100644
--- a/includes/admin/core/list-tables/emails-list-table.php
+++ b/includes/admin/core/list-tables/emails-list-table.php
@@ -37,91 +37,6 @@ $order = ( isset( $_GET['order'] ) && 'asc' == strtolower( $_GET['order'] ) ) ?
if( ! class_exists( 'WP_List_Table' ) )
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
- class UM_WPML_Column_Extends{
- static function add_management_column($columns){
- global $sitepress;
- $new_columns = $columns;
- $active_languages = $sitepress->get_active_languages();
- $current_language = $sitepress->get_current_language();
- unset( $active_languages[ $current_language ] );
-
- if ( count( $active_languages ) > 0 ) {
- $flags_column = '';
- foreach ( $active_languages as $language_data ) {
- $flags_column .= '
';
- }
-
- $new_columns = array();
- foreach ( $columns as $column_key => $column_content ) {
- $new_columns[ $column_key ] = $column_content;
- if ( 'email' === $column_key && ! isset( $new_columns['icl_translations'] ) ) {
- $new_columns['icl_translations'] = $flags_column;
- }
- }
- }
-
- return $new_columns;
- }
-
- static function add_content_for_management_column( $item ) {
- global $sitepress;
- $html = '';
-
- $active_languages = $sitepress->get_active_languages();
- $current_language = $sitepress->get_current_language();
- unset( $active_languages[ $current_language ] );
- foreach ( $active_languages as $language_data ) {
- $html .= self::get_status_html( $item['key'], $language_data['code'] );
- }
- return $html;
- }
-
- static function get_status_html( $template, $code ) {
- global $sitepress;
- $status = 'add';
- $lang = '';
- $active_languages = $sitepress->get_active_languages();
- $translation = array(
- 'edit' => array( 'icon' => 'edit_translation.png', 'text' => sprintf(
- __( 'Edit the %s translation', 'sitepress' ),
- $active_languages[$code]['display_name'] ) ),
- 'add' => array( 'icon' => 'add_translation.png', 'text' => sprintf(
- __( 'Add translation to %s', 'sitepress' ),
- $active_languages[$code]['display_name']
- )
- )
- );
-
- $default_language_code = $sitepress->get_locale_from_language_code($sitepress->get_default_language());
- $current_language_code = $sitepress->get_locale_from_language_code($code);
-
- if ( $default_language_code != $current_language_code ) {
- $lang = $current_language_code.'/';
- }
- $template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' ) . $lang . $template . '.php';
-
- if ( file_exists( $template_path ) ) {
- $status = 'edit';
- }
-
- $link = add_query_arg( array( 'email' => $template, 'lang' => $code ) );
-
- return self::render_status_icon( $link, $translation[$status]['text'], $translation[$status]['icon'] );
- }
-
- static function render_status_icon( $link, $text, $img ) {
-
- $icon_html = '';
- $icon_html .= '
';
- $icon_html .= '';
-
- return $icon_html;
- }
- }
-
class UM_Emails_List_Table extends WP_List_Table {
var $no_items_message = '';
@@ -193,9 +108,6 @@ class UM_Emails_List_Table extends WP_List_Table {
}
$this->columns = $args;
- if ( UM()->external_integrations()->is_wpml_active() ) {
- $this->columns = UM_WPML_Column_Extends::add_management_column( $this->columns );
- }
return $this;
}
@@ -241,11 +153,7 @@ class UM_Emails_List_Table extends WP_List_Table {
}
function column_icl_translations( $item ) {
- if ( UM()->external_integrations()->is_wpml_active() ) {
- return UM_WPML_Column_Extends::add_content_for_management_column( $item );
- }
-
- return '';
+ return UM()->external_integrations()->wpml_column_content( $item );
}
@@ -264,12 +172,14 @@ $ListTable = new UM_Emails_List_Table( array(
$per_page = 20;
$paged = $ListTable->get_pagenum();
-$ListTable->set_columns( array(
- 'email' => __( 'Email', 'ultimate-member' ),
- 'recipients' => __( 'Recipient(s)', 'ultimate-member' ),
- 'configure' => '',
+$columns = apply_filters( 'um_email_templates_columns', array(
+ 'email' => __( 'Email', 'ultimate-member' ),
+ 'recipients' => __( 'Recipient(s)', 'ultimate-member' ),
+ 'configure' => '',
) );
+$ListTable->set_columns( $columns );
+
$emails = UM()->config()->email_notifications;
$ListTable->prepare_items();
diff --git a/includes/core/class-external-integrations.php b/includes/core/class-external-integrations.php
index 450d2730..421d149c 100644
--- a/includes/core/class-external-integrations.php
+++ b/includes/core/class-external-integrations.php
@@ -11,11 +11,16 @@ if ( ! class_exists( 'External_Integrations' ) ) {
* Access constructor.
*/
function __construct() {
+ //WPML translations
add_filter( 'um_get_core_page_filter', array( &$this, 'get_core_page_url' ), 10, 3 );
+ add_filter( 'um_admin_settings_email_section_fields', array( &$this, 'um_admin_settings_email_section_fields' ), 10, 2 );
+ add_filter( 'um_email_send_subject', array( &$this , 'um_email_send_subject' ), 10, 2 );
+ add_filter( 'um_locate_email_template', array( &$this , 'locate_email_template' ), 10, 2 );
+ add_filter( 'um_change_email_template_file', array( &$this , 'change_email_template_file' ), 10, 1 );
+ add_filter( 'um_email_templates_columns', array( &$this , 'add_email_templates_wpml_column' ), 10, 1 );
+
- //check the site's accessible more priority have Individual Post/Term Restriction settings
- add_action( 'template_redirect', array( &$this, 'template_redirect' ), 1000 );
}
@@ -60,6 +65,27 @@ if ( ! class_exists( 'External_Integrations' ) ) {
}
+ /**
+ * @param bool|string $current_code
+ *
+ * @return array
+ */
+ function get_languages_codes( $current_code = false ) {
+ global $sitepress;
+
+ $current_code = ! empty( $current_code ) ? $current_code : $sitepress->get_current_language();
+
+ $default = $sitepress->get_locale_from_language_code( $sitepress->get_default_language() );
+ $current = $sitepress->get_locale_from_language_code( $current_code );
+
+
+ return array(
+ 'default' => $default,
+ 'current' => $current
+ );
+ }
+
+
/**
* @param $url
* @param $slug
@@ -87,5 +113,212 @@ if ( ! class_exists( 'External_Integrations' ) ) {
}
+ /**
+ * Adding endings to the "Subject Line" field, depending on the language.
+ * @exaple welcome_email_sub_de_DE
+ *
+ * @param $section_fields
+ * @param $email_key
+ *
+ * @return array
+ */
+ function um_admin_settings_email_section_fields( $section_fields, $email_key ) {
+ if ( ! $this->is_wpml_active() ) {
+ return $section_fields;
+ }
+
+ $language_codes = $this->get_languages_codes();
+
+ $lang = '';
+ if ( $language_codes['default'] != $language_codes['current'] ) {
+ $lang = '_' . $language_codes['current'];
+ }
+
+ $value_default = UM()->options()->get( $email_key . '_sub' );
+ $value = UM()->options()->get( $email_key . '_sub' . $lang );
+
+ $section_fields[2]['id'] = $email_key . '_sub' . $lang;
+ $section_fields[2]['value'] = ! empty( $value ) ? $value : $value_default;
+
+ return $section_fields;
+ }
+
+
+ /**
+ * Adding endings to the "Subject Line" field, depending on the language.
+ *
+ * @param $subject
+ * @param $template
+ *
+ * @return string
+ */
+ function um_email_send_subject( $subject, $template ) {
+ if ( ! $this->is_wpml_active() ) {
+ return $subject;
+ }
+
+ $language_codes = $this->get_languages_codes();
+
+ $lang = '';
+ if ( $language_codes['default'] != $language_codes['current'] ) {
+ $lang = '_' . $language_codes['current'];
+ }
+
+ $value_default = UM()->options()->get( $template . '_sub' );
+ $value = UM()->options()->get( $template . '_sub' . $lang );
+
+ $subject = ! empty( $value ) ? $value : $value_default;
+
+ return $subject;
+ }
+
+
+ function locate_email_template( $template, $template_name ) {
+ if ( ! $this->is_wpml_active() ) {
+ return $template;
+ }
+
+ //WPML compatibility and multilingual email templates
+ $language_codes = $this->get_languages_codes();
+
+ $lang = '';
+ if ( $language_codes['default'] != $language_codes['current'] &&
+ UM()->config()->email_notifications[ $template_name ]['recipient'] != 'admin' ) {
+ $lang = $language_codes['current'] . '/';
+ }
+
+ // check if there is template at theme folder
+ $template = locate_template( array(
+ trailingslashit( 'ultimate-member/email' ) . $lang . $template_name . '.php',
+ trailingslashit( 'ultimate-member/email' ) . $template_name . '.php'
+ ) );
+
+ //if there isn't template at theme folder get template file from plugin dir
+ if ( ! $template ) {
+ $path = ! empty( UM()->mail()->path_by_slug[ $template_name ] ) ? UM()->mail()->path_by_slug[ $template_name ] : um_path . 'templates/email';
+ $template = trailingslashit( $path ) . $lang . $template_name . '.php';
+ }
+
+ return $template;
+ }
+
+
+ function change_email_template_file( $template ) {
+ if ( ! $this->is_wpml_active() ) {
+ return $template;
+ }
+
+ $language_codes = $this->get_languages_codes();
+
+ $lang = '';
+ if ( $language_codes['default'] != $language_codes['current'] ) {
+ $lang = $language_codes['current'] . '/';
+ }
+
+ return $lang . $template;
+ }
+
+
+
+ function add_email_templates_wpml_column( $columns ) {
+ if ( ! $this->is_wpml_active() ) {
+ return $columns;
+ }
+
+ global $sitepress;
+ $new_columns = $columns;
+ $active_languages = $sitepress->get_active_languages();
+ $current_language = $sitepress->get_current_language();
+ unset( $active_languages[ $current_language ] );
+
+ if ( count( $active_languages ) > 0 ) {
+ $flags_column = '';
+ foreach ( $active_languages as $language_data ) {
+ $flags_column .= '
';
+ }
+
+ $new_columns = array();
+ foreach ( $columns as $column_key => $column_content ) {
+ $new_columns[ $column_key ] = $column_content;
+ if ( 'email' === $column_key && ! isset( $new_columns['icl_translations'] ) ) {
+ $new_columns['icl_translations'] = $flags_column;
+ }
+ }
+ }
+
+ return $new_columns;
+ }
+
+
+ function wpml_column_content( $item ) {
+ if ( ! $this->is_wpml_active() ) {
+ return '';
+ }
+
+ global $sitepress;
+ $html = '';
+
+ $active_languages = $sitepress->get_active_languages();
+ $current_language = $sitepress->get_current_language();
+ unset( $active_languages[ $current_language ] );
+ foreach ( $active_languages as $language_data ) {
+ $html .= $this->get_status_html( $item['key'], $language_data['code'] );
+ }
+ return $html;
+ }
+
+
+ function get_status_html( $template, $code ) {
+ global $sitepress;
+ $status = 'add';
+
+ $active_languages = $sitepress->get_active_languages();
+ $translation = array(
+ 'edit' => array(
+ 'icon' => 'edit_translation.png',
+ 'text' => sprintf(
+ __( 'Edit the %s translation', 'sitepress' ),
+ $active_languages[$code]['display_name']
+ )
+ ),
+ 'add' => array(
+ 'icon' => 'add_translation.png',
+ 'text' => sprintf(
+ __( 'Add translation to %s', 'sitepress' ),
+ $active_languages[$code]['display_name']
+ )
+ )
+ );
+
+ $language_codes = $this->get_languages_codes();
+
+ $lang = '';
+ if ( $language_codes['default'] != $language_codes['current'] ) {
+ $lang = $language_codes['current'] . '/';
+ }
+
+ $template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' ) . $lang . $template . '.php';
+ if ( file_exists( $template_path ) ) {
+ $status = 'edit';
+ }
+
+ $link = add_query_arg( array( 'email' => $template, 'lang' => $code ) );
+
+ return $this->render_status_icon( $link, $translation[ $status ]['text'], $translation[ $status ]['icon'] );
+ }
+
+ function render_status_icon( $link, $text, $img ) {
+
+ $icon_html = '';
+ $icon_html .= '
';
+ $icon_html .= '';
+
+ return $icon_html;
+ }
+
+
}
}
\ No newline at end of file
diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php
index a020daa4..932e5339 100644
--- a/includes/core/class-mail.php
+++ b/includes/core/class-mail.php
@@ -16,8 +16,6 @@ if ( ! class_exists( 'Mail' ) ) {
add_filter( 'mandrill_nl2br', array( &$this, 'mandrill_nl2br' ) );
add_action( 'plugins_loaded', array( &$this, 'init_paths' ), 99 );
- //wpml translations
- add_filter( 'um_email_send_subject', array( &$this , 'um_email_send_subject'), 10 , 2 );
}
@@ -143,31 +141,15 @@ if ( ! class_exists( 'Mail' ) ) {
* @return string
*/
function locate_template( $template_name ) {
- //WPML compatibility and multilingual email templates
-
- global $sitepress;
-
- $default_language_code = $sitepress->get_locale_from_language_code($sitepress->get_default_language());
- $current_language_code = $sitepress->get_locale_from_language_code($sitepress->get_current_language());
-
- $lang = '';
-
- if ( $default_language_code != $current_language_code &&
- UM()->config()->email_notifications[$template_name]['recipient'] != 'admin' ) {
- $lang = $current_language_code.'/';
- }
-
-
// check if there is template at theme folder
$template = locate_template( array(
- trailingslashit( 'ultimate-member/email' ) . $lang . $template_name . '.php',
trailingslashit( 'ultimate-member/email' ) . $template_name . '.php'
) );
//if there isn't template at theme folder get template file from plugin dir
if ( ! $template ) {
$path = ! empty( $this->path_by_slug[ $template_name ] ) ? $this->path_by_slug[ $template_name ] : um_path . 'templates/email';
- $template = trailingslashit( $path ) . $lang . $template_name . '.php';
+ $template = trailingslashit( $path ) . $template_name . '.php';
}
// Return what we found.
@@ -184,24 +166,12 @@ if ( ! class_exists( 'Mail' ) ) {
* @return string
*/
function template_in_theme( $template_name, $html = false ) {
- //WPML compatibility and multilingual email templates
- global $sitepress;
-
- $default_language_code = $sitepress->get_locale_from_language_code($sitepress->get_default_language());
- $current_language_code = $sitepress->get_locale_from_language_code($sitepress->get_current_language());
-
- $lang = '';
-
- if ( $default_language_code != $current_language_code ) {
- $lang = $current_language_code.'/';
- }
-
-
+ $template_name_file = apply_filters( 'um_change_email_template_file', $template_name );
$ext = ! $html ? '.php' : '.html';
// check if there is template at theme folder
$template = locate_template( array(
- trailingslashit( 'ultimate-member/email' ) . $lang . $template_name . $ext
+ trailingslashit( 'ultimate-member/email' ) . $template_name_file . $ext
) );
// Return what we found.
@@ -219,23 +189,14 @@ if ( ! class_exists( 'Mail' ) ) {
* @return string
*/
function get_template_file( $location, $template_name, $html = false ) {
- global $sitepress;
$template_path = '';
-
- $default_language_code = $sitepress->get_locale_from_language_code($sitepress->get_default_language());
- $current_language_code = $sitepress->get_locale_from_language_code($sitepress->get_current_language());
-
- $lang = '';
-
- if ( $default_language_code != $current_language_code ) {
- $lang = $current_language_code.'/';
- }
+ $template_name_file = apply_filters( 'um_change_email_template_file', $template_name );
$ext = ! $html ? '.php' : '.html';
switch( $location ) {
case 'theme':
- $template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' ). $lang . $template_name . $ext;
+ $template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' ). $template_name_file . $ext;
break;
case 'plugin':
$path = ! empty( $this->path_by_slug[ $template_name ] ) ? $this->path_by_slug[ $template_name ] : um_path . 'templates/email';
@@ -243,7 +204,6 @@ if ( ! class_exists( 'Mail' ) ) {
break;
}
- //return apply_filters( 'wpc_client_template_location', $template_path, $location, $template_name, $path );
return $template_path;
}
@@ -321,35 +281,5 @@ if ( ! class_exists( 'Mail' ) ) {
wp_send_json_error( new \WP_Error( 'template_not_exists', __( 'Can not remove template from theme', 'ultimate-member' ) ) );
}
}
-
- /**
- * Adding endings to the "Subject Line" field, depending on the language.
- *
- * @param $subject
- * @param $template
- *
- * @return string
- */
- function um_email_send_subject( $subject, $template ){
- if ( UM()->external_integrations()->is_wpml_active() ) {
- global $sitepress;
-
- $default_language_code = $sitepress->get_locale_from_language_code( $sitepress->get_default_language() );
- $current_language_code = $sitepress->get_locale_from_language_code( $sitepress->get_current_language() );
-
- $lang = '';
-
- if ( $default_language_code != $current_language_code ) {
- $lang = '_' . $current_language_code;
- }
-
- $value_default = UM()->options()->get( $template . '_sub' );
- $value = UM()->options()->get( $template . '_sub' . $lang );
-
- $subject = ! empty( $value ) ? $value : $value_default;
- }
- return $subject;
- }
-
}
}
\ No newline at end of file