From cb504d635e3a3d04e368d0f5a5ded1f5a799b88c Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Mon, 30 Oct 2017 15:01:50 +0200 Subject: [PATCH 01/41] - prepare to 2.0 release; --- includes/class-dependencies.php | 46 ++++++++++++++++----------------- ultimate-member.php | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/includes/class-dependencies.php b/includes/class-dependencies.php index df163cd0..421de273 100644 --- a/includes/class-dependencies.php +++ b/includes/class-dependencies.php @@ -20,29 +20,29 @@ if ( ! class_exists( 'um\Dependencies' ) ) { * @var array */ public $ext_required_version = array( - 'bbpress' => '2.0-beta1', - 'followers' => '2.0-beta1', - 'friends' => '2.0-beta1', - 'groups' => '2.0-beta1', - 'instagram' => '2.0-beta1', - 'invitations' => '2.0-beta1', - 'mailchimp' => '2.0-beta1', - 'messaging' => '2.0-beta1', - 'mycred' => '2.0-beta1', - 'notices' => '2.0-beta1', - 'notifications' => '2.0-beta1', - 'online' => '2.0-beta1', - 'private-content' => '2.0-beta1', - 'profile-completeness' => '2.0-beta1', - 'recaptcha' => '2.0-beta1', - 'reviews' => '2.0-beta1', - 'social-activity' => '2.0-beta1', - 'social-login' => '2.0-beta1', - 'terms-conditions' => '2.0-beta1', - 'user-location' => '2.0-beta1', - 'user-tags' => '2.0-beta1', - 'verified-users' => '2.0-beta1', - 'woocommerce' => '2.0-beta1', + 'bbpress' => '2.0', + 'followers' => '2.0', + 'friends' => '2.0', + 'groups' => '2.0', + 'instagram' => '2.0', + 'invitations' => '2.0', + 'mailchimp' => '2.0', + 'messaging' => '2.0', + 'mycred' => '2.0', + 'notices' => '2.0', + 'notifications' => '2.0', + 'online' => '2.0', + 'private-content' => '2.0', + 'profile-completeness' => '2.0', + 'recaptcha' => '2.0', + 'reviews' => '2.0', + 'social-activity' => '2.0', + 'social-login' => '2.0', + 'terms-conditions' => '2.0', + 'user-location' => '2.0', + 'user-tags' => '2.0', + 'verified-users' => '2.0', + 'woocommerce' => '2.0', ); /** diff --git a/ultimate-member.php b/ultimate-member.php index 797c2d7b..60d30255 100644 --- a/ultimate-member.php +++ b/ultimate-member.php @@ -3,7 +3,7 @@ Plugin Name: Ultimate Member Plugin URI: http://ultimatemember.com/ Description: The easiest way to create powerful online communities and beautiful user profiles with WordPress -Version: 2.0-beta1 +Version: 2.0 Author: Ultimate Member Author URI: http://ultimatemember.com/ Text Domain: ultimate-member From b2a67974bdf40ba3b94a9c8e27967e339daba1d4 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Tue, 31 Oct 2017 15:49:48 +0200 Subject: [PATCH 02/41] - hotfix, removed PHP notices and warnings; --- includes/admin/core/um-admin-filters-fields.php | 5 +++++ includes/admin/templates/dashboard/cache.php | 4 ++-- includes/core/um-actions-form.php | 3 +++ includes/core/um-actions-profile.php | 14 +++++++++----- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/includes/admin/core/um-admin-filters-fields.php b/includes/admin/core/um-admin-filters-fields.php index 69034286..8b625c0d 100644 --- a/includes/admin/core/um-admin-filters-fields.php +++ b/includes/admin/core/um-admin-filters-fields.php @@ -7,22 +7,27 @@ function um_admin_pre_save_field_to_form( $array ){ unset( $array['conditions'] ); if ( isset($array['conditional_field']) && !empty( $array['conditional_action'] ) && !empty( $array['conditional_operator'] ) ) { + $array['conditional_value'] = ! empty( $array['conditional_value'] ) ? $array['conditional_value'] : ''; $array['conditions'][] = array( $array['conditional_action'], $array['conditional_field'], $array['conditional_operator'], $array['conditional_value'] ); } if ( isset($array['conditional_field1']) && !empty( $array['conditional_action1'] ) && !empty( $array['conditional_operator1'] ) ) { + $array['conditional_value1'] = ! empty( $array['conditional_value1'] ) ? $array['conditional_value1'] : ''; $array['conditions'][] = array( $array['conditional_action1'], $array['conditional_field1'], $array['conditional_operator1'], $array['conditional_value1'] ); } if ( isset($array['conditional_field2']) && !empty( $array['conditional_action2'] ) && !empty( $array['conditional_operator2'] ) ) { + $array['conditional_value2'] = ! empty( $array['conditional_value2'] ) ? $array['conditional_value2'] : ''; $array['conditions'][] = array( $array['conditional_action2'], $array['conditional_field2'], $array['conditional_operator2'], $array['conditional_value2'] ); } if ( isset($array['conditional_field3']) && !empty( $array['conditional_action3'] ) && !empty( $array['conditional_operator3'] ) ) { + $array['conditional_value3'] = ! empty( $array['conditional_value3'] ) ? $array['conditional_value3'] : ''; $array['conditions'][] = array( $array['conditional_action3'], $array['conditional_field3'], $array['conditional_operator3'], $array['conditional_value3'] ); } if ( isset($array['conditional_field4']) && !empty( $array['conditional_action4'] ) && !empty( $array['conditional_operator4'] ) ) { + $array['conditional_value4'] = ! empty( $array['conditional_value4'] ) ? $array['conditional_value4'] : ''; $array['conditions'][] = array( $array['conditional_action4'], $array['conditional_field4'], $array['conditional_operator4'], $array['conditional_value4'] ); } diff --git a/includes/admin/templates/dashboard/cache.php b/includes/admin/templates/dashboard/cache.php index 779c25af..e9161ec9 100644 --- a/includes/admin/templates/dashboard/cache.php +++ b/includes/admin/templates/dashboard/cache.php @@ -3,9 +3,9 @@ $all_options = wp_load_alloptions(); $count = 0; -foreach( $all_options as $k => $v ) { +foreach ( $all_options as $k => $v ) { - if ( strstr( $k, 'um_cache_userdata_' ) ) { + if ( strstr( $k, 'um_cache_userdata_' ) !== false ) { $count++; } diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index 7e49972a..4ce3f273 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -150,6 +150,9 @@ foreach ( $array['conditions'] as $condition ) { list( $visibility, $parent_key, $op, $parent_value ) = $condition; + if ( ! isset( $args[ $parent_key ] ) ) + continue; + $cond_value = ( $fields[ $parent_key ]['type'] == 'radio' ) ? $args[ $parent_key ][0] : $args[ $parent_key ]; if ( $visibility == 'hide' ) { diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index 3c3a09db..a5ee6d2c 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -748,14 +748,17 @@ * @param integer $user_id * @param array $arr_files */ - add_action( "um_before_user_upload", "um_before_user_upload", 10, 2 ); function um_before_user_upload( $user_id, $arr_files ) { um_fetch_user( $user_id ); - foreach ($arr_files as $key => $filename) { - if (um_user( $key )) { - if (basename( $filename ) != basename( um_user( $key ) ) || in_array( $old_filename, array( basename( um_user( $key ) ), basename( $filename ) ) ) || $filename == 'empty_file') { - $old_filename = um_user( $key ); + foreach ( $arr_files as $key => $filename ) { + if ( um_user( $key ) ) { + $old_filename = um_user( $key ); + + if ( basename( $filename ) != basename( um_user( $key ) ) || + in_array( $old_filename, array( basename( um_user( $key ) ), basename( $filename ) ) ) || + $filename == 'empty_file' ) { + $path = UM()->files()->upload_basedir; delete_user_meta( $user_id, $old_filename ); if (file_exists( $path . $user_id . '/' . $old_filename )) { @@ -765,3 +768,4 @@ } } } + add_action( "um_before_user_upload", "um_before_user_upload", 10, 2 ); \ No newline at end of file From a8d45b1824f98253eb012b006d605d4a5d5bd851 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Wed, 1 Nov 2017 13:08:28 +0200 Subject: [PATCH 03/41] - fixed email notifications for extensions; --- includes/class-functions.php | 2 +- includes/core/class-mail.php | 499 ++++++++++++++++++----------------- 2 files changed, 253 insertions(+), 248 deletions(-) diff --git a/includes/class-functions.php b/includes/class-functions.php index c3362c4d..77a58143 100644 --- a/includes/class-functions.php +++ b/includes/class-functions.php @@ -192,7 +192,7 @@ if ( ! class_exists( 'UM_Functions' ) ) { * * @access public * @param string $template_name - * @param string $path (default: '') + * @param string $basename (default: '') * @param array $t_args (default: array()) * @param bool $echo * diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php index 25342733..f33bbf5a 100644 --- a/includes/core/class-mail.php +++ b/includes/core/class-mail.php @@ -5,295 +5,300 @@ namespace um\core; if ( ! defined( 'ABSPATH' ) ) exit; if ( ! class_exists( 'Mail' ) ) { - class Mail { + class Mail { - var $email_templates = array(); + var $email_templates = array(); + var $path_by_slug = array(); - function __construct() { + function __construct() { - $this->path_by_slug = apply_filters( 'um_email_templates_path_by_slug', array() ); + //mandrill compatibility + add_filter( 'mandrill_nl2br', array( &$this, 'mandrill_nl2br' ) ); + add_action( 'plugins_loaded', array( &$this, 'init_paths' ) ); - //mandrill compatibility - add_filter( 'mandrill_nl2br', array( &$this, 'mandrill_nl2br' ) ); + } - } + function init_paths() { + $this->path_by_slug = apply_filters( 'um_email_templates_path_by_slug', $this->path_by_slug ); + } - /** - * Mandrill compatibility - * - * @param $nl2br - * @param string $message - * @return bool - */ - function mandrill_nl2br( $nl2br, $message = '' ) { - // text emails - if ( ! um_get_option( 'email_html' ) ) { - $nl2br = true; - } + /** + * Mandrill compatibility + * + * @param $nl2br + * @param string $message + * @return bool + */ + function mandrill_nl2br( $nl2br, $message = '' ) { - return $nl2br; + // text emails + if ( ! um_get_option( 'email_html' ) ) { + $nl2br = true; + } - } + return $nl2br; + } - /** - * Send Email function - * - * @param string $email - * @param null $template - * @param array $args - */ - function send( $email, $template, $args = array() ) { - if ( ! is_email( $email ) ) return; - if ( um_get_option( $template . '_on' ) != 1 ) return; + /** + * Send Email function + * + * @param string $email + * @param null $template + * @param array $args + */ + function send( $email, $template, $args = array() ) { - $this->attachments = null; - $this->headers = 'From: '. um_get_option('mail_from') .' <'. um_get_option('mail_from_addr') .'>' . "\r\n"; + if ( ! is_email( $email ) ) return; + if ( um_get_option( $template . '_on' ) != 1 ) return; - $this->subject = um_convert_tags( um_get_option( $template . '_sub' ), $args ); + $this->attachments = null; + $this->headers = 'From: '. um_get_option('mail_from') .' <'. um_get_option('mail_from_addr') .'>' . "\r\n"; - $this->message = $this->prepare_template( $template, $args ); + $this->subject = um_convert_tags( um_get_option( $template . '_sub' ), $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' ) ); - } + $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' ) ); + } - /** - * @param $slug - * @param $args - * @return bool|string - */ - function get_email_template( $slug, $args = array() ) { - $located = $this->locate_template( $slug ); + /** + * @param $slug + * @param $args + * @return bool|string + */ + function get_email_template( $slug, $args = array() ) { - $located = apply_filters( 'um_email_template_path', $located, $slug, $args ); + $located = $this->locate_template( $slug ); - if ( ! file_exists( $located ) ) { - _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $located ), '2.1' ); - return false; - } + $located = apply_filters( 'um_email_template_path', $located, $slug, $args ); - ob_start(); + if ( ! file_exists( $located ) ) { + _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $located ), '2.1' ); + return false; + } - do_action( 'um_before_email_template_part', $slug, $located, $args ); + ob_start(); - include( $located ); + do_action( 'um_before_email_template_part', $slug, $located, $args ); - do_action( 'um_after_email_template_part', $slug, $located, $args ); + include( $located ); - return ob_get_clean(); - } + 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(); - if ( um_get_option( 'email_html' ) ) { ?> + /** + * Prepare email template to send + * + * @param $slug + * @param $args + * @return mixed|string + */ + function prepare_template( $slug, $args = array() ) { + ob_start(); - - + if ( um_get_option( 'email_html' ) ) { ?> - > + + - get_email_template( $slug, $args ); ?> + > - - + get_email_template( $slug, $args ); ?> - + - echo $this->get_email_template( $slug, $args ); + get_email_template( $slug, $args ); - $message = ob_get_clean(); + } - // Convert tags in email template - return um_convert_tags( $message, $args ); - } + $message = ob_get_clean(); + // Convert tags in email template + return um_convert_tags( $message, $args ); + } - /** - * Locate a template and return the path for inclusion. - * - * @access public - * @param string $template_name - * @return string - */ - function locate_template( $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 .= '/'; - } + /** + * Locate a template and return the path for inclusion. + * + * @access public + * @param string $template_name + * @return string + */ + function locate_template( $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' ); - // check if there is template at theme folder - $template = locate_template( array( - trailingslashit( 'ultimate-member/email' ) . $lang . $template_name . '.php' - ) ); + if ( in_array( $lang, $arr_english_lang ) || strpos( $lang , 'en_' ) > -1 || empty( $lang ) || $lang == 0 ) { + $lang = ''; + } else { + $lang .= '/'; + } - //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 - * @param bool $html - * @return string - */ - function template_in_theme( $template_name, $html = false ) { - //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 .= '/'; - } - - $ext = ! $html ? '.php' : '.html'; - - // check if there is template at theme folder - $template = locate_template( array( - trailingslashit( 'ultimate-member/email' ) . $lang . $template_name . $ext - ) ); - - // Return what we found. - return ! $template ? false : true; - } - - - /** - * Method returns expected path for template - * - * @access public - * @param string $location - * @param string $template_name - * @param bool $html - * @return string - */ - function get_template_file( $location, $template_name, $html = false ) { - $template_path = ''; - - $ext = ! $html ? '.php' : '.html'; - - switch( $location ) { - case 'theme': - $template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' ) . $template_name . $ext; - 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 . $ext; - 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 ) { - - if ( um_get_option( 'email_html' ) ) { - return 'text/html'; - } else { - 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' ) ) ); - } - } - - } + // 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 + * @param bool $html + * @return string + */ + function template_in_theme( $template_name, $html = false ) { + //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 .= '/'; + } + + $ext = ! $html ? '.php' : '.html'; + + // check if there is template at theme folder + $template = locate_template( array( + trailingslashit( 'ultimate-member/email' ) . $lang . $template_name . $ext + ) ); + + // Return what we found. + return ! $template ? false : true; + } + + + /** + * Method returns expected path for template + * + * @access public + * @param string $location + * @param string $template_name + * @param bool $html + * @return string + */ + function get_template_file( $location, $template_name, $html = false ) { + $template_path = ''; + + $ext = ! $html ? '.php' : '.html'; + + switch( $location ) { + case 'theme': + $template_path = trailingslashit( get_stylesheet_directory() . '/ultimate-member/email' ) . $template_name . $ext; + 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 . $ext; + 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 ) { + + if ( um_get_option( 'email_html' ) ) { + return 'text/html'; + } else { + 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 From c8278a7599e24fc5a61897419a925095904b3b4d Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Thu, 2 Nov 2017 13:59:57 +0200 Subject: [PATCH 04/41] - fixed modal window wp_editor; --- includes/admin/core/class-admin-metabox.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/admin/core/class-admin-metabox.php b/includes/admin/core/class-admin-metabox.php index ebf6a0fa..c385ea17 100644 --- a/includes/admin/core/class-admin-metabox.php +++ b/includes/admin/core/class-admin-metabox.php @@ -856,7 +856,7 @@ if ( ! class_exists( 'Admin_Metabox' ) ) { } // needed on forms only - if ( !isset( $this->is_loaded ) && isset( $screen->id ) && strstr( $screen->id, 'um_form' ) ) { + if ( ! isset( $this->is_loaded ) && isset( $screen->id ) && strstr( $screen->id, 'um_form' ) ) { $settings['textarea_rows'] = 8; @@ -868,6 +868,7 @@ if ( ! class_exists( 'Admin_Metabox' ) ) { wp_editor( '', 'um_editor_new', $settings ); echo ''; + $this->is_loaded = true; } } From 90c2063dbfceabe430b5c1d9fe8591f24650d284 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Thu, 2 Nov 2017 18:13:50 +0200 Subject: [PATCH 05/41] - fixed allow tracking option; - fixed hide wp-admin bar; --- includes/admin/core/class-admin-settings.php | 6 +++--- includes/admin/core/class-admin-upgrade.php | 18 +++++++++--------- includes/core/um-actions-wpadmin.php | 2 +- includes/um-short-functions.php | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 89e1719c..44676b87 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -1121,11 +1121,11 @@ if ( ! class_exists( 'Admin_Settings' ) ) { ) ), array( - 'id' => 'allow_tracking', + 'id' => 'um_allow_tracking', 'type' => 'checkbox', 'label' => __( 'Allow Tracking','ultimate-member' ), - 'value' => UM()->um_get_option( 'allow_tracking' ), - 'default' => UM()->um_get_default( 'allow_tracking' ), + 'value' => UM()->um_get_option( 'um_allow_tracking' ), + 'default' => UM()->um_get_default( 'um_allow_tracking' ), ), array( 'id' => 'uninstall_on_delete', diff --git a/includes/admin/core/class-admin-upgrade.php b/includes/admin/core/class-admin-upgrade.php index 7bfcb0de..884e423b 100644 --- a/includes/admin/core/class-admin-upgrade.php +++ b/includes/admin/core/class-admin-upgrade.php @@ -56,17 +56,17 @@ if ( ! class_exists( 'Admin_Upgrade' ) ) { function set_update_versions() { $update_versions = array(); $handle = opendir( $this->packages_dir ); - while ( false !== ( $filename = readdir( $handle ) ) ) { + if ( $handle ) { + while ( false !== ( $filename = readdir( $handle ) ) ) { + if ( $filename != '.' && $filename != '..' ) + $update_versions[] = preg_replace( '/(.*?)\.php/i', '$1', $filename ); + } + closedir( $handle ); - if ( $filename != '.' && $filename != '..' ) - $update_versions[] = preg_replace( '/(.*?)\.php/i', '$1', $filename ); + usort( $update_versions, array( &$this, 'version_compare_sort' ) ); - } - closedir( $handle ); - - usort( $update_versions, array( &$this, 'version_compare_sort' ) ); - - $this->update_versions = $update_versions; + $this->update_versions = $update_versions; + } } diff --git a/includes/core/um-actions-wpadmin.php b/includes/core/um-actions-wpadmin.php index 03b7c3c4..dbf8dba2 100644 --- a/includes/core/um-actions-wpadmin.php +++ b/includes/core/um-actions-wpadmin.php @@ -120,7 +120,7 @@ return $content; } - add_filter( 'show_admin_bar' , 'um_control_admin_bar'); + add_filter( 'show_admin_bar' , 'um_control_admin_bar', 9999, 1 ); /*** *** @fix permission for admin bar diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php index 4bd94cc6..85b25b21 100644 --- a/includes/um-short-functions.php +++ b/includes/um-short-functions.php @@ -1388,7 +1388,7 @@ function um_get_default_avatar_uri() { $uri = um_get_option( 'default_avatar' ); $uri = !empty( $uri['url'] ) ? $uri['url'] : ''; - if (!$uri) { + if ( ! $uri ) { $uri = um_url . 'assets/img/default_avatar.jpg'; } else { From 1be33b1c4af9c93cb4d19b6d318b0737be0ca0b8 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Mon, 6 Nov 2017 15:28:07 +0200 Subject: [PATCH 06/41] - fixed add/edit user/profile UM section at backend; - fixed submit of profile/registration page at frontend with user roles; - fixed notifications about change role; --- includes/core/class-builtin.php | 8 +- includes/core/class-fields.php | 22 ++++- includes/core/class-form.php | 16 ++-- includes/core/class-rest-api.php | 34 ++++--- includes/core/class-roles-capabilities.php | 4 +- includes/core/class-user.php | 106 ++++++++++++++------- 6 files changed, 128 insertions(+), 62 deletions(-) diff --git a/includes/core/class-builtin.php b/includes/core/class-builtin.php index e8220e8d..372e17ad 100644 --- a/includes/core/class-builtin.php +++ b/includes/core/class-builtin.php @@ -542,7 +542,13 @@ if ( ! class_exists( 'Builtin' ) ) { ***/ function set_predefined_fields() { - $um_roles = UM()->roles()->get_roles( false, array( 'admin' ) ); + global $wp_roles; + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, get_option( 'um_roles' ) ); + $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); + + $um_roles = UM()->roles()->get_roles( false, $exclude_roles ); $profile_privacy = apply_filters('um_profile_privacy_options', array( __('Everyone','ultimate-member'), __('Only me','ultimate-member') ) ); diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index fc025cb0..05224530 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -1909,9 +1909,15 @@ } // role field - if ($form_key == 'role') { - $roles = UM()->roles()->get_roles( false, array( 'administrator' ) ); - if (isset( $options )) + if ( $form_key == 'role' ) { + global $wp_roles; + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, get_option( 'um_roles' ) ); + $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); + + $roles = UM()->roles()->get_roles( false, $exclude_roles ); + if ( isset( $options ) ) $options = array_intersect( $options, $roles ); else $options = $roles; @@ -2098,7 +2104,13 @@ // role field if ($form_key == 'role') { - $options = UM()->roles()->get_roles( false, array( 'administrator' ) ); + global $wp_roles; + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, get_option( 'um_roles' ) ); + $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); + + $options = UM()->roles()->get_roles( false, $exclude_roles ); /*var_dump( UM()->roles()->get_roles() ); global $wpdb; @@ -2158,7 +2170,7 @@ $option_value = apply_filters( 'um_field_non_utf8_value', $option_value ); - $output .= 'is_radio_checked( $key, $option_value, $data )) { $output .= 'checked'; diff --git a/includes/core/class-form.php b/includes/core/class-form.php index d75a8052..de6ec7b6 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -170,19 +170,25 @@ if ( ! class_exists( 'Form' ) ) { $this->post_form = array_merge( $this->form_data, $this->post_form ); - - if( isset( $this->form_data['custom_fields'] ) && strstr( $this->form_data['custom_fields'], 'role_' ) ){ // Secure selected role + if ( isset( $this->form_data['custom_fields'] ) && strstr( $this->form_data['custom_fields'], 'role_' ) ) { // Secure selected role $custom_field_roles = $this->custom_field_roles( $this->form_data['custom_fields'] ); - if( ! empty( $_POST['role'] ) ){ + if ( ! empty( $_POST['role'] ) ) { $role = $_POST['role']; if( is_array( $_POST['role'] ) ){ $role = current( $_POST['role'] ); } - if ( /*isset( $custom_field_roles ) && is_array( $custom_field_roles ) &&*/ ! empty( $role ) && ! in_array( $role , $custom_field_roles ) ) { + global $wp_roles; + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, get_option( 'um_roles' ) ); + $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); + + if ( ! empty( $role ) && + ( ! in_array( $role , $custom_field_roles ) || in_array( $role , $exclude_roles ) ) ) { wp_die( __( 'This is not possible for security reasons.','ultimate-member') ); } @@ -190,8 +196,6 @@ if ( ! class_exists( 'Form' ) ) { $this->post_form['submitted']['role'] = $role; } - - } elseif ( isset( $this->post_form['mode'] ) && $this->post_form['mode'] == 'register' ) { $role = $this->assigned_role( $this->form_id ); $this->post_form['role'] = $role; diff --git a/includes/core/class-rest-api.php b/includes/core/class-rest-api.php index 2a2980c6..2a9d35f3 100644 --- a/includes/core/class-rest-api.php +++ b/includes/core/class-rest-api.php @@ -23,7 +23,7 @@ if ( ! class_exists( 'REST_API' ) ) { add_action( 'template_redirect', array( $this, 'process_query' ), -1 ); add_filter( 'query_vars', array( $this, 'query_vars' ) ); - add_action( 'um_user_profile_section', array( $this, 'user_key_field' ), 2 ); + add_filter( 'um_user_profile_additional_fields', array( $this, 'user_key_field' ), 3, 2 ); add_action( 'personal_options_update', array( $this, 'update_key' ) ); add_action( 'edit_user_profile_update', array( $this, 'update_key' ) ); @@ -278,7 +278,11 @@ if ( ! class_exists( 'REST_API' ) ) { break; case 'role': $wp_user_object = new \WP_User( $id ); - $wp_user_object->set_role( $value ); + $old_roles = $wp_user_object->roles; + $wp_user_object->set_role( $value ); + + do_action( 'um_after_member_role_upgrade', array( $value ), $old_roles ); + $response['success'] = __('User role has been changed.','ultimate-member'); break; default: @@ -598,21 +602,26 @@ if ( ! class_exists( 'REST_API' ) ) { die(); } - /** - * Modify User Profile - */ - function user_key_field( $user ) { - + /** + * Modify User Profile Page fields + * + * @param $content + * @param $user + * @return string + */ + function user_key_field( $content, $user ) { if ( empty( $user ) ) - return; + return $content; if( ! isset( $user->ID ) ) - return; + return $content; if ( current_user_can( 'edit_users' ) && current_user_can( 'edit_user', $user->ID ) ) { $user = get_userdata( $user->ID ); - ?> - + + ob_start(); ?> + +
@@ -636,6 +645,9 @@ if ( ! class_exists( 'REST_API' ) ) {
roles ); $role_keys = array_map( function( $item ) { - return 'um_' . $item; - }, $role_keys ); + return 'um_' . $item; + }, $role_keys ); $roles = array_intersect( array_values( $user->roles ), $role_keys ); if ( ! empty( $roles ) ) { diff --git a/includes/core/class-user.php b/includes/core/class-user.php index 182b0aa1..fbcf1ce8 100644 --- a/includes/core/class-user.php +++ b/includes/core/class-user.php @@ -36,6 +36,7 @@ if ( ! class_exists( 'User' ) ) { 'user_pass', 'user_password', 'display_name', + 'role', ); $this->target_id = null; @@ -52,16 +53,16 @@ if ( ! class_exists( 'User' ) ) { add_action('um_when_role_is_set', array(&$this, 'remove_cache') ); add_action('um_when_status_is_set', array(&$this, 'remove_cache') ); - add_action( 'show_user_profile', array( $this, 'community_role_edit' ) ); - add_action( 'edit_user_profile', array( $this, 'community_role_edit' ) ); - - add_action( 'user_new_form', array( $this, 'secondary_role_display' ) ); - add_action( 'edit_user_profile', array( $this, 'secondary_role_display' ) ); - add_action( 'show_user_profile', array( $this, 'secondary_role_display' ) ); + add_action( 'show_user_profile', array( $this, 'profile_form_additional_section' ), 10 ); + add_action( 'user_new_form', array( $this, 'profile_form_additional_section' ), 10 ); + add_action( 'edit_user_profile', array( $this, 'profile_form_additional_section' ), 10 ); + add_filter( 'um_user_profile_additional_fields', array( $this, 'secondary_role_field' ), 1, 2 ); + //on every update of user profile (hook from wp_update_user) add_action( 'profile_update', array( &$this, 'profile_update' ), 10, 2 ); // user_id and old_user_data - add_action( 'edit_user_profile_update', array( &$this, 'profile_update' ), 10, 1 ); + //on user update profile page + //add_action( 'edit_user_profile_update', array( &$this, 'profile_update' ), 10, 1 ); add_action( 'user_register', array( &$this, 'user_register_via_admin' ), 10, 1 ); add_action( 'user_register', array( &$this, 'set_gravatar' ), 11, 1 ); @@ -228,28 +229,63 @@ if ( ! class_exists( 'User' ) ) { } - function profile_update( $user_id ) { - // Bail if no user ID was passed - if ( empty( $user_id ) ) - return; + /** + * On wp_update_user function complete + * + * @param int $user_id + * @param \WP_User $old_data + */ + function profile_update( $user_id, $old_data ) { + // Bail if no user ID was passed + if ( empty( $user_id ) ) + return; - if ( ! empty( $_POST['um-role'] ) ) { - if ( ! user_can( $user_id, $_POST['um-role'] ) ) { - UM()->roles()->set_role( $user_id, $_POST['um-role'] ); - } - } + $old_roles = $old_data->roles; + $userdata = get_userdata( $user_id ); + $new_roles = $userdata->roles; - $this->remove_cache( $user_id ); - } + if ( ! empty( $_POST['um-role'] ) ) { + $new_roles = array_merge( $new_roles, array( $_POST['um-role'] ) ); + if ( ! user_can( $user_id, $_POST['um-role'] ) ) { + UM()->roles()->set_role( $user_id, $_POST['um-role'] ); + } + } + + do_action( 'um_after_member_role_upgrade', $new_roles, $old_roles ); + + $this->remove_cache( $user_id ); + } + + + /** + * Additional section for WP Profile page with UM data fields + * + * @param \WP_User $userdata User data + * @return void + */ + function profile_form_additional_section( $userdata ) { + + $section_content = apply_filters( 'um_user_profile_additional_fields', '', $userdata ); + + if ( ! empty( $section_content ) ) { + + if ( $userdata !== 'add-new-user' ) { ?> +

+ ID ) ) - return; + return $content; $user_role = UM()->roles()->um_get_user_role( $userdata->ID ); if ( $user_role && ! empty( $userdata->roles ) && count( $userdata->roles ) == 1 ) $style = 'style="display:none;"'; - } ?> + } + + ob_start(); ?>
> - -

- @@ -301,15 +339,10 @@ if ( ! class_exists( 'User' ) ) {
- id; $changes = apply_filters('um_before_update_profile', $changes, $this->id); - // save or update profile meta - foreach( $changes as $key => $value ) { - if ( !in_array( $key, $this->update_user_keys ) ) { + // save or update profile meta + foreach ( $changes as $key => $value ) { + if ( ! in_array( $key, $this->update_user_keys ) ) { update_user_meta( $this->id, $key, $value ); @@ -1043,7 +1076,6 @@ if ( ! class_exists( 'User' ) ) { } - // update user if ( count( $args ) > 1 ) { wp_update_user( $args ); From 23cb97cf6c5c4121b26505bae410ef2f098c073f Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Tue, 7 Nov 2017 16:24:43 +0200 Subject: [PATCH 07/41] - UM Woocommerce compatibility; - make "Shop" page restricted; --- includes/admin/core/class-admin-metabox.php | 9 +++++++-- includes/admin/core/um-admin-filters-fields.php | 12 ++++++++++++ includes/core/class-access.php | 3 +-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/includes/admin/core/class-admin-metabox.php b/includes/admin/core/class-admin-metabox.php index c385ea17..1374d1f7 100644 --- a/includes/admin/core/class-admin-metabox.php +++ b/includes/admin/core/class-admin-metabox.php @@ -103,8 +103,13 @@ if ( ! class_exists( 'Admin_Metabox' ) ) { //restrict content metabox $post_types = um_get_option( 'restricted_access_post_metabox' ); if ( ! empty( $post_types[ $current_screen->id ] ) ) { - add_action( 'add_meta_boxes', array(&$this, 'add_metabox_restrict_content'), 1 ); - add_action( 'save_post', array( &$this, 'save_metabox_restrict_content' ), 10, 2 ); + + $hide_metabox = apply_filters( 'um_restrict_content_hide_metabox', false ); + + if ( ! $hide_metabox ) { + add_action( 'add_meta_boxes', array(&$this, 'add_metabox_restrict_content'), 1 ); + add_action( 'save_post', array( &$this, 'save_metabox_restrict_content' ), 10, 2 ); + } if ( $current_screen->id == 'attachment' ) { add_action( 'add_attachment', array( &$this, 'save_attachment_metabox_restrict_content' ), 10, 2 ); diff --git a/includes/admin/core/um-admin-filters-fields.php b/includes/admin/core/um-admin-filters-fields.php index 8b625c0d..c8b553cf 100644 --- a/includes/admin/core/um-admin-filters-fields.php +++ b/includes/admin/core/um-admin-filters-fields.php @@ -131,3 +131,15 @@ return $break; } + + + + add_filter( 'um_restrict_content_hide_metabox', 'um_hide_metabox_restrict_content_shop', 10, 1 ); + function um_hide_metabox_restrict_content_shop( $hide ) { + if ( function_exists( 'wc_get_page_id' ) && ! empty( $_GET['post'] ) && + $_GET['post'] == wc_get_page_id( 'shop' ) ) { + return true; + } + + return $hide; + } diff --git a/includes/core/class-access.php b/includes/core/class-access.php index e03793b6..9f97d8ff 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -203,7 +203,7 @@ if ( ! class_exists( 'Access' ) ) { * @return array */ function filter_protected_posts( $posts, $query ) { - $filtered_posts = array(); + $filtered_posts = array(); //if empty if ( empty( $posts ) ) @@ -213,7 +213,6 @@ if ( ! class_exists( 'Access' ) ) { //other filter foreach ( $posts as $post ) { - $restriction = $this->get_post_privacy_settings( $post ); if ( ! $restriction ) { $filtered_posts[] = $post; From fdce17d420717ee93c21e3fbf363cbf30c3f1d8e Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Wed, 8 Nov 2017 13:00:02 +0200 Subject: [PATCH 08/41] - fixed user verification content restriction; --- includes/admin/core/class-admin-metabox.php | 424 ++++++++++---------- includes/core/class-access.php | 13 +- 2 files changed, 222 insertions(+), 215 deletions(-) diff --git a/includes/admin/core/class-admin-metabox.php b/includes/admin/core/class-admin-metabox.php index 1374d1f7..1a5c5f7a 100644 --- a/includes/admin/core/class-admin-metabox.php +++ b/includes/admin/core/class-admin-metabox.php @@ -214,111 +214,113 @@ if ( ! class_exists( 'Admin_Metabox' ) ) { function um_category_access_fields_create() { $data = array(); + $fields = apply_filters( 'um_admin_category_access_settings_fields', array( + array( + 'id' => '_um_custom_access_settings', + 'type' => 'checkbox', + 'name' => '_um_custom_access_settings', + 'label' => __( 'Restrict access to this content?', 'ultimate-member' ), + 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), + 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0, + ), + array( + 'id' => '_um_accessible', + 'type' => 'select', + 'name' => '_um_accessible', + 'label' => __( 'Who can access this content?', 'ultimate-member' ), + 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), + 'value' => ! empty( $data['_um_accessible'] ) ? $data['_um_accessible'] : 0, + 'options' => array( + '0' => __( 'Everyone', 'ultimate-member' ), + '1' => __( 'Logged out users', 'ultimate-member' ), + '2' => __( 'Logged in users', 'ultimate-member' ), + ), + 'conditional' => array( '_um_custom_access_settings', '=', '1' ) + ), + array( + 'id' => '_um_access_roles', + 'type' => 'multi_checkbox', + 'name' => '_um_access_roles', + 'label' => __( 'Select which roles can access this content', 'ultimate-member' ), + 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), + 'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ), + 'columns' => 3, + 'conditional' => array( '_um_accessible', '=', '2' ) + ), + array( + 'id' => '_um_noaccess_action', + 'type' => 'select', + 'name' => '_um_noaccess_action', + 'label' => __( 'What happens when users without access tries to view the content?', 'ultimate-member' ), + 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), + 'value' => ! empty( $data['_um_noaccess_action'] ) ? $data['_um_noaccess_action'] : 0, + 'options' => array( + '0' => __( 'Show access restricted message', 'ultimate-member' ), + '1' => __( 'Redirect user', 'ultimate-member' ), + ), + 'conditional' => array( '_um_accessible', '!=', '0' ) + ), + array( + 'id' => '_um_restrict_by_custom_message', + 'type' => 'select', + 'name' => '_um_restrict_by_custom_message', + 'label' => __( 'Would you like to use the global default message or apply a custom message to this content?', 'ultimate-member' ), + 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), + 'value' => ! empty( $data['_um_restrict_by_custom_message'] ) ? $data['_um_restrict_by_custom_message'] : '0', + 'options' => array( + '0' => __( 'Global default message (default)', 'ultimate-member' ), + '1' => __( 'Custom message', 'ultimate-member' ), + ), + 'conditional' => array( '_um_noaccess_action', '=', '0' ) + ), + array( + 'id' => '_um_restrict_custom_message', + 'type' => 'wp_editor', + 'name' => '_um_restrict_custom_message', + 'label' => __( 'Custom Restrict Content message', 'ultimate-member' ), + 'description' => __( 'Changed global restrict message', 'ultimate-member' ), + 'value' => ! empty( $data['_um_restrict_custom_message'] ) ? $data['_um_restrict_custom_message'] : '', + 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ) + ), + array( + 'id' => '_um_access_redirect', + 'type' => 'select', + 'name' => '_um_access_redirect', + 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ), + 'description' => __( 'Select redirect to page when user hasn\'t access to content', 'ultimate-member' ), + 'value' => ! empty( $data['_um_access_redirect'] ) ? $data['_um_access_redirect'] : '0', + 'conditional' => array( '_um_noaccess_action', '=', '1' ), + 'options' => array( + '0' => __( 'Login page', 'ultimate-member' ), + '1' => __( 'Custom URL', 'ultimate-member' ), + ), + ), + array( + 'id' => '_um_access_redirect_url', + 'type' => 'text', + 'name' => '_um_access_redirect_url', + 'label' => __( 'Redirect URL', 'ultimate-member' ), + 'description' => __( 'Changed global restrict message', 'ultimate-member' ), + 'value' => ! empty( $data['_um_access_redirect_url'] ) ? $data['_um_access_redirect_url'] : '', + 'conditional' => array( '_um_access_redirect', '=', '1' ) + ), + array( + 'id' => '_um_access_hide_from_queries', + 'type' => 'checkbox', + 'name' => '_um_access_hide_from_queries', + 'label' => __( 'Hide from queries', 'ultimate-member' ), + 'description' => __( 'Hide this content from archives, RSS feeds etc for users who do not have permission to view this content', 'ultimate-member' ), + 'value' => ! empty( $data['_um_access_hide_from_queries'] ) ? $data['_um_access_hide_from_queries'] : '', + 'conditional' => array( '_um_accessible', '!=', '0' ) + ) + ), $data, 'create' ); + UM()->admin_forms( array( 'class' => 'um-restrict-content um-third-column', 'prefix_id' => 'um_content_restriction', 'without_wrapper' => true, 'div_line' => true, - 'fields' => array( - array( - 'id' => '_um_custom_access_settings', - 'type' => 'checkbox', - 'name' => '_um_custom_access_settings', - 'label' => __( 'Restrict access to this content?', 'ultimate-member' ), - 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), - 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0, - ), - array( - 'id' => '_um_accessible', - 'type' => 'select', - 'name' => '_um_accessible', - 'label' => __( 'Who can access this content?', 'ultimate-member' ), - 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), - 'value' => ! empty( $data['_um_accessible'] ) ? $data['_um_accessible'] : 0, - 'options' => array( - '0' => __( 'Everyone', 'ultimate-member' ), - '1' => __( 'Logged out users', 'ultimate-member' ), - '2' => __( 'Logged in users', 'ultimate-member' ), - ), - 'conditional' => array( '_um_custom_access_settings', '=', '1' ) - ), - array( - 'id' => '_um_access_roles', - 'type' => 'multi_checkbox', - 'name' => '_um_access_roles', - 'label' => __( 'Select which roles can access this content', 'ultimate-member' ), - 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), - 'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ), - 'columns' => 3, - 'conditional' => array( '_um_accessible', '=', '2' ) - ), - array( - 'id' => '_um_noaccess_action', - 'type' => 'select', - 'name' => '_um_noaccess_action', - 'label' => __( 'What happens when users without access tries to view the content?', 'ultimate-member' ), - 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), - 'value' => ! empty( $data['_um_noaccess_action'] ) ? $data['_um_noaccess_action'] : 0, - 'options' => array( - '0' => __( 'Show access restricted message', 'ultimate-member' ), - '1' => __( 'Redirect user', 'ultimate-member' ), - ), - 'conditional' => array( '_um_accessible', '!=', '0' ) - ), - array( - 'id' => '_um_restrict_by_custom_message', - 'type' => 'select', - 'name' => '_um_restrict_by_custom_message', - 'label' => __( 'Would you like to use the global default message or apply a custom message to this content?', 'ultimate-member' ), - 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), - 'value' => ! empty( $data['_um_restrict_by_custom_message'] ) ? $data['_um_restrict_by_custom_message'] : '0', - 'options' => array( - '0' => __( 'Global default message (default)', 'ultimate-member' ), - '1' => __( 'Custom message', 'ultimate-member' ), - ), - 'conditional' => array( '_um_noaccess_action', '=', '0' ) - ), - array( - 'id' => '_um_restrict_custom_message', - 'type' => 'wp_editor', - 'name' => '_um_restrict_custom_message', - 'label' => __( 'Custom Restrict Content message', 'ultimate-member' ), - 'description' => __( 'Changed global restrict message', 'ultimate-member' ), - 'value' => ! empty( $data['_um_restrict_custom_message'] ) ? $data['_um_restrict_custom_message'] : '', - 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ) - ), - array( - 'id' => '_um_access_redirect', - 'type' => 'select', - 'name' => '_um_access_redirect', - 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ), - 'description' => __( 'Select redirect to page when user hasn\'t access to content', 'ultimate-member' ), - 'value' => ! empty( $data['_um_access_redirect'] ) ? $data['_um_access_redirect'] : '0', - 'conditional' => array( '_um_noaccess_action', '=', '1' ), - 'options' => array( - '0' => __( 'Login page', 'ultimate-member' ), - '1' => __( 'Custom URL', 'ultimate-member' ), - ), - ), - array( - 'id' => '_um_access_redirect_url', - 'type' => 'text', - 'name' => '_um_access_redirect_url', - 'label' => __( 'Redirect URL', 'ultimate-member' ), - 'description' => __( 'Changed global restrict message', 'ultimate-member' ), - 'value' => ! empty( $data['_um_access_redirect_url'] ) ? $data['_um_access_redirect_url'] : '', - 'conditional' => array( '_um_access_redirect', '=', '1' ) - ), - array( - 'id' => '_um_access_hide_from_queries', - 'type' => 'checkbox', - 'name' => '_um_access_hide_from_queries', - 'label' => __( 'Hide from queries', 'ultimate-member' ), - 'description' => __( 'Hide this content from archives, RSS feeds etc for users who do not have permission to view this content', 'ultimate-member' ), - 'value' => ! empty( $data['_um_access_hide_from_queries'] ) ? $data['_um_access_hide_from_queries'] : '', - 'conditional' => array( '_um_accessible', '!=', '0' ) - ) - ) + 'fields' => $fields ) )->render_form(); wp_nonce_field( basename( __FILE__ ), 'um_admin_save_taxonomy_restrict_content_nonce' ); @@ -339,120 +341,122 @@ if ( ! class_exists( 'Admin_Metabox' ) ) { } + $fields = apply_filters( 'um_admin_category_access_settings_fields', array( + array( + 'id' => '_um_custom_access_settings', + 'type' => 'checkbox', + 'class' => 'form-field', + 'name' => '_um_custom_access_settings', + 'label' => __( 'Restrict access to this content?', 'ultimate-member' ), + 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), + 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0, + ), + array( + 'id' => '_um_accessible', + 'type' => 'select', + 'class' => 'form-field', + 'name' => '_um_accessible', + 'label' => __( 'Who can access this content?', 'ultimate-member' ), + 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), + 'value' => ! empty( $data['_um_accessible'] ) ? $data['_um_accessible'] : 0, + 'options' => array( + '0' => __( 'Everyone', 'ultimate-member' ), + '1' => __( 'Logged out users', 'ultimate-member' ), + '2' => __( 'Logged in users', 'ultimate-member' ), + ), + 'conditional' => array( '_um_custom_access_settings', '=', '1' ) + ), + array( + 'id' => '_um_access_roles', + 'type' => 'multi_checkbox', + 'class' => 'form-field', + 'name' => '_um_access_roles', + 'label' => __( 'Select which roles can access this content', 'ultimate-member' ), + 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), + 'value' => $_um_access_roles_value, + 'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ), + 'columns' => 3, + 'conditional' => array( '_um_accessible', '=', '2' ) + ), + array( + 'id' => '_um_noaccess_action', + 'type' => 'select', + 'class' => 'form-field', + 'name' => '_um_noaccess_action', + 'label' => __( 'What happens when users without access tries to view the content?', 'ultimate-member' ), + 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), + 'value' => ! empty( $data['_um_noaccess_action'] ) ? $data['_um_noaccess_action'] : 0, + 'options' => array( + '0' => __( 'Show access restricted message', 'ultimate-member' ), + '1' => __( 'Redirect user', 'ultimate-member' ), + ), + 'conditional' => array( '_um_accessible', '!=', '0' ) + ), + array( + 'id' => '_um_restrict_by_custom_message', + 'type' => 'select', + 'class' => 'form-field', + 'name' => '_um_restrict_by_custom_message', + 'label' => __( 'Would you like to use the global default message or apply a custom message to this content?', 'ultimate-member' ), + 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), + 'value' => ! empty( $data['_um_restrict_by_custom_message'] ) ? $data['_um_restrict_by_custom_message'] : '0', + 'options' => array( + '0' => __( 'Global default message (default)', 'ultimate-member' ), + '1' => __( 'Custom message', 'ultimate-member' ), + ), + 'conditional' => array( '_um_noaccess_action', '=', '0' ) + ), + array( + 'id' => '_um_restrict_custom_message', + 'type' => 'wp_editor', + 'class' => 'form-field', + 'name' => '_um_restrict_custom_message', + 'label' => __( 'Custom Restrict Content message', 'ultimate-member' ), + 'description' => __( 'Changed global restrict message', 'ultimate-member' ), + 'value' => ! empty( $data['_um_restrict_custom_message'] ) ? $data['_um_restrict_custom_message'] : '', + 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ) + ), + array( + 'id' => '_um_access_redirect', + 'type' => 'select', + 'class' => 'form-field', + 'name' => '_um_access_redirect', + 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ), + 'description' => __( 'Select redirect to page when user hasn\'t access to content', 'ultimate-member' ), + 'value' => ! empty( $data['_um_access_redirect'] ) ? $data['_um_access_redirect'] : '0', + 'conditional' => array( '_um_noaccess_action', '=', '1' ), + 'options' => array( + '0' => __( 'Login page', 'ultimate-member' ), + '1' => __( 'Custom URL', 'ultimate-member' ), + ), + ), + array( + 'id' => '_um_access_redirect_url', + 'type' => 'text', + 'class' => 'form-field', + 'name' => '_um_access_redirect_url', + 'label' => __( 'Redirect URL', 'ultimate-member' ), + 'description' => __( 'Changed global restrict message', 'ultimate-member' ), + 'value' => ! empty( $data['_um_access_redirect_url'] ) ? $data['_um_access_redirect_url'] : '', + 'conditional' => array( '_um_access_redirect', '=', '1' ) + ), + array( + 'id' => '_um_access_hide_from_queries', + 'type' => 'checkbox', + 'class' => 'form-field', + 'name' => '_um_access_hide_from_queries', + 'label' => __( 'Hide from queries', 'ultimate-member' ), + 'description' => __( 'Hide this content from archives, RSS feeds etc for users who do not have permission to view this content', 'ultimate-member' ), + 'value' => ! empty( $data['_um_access_hide_from_queries'] ) ? $data['_um_access_hide_from_queries'] : '', + 'conditional' => array( '_um_accessible', '!=', '0' ) + ) + ), $data, 'edit' ); + UM()->admin_forms( array( 'class' => 'um-restrict-content um-third-column', 'prefix_id' => 'um_content_restriction', 'without_wrapper' => true, - 'fields' => array( - array( - 'id' => '_um_custom_access_settings', - 'type' => 'checkbox', - 'class' => 'form-field', - 'name' => '_um_custom_access_settings', - 'label' => __( 'Restrict access to this content?', 'ultimate-member' ), - 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), - 'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0, - ), - array( - 'id' => '_um_accessible', - 'type' => 'select', - 'class' => 'form-field', - 'name' => '_um_accessible', - 'label' => __( 'Who can access this content?', 'ultimate-member' ), - 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), - 'value' => ! empty( $data['_um_accessible'] ) ? $data['_um_accessible'] : 0, - 'options' => array( - '0' => __( 'Everyone', 'ultimate-member' ), - '1' => __( 'Logged out users', 'ultimate-member' ), - '2' => __( 'Logged in users', 'ultimate-member' ), - ), - 'conditional' => array( '_um_custom_access_settings', '=', '1' ) - ), - array( - 'id' => '_um_access_roles', - 'type' => 'multi_checkbox', - 'class' => 'form-field', - 'name' => '_um_access_roles', - 'label' => __( 'Select which roles can access this content', 'ultimate-member' ), - 'description' => __( 'Activate content restriction for this post', 'ultimate-member' ), - 'value' => $_um_access_roles_value, - 'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ), - 'columns' => 3, - 'conditional' => array( '_um_accessible', '=', '2' ) - ), - array( - 'id' => '_um_noaccess_action', - 'type' => 'select', - 'class' => 'form-field', - 'name' => '_um_noaccess_action', - 'label' => __( 'What happens when users without access tries to view the content?', 'ultimate-member' ), - 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), - 'value' => ! empty( $data['_um_noaccess_action'] ) ? $data['_um_noaccess_action'] : 0, - 'options' => array( - '0' => __( 'Show access restricted message', 'ultimate-member' ), - '1' => __( 'Redirect user', 'ultimate-member' ), - ), - 'conditional' => array( '_um_accessible', '!=', '0' ) - ), - array( - 'id' => '_um_restrict_by_custom_message', - 'type' => 'select', - 'class' => 'form-field', - 'name' => '_um_restrict_by_custom_message', - 'label' => __( 'Would you like to use the global default message or apply a custom message to this content?', 'ultimate-member' ), - 'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ), - 'value' => ! empty( $data['_um_restrict_by_custom_message'] ) ? $data['_um_restrict_by_custom_message'] : '0', - 'options' => array( - '0' => __( 'Global default message (default)', 'ultimate-member' ), - '1' => __( 'Custom message', 'ultimate-member' ), - ), - 'conditional' => array( '_um_noaccess_action', '=', '0' ) - ), - array( - 'id' => '_um_restrict_custom_message', - 'type' => 'wp_editor', - 'class' => 'form-field', - 'name' => '_um_restrict_custom_message', - 'label' => __( 'Custom Restrict Content message', 'ultimate-member' ), - 'description' => __( 'Changed global restrict message', 'ultimate-member' ), - 'value' => ! empty( $data['_um_restrict_custom_message'] ) ? $data['_um_restrict_custom_message'] : '', - 'conditional' => array( '_um_restrict_by_custom_message', '=', '1' ) - ), - array( - 'id' => '_um_access_redirect', - 'type' => 'select', - 'class' => 'form-field', - 'name' => '_um_access_redirect', - 'label' => __( 'Where should users be redirected to?', 'ultimate-member' ), - 'description' => __( 'Select redirect to page when user hasn\'t access to content', 'ultimate-member' ), - 'value' => ! empty( $data['_um_access_redirect'] ) ? $data['_um_access_redirect'] : '0', - 'conditional' => array( '_um_noaccess_action', '=', '1' ), - 'options' => array( - '0' => __( 'Login page', 'ultimate-member' ), - '1' => __( 'Custom URL', 'ultimate-member' ), - ), - ), - array( - 'id' => '_um_access_redirect_url', - 'type' => 'text', - 'class' => 'form-field', - 'name' => '_um_access_redirect_url', - 'label' => __( 'Redirect URL', 'ultimate-member' ), - 'description' => __( 'Changed global restrict message', 'ultimate-member' ), - 'value' => ! empty( $data['_um_access_redirect_url'] ) ? $data['_um_access_redirect_url'] : '', - 'conditional' => array( '_um_access_redirect', '=', '1' ) - ), - array( - 'id' => '_um_access_hide_from_queries', - 'type' => 'checkbox', - 'class' => 'form-field', - 'name' => '_um_access_hide_from_queries', - 'label' => __( 'Hide from queries', 'ultimate-member' ), - 'description' => __( 'Hide this content from archives, RSS feeds etc for users who do not have permission to view this content', 'ultimate-member' ), - 'value' => ! empty( $data['_um_access_hide_from_queries'] ) ? $data['_um_access_hide_from_queries'] : '', - 'conditional' => array( '_um_accessible', '!=', '0' ) - ) - ) + 'fields' => $fields ) )->render_form(); wp_nonce_field( basename( __FILE__ ), 'um_admin_save_taxonomy_restrict_content_nonce' ); diff --git a/includes/core/class-access.php b/includes/core/class-access.php index 9f97d8ff..59cb526f 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -148,7 +148,7 @@ if ( ! class_exists( 'Access' ) ) { $restricted_posts = um_get_option( 'restricted_access_post_metabox' ); - if ( ! empty( $restricted_posts[$post->post_type] ) ) { + if ( ! empty( $restricted_posts[ $post->post_type ] ) ) { $restriction = get_post_meta( $post->ID, 'um_content_restriction', true ); if ( ! empty( $restriction['_um_custom_access_settings'] ) ) { @@ -291,16 +291,16 @@ if ( ! class_exists( 'Access' ) ) { continue; } + $custom_restrict = apply_filters( 'um_custom_restriction', true, $restriction ); if ( ! empty( $restriction['_um_access_roles'] ) ) $user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] ); - if ( isset( $user_can ) && $user_can ) { + if ( isset( $user_can ) && $user_can && $custom_restrict ) { $filtered_posts[] = $post; continue; } - if ( empty( $query->is_singular ) ) { //if not single query when exclude if set _um_access_hide_from_queries if ( empty( $restriction['_um_access_hide_from_queries'] ) ) { @@ -467,9 +467,12 @@ if ( ! class_exists( 'Access' ) ) { //if post for logged in users and user is not logged in if ( is_user_logged_in() ) { - $user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] ); + $custom_restrict = apply_filters( 'um_custom_restriction', true, $restriction ); - if ( $user_can ) { + if ( ! empty( $restriction['_um_access_roles'] ) ) + $user_can = $this->user_can( get_current_user_id(), $restriction['_um_access_roles'] ); + + if ( isset( $user_can ) && $user_can && $custom_restrict ) { $filtered_items[] = $menu_item; continue; } From 1c1fb2c36996475bfd3d4c2c1674c0c151bf2932 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Fri, 10 Nov 2017 12:10:59 +0200 Subject: [PATCH 09/41] - fixed role predefined fields values; --- includes/core/class-builtin.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/core/class-builtin.php b/includes/core/class-builtin.php index 372e17ad..a1b17e1a 100644 --- a/includes/core/class-builtin.php +++ b/includes/core/class-builtin.php @@ -543,9 +543,15 @@ if ( ! class_exists( 'Builtin' ) ) { function set_predefined_fields() { global $wp_roles; - $role_keys = array_map( function( $item ) { - return 'um_' . $item; - }, get_option( 'um_roles' ) ); + $role_keys = get_option( 'um_roles' ); + if ( ! empty( $role_keys ) && is_array( $role_keys ) ) { + $role_keys = array_map( function( $item ) { + return 'um_' . $item; + }, $role_keys ); + } else { + $role_keys = array(); + } + $exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) ); $um_roles = UM()->roles()->get_roles( false, $exclude_roles ); From 5c8b9b10f54d44cfa649991e845b47ea2eff2c44 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Fri, 10 Nov 2017 16:47:48 +0200 Subject: [PATCH 10/41] - fixed get posts; --- includes/admin/core/packages/2.0-beta1.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/admin/core/packages/2.0-beta1.php b/includes/admin/core/packages/2.0-beta1.php index 06fb4770..018e48da 100644 --- a/includes/admin/core/packages/2.0-beta1.php +++ b/includes/admin/core/packages/2.0-beta1.php @@ -1022,7 +1022,8 @@ $roles_array = UM()->roles()->get_roles( false, array( 'administrator' ) ); $posts = get_posts( array( 'meta_key' => '_um_custom_access_settings', 'meta_value' => '1', - 'fields' => 'ids' + 'fields' => 'ids', + 'numberposts' => -1 ) ); if ( ! empty( $posts ) ) { foreach ( $posts as $post_id ) { From cfbdb688febeed5d01f661ca4b30138c4533f3d3 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Sun, 12 Nov 2017 15:55:43 +0200 Subject: [PATCH 11/41] - fixed email notifications integration; - fixed small notices; --- includes/class-init.php | 2 +- includes/core/class-access.php | 2 +- includes/core/class-mail.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class-init.php b/includes/class-init.php index 5139305c..322b7421 100644 --- a/includes/class-init.php +++ b/includes/class-init.php @@ -296,12 +296,12 @@ if ( ! class_exists( 'UM' ) ) { $this->register(); $this->user_posts(); $this->access(); - $this->mail(); $this->members(); $this->logout(); } //common includes + $this->mail(); $this->rest_api(); $this->shortcodes(); $this->roles(); diff --git a/includes/core/class-access.php b/includes/core/class-access.php index 59cb526f..29549a2c 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -148,7 +148,7 @@ if ( ! class_exists( 'Access' ) ) { $restricted_posts = um_get_option( 'restricted_access_post_metabox' ); - if ( ! empty( $restricted_posts[ $post->post_type ] ) ) { + if ( ! empty( $post->post_type ) && ! empty( $restricted_posts[ $post->post_type ] ) ) { $restriction = get_post_meta( $post->ID, 'um_content_restriction', true ); if ( ! empty( $restriction['_um_custom_access_settings'] ) ) { diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php index f33bbf5a..4d98a860 100644 --- a/includes/core/class-mail.php +++ b/includes/core/class-mail.php @@ -14,7 +14,7 @@ if ( ! class_exists( 'Mail' ) ) { //mandrill compatibility add_filter( 'mandrill_nl2br', array( &$this, 'mandrill_nl2br' ) ); - add_action( 'plugins_loaded', array( &$this, 'init_paths' ) ); + add_action( 'plugins_loaded', array( &$this, 'init_paths' ), 99 ); } From 65a7fe304bd34bb362c920e474955fea0d458c2c Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Sun, 12 Nov 2017 16:50:51 +0200 Subject: [PATCH 12/41] - fixed upgrade for content restriction posts; --- includes/admin/core/packages/2.0-beta1.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/admin/core/packages/2.0-beta1.php b/includes/admin/core/packages/2.0-beta1.php index 018e48da..655b5d0e 100644 --- a/includes/admin/core/packages/2.0-beta1.php +++ b/includes/admin/core/packages/2.0-beta1.php @@ -1020,11 +1020,13 @@ update_option( 'um_roles', $role_keys ); $roles_array = UM()->roles()->get_roles( false, array( 'administrator' ) ); $posts = get_posts( array( - 'meta_key' => '_um_custom_access_settings', - 'meta_value' => '1', - 'fields' => 'ids', + 'post_type' => 'any', + 'meta_key' => '_um_custom_access_settings', + 'meta_value' => '1', + 'fields' => 'ids', 'numberposts' => -1 ) ); + if ( ! empty( $posts ) ) { foreach ( $posts as $post_id ) { $um_accessible = get_post_meta( $post_id, '_um_accessible', true ); @@ -1217,7 +1219,8 @@ $menus = get_posts( array( 'key' => 'menu-item-um_nav_roles', 'compare' => 'EXISTS', ) - ) + ), + 'numberposts' => -1, ) ); foreach ( $menus as $menu ) { From 269bd2f7bb8aecf612ce9bfdef592780103ab935 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Sun, 12 Nov 2017 20:32:17 +0200 Subject: [PATCH 13/41] - fixed small notice; --- includes/core/class-mail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/class-mail.php b/includes/core/class-mail.php index 4d98a860..14b0de49 100644 --- a/includes/core/class-mail.php +++ b/includes/core/class-mail.php @@ -275,7 +275,7 @@ if ( ! class_exists( 'Mail' ) ) { } } - if ( copy( $plugin_template_path, $theme_template_path ) ) { + if ( file_exists( $plugin_template_path ) && copy( $plugin_template_path, $theme_template_path ) ) { return true; } else { return false; From e664c328d0ca3b08fa46baabb20471670d6c5a28 Mon Sep 17 00:00:00 2001 From: yura_nalivaiko Date: Mon, 13 Nov 2017 16:18:56 +0200 Subject: [PATCH 14/41] - fixed autoloader; --- includes/class-init.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/class-init.php b/includes/class-init.php index 322b7421..9e24a323 100644 --- a/includes/class-init.php +++ b/includes/class-init.php @@ -220,7 +220,7 @@ if ( ! class_exists( 'UM' ) ) { $path = implode( DIRECTORY_SEPARATOR, $array ); $path = str_replace( '_', '-', $path ); $full_path .= $path . '.php'; - } else { + } else if ( strpos( $class, 'um\\' ) === 0 ) { $class = implode( '\\', $array ); $slash = DIRECTORY_SEPARATOR; $path = str_replace( @@ -230,7 +230,9 @@ if ( ! class_exists( 'UM' ) ) { $full_path = um_path . 'includes' . $path . '.php'; } - include_once $full_path; + if( isset( $full_path ) && file_exists( $full_path ) ) { + include_once $full_path; + } } } From ef653c29d367228d9b4acde2f307a3756a7c79ad Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Tue, 14 Nov 2017 12:36:44 +0200 Subject: [PATCH 15/41] - small notices fixes; - fixed issue #344; --- includes/admin/core/class-admin-metabox.php | 17 +++++----- includes/admin/core/class-admin-settings.php | 2 +- includes/um-short-functions.php | 33 +++++++++++++++++--- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/includes/admin/core/class-admin-metabox.php b/includes/admin/core/class-admin-metabox.php index 1a5c5f7a..5b99941a 100644 --- a/includes/admin/core/class-admin-metabox.php +++ b/includes/admin/core/class-admin-metabox.php @@ -1962,20 +1962,17 @@ if ( ! class_exists( 'Admin_Metabox' ) ) { case '_parent_dropdown_relationship': ?> -

+

diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 44676b87..0ba5b526 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -1404,7 +1404,7 @@ if ( ! class_exists( 'Admin_Settings' ) ) { $filtered_settings[$key] = $value; foreach( $fields as $field ) { - if ( $field['id'] == $key && $field['type'] == 'multi_text' ) { + if ( $field['id'] == $key && isset( $field['type'] ) && $field['type'] == 'multi_text' ) { $filtered_settings[$key] = array_filter( $settings[$key] ); } } diff --git a/includes/um-short-functions.php b/includes/um-short-functions.php index 85b25b21..28987c4a 100644 --- a/includes/um-short-functions.php +++ b/includes/um-short-functions.php @@ -585,14 +585,21 @@ return false; } - /*** - *** @Get a translated core page URL - ***/ + + /** + * Get a translated core page URL + * + * @param $post_id + * @param $language + * @return bool|false|string + */ function um_get_url_for_language( $post_id, $language ) { + if ( ! um_is_wpml_active() ) + return ''; + $lang_post_id = icl_object_id( $post_id, 'page', true, $language ); - $url = ""; - if ($lang_post_id != 0) { + if ( $lang_post_id != 0 ) { $url = get_permalink( $lang_post_id ); } else { // No page found, it's most likely the homepage @@ -603,6 +610,22 @@ return $url; } + + /** + * Check if WPML is active + * + * @return bool|mixed + */ + function um_is_wpml_active() { + if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { + global $sitepress; + + return $sitepress->get_setting( 'setup_complete' ); + } + + return false; + } + /*** *** @Get core page url ***/ From 824da3f0368d02bf2be9bef72637395872fde409 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Tue, 14 Nov 2017 17:50:37 +0200 Subject: [PATCH 16/41] - fixed allowed memory size on multisites; --- includes/core/class-permalinks.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/core/class-permalinks.php b/includes/core/class-permalinks.php index a17547cf..5f3ce7e7 100644 --- a/includes/core/class-permalinks.php +++ b/includes/core/class-permalinks.php @@ -11,7 +11,7 @@ if ( ! class_exists( 'Permalinks' ) ) { function __construct() { - $this->current_url = $this->get_current_url(); + add_action( 'init', array( &$this, 'set_current_url' ), 0 ); add_action( 'init', array( &$this, 'check_for_querystrings' ), 1 ); @@ -25,6 +25,13 @@ if ( ! class_exists( 'Permalinks' ) ) { } + /** + * Set current URL variable + */ + function set_current_url() { + $this->current_url = $this->get_current_url(); + } + /*** *** @SEO canonical href bugfix From 7440a16edae9ba4492faa7fcdb1b427fca3996ac Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Thu, 16 Nov 2017 00:32:36 +0200 Subject: [PATCH 17/41] - renamed mobile detect class (removed conflict); --- includes/class-init.php | 4 ++-- .../{class-mobile-detect.php => class-um-mobile-detect.php} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename includes/lib/mobiledetect/{class-mobile-detect.php => class-um-mobile-detect.php} (99%) diff --git a/includes/class-init.php b/includes/class-init.php index 9e24a323..bdb0fd2b 100644 --- a/includes/class-init.php +++ b/includes/class-init.php @@ -989,11 +989,11 @@ if ( ! class_exists( 'UM' ) ) { /** * @since 2.0 * - * @return um\lib\mobiledetect\Mobile_Detect + * @return um\lib\mobiledetect\Um_Mobile_Detect */ function mobile() { if ( empty( $this->classes['mobile'] ) ) { - $this->classes['mobile'] = new um\lib\mobiledetect\Mobile_Detect(); + $this->classes['mobile'] = new um\lib\mobiledetect\Um_Mobile_Detect(); } return $this->classes['mobile']; diff --git a/includes/lib/mobiledetect/class-mobile-detect.php b/includes/lib/mobiledetect/class-um-mobile-detect.php similarity index 99% rename from includes/lib/mobiledetect/class-mobile-detect.php rename to includes/lib/mobiledetect/class-um-mobile-detect.php index 224d4339..08c3384c 100644 --- a/includes/lib/mobiledetect/class-mobile-detect.php +++ b/includes/lib/mobiledetect/class-um-mobile-detect.php @@ -4,8 +4,8 @@ namespace um\lib\mobiledetect; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; -if ( ! class_exists( 'Mobile_Detect' ) ) { - class Mobile_Detect { +if ( ! class_exists( 'Um_Mobile_Detect' ) ) { + class Um_Mobile_Detect { /** * Mobile detection type. * From d3990feb4ce5798d3d085ce8940ab019538abd32 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Thu, 16 Nov 2017 00:37:32 +0200 Subject: [PATCH 18/41] - fixed issue #321; --- includes/admin/core/class-admin-settings.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 0ba5b526..4055e978 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -115,6 +115,9 @@ if ( ! class_exists( 'Admin_Settings' ) ) { $tabs = UM()->profile()->tabs_primary(); foreach( $tabs as $id => $tab ) { + + $profile_tab_roles = UM()->um_get_option( 'profile_tab_' . $id . '_roles' ); + $appearances_profile_menu_fields = array_merge( $appearances_profile_menu_fields, array( array( 'id' => 'profile_tab_' . $id, @@ -144,7 +147,7 @@ if ( ! class_exists( 'Admin_Settings' ) ) { 'options' => UM()->roles()->get_roles(), 'placeholder' => __( 'Choose user roles...','ultimate-member' ), 'conditional' => array( 'profile_tab_' . $id . '_privacy', '=', 4 ), - 'value' => ! empty( UM()->um_get_option( 'profile_tab_' . $id . '_roles' ) ) ? UM()->um_get_option( 'profile_tab_' . $id . '_roles' ) : array(), + 'value' => ! empty( $profile_tab_roles ) ? $profile_tab_roles : array(), 'default' => UM()->um_get_default( 'profile_tab_' . $id . '_roles' ), 'size' => 'small' ) From 7d45a0a229985ec2e33cce74e32738b4f6b09052 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Thu, 16 Nov 2017 01:07:08 +0200 Subject: [PATCH 19/41] - fixed issue with deleting custom roles; --- includes/admin/core/list-tables/roles-list-table.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/admin/core/list-tables/roles-list-table.php b/includes/admin/core/list-tables/roles-list-table.php index 7a0e463c..bbf76009 100644 --- a/includes/admin/core/list-tables/roles-list-table.php +++ b/includes/admin/core/list-tables/roles-list-table.php @@ -39,6 +39,8 @@ if ( isset( $_GET['action'] ) ) { delete_option( "um_role_{$role_key}_meta" ); + $um_roles = array_diff( $um_roles, array( $role_key ) ); + $role_keys[$k] = 'um_' . $role_key; } @@ -67,6 +69,8 @@ if ( isset( $_GET['action'] ) ) { } } + update_option( 'um_roles', $um_roles ); + um_js_redirect( add_query_arg( 'msg', 'd', $redirect ) ); break; } From 31c3ad62c0bb01e38867d03027dd1b356a800873 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Thu, 16 Nov 2017 01:43:47 +0200 Subject: [PATCH 20/41] - fixed add/edit UM Forms footer text layout; --- includes/admin/assets/js/um-admin-builder.js | 3 ++- includes/admin/core/class-admin-enqueue.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/admin/assets/js/um-admin-builder.js b/includes/admin/assets/js/um-admin-builder.js index 380a1e0a..432a6d6d 100644 --- a/includes/admin/assets/js/um-admin-builder.js +++ b/includes/admin/assets/js/um-admin-builder.js @@ -40,5 +40,6 @@ function um_admin_update_builder() { } jQuery(document).ready(function() { - + if ( um_admin_builder_data.hide_footer ) + jQuery('#wpfooter').hide(); }); \ No newline at end of file diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index f58eb336..e26be8e7 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -227,8 +227,20 @@ if ( ! class_exists( 'Admin_Enqueue' ) ) { wp_register_script( 'um_admin_builder', $this->js_url . 'um-admin-builder.js', '', '', true ); wp_enqueue_script( 'um_admin_builder' ); + //hide footer text on add/edit UM Forms + //layouts crashed because we load and hide metaboxes + //and WP calculate page height + $hide_footer = false; + global $pagenow, $post; + if ( ( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) && + ( ( isset( $_GET['post_type'] ) && 'um_form' == $_GET['post_type'] ) || + ( isset( $post->post_type ) && 'um_form' == $post->post_type ) ) ) { + $hide_footer = true; + } + $localize_data = array( 'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'update_builder' ), + 'hide_footer' => $hide_footer, ); wp_localize_script( 'um_admin_builder', 'um_admin_builder_data', $localize_data ); From b6e39844af50e678803a7a94244b33230fe84bc2 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Thu, 16 Nov 2017 12:19:05 +0200 Subject: [PATCH 21/41] - fixed email notifications status at list table; --- includes/admin/core/list-tables/emails-list-table.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/admin/core/list-tables/emails-list-table.php b/includes/admin/core/list-tables/emails-list-table.php index 3a8ba7e1..67580ccc 100644 --- a/includes/admin/core/list-tables/emails-list-table.php +++ b/includes/admin/core/list-tables/emails-list-table.php @@ -135,8 +135,7 @@ class UM_Emails_List_Table extends WP_List_Table { function column_email( $item ) { $active = um_get_option( $item['key'] . '_on' ); - if ( $active === '' ) - $active = ! empty( $item['default_active'] ); + return ''. $item['title'] . ''; } From 743e1c3b7dc97ddb73bfc2fc1b932e6238f5fa3f Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Thu, 16 Nov 2017 14:07:13 +0200 Subject: [PATCH 22/41] - hide registration form for logged in users; --- includes/core/class-shortcodes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index 72d7a9f0..f6534aa1 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -303,6 +303,10 @@ if ( ! class_exists( 'Shortcodes' ) ) { extract($args, EXTR_SKIP); + if ( 'register' == $mode && is_user_logged_in() ) { + return __( 'You are already registered', 'ultimate-member' ); + } + // for profiles only if ($mode == 'profile' && um_profile_id() && isset($args['role']) && $args['role'] && $args['role'] != UM()->roles()->um_get_user_role( um_profile_id() ) ) { From a3dfb82a78aa1aa4bb71a97c352a19a77c746fad Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Thu, 16 Nov 2017 16:25:52 +0200 Subject: [PATCH 23/41] - fixed posts on user profile page; --- templates/profile/posts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/profile/posts.php b/templates/profile/posts.php index 564aff4f..77091e12 100644 --- a/templates/profile/posts.php +++ b/templates/profile/posts.php @@ -1,4 +1,4 @@ -query()->make('post_type=post&posts_per_page=10&offset=0&author=' . um_user('ID') ); ?> +query()->make('post_type=post&posts_per_page=10&offset=0&author=' . um_get_requested_user() ); ?> shortcodes()->loop = apply_filters('um_profile_query_make_posts', $query_posts ); ?> @@ -13,7 +13,7 @@ shortcodes()->loop->found_posts >= 10 ) { ?>
- +
From 13cf985acdf79cee0154a8bd763589184bd6b6e6 Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Fri, 17 Nov 2017 11:18:46 +0200 Subject: [PATCH 24/41] - small notice fix; --- includes/core/um-actions-register.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php index f125f156..5412a7ad 100644 --- a/includes/core/um-actions-register.php +++ b/includes/core/um-actions-register.php @@ -303,6 +303,10 @@ */ add_action( 'um_registration_set_extra_data', 'um_registration_save_files', 10, 2 ); function um_registration_save_files( $user_id, $args ) { + + if ( empty( $args['custom_fields'] ) ) + return; + $files = array(); $fields = unserialize( $args['custom_fields'] ); From 6f5b6205d0ad35a6d7204380730f0bf6f0ad9acc Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Fri, 17 Nov 2017 14:14:51 +0200 Subject: [PATCH 25/41] - fixed transferring restriction content options; - fixed user add/edit section for multisite (in processing); --- includes/admin/core/packages/2.0-beta1.php | 16 +++++++++++----- includes/core/class-user.php | 8 +++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/includes/admin/core/packages/2.0-beta1.php b/includes/admin/core/packages/2.0-beta1.php index 655b5d0e..866b4490 100644 --- a/includes/admin/core/packages/2.0-beta1.php +++ b/includes/admin/core/packages/2.0-beta1.php @@ -1014,7 +1014,12 @@ if ( ! empty( $um_roles ) ) { update_option( 'um_roles', $role_keys ); - +global $wp_roles, $wp_version; +if ( version_compare( $wp_version, '4.9.0', '<' ) && method_exists( $wp_roles, '_init' ) ) { + wp_roles()->_init(); +} elseif ( method_exists( $wp_roles, 'for_site' ) ) { + wp_roles()->for_site( get_current_blog_id() ); +} //Content Restriction transfer $roles_array = UM()->roles()->get_roles( false, array( 'administrator' ) ); @@ -1035,17 +1040,18 @@ if ( ! empty( $posts ) ) { $access_roles = array(); if ( ! empty( $um_access_roles ) ) { - foreach ( $roles_array as $role ) { + foreach ( $roles_array as $role => $role_label ) { if ( in_array( substr( $role, 3 ), $um_access_roles ) ) - $access_roles[$role] = '1'; + $access_roles[ $role ] = '1'; else - $access_roles[$role] = '0'; + $access_roles[ $role ] = '0'; } } else { foreach ( $roles_array as $role ) { - $access_roles[$role] = '0'; + $access_roles[ $role ] = '0'; } } + $restrict_options = array( '_um_custom_access_settings' => '1', '_um_accessible' => $um_accessible, diff --git a/includes/core/class-user.php b/includes/core/class-user.php index fbcf1ce8..70a7be10 100644 --- a/includes/core/class-user.php +++ b/includes/core/class-user.php @@ -269,7 +269,7 @@ if ( ! class_exists( 'User' ) ) { if ( ! empty( $section_content ) ) { - if ( $userdata !== 'add-new-user' ) { ?> + if ( $userdata !== 'add-new-user' && $userdata !== 'add-existing-user' ) { ?>

ID ) ) return $content; @@ -320,9 +320,11 @@ if ( ! class_exists( 'User' ) ) { } + $class = ( $userdata == 'add-existing-user' ) ? 'um_role_existing_selector_wrapper' : 'um_role_selector_wrapper'; + ob_start(); ?> -
> +
> From c01d22d61b773c5feb9bb4093d0fb580c715b355 Mon Sep 17 00:00:00 2001 From: Denis Baranov Date: Mon, 20 Nov 2017 12:38:48 +0200 Subject: [PATCH 26/41] - fixed "add friend" button not working in desktop view for logged out users. - fixed members directory template. - fixed Content Restriction transfer --- assets/js/um-profile.js | 2 +- includes/admin/core/packages/2.0-beta1.php | 8 ++++++-- includes/core/class-shortcodes.php | 14 ++++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/assets/js/um-profile.js b/assets/js/um-profile.js index 12238b55..60a7861c 100644 --- a/assets/js/um-profile.js +++ b/assets/js/um-profile.js @@ -23,7 +23,7 @@ jQuery(document).ready(function() { jQuery(this).addClass('active'); }); - jQuery(document).on('click', '.um-cover a, .um-photo a', function(e){ + jQuery(document).on('click', '.um-cover a.um-cover-add, .um-photo a', function(e){ e.preventDefault(); return false; }); diff --git a/includes/admin/core/packages/2.0-beta1.php b/includes/admin/core/packages/2.0-beta1.php index 655b5d0e..a554c1be 100644 --- a/includes/admin/core/packages/2.0-beta1.php +++ b/includes/admin/core/packages/2.0-beta1.php @@ -1017,6 +1017,10 @@ update_option( 'um_roles', $role_keys ); //Content Restriction transfer +global $wp_roles; +if( method_exists($wp_roles,'_init') ){ + $wp_roles->_init(); +} $roles_array = UM()->roles()->get_roles( false, array( 'administrator' ) ); $posts = get_posts( array( @@ -1035,14 +1039,14 @@ if ( ! empty( $posts ) ) { $access_roles = array(); if ( ! empty( $um_access_roles ) ) { - foreach ( $roles_array as $role ) { + foreach ( $roles_array as $role => $role_label ) { if ( in_array( substr( $role, 3 ), $um_access_roles ) ) $access_roles[$role] = '1'; else $access_roles[$role] = '0'; } } else { - foreach ( $roles_array as $role ) { + foreach ( $roles_array as $role => $role_label ) { $access_roles[$role] = '0'; } } diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index f6534aa1..553b98ac 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -290,14 +290,16 @@ if ( ! class_exists( 'Shortcodes' ) ) { $post_data['template'] = $post_data['mode']; } - $args = array_merge($post_data, $args); + if( 'directory' != $args['mode'] ) { - if ( empty( $args['use_custom_settings'] ) ) { - $args = array_merge( $args, $this->get_css_args( $args ) ); - } else { - $args = array_merge( $this->get_css_args( $args ), $args ); - } + $args = array_merge( $post_data, $args ); + if (empty( $args['use_custom_settings'] )) { + $args = array_merge( $args, $this->get_css_args( $args ) ); + } else { + $args = array_merge( $this->get_css_args( $args ), $args ); + } + } // filter for arguments $args = apply_filters('um_shortcode_args_filter', $args); From d894c67d8ef36c8fead6c66eeca28fe2bdc4988e Mon Sep 17 00:00:00 2001 From: nikitozzzzzzz Date: Wed, 22 Nov 2017 16:25:41 +0200 Subject: [PATCH 27/41] - fixed Roles (Radio) field's options; --- includes/core/class-fields.php | 153 ++++++++++++++++----------------- 1 file changed, 73 insertions(+), 80 deletions(-) diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index c963e1f6..496c20f2 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -1887,37 +1887,24 @@ $output .= '