diff --git a/addons/bp_avatar_transfer.php b/addons/bp_avatar_transfer.php
deleted file mode 100644
index 6a690702..00000000
--- a/addons/bp_avatar_transfer.php
+++ /dev/null
@@ -1,99 +0,0 @@
-addon = $ultimatemember->addons['bp_avatar_transfer'];
- add_submenu_page('ultimatemember', $this->addon[0], $this->addon[0], 'manage_options', 'bp_avatar_transfer', array(&$this, 'content') );
-
- }
-
- function um_admin_addon_hook( $hook ) {
- global $ultimatemember;
- switch( $hook ) {
- case 'bp_avatar_transfer':
- if ( class_exists('BuddyPress') ) {
-
- $path = bp_core_avatar_upload_path() . '/avatars';
-
- $files = glob( $path . '/*');
- $i = 0;
- foreach( $files as $key ) {
- $q = (count(glob("$key/*")) === 0) ? 0 : 1;
- if ( $q == 1 ) {
- $photo = glob( $key . '/*');
- foreach( $photo as $file ) {
- if ( strstr( $file, 'bpfull' ) ) {
- $get_user_id = explode('/', $file);
- array_pop($get_user_id);
- $user_id = end($get_user_id);
- if ( !file_exists( $ultimatemember->files->upload_basedir . $user_id . '/profile_photo.jpg' ) ) {
- $ultimatemember->files->new_user( $user_id );
- copy( $file, $ultimatemember->files->upload_basedir . $user_id . '/profile_photo.jpg' );
- update_user_meta($user_id, 'profile_photo', 'profile_photo.jpg');
- $i++;
- }
- }
- }
- }
- }
-
- $this->content = '
Done. Process completed!
';
- $this->content .= $i . ' user(s) changed.';
-
- }
- break;
- }
- }
-
- function admin_init() {
- if ( isset( $_REQUEST['um-addon-hook'] ) ) {
- $hook = $_REQUEST['um-addon-hook'];
- do_action("um_admin_addon_hook", $hook);
- }
- }
-
- function content() {
-
- $this->process_link = add_query_arg('um-addon-hook','bp_avatar_transfer');
-
- ?>
-
-
-
-
Ultimate Member
-
-
addon[0]; ?>
-
- content ) ) {
- echo $this->content;
- } else { ?>
-
-
This tool allows you to move all custom user photos/avatars from BuddyPress to Ultimate Member platform. This can help you If you are switching from BuddyPress.
-
Depending on your users database, this could take a few moments. To start the process, click the following button.
-
-
Start transferring avatars
-
-
-
-
-
- addon = $ultimatemember->addons['generate_random_users'];
- add_submenu_page('ultimatemember', $this->addon[0], $this->addon[0], 'manage_options', 'generate_random_users', array(&$this, 'content') );
-
- }
-
- function um_admin_addon_hook( $hook ) {
- switch ( $hook ) {
- case 'generate_random_users':
- $json_url = "https://randomuser.me/api/";
-
- $arr_post_header = array( );
-
- if( isset( $_GET['gender'] ) ){
- $gender = $_GET['gender'];
- if( $gender != 'both' ){
- $json_url = add_query_arg('gender', $gender, $json_url );
- $arr_post_header['gender'] = $gender;
- }
- }
-
- if( isset( $_GET['nationality'] ) ){
- $nationality = implode(",", $_GET['nationality']);
- if( ! empty( $nationality ) ){
- $json_url = add_query_arg('nat', $nationality, $json_url );
- }
- $arr_post_header['nat'] = $nationality;
- }
-
- if( isset( $_GET['total_users'] ) ){
- $total_users = intval( $_GET['total_users'] );
- $json_url = add_query_arg('results', $total_users, $json_url );
- $arr_post_header['results'] = $total_users;
- }
-
-
- $response = wp_remote_get( $json_url, array('timeout' => 120 ) );
- $json = '';
-
- if( is_array($response) ) {
- if( isset( $response['body'] ) && ! empty( $response['body'] ) ){
- $json = json_decode( $response['body'] );
- }
- }
-
- if( is_wp_error( $response ) ){
- wp_die( $response->get_error_message() );
- }
-
- if( ! empty( $json ) ){
-
- remove_action('um_after_new_user_register', 'um_after_new_user_register', 10, 2);
-
- $failed_dummies = 0;
- //$default_role = um_get_option("default_role");
- $default_role = get_option( "default_role", true );
-
- foreach( $json->results as $dummy ){
-
- if( isset( $_GET['password'] ) && ! empty( $_GET['password'] ) ){
- $password = $_GET['password'];
- }else{
- $password = wp_generate_password( 8, false );
- }
-
- $site_url = @$_SERVER['SERVER_NAME'];
- $random_generate = wp_generate_password( 4, false );
-
- if( username_exists( $dummy->login->username ) ){
- $dummy->login->username = $dummy->login->username.'_'. $random_generate;
- }
-
- $dummy->login->email = $dummy->login->username."_dummy@{$site_url}";
-
- if( email_exists( $dummy->login->email ) ){
- $dummy->login->email = $dummy->login->username."_dummy_{$random_generate}@{$site_url}";
- }
-
- $userdata = array(
- 'display_name' => ucfirst( $dummy->name->first )." ".ucfirst( $dummy->name->last ),
- 'first_name' => ucfirst( $dummy->name->first ),
- 'last_name' => ucfirst( $dummy->name->last ),
- 'user_email' => $dummy->login->email,
- 'user_login' => $dummy->login->username,
- 'user_pass' => $password,
- );
-
- $user_id = wp_insert_user( $userdata );
-
- if( is_wp_error( $user_id ) ){
- $failed_dummies++;
- }
-
- $usermeta = array(
- 'synced_profile_photo' => $dummy->picture->large,
- 'gender' => ucfirst($dummy->gender),
- 'birth_date' => date("Y/m/d", strtotime( $dummy->dob) ),
- '_um_last_login' => date("Y/m/d", strtotime( $dummy->registered ) ),
- 'mobile_number' => $dummy->cell,
- 'phone_number' => $dummy->phone,
- 'synced_gravatar_hashed_id' => md5( strtolower( trim( $dummy->email ) ) ),
- 'account_status' => 'approved',
- '_um_profile_dummy' => true,
- 'role' => isset( $default_role ) ? $default_role: 'subscriber'
- );
-
- if( isset( $_GET['add_cover_photo'] ) && $_GET['add_cover_photo'] == 1 ){
-
- $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
- $color = $rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
-
- $usermeta['synced_cover_photo'] = 'http://placehold.it/650x350/'.$color.'/'.$color;
-
- }
-
- foreach ( $usermeta as $key => $value ) {
- update_user_meta( $user_id, $key, $value );
- }
-
-
- }
- wp_redirect( admin_url("admin.php?page=generate_random_users") ); exit;
- }
-
- break;
-
- case 'remove_random_users':
-
- $dummies = new WP_User_Query(
- array(
- 'fields' => array('ID'),
- 'meta_key' => '_um_profile_dummy',
- 'meta_value' => true,
- 'meta_compare' => '='
- )
- );
-
- if( $dummies->total_users > 0 ){
- foreach ( $dummies->get_results() as $dummy ) {
-
- if( isset( $dummy->ID ) ){
- wp_delete_user( $dummy->ID );
- }
-
- }
- }
-
- delete_option('um_generated_dumies');
- wp_redirect( admin_url("admin.php?page=generate_random_users") );
- exit;
-
- break;
-
- default:
-
- break;
- }
-
- }
-
- function admin_init() {
- if ( isset( $_REQUEST['um-addon-hook'] ) ) {
- $hook = $_REQUEST['um-addon-hook'];
- do_action("um_admin_addon_hook", $hook );
- }
- }
-
- function content() {
-
- ?>
-
-
-
-
Ultimate Member
-
-
addon[0]; ?>
-
- content ) ) {
- echo $this->content;
- } else { ?>
-
-
This tool allows you to add dummies as Ultimate Member users.
- array('ID'),
- 'meta_key' => '_um_profile_dummy',
- 'meta_value' => true,
- 'meta_compare' => '='
- )
- );
- ?>
- total_users > 0 ): ?>
-
-
-
-
-
-
-
- query('DELETE FROM '.$wpdb->usermeta.' WHERE meta_key = "synced_gravatar_hashed_id" ');
-
- $wpdb->query('INSERT INTO '.$wpdb->usermeta.'(user_id, meta_key, meta_value)
- SELECT ID, "synced_gravatar_hashed_id", MD5( LOWER( TRIM(user_email) ) ) FROM '.$wpdb->users.' ');
-
- return true;
- }
-
- function admin_menu() {
-
- global $ultimatemember;
- $this->addon = $ultimatemember->addons['gravatar_transfer'];
- add_submenu_page('ultimatemember', $this->addon[0], $this->addon[0], 'manage_options', 'gravatar_transfer', array(&$this, 'content') );
-
- }
-
- function um_admin_addon_hook( $hook ) {
- switch( $hook ) {
- case 'gravatar_transfer':
- if( $this->gravatar_hash() ){
- $this->content = 'Done. Process completed!
';
- $result = count_users();
- $this->content .= $result['total_users'] . ' user(s) changed.';
- }
- break;
- }
- }
-
- function admin_init() {
- if ( isset( $_REQUEST['um-addon-hook'] ) ) {
- $hook = $_REQUEST['um-addon-hook'];
- do_action("um_admin_addon_hook", $hook);
- }
- }
-
- function content() {
-
- $this->process_link = add_query_arg('um-addon-hook','gravatar_transfer');
-
- ?>
-
-
-
-
Ultimate Member
-
-
addon[0]; ?>
-
- content ) ) {
- echo $this->content;
- } else { ?>
-
-
This tool allows you to add gravatars to Ultimate Member users. This can help you to link gravatar photos to user accounts with their email address.
-
Depending on your users database, this could take a few moments. To start the process, click the following button.
-
-
Start adding gravatars
-
-
-
-
-
- span {
+ color: #444;
+ margin: 0 0 15px 0;
+ display: inline-block;
+}
+
+.email_template_wrapper.in_theme .copy_button_overlay {
+ display: none !important;
+}
+*/
+
+.email_template_wrapper .reset_email_template {
+ display: none;
+}
+
+.email_template_wrapper.in_theme .reset_email_template {
+ display: block;
}
\ No newline at end of file
diff --git a/includes/admin/assets/js/um-admin-settings.js b/includes/admin/assets/js/um-admin-settings.js
index 27533528..654c92a9 100644
--- a/includes/admin/assets/js/um-admin-settings.js
+++ b/includes/admin/assets/js/um-admin-settings.js
@@ -1,4 +1,42 @@
jQuery( document ).ready( function() {
+ /**
+ * Email templates
+ */
+ /*jQuery( 'body' ).on( 'click', '.copy_email_template', function() {
+ var obj = jQuery(this);
+
+ jQuery.ajax({
+ url: php_data.copy_email_template,
+ type: 'POST',
+ data: { email_key : obj.parents('.email_template_wrapper').data('key') },
+ success: function(data){
+ obj.parents('.email_template_wrapper').addClass('in_theme');
+ },
+ error: function(data){
+ alert('Something went wrong');
+ }
+ });
+ });*/
+
+ jQuery( 'body' ).on( 'click', '.reset_email_template', function() {
+ var obj = jQuery(this);
+
+ jQuery.ajax({
+ url: php_data.delete_email_template,
+ type: 'POST',
+ data: { email_key : obj.parents('.email_template_wrapper').data('key') },
+ success: function(data){
+ obj.parents('.email_template_wrapper').removeClass('in_theme');
+ },
+ error: function(data){
+ alert('Something went wrong');
+ }
+ });
+ });
+
+
+
+
/**
* Licenses
*/
diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php
index e97a137c..6ed2cc59 100644
--- a/includes/admin/core/class-admin-enqueue.php
+++ b/includes/admin/core/class-admin-enqueue.php
@@ -169,6 +169,7 @@ if ( ! class_exists( 'Admin_Enqueue' ) ) {
wp_enqueue_script( 'um_admin_settings' );
$localize_data = array(
+ 'delete_email_template' => UM()->get_ajax_route( 'um\core\Mail', 'delete_email_template' ),
'onbeforeunload_text' => __( 'Are sure, maybe some settings not saved', 'ultimate-member' ),
'texts' => array(
'remove' => __( 'Remove', 'ultimate-member' ),
diff --git a/includes/admin/core/class-admin-forms.php b/includes/admin/core/class-admin-forms.php
index dc608e38..3e6ac554 100644
--- a/includes/admin/core/class-admin-forms.php
+++ b/includes/admin/core/class-admin-forms.php
@@ -888,5 +888,58 @@ if ( ! class_exists( 'Admin_Forms' ) ) {
return $html;
}
+
+ function render_email_template( $field_data ) {
+ if ( empty( $field_data['id'] ) )
+ return false;
+
+ $id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
+
+ $class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
+ $class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field';
+
+ $data = array(
+ 'field_id' => $field_data['id']
+ );
+
+ $data_attr = '';
+ foreach ( $data as $key => $value ) {
+ $data_attr .= " data-{$key}=\"{$value}\" ";
+ }
+
+ $name = $field_data['id'];
+ $name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
+
+ $default = isset( $field_data['default'] ) ? $field_data['default'] : '';
+ $value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
+
+ ob_start(); ?>
+
+
+
+
+
+ $name,
+ 'textarea_rows' => 20,
+ 'editor_height' => 425,
+ 'wpautop' => false,
+ 'media_buttons' => false,
+ 'editor_class' => $class
+ )
+ ); ?>
+
+
+
+ $value ) {
$edd_action = '';
$license_key = '';
- if ( empty( $this->previous_licenses[$key] ) && ! empty( $value ) ) {
+ if ( empty( $this->previous_licenses[$key] ) && ! empty( $value ) || ( ! empty( $this->previous_licenses[$key] ) && ! empty( $value ) && $this->previous_licenses[$key] != $value ) ) {
$edd_action = 'activate_license';
$license_key = $value;
} elseif ( ! empty( $this->previous_licenses[$key] ) && empty( $value ) ) {
@@ -1567,12 +1570,19 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
if ( empty( $email_key ) || empty( $emails[$email_key] ) )
return $section;
+ $in_theme = UM()->mail()->template_in_theme( $email_key );
+
$section_fields = array(
+ array(
+ 'id' => 'um_email_template',
+ 'type' => 'hidden',
+ 'value' => $email_key,
+ ),
array(
'id' => $email_key . '_on',
'type' => 'checkbox',
'label' => $emails[$email_key]['title'],
- 'tooltip' => $emails[$email_key]['description'],
+ 'tooltip' => $emails[$email_key]['description'],
'value' => UM()->um_get_option( $email_key . '_on' ),
'default' => UM()->um_get_default( $email_key . '_on' ),
),
@@ -1586,13 +1596,14 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
'default' => UM()->um_get_default( $email_key . '_sub' ),
),
array(
- 'id' => $email_key,
- 'type' => 'wp_editor',
- 'label' => __( 'Message Body','ultimate-member' ),
- 'conditional' => array( $email_key . '_on', '=', 1 ),
- 'tooltip' => __('This is the content of the e-mail','ultimate-member'),
- 'value' => UM()->um_get_option( $email_key ),
+ 'id' => $email_key,
+ 'type' => 'email_template',
+ 'label' => __( 'Message Body','ultimate-member' ),
+ 'conditional' => array( $email_key . '_on', '=', 1 ),
+ 'tooltip' => __('This is the content of the e-mail','ultimate-member'),
+ 'value' => UM()->mail()->get_email_template( $email_key ),
'default' => UM()->um_get_default( $email_key ),
+ 'in_theme' => $in_theme
),
);
@@ -2267,168 +2278,31 @@ Use Only Cookies: ' . $data['label'] . ' ';
+ $template = $settings['um_email_template'];
+ $content = stripslashes( $settings[$template] );
+ $theme_template_path = UM()->mail()->get_template_file( 'theme', $template );
- $option_value = UM()->um_get_option( $data['id'] );
- $default = ! empty( $data['default'] ) ? $data['default'] : UM()->um_get_default( $data['id'] );
-
- switch ( $data['type'] ) {
- case 'hidden':
- $value = ! empty( $option_value ) ? $option_value : $default;
-
- if ( empty( $data['is_option'] ) )
- $html .= ' ';
- else
- $html .= ' ';
-
- break;
- case 'text':
- $value = ! empty( $option_value ) ? $option_value : $default;
- $field_length = ! empty( $data['size'] ) ? $data['size'] : 'um-long-field';
-
- $html .= ' ';
- break;
- case 'multi-text':
- $values = ! empty( $option_value ) ? $option_value : $default;
-
- $html .= '' . $data['add_text'] . ' ';
- break;
- case 'textarea':
- $value = ! empty( $option_value ) ? $option_value : $default;
- $field_length = ! empty( $data['size'] ) ? $data['size'] : 'um-long-field';
-
- $html .= '';
- break;
- case 'wp_editor':
- $value = ! empty( $option_value ) ? $option_value : $default;
-
- ob_start();
- wp_editor( $value,
- 'um_options_' . $data['id'],
- array(
- 'textarea_name' => 'um_options[' . $data['id'] . ']',
- 'textarea_rows' => 20,
- 'editor_height' => 425,
- 'wpautop' => false,
- 'media_buttons' => false,
- 'editor_class' => 'um-option-field'
- )
- );
-
- $html .= ob_get_clean();
- break;
- case 'checkbox':
- $value = ( '' !== $option_value ) ? $option_value : $default;
-
- $html .= ' ';
- break;
- case 'multi-checkbox':
- $value = ( '' !== $option_value ) ? $option_value : $default;
- $columns = ! empty( $data['columns'] ) ? $data['columns'] : 1;
-
- $per_column = ceil( count( $data['options'] ) / $columns );
-
- $html .= '';
-
- $current_option = 1;
- $iter = 1;
- foreach ( $data['options'] as $key=>$option ) {
- if ( $current_option == 1 )
- $html .= '
';
-
- $html .= '
- ' . $option . ' ';
-
- if ( $current_option == $per_column || $iter == count( $data['options'] ) ) {
- $current_option = 1;
- $html .= '
';
- } else {
- $current_option++;
- }
-
- $iter++;
- }
-
- $html .= '
';
-
- break;
- case 'selectbox':
- $value = ! empty( $option_value ) ? $option_value : $default;
-
- $html .= '';
- foreach ( $data['options'] as $key=>$option ) {
- if ( ! empty( $data['multi'] ) ) {
- $html .= '' . $option . ' ';
- } else {
- $html .= '' . $option . ' ';
- }
- }
- $html .= ' ';
-
- break;
- case 'media':
- $upload_frame_title = ! empty( $data['upload_frame_title'] ) ? $data['upload_frame_title'] : __( 'Select media', 'ultimate-member' );
- $value = ! empty( $option_value ) ? $option_value : $default;
-
- $image_id = ! empty( $value['id'] ) ? $value['id'] : '';
- $image_width = ! empty( $value['width'] ) ? $value['width'] : '';
- $image_height = ! empty( $value['height'] ) ? $value['height'] : '';
- $image_thumbnail = ! empty( $value['thumbnail'] ) ? $value['thumbnail'] : '';
- $image_url = ! empty( $value['url'] ) ? $value['url'] : '';
-
- $data_default = ! empty( $default ) ? 'data-default="' . esc_attr( $default['url'] ) .'"' : '';
-
- $html .= '';
- break;
+ $in_theme = UM()->mail()->template_in_theme( $template );
+ if ( ! $in_theme ) {
+ UM()->mail()->copy_email_template( $template );
}
- if ( ! empty( $data['description'] ) )
- $html .= '' . $data['description'] . '
';
+ $fp = fopen( $theme_template_path, "w" );
+ $result = fputs( $fp, $content );
+ fclose( $fp );
- $html .= ' ';
+ if ( $result !== false ) {
+ unset( $settings['um_email_template'] );
+ unset( $settings[$template] );
+ }
- return $html;
+ return $settings;
}
-
}
}
\ No newline at end of file
diff --git a/includes/admin/core/packages/2.0.php b/includes/admin/core/packages/2.0.php
index 739b0d95..c32f3fc4 100644
--- a/includes/admin/core/packages/2.0.php
+++ b/includes/admin/core/packages/2.0.php
@@ -910,7 +910,7 @@ um_remove_option( 'profile_header_icon_hcolor' );
//remove duplicates for UM Pages settings
delete_option( 'um_core_pages' );
-
+global $wpdb;
//UM Roles to WP Roles
//all UM Roles from post type
@@ -1109,6 +1109,9 @@ foreach ( $all_taxonomies as $key => $taxonomy ) {
//for metadata for all UM forms
+//"use_global" meta change to "_use_custom_settings"
+
+//also update for forms metadata where "member" or "admin"
$forms = get_posts( array(
'post_type' => 'um_form',
'numberposts' => -1,
@@ -1124,5 +1127,10 @@ foreach ( $forms as $form_id ) {
update_post_meta( $form_id, "_um_{$form_type}_use_custom_settings", $use_custom_settings );
delete_post_meta( $form_id, "_um_{$form_type}_use_globals" );
+
+ $role = get_post_meta( $form_id, "_um_{$form_type}_role", true );
+ if ( $role ) {
+ update_post_meta( $form_id, "_um_{$form_type}_role", 'um_' . $role );
+ }
}
}
\ No newline at end of file
diff --git a/includes/admin/templates/role/register.php b/includes/admin/templates/role/register.php
index c54a117f..e24c80e7 100644
--- a/includes/admin/templates/role/register.php
+++ b/includes/admin/templates/role/register.php
@@ -66,7 +66,7 @@
'type' => 'textarea',
'name' => '_um_checkmail_message',
'label' => __( 'Personalize the custom message', 'ultimate-member' ),
- 'value' => ! empty( $role['_um_checkmail_message'] ) ? $role['_um_checkmail_message'] : '',
+ 'value' => ! empty( $role['_um_checkmail_message'] ) ? $role['_um_checkmail_message'] : __('Thank you for registering. Before you can login we need you to activate your account by clicking the activation link in the email we just sent you.','ultimate-member'),
'conditional' => array( '_um_checkmail_action', '=', 'show_message' )
),
array(
@@ -104,7 +104,7 @@
'type' => 'textarea',
'name' => '_um_pending_message',
'label' => __( 'Personalize the custom message', 'ultimate-member' ),
- 'value' => ! empty( $role['_um_pending_message'] ) ? $role['_um_pending_message'] : '',
+ 'value' => ! empty( $role['_um_pending_message'] ) ? $role['_um_pending_message'] : __('Thank you for applying for membership to our site. We will review your details and send you an email letting you know whether your application has been successful or not.','ultimate-member'),
'conditional' => array( '_um_pending_action', '=', 'show_message' )
),
array(
diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php
index 87e6d6c1..e8424407 100644
--- a/includes/core/class-mail.php
+++ b/includes/core/class-mail.php
@@ -7,21 +7,29 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Mail' ) ) {
class Mail {
+ var $email_templates = array();
+
function __construct() {
- add_filter('mandrill_nl2br', array(&$this, 'mandrill_nl2br') );
+ $this->path_by_slug = apply_filters( 'um_email_templates_path_by_slug', array() );
- $this->force_plain_text = '';
+ //mandrill compatibility
+ add_filter( 'mandrill_nl2br', array( &$this, 'mandrill_nl2br' ) );
}
- /***
- *** @mandrill compatibility
- ***/
- function mandrill_nl2br($nl2br, $message = '') {
+
+ /**
+ * Mandrill compatibility
+ *
+ * @param $nl2br
+ * @param string $message
+ * @return bool
+ */
+ function mandrill_nl2br( $nl2br, $message = '' ) {
// text emails
- if ( !um_get_option('email_html') ) {
+ if ( ! um_get_option( 'email_html' ) ) {
$nl2br = true;
}
@@ -29,103 +37,248 @@ if ( ! class_exists( 'Mail' ) ) {
}
- /***
- *** @check If template exists
- ***/
- function email_template( $template, $args = array() ) {
- $lang = '';
- $template_path = false;
- if ( function_exists('icl_get_current_language') ) {
- if ( icl_get_current_language() != 'en' ) {
- $lang = icl_get_current_language() . '/';
- }
- } else {
+ /**
+ * Send Email function
+ *
+ * @param string $email
+ * @param null $template
+ * @param array $args
+ */
+ function send( $email, $template, $args = array() ) {
- $lang = get_locale();
- $arr_english_lang = array('en','en_US','en_NZ','en_ZA','en_AU','en_GB');
-
- if( in_array( $lang, $arr_english_lang ) || strpos( $lang , 'en_' ) > -1 || empty( $lang ) || $lang == 0 ){
- $lang = '';
- } else {
- $lang .= '/';
- }
-
- }
-
- if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/email/' . $lang . $template . '.html' ) ) {
- $template_path = get_stylesheet_directory() . '/ultimate-member/templates/email/' . $lang . $template . '.html';
- } else {
- if ( isset( $args['path'] ) ) {
- $path = $args['path'] . $lang;
- } else {
- $path = um_path . 'templates/email/' . $lang;
- }
-
- if ( file_exists( $path . $template . '.html' ) ) {
- $template_path = $path . $template . '.html';
- }
- }
-
- return apply_filters( 'um_email_template_path', $template_path, $template, $args );
-
- }
-
- /***
- *** @sends an email to any user
- ***/
- function send( $email, $template=null, $args = array() ) {
-
- if ( !$template ) return;
+ if ( ! is_email( $email ) ) return;
if ( um_get_option( $template . '_on' ) != 1 ) return;
- if ( !is_email( $email ) ) return;
$this->attachments = null;
$this->headers = 'From: '. um_get_option('mail_from') .' <'. um_get_option('mail_from_addr') .'>' . "\r\n";
- $this->subject = um_get_option( $template . '_sub' );
- $this->subject = um_convert_tags( $this->subject, $args );
+ $this->subject = um_convert_tags( um_get_option( $template . '_sub' ), $args );
- if ( isset( $args['admin'] ) || isset( $args['plain_text'] ) ) {
- $this->force_plain_text = 'forced';
- }
-
-
- add_filter( 'wp_mail_content_type', array(&$this, 'set_content_type') );
- // HTML e-mail or text
- if ( um_get_option('email_html') && $this->email_template( $template, $args ) ) {
- $this->message = file_get_contents( $this->email_template( $template, $args ) );
- } else {
- $this->message = um_get_option( $template );
- }
-
- // Convert tags in body
- $this->message = um_convert_tags( $this->message, $args );
+ $this->message = $this->prepare_template( $template, $args );
+ add_filter( 'wp_mail_content_type', array( &$this, 'set_content_type' ) );
// Send mail
wp_mail( $email, $this->subject, $this->message, $this->headers, $this->attachments );
- remove_filter( 'wp_mail_content_type', array(&$this, 'set_content_type') );
-
- // reset globals
- $this->force_plain_text = '';
-
+ remove_filter( 'wp_mail_content_type', array( &$this, 'set_content_type' ) );
}
- /***
- *** @maybe sending HTML emails
- ***/
+
+ /**
+ * @param $slug
+ * @param $args
+ * @return bool|string
+ */
+ function get_email_template( $slug, $args = array() ) {
+
+ $located = $this->locate_template( $slug );
+
+ $located = apply_filters( 'um_email_template_path', $located, $slug, $args );
+
+ if ( ! file_exists( $located ) ) {
+ _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $located ), '2.1' );
+ return false;
+ }
+
+ ob_start();
+
+ do_action( 'um_before_email_template_part', $slug, $located, $args );
+
+ include( $located );
+
+ do_action( 'um_after_email_template_part', $slug, $located, $args );
+
+ return ob_get_clean();
+ }
+
+
+ /**
+ * Prepare email template to send
+ *
+ * @param $slug
+ * @param $args
+ * @return mixed|string
+ */
+ function prepare_template( $slug, $args = array() ) {
+ ob_start(); ?>
+
+
+
+
+ >
+
+ get_email_template( $slug, $args ); ?>
+
+
+
+
+ -1 || empty( $lang ) || $lang == 0 ) {
+ $lang = '';
+ } else {
+ $lang .= '/';
+ }
+
+ // check if there is template at theme folder
+ $template = locate_template( array(
+ trailingslashit( 'ultimate-member/email' ) . $lang . $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';
+ }
+
+ // Return what we found.
+ return apply_filters( 'um_locate_email_template', $template, $template_name );
+ }
+
+
+ /**
+ * Locate a template and return the path for inclusion.
+ *
+ * @access public
+ * @param string $template_name
+ * @return string
+ */
+ function template_in_theme( $template_name ) {
+ //WPML compatibility and multilingual email templates
+ $lang = get_locale();
+ $arr_english_lang = array( 'en', 'en_US', 'en_NZ', 'en_ZA', 'en_AU', 'en_GB' );
+
+ if ( in_array( $lang, $arr_english_lang ) || strpos( $lang , 'en_' ) > -1 || empty( $lang ) || $lang == 0 ) {
+ $lang = '';
+ } else {
+ $lang .= '/';
+ }
+
+ // check if there is template at theme folder
+ $template = locate_template( array(
+ trailingslashit( 'ultimate-member/email' ) . $lang . $template_name . '.php'
+ ) );
+
+ // Return what we found.
+ return ! $template ? false : true;
+ }
+
+
+ /**
+ * Method returns expected path for template
+ *
+ * @access public
+ * @param string $location
+ * @param string $template_name
+ * @return string
+ */
+ function get_template_file( $location, $template_name ) {
+ $template_path = '';
+ switch( $location ) {
+ case 'theme':
+ $template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' ) . $template_name . '.php';
+ break;
+ case 'plugin':
+ $path = ! empty( $this->path_by_slug[ $template_name ] ) ? $this->path_by_slug[ $template_name ] : um_path . 'templates/email';
+ $template_path = trailingslashit( $path ) . $template_name . '.php';
+ break;
+ }
+
+ //return apply_filters( 'wpc_client_template_location', $template_path, $location, $template_name, $path );
+ return $template_path;
+ }
+
+
+ /**
+ * Set email content type
+ *
+ *
+ * @param $content_type
+ * @return string
+ */
function set_content_type( $content_type ) {
- return 'text/html';
- /*if ( $this->force_plain_text == 'forced' )
- return 'text/plain';
-
- if ( um_get_option( 'email_html' ) )
+ if ( um_get_option( 'email_html' ) ) {
return 'text/html';
+ } else {
+ return 'text/plain';
+ }
- return 'text/plain';*/
}
+ /**
+ * Ajax copy template to the theme
+ *
+ * @param bool $template
+ * @return bool
+ */
+ function copy_email_template( $template = false ) {
+
+ $in_theme = $this->template_in_theme( $template );
+ if ( $in_theme ) {
+ return false;
+ }
+
+ $plugin_template_path = $this->get_template_file( 'plugin', $template );
+ $theme_template_path = $this->get_template_file( 'theme', $template );
+
+ $temp_path = str_replace( trailingslashit( get_stylesheet_directory() ), '', $theme_template_path );
+ $temp_path = str_replace( '/', DIRECTORY_SEPARATOR, $temp_path );
+ $folders = explode( DIRECTORY_SEPARATOR, $temp_path );
+ $folders = array_splice( $folders, 0, count( $folders ) - 1 );
+ $cur_folder = '';
+ $theme_dir = trailingslashit( get_stylesheet_directory() );
+
+ foreach ( $folders as $folder ) {
+ $prev_dir = $cur_folder;
+ $cur_folder .= $folder . DIRECTORY_SEPARATOR;
+ if ( ! is_dir( $theme_dir . $cur_folder ) && wp_is_writable( $theme_dir . $prev_dir ) ) {
+ mkdir( $theme_dir . $cur_folder, 0777 );
+ }
+ }
+
+ if ( copy( $plugin_template_path, $theme_template_path ) ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ function delete_email_template() {
+ $template = $_POST['email_key'];
+
+ $in_theme = $this->template_in_theme( $template );
+ if ( ! $in_theme ) {
+ wp_send_json_error( new \WP_Error( 'template_in_theme', __( 'Template does not exists in theme', 'ultimate-member' ) ) );
+ }
+
+ $theme_template_path = $this->get_template_file( 'theme', $template );
+
+ if ( unlink( $theme_template_path ) ) {
+ wp_send_json_success();
+ } else {
+ wp_send_json_error( new \WP_Error( 'template_not_exists', __( 'Can not remove template from theme', 'ultimate-member' ) ) );
+ }
+ }
+
}
}
\ No newline at end of file
diff --git a/includes/core/class-user.php b/includes/core/class-user.php
index d0d45e3c..90352d8b 100644
--- a/includes/core/class-user.php
+++ b/includes/core/class-user.php
@@ -746,9 +746,9 @@ if ( ! class_exists( 'User' ) ) {
*
*
*/
- function pending(){
- $this->set_status('awaiting_admin_review');
- UM()->mail()->send( um_user('user_email'), 'pending_email' );
+ function pending() {
+ $this->set_status( 'awaiting_admin_review' );
+ UM()->mail()->send( um_user( 'user_email' ), 'pending_email' );
}
/**
diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php
index 8ef527f5..938d6354 100644
--- a/includes/core/um-actions-register.php
+++ b/includes/core/um-actions-register.php
@@ -84,7 +84,9 @@
*/
add_action('um_post_registration_listener', 'um_post_registration_listener', 10, 2);
function um_post_registration_listener( $user_id, $args ) {
- if ( um_user('status') != 'pending' ) {
+ um_fetch_user( $user_id );
+
+ if ( um_user( 'status' ) != 'pending' ) {
UM()->mail()->send( um_admin_email(), 'notification_new_user', array( 'admin' => true ) );
} else {
UM()->mail()->send( um_admin_email(), 'notification_review', array( 'admin' => true ) );
diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php
index 788c0d8a..8becf14a 100644
--- a/includes/um-short-functions.php
+++ b/includes/um-short-functions.php
@@ -5,37 +5,6 @@
return 'text/html';
}
- function UM_Mail( $user_id_or_email = 1, $subject_line = 'Email Subject', $template, $path = null, $args = array() ) {
-
- if ( absint( $user_id_or_email ) ) {
- $user = get_userdata( $user_id_or_email );
- $email = $user->user_email;
- } else {
- $email = $user_id_or_email;
- }
-
- $headers = 'From: '. um_get_option('mail_from') .' <'. um_get_option('mail_from_addr') .'>' . "\r\n";
- $attachments = null;
-
- if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/email/' . get_locale() . '/' . $template . '.html' ) ) {
- $path_to_email = get_stylesheet_directory() . '/ultimate-member/templates/email/' . get_locale() . '/' . $template . '.html';
- } else if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/email/' . $template . '.html' ) ) {
- $path_to_email = get_stylesheet_directory() . '/ultimate-member/templates/email/' . $template . '.html';
- } else {
- $path_to_email = $path . $template . '.html';
- }
-
- if ( um_get_option('email_html') ) {
- $message = file_get_contents( $path_to_email );
- add_filter( 'wp_mail_content_type', 'um_mail_content_type' );
- } else {
- $message = ( um_get_option('email-' . $template ) ) ? um_get_option('email-' . $template ) : 'Untitled';
- }
-
- $message = um_convert_tags( $message, $args );
- wp_mail( $email, $subject_line, $message, $headers, $attachments );
- }
-
/***
*** @Trim string by char length
***/
@@ -568,7 +537,8 @@
***/
function um_is_temp_upload( $url ) {
- $url = realpath( $url );
+ if ( filter_var( $url, FILTER_VALIDATE_URL ) === false )
+ $url = realpath( $url );
if ( ! $url )
return false;
diff --git a/templates/email/approved_email.html b/templates/email/approved_email.php
similarity index 92%
rename from templates/email/approved_email.html
rename to templates/email/approved_email.php
index 490ec602..57dacfdc 100644
--- a/templates/email/approved_email.html
+++ b/templates/email/approved_email.php
@@ -1,6 +1,6 @@
-
-
+
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/templates/email/changedpw_email.html b/templates/email/changedpw_email.php
similarity index 90%
rename from templates/email/changedpw_email.html
rename to templates/email/changedpw_email.php
index 635c9f14..2c57ec00 100644
--- a/templates/email/changedpw_email.html
+++ b/templates/email/changedpw_email.php
@@ -1,5 +1,6 @@
-
-
+
@@ -26,7 +27,4 @@
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/templates/email/checkmail_email.html b/templates/email/checkmail_email.php
similarity index 90%
rename from templates/email/checkmail_email.html
rename to templates/email/checkmail_email.php
index e29ddb09..93123c9d 100644
--- a/templates/email/checkmail_email.html
+++ b/templates/email/checkmail_email.php
@@ -1,5 +1,6 @@
-
-
+
@@ -26,7 +27,4 @@
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/templates/email/deletion_email.html b/templates/email/deletion_email.php
similarity index 89%
rename from templates/email/deletion_email.html
rename to templates/email/deletion_email.php
index 3bc2ce79..4b3e1392 100644
--- a/templates/email/deletion_email.html
+++ b/templates/email/deletion_email.php
@@ -1,5 +1,6 @@
-
-
+
@@ -24,7 +25,4 @@
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/templates/email/inactive_email.html b/templates/email/inactive_email.php
similarity index 88%
rename from templates/email/inactive_email.html
rename to templates/email/inactive_email.php
index cbcdb3e1..03709968 100644
--- a/templates/email/inactive_email.html
+++ b/templates/email/inactive_email.php
@@ -1,6 +1,6 @@
-
-
+
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/templates/email/notification_deletion.php b/templates/email/notification_deletion.php
new file mode 100644
index 00000000..6341bfba
--- /dev/null
+++ b/templates/email/notification_deletion.php
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
{display_name} has just deleted their {site_name} account.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/templates/email/notification_new_user.php b/templates/email/notification_new_user.php
new file mode 100644
index 00000000..f7ca5dc9
--- /dev/null
+++ b/templates/email/notification_new_user.php
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
{display_name} has just created an account on {site_name}.
+
+
To view their profile click here: {user_profile_link}
+
+
+
+
Here is the submitted registration form:
+ {submitted_registration}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/templates/email/notification_review.php b/templates/email/notification_review.php
new file mode 100644
index 00000000..edcba4cb
--- /dev/null
+++ b/templates/email/notification_review.php
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
{display_name} has just applied for membership to {site_name} and is waiting to be reviewed.
+
+
To review this member please click the following link: {user_profile_link}
+
+
+
+
Here is the submitted registration form:
+ {submitted_registration}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/templates/email/pending_email.html b/templates/email/pending_email.php
similarity index 88%
rename from templates/email/pending_email.html
rename to templates/email/pending_email.php
index 57688aa9..2da53fe9 100644
--- a/templates/email/pending_email.html
+++ b/templates/email/pending_email.php
@@ -1,6 +1,6 @@
-
-
+
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/templates/email/rejected_email.html b/templates/email/rejected_email.php
similarity index 89%
rename from templates/email/rejected_email.html
rename to templates/email/rejected_email.php
index 2a7b16af..41fcc782 100644
--- a/templates/email/rejected_email.html
+++ b/templates/email/rejected_email.php
@@ -1,5 +1,6 @@
-
-
+
@@ -24,7 +25,4 @@
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/templates/email/resetpw_email.html b/templates/email/resetpw_email.php
similarity index 91%
rename from templates/email/resetpw_email.html
rename to templates/email/resetpw_email.php
index c28691d3..30177ad2 100644
--- a/templates/email/resetpw_email.html
+++ b/templates/email/resetpw_email.php
@@ -1,5 +1,6 @@
-
-
+
@@ -26,7 +27,4 @@
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/templates/email/welcome_email.html b/templates/email/welcome_email.php
similarity index 89%
rename from templates/email/welcome_email.html
rename to templates/email/welcome_email.php
index 2de878b8..ab7e8457 100644
--- a/templates/email/welcome_email.html
+++ b/templates/email/welcome_email.php
@@ -1,5 +1,6 @@
-
-
+
@@ -27,7 +28,4 @@
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file