This commit is contained in:
yura_nalivaiko
2018-02-09 10:09:15 +02:00
52 changed files with 5661 additions and 6741 deletions
+1
View File
@@ -192,6 +192,7 @@
.um-profile-photo {
float: left;
position: relative;
width:200px;
}
.um-profile-photo a.um-profile-photo-img {
+2 -2
View File
@@ -468,7 +468,7 @@ jQuery(document).ready( function (){
* @param object $dom
*/
function _hide_in_ie( $dom ){
if( jQuery.browser.msie ){
if ( typeof( jQuery.browser ) != 'undefined' && jQuery.browser.msie ) {
$dom.css({"visibility":"hidden"});
}
}
@@ -478,7 +478,7 @@ jQuery(document).ready( function (){
* @param object $dom
*/
function _show_in_ie( $dom ){
if( jQuery.browser.msie ){
if ( typeof( jQuery.browser ) != 'undefined' && jQuery.browser.msie ) {
$dom.css({"visibility":"visible"});
}
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+12 -12
View File
@@ -20,7 +20,7 @@
methods.destroy.call(this.self);
this.opt = $.extend(true, {}, $.fn.raty.defaults, options);
this.opt = $.extend(true, {}, $.fn.um_raty.defaults, options);
methods._adjustCallback.call(this);
@@ -125,7 +125,7 @@
_bindClick: function() {
var that = this;
that.stars.on('click.raty', function(evt) {
that.stars.on('click.um_raty', function(evt) {
var star = $(this);
that.score.val((that.opt.half || that.opt.precision) ? that.self.data('score') : (this.alt || star.data('alt')));
@@ -139,7 +139,7 @@
_bindClickCancel: function() {
var that = this;
that.cancel.on('click.raty', function(evt) {
that.cancel.on('click.um_raty', function(evt) {
that.score.removeAttr('value');
if (that.opt.click) {
@@ -151,7 +151,7 @@
_bindOut: function() {
var that = this;
that.self.on('mouseleave.raty', function(evt) {
that.self.on('mouseleave.um_raty', function(evt) {
var score = +that.score.val() || undefined;
methods._apply.call(that, score);
@@ -166,7 +166,7 @@
_bindOutCancel: function() {
var that = this;
that.cancel.on('mouseleave.raty', function(evt) {
that.cancel.on('mouseleave.um_raty', function(evt) {
var icon = that.opt.cancelOff;
if (that.opt.starType !== 'img') {
@@ -185,7 +185,7 @@
_bindOver: function() {
var that = this,
action = that.opt.half ? 'mousemove.raty' : 'mouseover.raty';
action = that.opt.half ? 'mousemove.um_raty' : 'mouseover.um_raty';
that.stars.on(action, function(evt) {
var score = methods._getScoreByPosition.call(that, evt, this);
@@ -209,7 +209,7 @@
_bindOverCancel: function() {
var that = this;
that.cancel.on('mouseover.raty', function(evt) {
that.cancel.on('mouseover.um_raty', function(evt) {
var
starOff = that.opt.path + that.opt.starOff,
icon = that.opt.cancelOn;
@@ -504,7 +504,7 @@
raw = self.data('raw');
if (raw) {
self.off('.raty').empty().css({ cursor: raw.style.cursor }).removeData('readonly');
self.off('.um_raty').empty().css({ cursor: raw.style.cursor }).removeData('readonly');
} else {
self.data('raw', self.clone()[0]);
}
@@ -553,7 +553,7 @@
if (self.data('readonly') !== readonly) {
if (readonly) {
self.off('.raty').children('img').off('.raty');
self.off('.um_raty').children('img').off('.um_raty');
methods._lock.call(this);
} else {
@@ -582,7 +582,7 @@
actual = self.data('options'),
news = $.extend({}, actual, options);
self.raty(news);
self.um_raty(news);
});
},
@@ -596,7 +596,7 @@
}
};
$.fn.raty = function(method) {
$.fn.um_raty = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
@@ -606,7 +606,7 @@
}
};
$.fn.raty.defaults = {
$.fn.um_raty.defaults = {
cancel : false,
cancelClass : 'raty-cancel',
cancelHint : 'Cancel this rating!',
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -113,7 +113,7 @@ jQuery(document).ready(function() {
});
});
jQuery('.um-rating').raty({
jQuery('.um-rating').um_raty({
half: false,
starType: 'i',
number: function() {return jQuery(this).attr('data-number');},
@@ -127,7 +127,7 @@ jQuery(document).ready(function() {
}
});
jQuery('.um-rating-readonly').raty({
jQuery('.um-rating-readonly').um_raty({
half: false,
starType: 'i',
number: function() {return jQuery(this).attr('data-number');},
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -102,7 +102,8 @@ a.um-delete{ color: #a00; }
.wp-list-table.roles .column-core,
.wp-list-table.roles .column-users,
.wp-list-table.roles .column-admin_access {
.wp-list-table.roles .column-admin_access,
.wp-list-table.roles .column-priority {
width:15%;
text-align: center !important;
}
@@ -110,7 +111,8 @@ a.um-delete{ color: #a00; }
@media screen and (max-width: 782px) {
.wp-list-table.roles .column-core,
.wp-list-table.roles .column-users,
.wp-list-table.roles .column-admin_access {
.wp-list-table.roles .column-admin_access,
.wp-list-table.roles .column-priority {
text-align: left !important;
}
}
@@ -0,0 +1,36 @@
jQuery(document).ready(function ($) {
var template = wp.template( 'um-nav-menus-fields' );
$( document ).on( 'menu-item-added', function ( e, $menuMarkup ) {
var id = $( $menuMarkup ).attr('id').substr(10);
var template_content = template({
menuItemID: id,
restriction_data:{
um_nav_public:0,
um_nav_roles:[]
}
});
if ( $( $menuMarkup ).find( 'fieldset.field-move' ).length > 0 ) {
$( $menuMarkup ).find( 'fieldset.field-move' ).before( template_content );
} else {
$( $menuMarkup ).find( '.menu-item-actions' ).before( template_content );
}
});
$( 'ul#menu-to-edit > li' ).each( function(){
var id = $(this).attr('id').substr(10);
var template_content = template({
menuItemID: id,
restriction_data: um_menu_restriction_data[ id ]
});
if ( $( this ).find( 'fieldset.field-move' ).length > 0 ) {
$( this ).find( 'fieldset.field-move' ).before( template_content );
} else {
$( this ).find( '.menu-item-actions' ).before( template_content );
}
});
});
+23
View File
@@ -21,6 +21,29 @@ if ( ! class_exists( 'Admin' ) ) {
}
/**
* Check if current page load UM post type
*
*
* @return bool
*/
function is_plugin_post_type() {
if ( isset( $_REQUEST['post_type'] ) ) {
$post_type = $_REQUEST['post_type'];
if ( in_array( $post_type, array( 'um_form','um_directory' ) ) ) {
return true;
}
} elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) {
$post_type = get_post_type();
if ( in_array( $post_type, array( 'um_form', 'um_directory' ) ) ) {
return true;
}
}
return false;
}
/**
* Check if plugin is installed with correct folder
*/
+12 -24
View File
@@ -51,26 +51,24 @@ if ( ! class_exists( 'Admin_Enqueue' ) ) {
/***
*** @enter title placeholder
***/
function enter_title_here( $title ){
function enter_title_here( $title ) {
$screen = get_current_screen();
if ( 'um_directory' == $screen->post_type ){
$title = 'e.g. Member Directory';
}
if ( 'um_role' == $screen->post_type ){
$title = 'e.g. Community Member';
}
if ( 'um_form' == $screen->post_type ){
$title = 'e.g. New Registration Form';
}
return $title;
}
/***
*** @Runs on admin head
***/
function admin_head(){
if ( $this->is_plugin_post_type() ){
if ( UM()->admin()->is_plugin_post_type() ){
?>
@@ -87,25 +85,6 @@ if ( ! class_exists( 'Admin_Enqueue' ) ) {
}
/***
*** @check that we're on a custom post type supported by UM
***/
function is_plugin_post_type(){
if (isset($_REQUEST['post_type'])){
$post_type = $_REQUEST['post_type'];
if ( in_array($post_type, array('um_form','um_role','um_directory'))){
return true;
}
} else if ( isset($_REQUEST['action'] ) && $_REQUEST['action'] == 'edit') {
$post_type = get_post_type();
if ( in_array($post_type, array('um_form','um_role','um_directory'))){
return true;
}
}
return false;
}
/***
*** @Load Form
***/
@@ -339,6 +318,15 @@ if ( ! class_exists( 'Admin_Enqueue' ) ) {
}
/***
*** @Load jQuery custom code
***/
function load_nav_manus_scripts() {
wp_register_script( 'um_admin_nav_manus', $this->js_url . 'um-admin-nav-menu.js', array('jquery','wp-util'), '', true );
wp_enqueue_script( 'um_admin_nav_manus' );
}
/***
*** @Load AJAX
+1 -36
View File
@@ -44,44 +44,9 @@ if ( ! class_exists( 'Admin_Functions' ) ) {
}
if ($post_type == 'um_role') {
$messages['um_role'] = array(
0 => '',
1 => __('Role updated.'),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Role updated.'),
5 => isset($_GET['revision']) ? __('Role restored to revision.') : false,
6 => __('Role created.'),
7 => __('Role saved.'),
8 => __('Role submitted.'),
9 => __('Role scheduled.'),
10=> __('Role draft updated.'),
);
}
return $messages;
}
/***
*** @check that we're on a custom post type supported by UM
***/
function is_plugin_post_type(){
if (isset($_REQUEST['post_type'])){
$post_type = $_REQUEST['post_type'];
if ( in_array($post_type, array('um_form','um_role','um_directory'))){
return true;
}
} else if ( isset($_REQUEST['action'] ) && $_REQUEST['action'] == 'edit') {
$post_type = get_post_type();
if ( in_array($post_type, array('um_form','um_role','um_directory'))){
return true;
}
}
return false;
}
/***
*** @gettext filters
@@ -89,7 +54,7 @@ if ( ! class_exists( 'Admin_Functions' ) ) {
function gettext($translation, $text, $domain) {
global $post;
//$screen = get_current_screen();
if ( isset( $post->post_type ) && $this->is_plugin_post_type() ) {
if ( isset( $post->post_type ) && UM()->admin()->is_plugin_post_type() ) {
$translations = get_translations_for_domain( $domain);
if ( $text == 'Publish') {
return $translations->translate( 'Create' );
+1 -58
View File
@@ -39,23 +39,6 @@ if ( ! class_exists( 'Admin_Metabox' ) ) {
return false;
}
/***
*** @check that we're on a custom post type supported by UM
***/
function is_plugin_post_type() {
if (isset($_REQUEST['post_type'])){
$post_type = $_REQUEST['post_type'];
if ( in_array($post_type, array('um_form','um_role','um_directory'))){
return true;
}
} else if ( isset($_REQUEST['action'] ) && $_REQUEST['action'] == 'edit') {
$post_type = get_post_type();
if ( in_array($post_type, array('um_form','um_role','um_directory'))){
return true;
}
}
return false;
}
/***
*** @Gets the role meta
@@ -76,7 +59,7 @@ if ( ! class_exists( 'Admin_Metabox' ) ) {
***/
function admin_head(){
global $post;
if ( $this->is_plugin_post_type() && isset($post->ID) ){
if ( UM()->admin()->is_plugin_post_type() && isset($post->ID) ){
$this->postmeta = $this->get_custom_post_meta($post->ID);
}
}
@@ -767,46 +750,6 @@ if ( ! class_exists( 'Admin_Metabox' ) ) {
}
/***
*** @save role metabox
***/
/* function save_metabox_role( $post_id, $post ) {
global $wpdb;
// validate nonce
if ( !isset( $_POST['um_admin_save_metabox_role_nonce'] ) || !wp_verify_nonce( $_POST['um_admin_save_metabox_role_nonce'], basename( __FILE__ ) ) ) return $post_id;
// validate post type
if ( $post->post_type != 'um_role' ) return $post_id;
// validate user
$post_type = get_post_type_object( $post->post_type );
if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id;
$where = array( 'ID' => $post_id );
if (empty($_POST['post_title'])) $_POST['post_title'] = 'Role #'.$post_id;
$wpdb->update( $wpdb->posts, array( 'post_title' => $_POST['post_title'], 'post_name' => sanitize_title( $_POST['post_title'] ) ), $where );
// save
delete_post_meta( $post_id, '_um_can_view_roles' );
delete_post_meta( $post_id, '_um_can_edit_roles' );
delete_post_meta( $post_id, '_um_can_delete_roles' );
do_action('um_admin_before_saving_role_meta', $post_id );
do_action('um_admin_before_save_role', $post_id, $post );
foreach( $_POST as $k => $v ) {
if (strstr($k, '_um_')){
update_post_meta( $post_id, $k, $v);
}
}
do_action('um_admin_after_editing_role', $post_id, $post);
do_action('um_admin_after_save_role', $post_id, $post );
}*/
/***
*** @save form metabox
+2 -2
View File
@@ -1830,7 +1830,7 @@ Host: <?php echo $host . "\n"; ?>
---- Current User Details --
<?php $user = wp_get_current_user(); ?>
Role: <?php echo um_user( 'role' ). "\n"; ?>
Role: <?php echo implode( ', ', um_user( 'roles' ) ). "\n"; ?>
--- WordPress Configurations ---
@@ -1907,7 +1907,7 @@ Password Reset: <?php echo get_permalink( UM()->options()->get('core_password
--- UM Users Configuration ---
Default New User Role: <?php echo UM()->options()->get('default_role') . "\n"; ?>
Default New User Role: <?php echo UM()->options()->get('register_role') . "\n"; ?>
Profile Permalink Base: <?php echo UM()->options()->get('permalink_base') . "\n"; ?>
User Display Name: <?php echo UM()->options()->get('display_name') . "\n"; ?>
Force Name to Uppercase: <?php echo $this->info_value( UM()->options()->get('force_display_name_capitlized'), 'yesno', true ); ?>
+23 -19
View File
@@ -23,31 +23,35 @@ if ( ! class_exists( 'Admin_Upgrade' ) ) {
}
/**
* Load packages
*/
public function packages() {
$this->set_update_versions();
/**
* Load packages
*/
public function packages() {
if ( ! ini_get( 'safe_mode' ) ) {
@set_time_limit(0);
}
$um_last_version_upgrade = get_option( 'um_last_version_upgrade' );
$um_last_version_upgrade = ! $um_last_version_upgrade ? '0.0.0' : $um_last_version_upgrade;
$this->set_update_versions();
foreach ( $this->update_versions as $update_version ) {
$um_last_version_upgrade = get_option( 'um_last_version_upgrade' );
$um_last_version_upgrade = ! $um_last_version_upgrade ? '0.0.0' : $um_last_version_upgrade;
if ( version_compare( $update_version, $um_last_version_upgrade, '<=' ) )
continue;
foreach ( $this->update_versions as $update_version ) {
if ( version_compare( $update_version, ultimatemember_version, '>' ) )
continue;
if ( version_compare( $update_version, $um_last_version_upgrade, '<=' ) )
continue;
$file_path = $this->packages_dir . $update_version . '.php';
if ( version_compare( $update_version, ultimatemember_version, '>' ) )
continue;
if ( file_exists( $file_path ) ) {
include_once( $file_path );
update_option( 'um_last_version_upgrade', $update_version );
}
}
}
$file_path = $this->packages_dir . $update_version . '.php';
if ( file_exists( $file_path ) ) {
include_once( $file_path );
update_option( 'um_last_version_upgrade', $update_version );
}
}
}
/**
@@ -4,287 +4,293 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $wpdb;
if ( isset( $_REQUEST['_wp_http_referer'] ) ) {
$redirect = remove_query_arg(array('_wp_http_referer' ), wp_unslash( $_REQUEST['_wp_http_referer'] ) );
$redirect = remove_query_arg(array('_wp_http_referer' ), wp_unslash( $_REQUEST['_wp_http_referer'] ) );
} else {
$redirect = get_admin_url(). 'admin.php?page=um_roles';
$redirect = get_admin_url(). 'admin.php?page=um_roles';
}
global $wp_roles;
if ( isset( $_GET['action'] ) ) {
switch ( $_GET['action'] ) {
/* delete action */
case 'delete': {
$role_keys = array();
if ( isset( $_REQUEST['id'] ) ) {
check_admin_referer( 'um_role_delete' . $_REQUEST['id'] . get_current_user_id() );
$role_keys = (array)$_REQUEST['id'];
} elseif( isset( $_REQUEST['item'] ) ) {
check_admin_referer( 'bulk-' . sanitize_key( __( 'Roles', 'ultimate-member' ) ) );
$role_keys = $_REQUEST['item'];
}
switch ( $_GET['action'] ) {
/* delete action */
case 'delete': {
$role_keys = array();
if ( isset( $_REQUEST['id'] ) ) {
check_admin_referer( 'um_role_delete' . $_REQUEST['id'] . get_current_user_id() );
$role_keys = (array)$_REQUEST['id'];
} elseif( isset( $_REQUEST['item'] ) ) {
check_admin_referer( 'bulk-' . sanitize_key( __( 'Roles', 'ultimate-member' ) ) );
$role_keys = $_REQUEST['item'];
}
if ( ! count( $role_keys ) )
um_js_redirect( $redirect );
if ( ! count( $role_keys ) )
um_js_redirect( $redirect );
$um_roles = get_option( 'um_roles' );
$um_roles = get_option( 'um_roles' );
$um_custom_roles = array();
foreach ( $role_keys as $k => $role_key ) {
$role_meta = get_option( "um_role_{$role_key}_meta" );
$um_custom_roles = array();
foreach ( $role_keys as $k => $role_key ) {
$role_meta = get_option( "um_role_{$role_key}_meta" );
if ( empty( $role_meta['_um_is_custom'] ) ) {
continue;
}
if ( empty( $role_meta['_um_is_custom'] ) ) {
continue;
}
delete_option( "um_role_{$role_key}_meta" );
$um_roles = array_diff( $um_roles, array( $role_key ) );
delete_option( "um_role_{$role_key}_meta" );
$um_roles = array_diff( $um_roles, array( $role_key ) );
$roleID = 'um_' . $role_key;
$um_custom_roles[] = $roleID;
$roleID = 'um_' . $role_key;
$um_custom_roles[] = $roleID;
//check if role exist before removing it
if ( get_role( $roleID ) ) {
remove_role( $roleID );
}
}
//check if role exist before removing it
if ( get_role( $roleID ) ) {
remove_role( $roleID );
}
}
//set for users with deleted roles role "Subscriber"
$args = array(
'blog_id' => get_current_blog_id(),
'role__in' => $um_custom_roles,
'number' => -1,
'count_total' => false,
'fields' => 'ids',
);
$users_to_subscriber = get_users( $args );
if ( ! empty( $users_to_subscriber ) ) {
foreach ( $users_to_subscriber as $user_id ) {
$object_user = get_userdata( $user_id );
//set for users with deleted roles role "Subscriber"
$args = array(
'blog_id' => get_current_blog_id(),
'role__in' => $um_custom_roles,
'number' => -1,
'count_total' => false,
'fields' => 'ids',
);
$users_to_subscriber = get_users( $args );
if ( ! empty( $users_to_subscriber ) ) {
foreach ( $users_to_subscriber as $user_id ) {
$object_user = get_userdata( $user_id );
if ( ! empty( $object_user ) ) {
foreach ( $um_custom_roles as $roleID ) {
$object_user->remove_role( $roleID );
}
}
if ( ! empty( $object_user ) ) {
foreach ( $um_custom_roles as $roleID ) {
$object_user->remove_role( $roleID );
}
}
//update user role if it's empty
if ( empty( $object_user->roles ) )
wp_update_user( array( 'ID' => $user_id, 'role' => 'subscriber' ) );
}
}
//update user role if it's empty
if ( empty( $object_user->roles ) )
wp_update_user( array( 'ID' => $user_id, 'role' => 'subscriber' ) );
}
}
update_option( 'um_roles', $um_roles );
update_option( 'um_roles', $um_roles );
um_js_redirect( add_query_arg( 'msg', 'd', $redirect ) );
break;
}
case 'reset': {
$role_keys = array();
if ( isset( $_REQUEST['id'] ) ) {
check_admin_referer( 'um_role_reset' . $_REQUEST['id'] . get_current_user_id() );
$role_keys = (array)$_REQUEST['id'];
} elseif( isset( $_REQUEST['item'] ) ) {
check_admin_referer( 'bulk-' . sanitize_key( __( 'Roles', 'ultimate-member' ) ) );
$role_keys = $_REQUEST['item'];
}
um_js_redirect( add_query_arg( 'msg', 'd', $redirect ) );
break;
}
case 'reset': {
$role_keys = array();
if ( isset( $_REQUEST['id'] ) ) {
check_admin_referer( 'um_role_reset' . $_REQUEST['id'] . get_current_user_id() );
$role_keys = (array)$_REQUEST['id'];
} elseif( isset( $_REQUEST['item'] ) ) {
check_admin_referer( 'bulk-' . sanitize_key( __( 'Roles', 'ultimate-member' ) ) );
$role_keys = $_REQUEST['item'];
}
if ( ! count( $role_keys ) )
um_js_redirect( $redirect );
if ( ! count( $role_keys ) )
um_js_redirect( $redirect );
foreach ( $role_keys as $k=>$role_key ) {
$role_meta = get_option( "um_role_{$role_key}_meta" );
foreach ( $role_keys as $k=>$role_key ) {
$role_meta = get_option( "um_role_{$role_key}_meta" );
if ( ! empty( $role_meta['_um_is_custom'] ) ) {
unset( $role_keys[array_search( $role_key, $role_keys )] );
continue;
}
if ( ! empty( $role_meta['_um_is_custom'] ) ) {
unset( $role_keys[array_search( $role_key, $role_keys )] );
continue;
}
delete_option( "um_role_{$role_key}_meta" );
}
delete_option( "um_role_{$role_key}_meta" );
}
um_js_redirect( add_query_arg( 'msg', 'reset', $redirect ) );
break;
}
}
um_js_redirect( add_query_arg( 'msg', 'reset', $redirect ) );
break;
}
}
}
//remove extra query arg
if ( ! empty( $_GET['_wp_http_referer'] ) )
um_js_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce'), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
um_js_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce'), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
$order_by = 'name';
$order = ( isset( $_GET['order'] ) && 'asc' == strtolower( $_GET['order'] ) ) ? 'ASC' : 'DESC';
if( ! class_exists( 'WP_List_Table' ) )
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
class UM_Roles_List_Table extends WP_List_Table {
var $no_items_message = '';
var $sortable_columns = array();
var $default_sorting_field = '';
var $actions = array();
var $bulk_actions = array();
var $columns = array();
var $no_items_message = '';
var $sortable_columns = array();
var $default_sorting_field = '';
var $actions = array();
var $bulk_actions = array();
var $columns = array();
function __construct( $args = array() ){
$args = wp_parse_args( $args, array(
'singular' => __( 'item', 'ultimate-member' ),
'plural' => __( 'items', 'ultimate-member' ),
'ajax' => false
) );
function __construct( $args = array() ){
$args = wp_parse_args( $args, array(
'singular' => __( 'item', 'ultimate-member' ),
'plural' => __( 'items', 'ultimate-member' ),
'ajax' => false
) );
$this->no_items_message = $args['plural'] . ' ' . __( 'not found.', 'ultimate-member' );
$this->no_items_message = $args['plural'] . ' ' . __( 'not found.', 'ultimate-member' );
parent::__construct( $args );
parent::__construct( $args );
}
}
function __call( $name, $arguments ) {
return call_user_func_array( array( $this, $name ), $arguments );
}
function __call( $name, $arguments ) {
return call_user_func_array( array( $this, $name ), $arguments );
}
function prepare_items() {
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
}
function prepare_items() {
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
}
function column_default( $item, $column_name ) {
if( isset( $item[ $column_name ] ) ) {
return $item[ $column_name ];
} else {
return '';
}
}
function column_default( $item, $column_name ) {
if( isset( $item[ $column_name ] ) ) {
return $item[ $column_name ];
} else {
return '';
}
}
function no_items() {
echo $this->no_items_message;
}
function no_items() {
echo $this->no_items_message;
}
function set_sortable_columns( $args = array() ) {
$return_args = array();
foreach( $args as $k=>$val ) {
if( is_numeric( $k ) ) {
$return_args[ $val ] = array( $val, $val == $this->default_sorting_field );
} else if( is_string( $k ) ) {
$return_args[ $k ] = array( $val, $k == $this->default_sorting_field );
} else {
continue;
}
}
$this->sortable_columns = $return_args;
return $this;
}
function set_sortable_columns( $args = array() ) {
$return_args = array();
foreach( $args as $k=>$val ) {
if( is_numeric( $k ) ) {
$return_args[ $val ] = array( $val, $val == $this->default_sorting_field );
} else if( is_string( $k ) ) {
$return_args[ $k ] = array( $val, $k == $this->default_sorting_field );
} else {
continue;
}
}
$this->sortable_columns = $return_args;
return $this;
}
function get_sortable_columns() {
return $this->sortable_columns;
}
function get_sortable_columns() {
return $this->sortable_columns;
}
function set_columns( $args = array() ) {
if( count( $this->bulk_actions ) ) {
$args = array_merge( array( 'cb' => '<input type="checkbox" />' ), $args );
}
$this->columns = $args;
return $this;
}
function set_columns( $args = array() ) {
if( count( $this->bulk_actions ) ) {
$args = array_merge( array( 'cb' => '<input type="checkbox" />' ), $args );
}
$this->columns = $args;
return $this;
}
function get_columns() {
return $this->columns;
}
function get_columns() {
return $this->columns;
}
function set_actions( $args = array() ) {
$this->actions = $args;
return $this;
}
function set_actions( $args = array() ) {
$this->actions = $args;
return $this;
}
function get_actions() {
return $this->actions;
}
function get_actions() {
return $this->actions;
}
function set_bulk_actions( $args = array() ) {
$this->bulk_actions = $args;
return $this;
}
function set_bulk_actions( $args = array() ) {
$this->bulk_actions = $args;
return $this;
}
function get_bulk_actions() {
return $this->bulk_actions;
}
function get_bulk_actions() {
return $this->bulk_actions;
}
function column_cb( $item ) {
return sprintf( '<input type="checkbox" name="item[]" value="%s" />', $item['key'] );
}
function column_cb( $item ) {
return sprintf( '<input type="checkbox" name="item[]" value="%s" />', $item['key'] );
}
function column_title( $item ) {
$actions = array();
function column_title( $item ) {
$actions = array();
$actions['edit'] = '<a href="admin.php?page=um_roles&tab=edit&id=' . $item['key'] . '">' . __( 'Edit', 'ultimate-member' ). '</a>';
$actions['edit'] = '<a href="admin.php?page=um_roles&tab=edit&id=' . $item['key'] . '">' . __( 'Edit', 'ultimate-member' ). '</a>';
if ( ! empty( $item['_um_is_custom'] ) ) {
$actions['delete'] = '<a href="admin.php?page=um_roles&action=delete&id=' . $item['key'] . '&_wpnonce=' . wp_create_nonce( 'um_role_delete' . $item['key'] . get_current_user_id() ) . '" onclick="return confirm( \'' . __( 'Are you sure you want to delete this role?', 'ultimate-member' ) . '\' );">' . __( 'Delete', 'ultimate-member' ). '</a>';
} else {
$role_meta = get_option( "um_role_{$item['key']}_meta" );
if ( ! empty( $item['_um_is_custom'] ) ) {
$actions['delete'] = '<a href="admin.php?page=um_roles&action=delete&id=' . $item['key'] . '&_wpnonce=' . wp_create_nonce( 'um_role_delete' . $item['key'] . get_current_user_id() ) . '" onclick="return confirm( \'' . __( 'Are you sure you want to delete this role?', 'ultimate-member' ) . '\' );">' . __( 'Delete', 'ultimate-member' ). '</a>';
} else {
$role_meta = get_option( "um_role_{$item['key']}_meta" );
if ( ! empty( $role_meta ) ) {
$actions['reset'] = '<a href="admin.php?page=um_roles&action=reset&id=' . $item['key'] . '&_wpnonce=' . wp_create_nonce( 'um_role_reset' . $item['key'] . get_current_user_id() ) . '" onclick="return confirm( \'' . __( 'Are you sure you want to reset UM role meta?', 'ultimate-member' ) . '\' );">' . __( 'Reset UM Role meta', 'ultimate-member' ). '</a>';
}
}
if ( ! empty( $role_meta ) ) {
$actions['reset'] = '<a href="admin.php?page=um_roles&action=reset&id=' . $item['key'] . '&_wpnonce=' . wp_create_nonce( 'um_role_reset' . $item['key'] . get_current_user_id() ) . '" onclick="return confirm( \'' . __( 'Are you sure you want to reset UM role meta?', 'ultimate-member' ) . '\' );">' . __( 'Reset UM Role meta', 'ultimate-member' ). '</a>';
}
}
return sprintf('%1$s %2$s', '<strong><a class="row-title" href="admin.php?page=um_roles&tab=edit&id=' . $item['key'] . '">' . $item['name'] . '</a></strong>', $this->row_actions( $actions ) );
}
return sprintf('%1$s %2$s', '<strong><a class="row-title" href="admin.php?page=um_roles&tab=edit&id=' . $item['key'] . '">' . $item['name'] . '</a></strong>', $this->row_actions( $actions ) );
}
function column_roleid( $item ) {
return ! empty( $item['_um_is_custom'] ) ? 'um_' . $item['key'] : $item['key'];
}
function column_roleid( $item ) {
return ! empty( $item['_um_is_custom'] ) ? 'um_' . $item['key'] : $item['key'];
}
function column_core( $item ) {
echo ! empty( $item['_um_is_custom'] ) ? __( 'Yes', 'ultimate-member' ) : __( 'No', 'ultimate-member' );
}
function column_core( $item ) {
echo ! empty( $item['_um_is_custom'] ) ? __( 'Yes', 'ultimate-member' ) : __( 'No', 'ultimate-member' );
}
function column_admin_access( $item ) {
echo ! empty( $item['_um_can_access_wpadmin'] ) ? __( 'Yes', 'ultimate-member' ) : __( 'No', 'ultimate-member' );
}
function column_admin_access( $item ) {
echo ! empty( $item['_um_can_access_wpadmin'] ) ? __( 'Yes', 'ultimate-member' ) : __( 'No', 'ultimate-member' );
}
function um_set_pagination_args( $attr = array() ) {
$this->set_pagination_args( $attr );
}
function column_priority( $item ) {
echo ! empty( $item['_um_priority'] ) ? $item['_um_priority'] : '-';
}
function um_set_pagination_args( $attr = array() ) {
$this->set_pagination_args( $attr );
}
}
$ListTable = new UM_Roles_List_Table( array(
'singular' => __( 'Role', 'ultimate-member' ),
'plural' => __( 'Roles', 'ultimate-member' ),
'ajax' => false
'singular' => __( 'Role', 'ultimate-member' ),
'plural' => __( 'Roles', 'ultimate-member' ),
'ajax' => false
));
$per_page = 20;
$paged = $ListTable->get_pagenum();
$ListTable->set_bulk_actions( array(
'delete' => __( 'Delete', 'ultimate-member' )
'delete' => __( 'Delete', 'ultimate-member' )
) );
$ListTable->set_columns( array(
'title' => __( 'Role Title', 'ultimate-member' ),
'roleid' => __( 'Role ID', 'ultimate-member' ),
'users' => __( 'No.of Members', 'ultimate-member' ),
'core' => __( 'UM Custom Role', 'ultimate-member' ),
'admin_access' => __( 'WP-Admin Access', 'ultimate-member' ),
'title' => __( 'Role Title', 'ultimate-member' ),
'roleid' => __( 'Role ID', 'ultimate-member' ),
'users' => __( 'No.of Members', 'ultimate-member' ),
'core' => __( 'UM Custom Role', 'ultimate-member' ),
'admin_access' => __( 'WP-Admin Access', 'ultimate-member' ),
'priority' => __( 'Priority', 'ultimate-member' ),
) );
$ListTable->set_sortable_columns( array(
'title' => 'title'
'title' => 'title'
) );
$users_count = count_users();
@@ -293,53 +299,53 @@ $roles = array();
$role_keys = get_option( 'um_roles' );
if ( $role_keys ) {
foreach ( $role_keys as $role_key ) {
$role_meta = get_option( "um_role_{$role_key}_meta" );
if ( $role_meta ) {
foreach ( $role_keys as $role_key ) {
$role_meta = get_option( "um_role_{$role_key}_meta" );
if ( $role_meta ) {
$roles['um_' . $role_key] = array(
'key' => $role_key,
'users' => ! empty( $users_count['avail_roles']['um_' . $role_key] ) ? $users_count['avail_roles']['um_' . $role_key] : 0
);
$roles['um_' . $role_key] = array_merge( $roles['um_' . $role_key], $role_meta );
}
}
$roles['um_' . $role_key] = array(
'key' => $role_key,
'users' => ! empty( $users_count['avail_roles']['um_' . $role_key] ) ? $users_count['avail_roles']['um_' . $role_key] : 0
);
$roles['um_' . $role_key] = array_merge( $roles['um_' . $role_key], $role_meta );
}
}
}
global $wp_roles;
foreach ( $wp_roles->roles as $roleID => $role_data ) {
if ( in_array( $roleID, array_keys( $roles ) ) )
continue;
if ( in_array( $roleID, array_keys( $roles ) ) )
continue;
$roles[$roleID] = array(
'key' => $roleID,
'users' => ! empty( $users_count['avail_roles'][$roleID] ) ? $users_count['avail_roles'][$roleID] : 0,
'name' => $role_data['name']
);
$roles[$roleID] = array(
'key' => $roleID,
'users' => ! empty( $users_count['avail_roles'][$roleID] ) ? $users_count['avail_roles'][$roleID] : 0,
'name' => $role_data['name']
);
$role_meta = get_option( "um_role_{$roleID}_meta" );
if ( $role_meta )
$roles[$roleID] = array_merge( $roles[$roleID], $role_meta );
$role_meta = get_option( "um_role_{$roleID}_meta" );
if ( $role_meta )
$roles[$roleID] = array_merge( $roles[$roleID], $role_meta );
}
switch( strtolower( $order ) ) {
case 'asc':
uasort( $roles, function( $a, $b ) {
//$a['name'] = ! empty( $a['_um_is_custom'] ) ? 'UM ' . $a['name'] : $a['name'];
//$b['name'] = ! empty( $b['_um_is_custom'] ) ? 'UM ' . $b['name'] : $b['name'];
case 'asc':
uasort( $roles, function( $a, $b ) {
//$a['name'] = ! empty( $a['_um_is_custom'] ) ? 'UM ' . $a['name'] : $a['name'];
//$b['name'] = ! empty( $b['_um_is_custom'] ) ? 'UM ' . $b['name'] : $b['name'];
return strnatcmp( $a['name'], $b['name'] );
} );
break;
case 'desc':
uasort( $roles, function( $a, $b ) {
//$a['name'] = ! empty( $a['_um_is_custom'] ) ? 'UM ' . $a['name'] : $a['name'];
//$b['name'] = ! empty( $b['_um_is_custom'] ) ? 'UM ' . $b['name'] : $b['name'];
return strnatcmp( $a['name'], $b['name'] );
} );
break;
case 'desc':
uasort( $roles, function( $a, $b ) {
//$a['name'] = ! empty( $a['_um_is_custom'] ) ? 'UM ' . $a['name'] : $a['name'];
//$b['name'] = ! empty( $b['_um_is_custom'] ) ? 'UM ' . $b['name'] : $b['name'];
return strnatcmp( $a['name'], $b['name'] ) * -1;
} );
break;
return strnatcmp( $a['name'], $b['name'] ) * -1;
} );
break;
}
$ListTable->prepare_items();
@@ -347,21 +353,21 @@ $ListTable->items = array_slice( $roles, ( $paged - 1 ) * $per_page, $per_page )
$ListTable->um_set_pagination_args( array( 'total_items' => count( $roles ), 'per_page' => $per_page ) ); ?>
<div class="wrap">
<h2>
<?php _e( 'User Roles', 'ultimate-member' ) ?>
<a class="add-new-h2" href="<?php echo add_query_arg( array( 'page' => 'um_roles', 'tab' => 'add' ), admin_url( 'admin.php' ) ) ?>"><?php _e( 'Add New', 'ultimate-member' ) ?></a>
</h2>
<h2>
<?php _e( 'User Roles', 'ultimate-member' ) ?>
<a class="add-new-h2" href="<?php echo add_query_arg( array( 'page' => 'um_roles', 'tab' => 'add' ), admin_url( 'admin.php' ) ) ?>"><?php _e( 'Add New', 'ultimate-member' ) ?></a>
</h2>
<?php if ( ! empty( $_GET['msg'] ) ) {
switch( $_GET['msg'] ) {
case 'd':
echo '<div id="message" class="updated fade"><p>' . __( 'User Role <strong>Deleted</strong> Successfully.', 'ultimate-member' ) . '</p></div>';
break;
}
} ?>
<?php if ( ! empty( $_GET['msg'] ) ) {
switch( $_GET['msg'] ) {
case 'd':
echo '<div id="message" class="updated fade"><p>' . __( 'User Role <strong>Deleted</strong> Successfully.', 'ultimate-member' ) . '</p></div>';
break;
}
} ?>
<form action="" method="get" name="um-roles" id="um-roles" style="float: left;margin-right: 10px;">
<input type="hidden" name="page" value="um_roles" />
<?php $ListTable->display(); ?>
</form>
<form action="" method="get" name="um-roles" id="um-roles" style="float: left;margin-right: 10px;">
<input type="hidden" name="page" value="um_roles" />
<?php $ListTable->display(); ?>
</form>
</div>
+173 -57
View File
@@ -940,6 +940,7 @@ $um_roles = get_posts( array(
'post_status' => 'publish'
) );
$roles_associations = array();
$all_wp_roles = array_keys( get_editable_roles() );
if ( ! empty( $um_roles ) ) {
@@ -968,33 +969,36 @@ if ( ! empty( $um_roles ) ) {
|| '_um_can_view_roles' == $metadata['meta_key'] || '_um_can_follow_roles' == $metadata['meta_key']
|| '_um_can_friend_roles' == $metadata['meta_key'] || '_um_can_review_roles' == $metadata['meta_key'] ) {
$metadata['meta_value'] = maybe_unserialize( $metadata['meta_value'] );
$metadata['meta_value'] = array_map( function( $item ) {
return 'um_' . $item;
}, $metadata['meta_value'] );
} elseif ( '_um_profilec_upgrade_role' == $metadata['meta_key'] ) {
$metadata['meta_value'] = 'um_' . $metadata['meta_value'];
}
$role_metadata[$metadata['meta_key']] = $metadata['meta_value'];
$role_metadata[ $metadata['meta_key'] ] = $metadata['meta_value'];
}
}
if ( ! in_array( $role_key, $all_wp_roles ) ) {
$role_meta = array_merge( $role_metadata, array(
'name' => $um_role->post_title,
'_um_is_custom' => true,
'name' => $um_role->post_title,
'wp_capabilities' => array( 'read' => true ),
'_um_is_custom' => true,
) );
} else {
$role_meta = $role_metadata;
}
$old_key = ! empty( $role_meta['_um_core'] ) ? $role_meta['_um_core'] : $role_key;
if ( ! in_array( $role_key, $all_wp_roles ) ) {
$roles_associations[ $old_key ] = 'um_' . $role_key;
} else {
$roles_associations[ $old_key ] = $role_key;
}
$r_key = ! empty( $role_meta['_um_core'] ) ? $role_meta['_um_core'] : $role_key;
//get all users with UM role
$args = array(
'meta_query' => array(
array(
'key' => 'role',
'value' => $role_meta['_um_core']
'value' => $r_key
)
),
'number' => '',
@@ -1020,7 +1024,37 @@ if ( ! empty( $um_roles ) ) {
update_option( "um_role_{$role_key}_meta", $role_meta );
}
foreach ( $um_roles as $um_role ) {
$role_key = sanitize_title( $um_role->post_title );
$role_meta = get_option( "um_role_{$role_key}_meta" );
$role_metadata = array();
if ( ! empty( $role_meta ) ) {
foreach ( $role_meta as $metakey => $metadata ) {
if ( '_um_can_edit_roles' == $metakey || '_um_can_delete_roles' == $metakey
|| '_um_can_view_roles' == $metakey || '_um_can_follow_roles' == $metakey
|| '_um_can_friend_roles' == $metakey || '_um_can_review_roles' == $metakey ) {
if ( ! empty( $metadata ) ) {
foreach ( $metadata as $i => $role_k ) {
$metadata[ $i ] = $roles_associations[ $role_k ];
}
}
} elseif ( '_um_profilec_upgrade_role' == $metakey ) {
$metadata = $roles_associations[ $metadata ];
}
$role_meta[ $metakey ] = $metadata;
}
}
update_option( "um_role_{$role_key}_meta", $role_meta );
}
}
update_option( 'um_roles', $role_keys );
global $wp_roles, $wp_version;
@@ -1074,7 +1108,8 @@ if ( ! empty( $posts ) ) {
$access_roles = array();
if ( ! empty( $um_access_roles ) ) {
foreach ( $roles_array as $role => $role_label ) {
if ( in_array( substr( $role, 3 ), $um_access_roles ) )
//if ( in_array( substr( $role, 3 ), $um_access_roles ) )
if ( false !== array_search( $role, $roles_associations ) && in_array( array_search( $role, $roles_associations ), $um_access_roles ) )
$access_roles[ $role ] = '1';
else
$access_roles[ $role ] = '0';
@@ -1133,7 +1168,8 @@ foreach ( $all_taxonomies as $key => $taxonomy ) {
$access_roles = array();
if ( ! empty( $um_access_roles ) ) {
foreach ( $roles_array as $role => $role_label ) {
if ( in_array( substr( $role, 3 ), $um_access_roles ) )
//if ( in_array( substr( $role, 3 ), $um_access_roles ) )
if ( false !== array_search( $role, $roles_associations ) && in_array( array_search( $role, $roles_associations ), $um_access_roles ) )
$access_roles[ $role ] = '1';
else
$access_roles[ $role ] = '0';
@@ -1184,7 +1220,8 @@ foreach ( $forms as $form_id ) {
$role = get_post_meta( $form_id, "_um_{$form_type}_role", true );
if ( $role ) {
update_post_meta( $form_id, "_um_{$form_type}_role", 'um_' . $role );
//update_post_meta( $form_id, "_um_{$form_type}_role", 'um_' . $role );
update_post_meta( $form_id, "_um_{$form_type}_role", $roles_associations[ $role ] );
}
}
}
@@ -1201,9 +1238,14 @@ foreach ( $member_directories as $directory_id ) {
$directory_roles = get_post_meta( $directory_id, '_um_roles', true );
if ( ! empty( $directory_roles ) ) {
$directory_roles = array_map( function( $item ) {
/*$directory_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $directory_roles );
}, $directory_roles );*/
foreach ( $directory_roles as $i => $role_k ) {
$directory_roles[ $i ] = $roles_associations[ $role_k ];
}
update_post_meta( $directory_id, '_um_roles', $directory_roles );
}
@@ -1211,9 +1253,13 @@ foreach ( $member_directories as $directory_id ) {
$um_roles_can_search = get_post_meta( $directory_id, '_um_roles_can_search', true );
if ( ! empty( $um_roles_can_search ) ) {
$um_roles_can_search = array_map( function( $item ) {
/*$um_roles_can_search = array_map( function( $item ) {
return 'um_' . $item;
}, $um_roles_can_search );
}, $um_roles_can_search );*/
foreach ( $um_roles_can_search as $i => $role_k ) {
$um_roles_can_search[ $i ] = $roles_associations[ $role_k ];
}
update_post_meta( $directory_id, '_um_roles_can_search', $um_roles_can_search );
}
@@ -1270,23 +1316,31 @@ $menus = get_posts( array(
foreach ( $menus as $menu ) {
$menu_roles = get_post_meta( $menu->ID, 'menu-item-um_nav_roles', true );
$menu_roles = array_map( function( $item ) {
foreach ( $menu_roles as $i => $role_k ) {
$menu_roles[ $i ] = $roles_associations[ $role_k ];
}
/*$menu_roles = array_map( function( $item ) {
if ( strpos( $item, 'um_' ) === 0 )
return $item;
return 'um_' . $item;
}, $menu_roles );
}, $menu_roles );*/
update_post_meta( $menu->ID, 'menu-item-um_nav_roles', $menu_roles );
}
$profile_tab_main_roles = UM()->options()->get( 'profile_tab_main_roles' );
$profile_tab_main_roles = ! $profile_tab_main_roles ? array() : $profile_tab_main_roles;
if ( ! empty( $profile_tab_main_roles ) ) {
$profile_tab_main_roles = array_map( function( $item ) {
/*$profile_tab_main_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_main_roles );
}, $profile_tab_main_roles );*/
foreach ( $profile_tab_main_roles as $i => $role_k ) {
$profile_tab_main_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_main_roles', $profile_tab_main_roles );
}
@@ -1294,9 +1348,13 @@ if ( ! empty( $profile_tab_main_roles ) ) {
$profile_tab_posts_roles = UM()->options()->get( 'profile_tab_posts_roles' );
$profile_tab_posts_roles = ! $profile_tab_posts_roles ? array() : $profile_tab_posts_roles;
if ( ! empty( $profile_tab_posts_roles ) ) {
$profile_tab_posts_roles = array_map( function( $item ) {
/*$profile_tab_posts_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_posts_roles );
}, $profile_tab_posts_roles );*/
foreach ( $profile_tab_posts_roles as $i => $role_k ) {
$profile_tab_posts_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_posts_roles', $profile_tab_posts_roles );
}
@@ -1304,9 +1362,13 @@ if ( ! empty( $profile_tab_posts_roles ) ) {
$profile_tab_comments_roles = UM()->options()->get( 'profile_tab_comments_roles' );
$profile_tab_comments_roles = ! $profile_tab_comments_roles ? array() : $profile_tab_comments_roles;
if ( ! empty( $profile_tab_comments_roles ) ) {
$profile_tab_comments_roles = array_map( function( $item ) {
/*$profile_tab_comments_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_comments_roles );
}, $profile_tab_comments_roles );*/
foreach ( $profile_tab_comments_roles as $i => $role_k ) {
$profile_tab_comments_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_comments_roles', $profile_tab_comments_roles );
}
@@ -1314,9 +1376,13 @@ if ( ! empty( $profile_tab_comments_roles ) ) {
$profile_tab_activity_roles = UM()->options()->get( 'profile_tab_activity_roles' );
$profile_tab_activity_roles = ! $profile_tab_activity_roles ? array() : $profile_tab_activity_roles;
if ( ! empty( $profile_tab_activity_roles ) ) {
$profile_tab_activity_roles = array_map( function( $item ) {
/*$profile_tab_activity_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_activity_roles );
}, $profile_tab_activity_roles );*/
foreach ( $profile_tab_activity_roles as $i => $role_k ) {
$profile_tab_activity_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_activity_roles', $profile_tab_activity_roles );
}
@@ -1324,9 +1390,13 @@ if ( ! empty( $profile_tab_activity_roles ) ) {
$profile_tab_messages_roles = UM()->options()->get( 'profile_tab_messages_roles' );
$profile_tab_messages_roles = ! $profile_tab_messages_roles ? array() : $profile_tab_messages_roles;
if ( ! empty( $profile_tab_messages_roles ) ) {
$profile_tab_messages_roles = array_map( function( $item ) {
/*$profile_tab_messages_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_messages_roles );
}, $profile_tab_messages_roles );*/
foreach ( $profile_tab_messages_roles as $i => $role_k ) {
$profile_tab_messages_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_messages_roles', $profile_tab_messages_roles );
}
@@ -1334,9 +1404,13 @@ if ( ! empty( $profile_tab_messages_roles ) ) {
$profile_tab_reviews_roles = UM()->options()->get( 'profile_tab_reviews_roles' );
$profile_tab_reviews_roles = ! $profile_tab_reviews_roles ? array() : $profile_tab_reviews_roles;
if ( ! empty( $profile_tab_reviews_roles ) ) {
$profile_tab_reviews_roles = array_map( function( $item ) {
/*$profile_tab_reviews_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_reviews_roles );
}, $profile_tab_reviews_roles );*/
foreach ( $profile_tab_reviews_roles as $i => $role_k ) {
$profile_tab_reviews_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_reviews_roles', $profile_tab_reviews_roles );
}
@@ -1344,9 +1418,13 @@ if ( ! empty( $profile_tab_reviews_roles ) ) {
$profile_tab_purchases_roles = UM()->options()->get( 'profile_tab_purchases_roles' );
$profile_tab_purchases_roles = ! $profile_tab_purchases_roles ? array() : $profile_tab_purchases_roles;
if ( ! empty( $profile_tab_purchases_roles ) ) {
$profile_tab_purchases_roles = array_map( function( $item ) {
/*$profile_tab_purchases_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_purchases_roles );
}, $profile_tab_purchases_roles );*/
foreach ( $profile_tab_purchases_roles as $i => $role_k ) {
$profile_tab_purchases_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_purchases_roles', $profile_tab_purchases_roles );
}
@@ -1354,9 +1432,13 @@ if ( ! empty( $profile_tab_purchases_roles ) ) {
$profile_tab_product_reviews = UM()->options()->get( 'profile_tab_product-reviews_roles' );
$profile_tab_product_reviews = ! $profile_tab_product_reviews ? array() : $profile_tab_product_reviews;
if ( ! empty( $profile_tab_product_reviews ) ) {
$profile_tab_product_reviews = array_map( function( $item ) {
/*$profile_tab_product_reviews = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_product_reviews );
}, $profile_tab_product_reviews );*/
foreach ( $profile_tab_product_reviews as $i => $role_k ) {
$profile_tab_product_reviews[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_product-reviews_roles', $profile_tab_product_reviews );
}
@@ -1365,9 +1447,13 @@ if ( ! empty( $profile_tab_product_reviews ) ) {
$profile_tab_forums_roles = UM()->options()->get( 'profile_tab_forums_roles' );
$profile_tab_forums_roles = ! $profile_tab_forums_roles ? array() : $profile_tab_forums_roles;
if ( ! empty( $profile_tab_forums_roles ) ) {
$profile_tab_forums_roles = array_map( function( $item ) {
/*$profile_tab_forums_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_forums_roles );
}, $profile_tab_forums_roles );*/
foreach ( $profile_tab_forums_roles as $i => $role_k ) {
$profile_tab_forums_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_forums_roles', $profile_tab_forums_roles );
}
@@ -1375,9 +1461,13 @@ if ( ! empty( $profile_tab_forums_roles ) ) {
$profile_tab_friends_roles = UM()->options()->get( 'profile_tab_friends_roles' );
$profile_tab_friends_roles = ! $profile_tab_friends_roles ? array() : $profile_tab_friends_roles;
if ( ! empty( $profile_tab_friends_roles ) ) {
$profile_tab_friends_roles = array_map( function( $item ) {
/*$profile_tab_friends_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $profile_tab_friends_roles );
}, $profile_tab_friends_roles );*/
foreach ( $profile_tab_friends_roles as $i => $role_k ) {
$profile_tab_friends_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'profile_tab_friends_roles', $profile_tab_friends_roles );
}
@@ -1385,22 +1475,29 @@ if ( ! empty( $profile_tab_friends_roles ) ) {
$register_role = UM()->options()->get( 'register_role' );
if ( ! empty( $register_role ) ) {
$register_role = 'um_' . $register_role;
//$register_role = 'um_' . $register_role;
$register_role = $roles_associations[ $register_role ];
UM()->options()->update( 'register_role', $register_role );
}
$woo_oncomplete_role = UM()->options()->get( 'woo_oncomplete_role' );
if ( ! empty( $woo_oncomplete_role ) ) {
$woo_oncomplete_role = 'um_' . $woo_oncomplete_role;
//$woo_oncomplete_role = 'um_' . $woo_oncomplete_role;
$woo_oncomplete_role = $roles_associations[ $woo_oncomplete_role ];
UM()->options()->update( 'woo_oncomplete_role', $woo_oncomplete_role );
}
$woo_oncomplete_except_roles = UM()->options()->get( 'woo_oncomplete_except_roles' );
$woo_oncomplete_except_roles = ! $woo_oncomplete_except_roles ? array() : $woo_oncomplete_except_roles;
if ( ! empty( $woo_oncomplete_except_roles ) ) {
$woo_oncomplete_except_roles = array_map( function( $item ) {
/*$woo_oncomplete_except_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $woo_oncomplete_except_roles );
}, $woo_oncomplete_except_roles );*/
foreach ( $woo_oncomplete_except_roles as $i => $role_k ) {
$woo_oncomplete_except_roles[ $i ] = $roles_associations[ $role_k ];
}
UM()->options()->update( 'woo_oncomplete_except_roles', $woo_oncomplete_except_roles );
}
@@ -1417,42 +1514,48 @@ foreach ( $wc_products as $product_id ) {
$woo_product_role = get_post_meta( $product_id, '_um_woo_product_role', true );
if ( ! empty( $woo_product_role ) ) {
$woo_product_role = 'um_' . $woo_product_role;
//$woo_product_role = 'um_' . $woo_product_role;
$woo_product_role = $roles_associations[ $woo_product_role ];
update_post_meta( $product_id, '_um_woo_product_role', $woo_product_role );
}
$woo_product_activated_role = get_post_meta( $product_id, '_um_woo_product_activated_role', true );
if ( ! empty( $woo_product_activated_role ) ) {
$woo_product_activated_role = 'um_' . $woo_product_activated_role;
//$woo_product_activated_role = 'um_' . $woo_product_activated_role;
$woo_product_activated_role = $roles_associations[ $woo_product_activated_role ];
update_post_meta( $product_id, '_um_woo_product_activated_role', $woo_product_activated_role );
}
$woo_product_downgrade_pending_role = get_post_meta( $product_id, '_um_woo_product_downgrade_pending_role', true );
if ( ! empty( $woo_product_downgrade_pending_role ) ) {
$woo_product_downgrade_pending_role = 'um_' . $woo_product_downgrade_pending_role;
//$woo_product_downgrade_pending_role = 'um_' . $woo_product_downgrade_pending_role;
$woo_product_downgrade_pending_role = $roles_associations[ $woo_product_downgrade_pending_role ];
update_post_meta( $product_id, '_um_woo_product_downgrade_pending_role', $woo_product_downgrade_pending_role );
}
$woo_product_downgrade_onhold_role = get_post_meta( $product_id, '_um_woo_product_downgrade_onhold_role', true );
if ( ! empty( $woo_product_downgrade_onhold_role ) ) {
$woo_product_downgrade_onhold_role = 'um_' . $woo_product_downgrade_onhold_role;
//$woo_product_downgrade_onhold_role = 'um_' . $woo_product_downgrade_onhold_role;
$woo_product_downgrade_onhold_role = $roles_associations[ $woo_product_downgrade_onhold_role ];
update_post_meta( $product_id, '_um_woo_product_downgrade_onhold_role', $woo_product_downgrade_onhold_role );
}
$woo_product_downgrade_expired_role = get_post_meta( $product_id, '_um_woo_product_downgrade_expired_role', true );
if ( ! empty( $woo_product_downgrade_expired_role ) ) {
$woo_product_downgrade_expired_role = 'um_' . $woo_product_downgrade_expired_role;
//$woo_product_downgrade_expired_role = 'um_' . $woo_product_downgrade_expired_role;
$woo_product_downgrade_expired_role = $roles_associations[ $woo_product_downgrade_expired_role ];
update_post_meta( $product_id, '_um_woo_product_downgrade_expired_role', $woo_product_downgrade_expired_role );
}
$woo_product_downgrade_cancelled_role = get_post_meta( $product_id, '_um_woo_product_downgrade_cancelled_role', true );
if ( ! empty( $woo_product_downgrade_cancelled_role ) ) {
$woo_product_downgrade_cancelled_role = 'um_' . $woo_product_downgrade_cancelled_role;
//$woo_product_downgrade_cancelled_role = 'um_' . $woo_product_downgrade_cancelled_role;
$woo_product_downgrade_cancelled_role = $roles_associations[ $woo_product_downgrade_cancelled_role ];
update_post_meta( $product_id, '_um_woo_product_downgrade_cancelled_role', $woo_product_downgrade_cancelled_role );
}
}
@@ -1468,9 +1571,13 @@ foreach ( $bb_forums as $forum_id ) {
$bbpress_can_topic = get_post_meta( $forum_id, '_um_bbpress_can_topic', true );
$bbpress_can_topic = ! $bbpress_can_topic ? array() : $bbpress_can_topic;
if ( ! empty( $bbpress_can_topic ) ) {
$bbpress_can_topic = array_map( function( $item ) {
/*$bbpress_can_topic = array_map( function( $item ) {
return 'um_' . $item;
}, $bbpress_can_topic );
}, $bbpress_can_topic );*/
foreach ( $bbpress_can_topic as $i => $role_k ) {
$bbpress_can_topic[ $i ] = $roles_associations[ $role_k ];
}
update_post_meta( $forum_id, '_um_bbpress_can_topic', $bbpress_can_topic );
}
@@ -1479,9 +1586,13 @@ foreach ( $bb_forums as $forum_id ) {
$bbpress_can_reply = get_post_meta( $forum_id, '_um_bbpress_can_reply', true );
$bbpress_can_reply = ! $bbpress_can_reply ? array() : $bbpress_can_reply;
if ( ! empty( $bbpress_can_reply ) ) {
$bbpress_can_reply = array_map( function( $item ) {
/*$bbpress_can_reply = array_map( function( $item ) {
return 'um_' . $item;
}, $bbpress_can_reply );
}, $bbpress_can_reply );*/
foreach ( $bbpress_can_reply as $i => $role_k ) {
$bbpress_can_reply[ $i ] = $roles_associations[ $role_k ];
}
update_post_meta( $forum_id, '_um_bbpress_can_reply', $bbpress_can_reply );
}
@@ -1499,9 +1610,13 @@ foreach ( $mc_lists as $list_id ) {
$um_roles = get_post_meta( $list_id, '_um_roles', true );
$um_roles = ! $um_roles ? array() : $um_roles;
if ( ! empty( $um_roles ) ) {
$um_roles = array_map( function( $item ) {
/*$um_roles = array_map( function( $item ) {
return 'um_' . $item;
}, $um_roles );
}, $um_roles );*/
foreach ( $um_roles as $i => $role_k ) {
$um_roles[ $i ] = $roles_associations[ $role_k ];
}
update_post_meta( $list_id, '_um_roles', $um_roles );
}
@@ -1518,7 +1633,8 @@ foreach ( $um_social_login as $social_login_id ) {
$assigned_role = get_post_meta( $social_login_id, '_um_assigned_role', true );
if ( ! empty( $assigned_role ) ) {
$assigned_role = 'um_' . $assigned_role;
//$assigned_role = 'um_' . $assigned_role;
$assigned_role = $roles_associations[ $assigned_role ];
update_post_meta( $social_login_id, '_um_assigned_role', $assigned_role );
}
}
-29
View File
@@ -157,36 +157,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
/***
*** @Opt-in tracking
***/
add_action('um_admin_do_action__opt_into_tracking', 'um_admin_do_action__opt_into_tracking');
function um_admin_do_action__opt_into_tracking( $action ) {
if ( !is_admin() || !current_user_can('manage_options') ) die();
UM()->options()->update( 'um_allow_tracking', 1 );
update_option( 'um_tracking_notice', 1 );
$tracking = new um\core\Tracking();
$tracking->send_checkin(true);
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
/***
*** @Opt-out of tracking
***/
add_action('um_admin_do_action__opt_out_of_tracking', 'um_admin_do_action__opt_out_of_tracking');
function um_admin_do_action__opt_out_of_tracking( $action ){
if ( !is_admin() || !current_user_can('manage_options') ) die();
UM()->options()->update( 'um_allow_tracking', 0 );
update_option('um_tracking_notice', 1 );
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
/***
*** @various user actions
***/
+22 -6
View File
@@ -1,11 +1,27 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?>
$role = $object['data']; ?>
<div class="um-admin-metabox">
<?php UM()->admin_forms( array(
'class' => 'um-role-publish um-top-label',
'prefix_id' => 'role',
'fields' => array(
array(
'id' => '_um_priority',
'type' => 'text',
'label' => __( 'Role Priority', 'ultimate-member' ),
'tooltip' => __( 'The higher the number, the higher the priority', 'ultimate-member' ),
'value' => ! empty( $role['_um_priority'] ) ? $role['_um_priority'] : '',
),
)
) )->render_form(); ?>
</div>
<div class="submitbox" id="submitpost">
<div id="major-publishing-actions">
<input type="submit" value="<?php echo ! empty( $_GET['id'] ) ? __( 'Update Role', 'ultimate-member' ) : __( 'Create Role', 'ultimate-member' ) ?>" class="button-primary" id="create_role" name="create_role">
<input type="button" class="cancel_popup button" value="<?php _e( 'Cancel', 'ultimate-member' ) ?>" onclick="window.location = '<?php echo add_query_arg( array( 'page' => 'um_roles' ), admin_url( 'admin.php' ) ) ?>';" />
<div class="clear"></div>
</div>
<div id="major-publishing-actions">
<input type="submit" value="<?php echo ! empty( $_GET['id'] ) ? __( 'Update Role', 'ultimate-member' ) : __( 'Create Role', 'ultimate-member' ) ?>" class="button-primary" id="create_role" name="create_role">
<input type="button" class="cancel_popup button" value="<?php _e( 'Cancel', 'ultimate-member' ) ?>" onclick="window.location = '<?php echo add_query_arg( array( 'page' => 'um_roles' ), admin_url( 'admin.php' ) ) ?>';" />
<div class="clear"></div>
</div>
</div>
+19 -9
View File
@@ -20,24 +20,24 @@ if ( ! class_exists( 'um\Dependencies' ) ) {
* @var array
*/
public $ext_required_version = array(
'bbpress' => '2.0',
'followers' => '2.0',
'friends' => '2.0',
'bbpress' => '2.0.1',
'followers' => '2.0.1',
'friends' => '2.0.1',
'groups' => '2.0',
'instagram' => '2.0',
'invitations' => '2.0',
'mailchimp' => '2.0',
'messaging' => '2.0',
'mailchimp' => '2.0.1',
'messaging' => '2.0.1',
'mycred' => '2.0',
'notices' => '2.0',
'notices' => '2.0.1',
'notifications' => '2.0',
'online' => '2.0',
'private-content' => '2.0',
'profile-completeness' => '2.0',
'profile-completeness' => '2.0.1',
'recaptcha' => '2.0',
'reviews' => '2.0',
'reviews' => '2.0.1',
'social-activity' => '2.0',
'social-login' => '2.0',
'social-login' => '2.0.1',
'terms-conditions' => '2.0',
'user-location' => '2.0',
'user-tags' => '2.0',
@@ -59,6 +59,16 @@ if ( ! class_exists( 'um\Dependencies' ) ) {
}
/**
* @return mixed
*/
public function get_active_plugins() {
if ( ! self::$active_plugins ) self::init();
return self::$active_plugins;
}
/**
* Check if UltimateMember core plugin is active
*
+44 -1
View File
@@ -189,6 +189,8 @@ if ( ! class_exists( 'UM' ) ) {
// include hook files
add_action( 'plugins_loaded', array( &$this, 'init' ), 0 );
add_action( 'init', array( &$this, 'old_extensions_notice' ), 0 );
//run activation
register_activation_hook( um_plugin, array( &$this, 'activation' ) );
@@ -203,6 +205,47 @@ if ( ! class_exists( 'UM' ) ) {
}
/**
* Show notice for customers with old extension's versions
*/
function old_extensions_notice() {
if ( ! is_admin() ) {
return;
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
$show = false;
$slugs = array_map( function( $item ) {
return 'um-' . $item . '/um-' . $item . '.php';
}, array_keys( $this->dependencies()->ext_required_version ) );
$active_plugins = $this->dependencies()->get_active_plugins();
foreach ( $slugs as $slug ) {
if ( in_array( $slug, $active_plugins ) ) {
$plugin_data = get_plugin_data( um_path . '..' . DIRECTORY_SEPARATOR . $slug );
if ( version_compare( '2.0', $plugin_data['Version'], '>' ) ) {
$show = true;
break;
}
}
}
if ( ! $show ) {
return;
}
/*global $um_woocommerce;
remove_action( 'init', array( $um_woocommerce, 'plugin_check' ), 1 );
$um_woocommerce->plugin_inactive = true;*/
echo '<div class="error"><p>' . sprintf( __( '<strong>%s %s</strong> requires 2.0 extensions. You have pre 2.0 extensions installed on your site. <br /> Please update %s extensions to latest versions. For more info see this <a href="%s" target="_blank">doc</a>.', 'ultimate-member' ), ultimatemember_plugin_name, ultimatemember_version, ultimatemember_plugin_name, 'http://docs.ultimatemember.com/article/266-updating-to-2-0-versions-of-extensions' ) . '</p></div>';
}
/**
* Autoload UM classes handler
*
@@ -258,6 +301,7 @@ if ( ! class_exists( 'UM' ) ) {
update_option( 'um_version', ultimatemember_version );
//run setup
$this->common()->create_post_types();
$this->setup()->run_setup();
}
@@ -1077,7 +1121,6 @@ if ( ! class_exists( 'UM' ) ) {
require_once 'core/um-filters-files.php';
require_once 'core/um-filters-navmenu.php';
require_once 'core/um-filters-avatars.php';
require_once 'core/um-filters-arguments.php';
require_once 'core/um-filters-user.php';
require_once 'core/um-filters-members.php';
require_once 'core/um-filters-profile.php';
+28 -6
View File
@@ -28,6 +28,12 @@ if ( ! class_exists( 'Access' ) ) {
private $allow_access;
/**
* @var \WP_Post
*/
private $current_single_post;
/**
* Access constructor.
*/
@@ -35,7 +41,6 @@ if ( ! class_exists( 'Access' ) ) {
$this->singular_page = false;
$this->redirect_handler = false;
$this->allow_access = false;
@@ -184,12 +189,11 @@ if ( ! class_exists( 'Access' ) ) {
if ( is_front_page() ) {
if ( is_user_logged_in() ) {
$role_meta = UM()->roles()->role_data( um_user( 'role' ) );
if ( ! empty( $role_meta['default_homepage'] ) )
if ( ! empty( um_user( 'default_homepage' ) ) )
return;
$redirect_to = ! empty( $role_meta['redirect_homepage'] ) ? $role_meta['redirect_homepage'] : um_get_core_page( 'user' );
$redirect_homepage = um_user( 'redirect_homepage' );
$redirect_to = ! empty( $redirect_homepage ) ? $redirect_homepage : um_get_core_page( 'user' );
$this->redirect_handler = $this->set_referer( esc_url( add_query_arg( 'redirect_to', urlencode_deep( $curr ), $redirect_to ) ), "custom_homepage" );
} else {
@@ -592,13 +596,19 @@ if ( ! class_exists( 'Access' ) ) {
if ( ! isset( $restriction['_um_restrict_by_custom_message'] ) || '0' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = stripslashes( $restricted_global_message );
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
} elseif ( '1' == $restriction['_um_restrict_by_custom_message'] ) {
$post->post_content = ! empty( $restriction['_um_restrict_custom_message'] ) ? stripslashes( $restriction['_um_restrict_custom_message'] ) : '';
if ( 'attachment' == $post->post_type ) {
$this->current_single_post = $post;
add_filter( 'the_content', array( &$this, 'replace_post_content' ), 9999, 1 );
if ( 'attachment' == $post->post_type ) {
remove_filter( 'the_content', 'prepend_attachment' );
}
}
@@ -694,6 +704,18 @@ if ( ! class_exists( 'Access' ) ) {
}
/**
* @param $content
*
* @return string
*/
function replace_post_content( $content ) {
$content = $this->current_single_post->post_content;
return $content;
}
/**
* Protect Post Types in menu query
* Restrict content new logic
+6
View File
@@ -309,6 +309,8 @@ if ( ! class_exists( 'Account' ) ) {
$args = 'single_user_password';
$args = apply_filters( 'um_account_tab_delete_fields', $args, $shortcode_args );
$fields = UM()->builtin()->get_specific_fields( $args );
$fields = apply_filters( 'um_account_secure_fields', $fields, $id );
@@ -333,6 +335,8 @@ if ( ! class_exists( 'Account' ) ) {
$args = str_replace(',user_email','', $args );
}
$args = apply_filters( 'um_account_tab_general_fields', $args, $shortcode_args );
$fields = UM()->builtin()->get_specific_fields( $args );
$fields = apply_filters( 'um_account_secure_fields', $fields, $id );
@@ -349,6 +353,8 @@ if ( ! class_exists( 'Account' ) ) {
$args = 'user_password';
$args = apply_filters( 'um_account_tab_password_fields', $args, $shortcode_args );
$fields = UM()->builtin()->get_specific_fields( $args );
$fields = apply_filters( 'um_account_secure_fields', $fields, $id );
+1 -1
View File
@@ -683,7 +683,7 @@ if ( ! class_exists( 'Builtin' ) ) {
'public' => 1,
'editable' => 1,
'max_words' => 40,
'placeholder' => 'Enter a bit about yourself...',
'placeholder' => __('Enter a bit about yourself...','ultimate-member'),
),
'birth_date' => array(
+4 -1
View File
@@ -118,7 +118,10 @@ if ( ! class_exists( 'Enqueue' ) ) {
$uploads = wp_upload_dir();
$upload_dir = $uploads['basedir'] . DIRECTORY_SEPARATOR . 'ultimatemember' . DIRECTORY_SEPARATOR;
if ( file_exists( $upload_dir . 'um_old_settings.css' ) ) {
wp_register_style('um_old_css', $uploads['baseurl'] . '/ultimatemember/um_old_settings.css' );
//was the issues with HTTPS
//wp_register_style('um_old_css', $uploads['baseurl'] . '/ultimatemember/um_old_settings.css' );
//fixed using "../../"
wp_register_style('um_old_css', um_url . '../../uploads/ultimatemember/um_old_settings.css' );
wp_enqueue_style('um_old_css');
}
}
+22 -16
View File
@@ -673,26 +673,29 @@ if ( ! class_exists( 'Fields' ) ) {
*/
function get_option_value_from_callback( $value, $data, $type ) {
if (in_array( $type, array( 'select', 'multiselect' ) ) && isset( $data['custom_dropdown_options_source'] ) && !empty( $data['custom_dropdown_options_source'] )) {
if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
if ( function_exists( $data['custom_dropdown_options_source'] ) ) {
$arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
$arr_options = call_user_func(
$data['custom_dropdown_options_source'],
( ! empty( $data['parent_dropdown_relationship'] ) ? $data['parent_dropdown_relationship'] : '' )
);
if ($type == 'select') {
if (isset( $arr_options[$value] ) && !empty( $arr_options[$value] )) {
return $arr_options[$value];
} else if (isset( $data['default'] ) && !empty( $data['default'] ) && empty( $arr_options[$value] )) {
return $arr_options[$data['default']];
if ( $type == 'select' ) {
if ( ! empty( $arr_options[ $value ] ) ) {
return $arr_options[ $value ];
} elseif ( ! empty( $data['default'] ) && empty( $arr_options[ $value ] ) ) {
return $arr_options[ $data['default'] ];
} else {
return '';
}
}
if ($type == 'multiselect') {
if ( $type == 'multiselect' ) {
if (is_array( $value )) {
if ( is_array( $value ) ) {
$values = $value;
} else {
$values = explode( ', ', $value );
@@ -700,9 +703,9 @@ if ( ! class_exists( 'Fields' ) ) {
$arr_paired_options = array();
foreach ($values as $option) {
if (isset( $arr_options[$option] )) {
$arr_paired_options[] = $arr_options[$option];
foreach ( $values as $option ) {
if ( isset( $arr_options[ $option ] ) ) {
$arr_paired_options[] = $arr_options[ $option ];
}
}
@@ -1162,18 +1165,21 @@ if ( ! class_exists( 'Fields' ) ) {
) {
um_fetch_user( get_current_user_id() );
if (!um_user( 'can_edit_everyone' ))
if ( ! um_user( 'can_edit_everyone' ) ) {
$disabled = ' disabled="disabled" ';
}
um_fetch_user( $_um_profile_id );
if (isset( $data['public'] ) && $data['public'] == '-2' && $data['roles']) {
if (in_array( UM()->roles()->um_get_user_role( get_current_user_id() ), $data['roles'] )) {
if ( isset( $data['public'] ) && $data['public'] == '-2' && $data['roles'] ) {
$current_user_roles = um_user( 'roles' );
if ( count( array_intersect( $current_user_roles, $data['roles'] ) ) > 0 ) {
$disabled = '';
}
}
}
if (!isset( $data['autocomplete'] )) {
if ( ! isset( $data['autocomplete'] ) ) {
$autocomplete = 'off';
}
um_fetch_user( get_current_user_id() );
+2 -1
View File
@@ -199,7 +199,8 @@ if ( ! class_exists( 'Form' ) ) {
} elseif ( isset( $this->post_form['mode'] ) && $this->post_form['mode'] == 'register' ) {
$role = $this->assigned_role( $this->form_id );
$this->post_form['role'] = $role;
$this->post_form['submitted']['role'] = $role;
//fix for social login
//$this->post_form['submitted']['role'] = $role;
}
if ( isset( $_POST[ UM()->honeypot ] ) && $_POST[ UM()->honeypot ] != '' ){
+14 -26
View File
@@ -18,44 +18,32 @@ if ( ! class_exists( 'Logout' ) ) {
***/
function logout_page() {
global $sitepress;
$language_code = '';
$current_page_ID = get_the_ID();
$logout_page_id = UM()->config()->permalinks['logout'];
$has_translation = false;
$trid = 0;
$not_default_lang = false;
if ( is_home() /*|| is_front_page()*/ ) {
return;
}
if ( function_exists('icl_object_id') || function_exists('icl_get_current_language') ) {
if ( UM()->external_integrations()->is_wpml_active() ) {
global $sitepress;
$default_lang = $sitepress->get_default_language();
$language_code = $sitepress->get_current_language();
if( function_exists('icl_get_current_language') ){
$language_code = icl_get_current_language();
}else if( function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE') ){ // checks if WPML exists
$language_code = ICL_LANGUAGE_CODE;
}
if ( function_exists( 'icl_object_id' ) ) {
$trid = icl_object_id( $current_page_ID, 'page', true, $default_lang );
} else {
$trid = wpml_object_id_filter( $current_page_ID, 'page', true, $default_lang );
}
$has_translation = true;
if ( $language_code == $default_lang ) {
$language_code = '';
}
}
if( function_exists('icl_object_id') && defined('ICL_LANGUAGE_CODE') && isset( $sitepress ) ){ // checks if WPML exists
$trid = $sitepress->get_element_trid( $current_page_ID );
}
if( icl_get_default_language() !== $language_code ){
$not_default_lang = true;
}else{
$language_code = '';
}
}
if ( um_is_core_page('logout') || ( $trid > 0 && $has_translation && $trid == $logout_page_id && $not_default_lang ) ) {
if ( um_is_core_page( 'logout' ) || ( $trid > 0 && $trid == $logout_page_id ) ) {
if ( is_user_logged_in() ) {
+1
View File
@@ -441,6 +441,7 @@ if ( ! class_exists( 'REST_API' ) ) {
break;
case 'role':
//get priority role here
$response['role'] = um_user( 'role' );
break;
+122 -38
View File
@@ -52,7 +52,7 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
$details['capabilities'] = array_fill_keys( array_values( $capabilities ), true );
unset( $details['wp_capabilities'] );
$wp_roles->roles[$role_id] = $details;
$wp_roles->role_objects[$role_id] = new \WP_Role( $role_id, $capabilities );
$wp_roles->role_objects[$role_id] = new \WP_Role( $role_id, $details['capabilities'] );
$wp_roles->role_names[$role_id] = $details['name'];
}
@@ -100,7 +100,7 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
// User exists
if ( ! empty( $user ) ) {
// Get users old UM role
$role = $this->um_get_user_role( $user_id );
$role = UM()->roles()->get_um_user_role( $user_id );
// User already has this role so no new role is set
if ( $new_role === $role || ( ! $this->is_role_custom( $new_role ) && user_can( $user, $new_role ) ) ) {
@@ -170,35 +170,107 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
}
/**
* Get user one of UM roles if it has it
*
* @param int $user_id
* @return bool|mixed
*/
function um_get_user_role( $user_id ) {
$user = get_userdata( $user_id );
/**
* Get user one of UM roles if it has it
*
* @deprecated since 2.0
* @param int $user_id
* @return bool|mixed
*/
function um_get_user_role( $user_id ) {
return $this->get_um_user_role( $user_id );
}
if ( empty( $user->roles ) )
return false;
// User has roles so look for a UM Role one
$role_keys = get_option( 'um_roles' );
/**
* @param $user_id
*
* @return array|bool
*/
function get_all_user_roles( $user_id ) {
$user = get_userdata( $user_id );
if ( empty( $role_keys ) )
return array_shift( $user->roles );
if ( empty( $user->roles ) ) {
return false;
}
$role_keys = array_map( function( $item ) {
return 'um_' . $item;
}, $role_keys );
return array_values( $user->roles );
}
$roles = array_intersect( array_values( $user->roles ), $role_keys );
if ( ! empty( $roles ) ) {
return array_shift( $roles );
} else {
return array_shift( $user->roles );
}
}
/**
* @param $user_id
*
* @return bool|mixed
*/
function get_priority_user_role( $user_id ) {
$user = get_userdata( $user_id );
if ( empty( $user->roles ) )
return false;
// User has roles so look for a UM Role one
$um_roles_keys = get_option( 'um_roles' );
if ( ! empty( $um_roles_keys ) ) {
$um_roles_keys = array_map( function( $item ) {
return 'um_' . $item;
}, $um_roles_keys );
}
$orders = array();
foreach ( array_values( $user->roles ) as $userrole ) {
if ( ! empty( $um_roles_keys ) && in_array( $userrole, $um_roles_keys ) ) {
$userrole_metakey = substr( $userrole, 3 );
} else {
$userrole_metakey = $userrole;
}
$rolemeta = get_option( "um_role_{$userrole_metakey}_meta", false );
if ( ! $rolemeta ) {
$orders[ $userrole ] = 0;
continue;
}
$orders[ $userrole ] = ! empty( $rolemeta['_um_priority'] ) ? $rolemeta['_um_priority'] : 0;
}
arsort( $orders );
$roles_in_priority = array_keys( $orders );
return array_shift( $roles_in_priority );
}
/**
* @param $user_id
*
* @return bool|mixed
*/
function get_um_user_role( $user_id ) {
// User has roles so look for a UM Role one
$um_roles_keys = get_option( 'um_roles' );
if ( empty( $um_roles_keys ) )
return false;
$user = get_userdata( $user_id );
if ( empty( $user->roles ) )
return false;
$um_roles_keys = array_map( function( $item ) {
return 'um_' . $item;
}, $um_roles_keys );
$user_um_roles_array = array_intersect( $um_roles_keys, array_values( $user->roles ) );
if ( empty( $user_um_roles_array ) )
return false;
return array_shift( $user_um_roles_array );
}
/**
@@ -249,9 +321,14 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
}
/***
*** @Query for UM roles
***/
/**
* Query for UM roles
*
* @param bool $add_default
* @param null $exclude
*
* @return array
*/
function get_roles( $add_default = false, $exclude = null ){
global $wp_roles;
@@ -275,9 +352,14 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
}
/***
*** @Current user can
***/
/**
* Current user can
*
* @param $cap
* @param $user_id
*
* @return bool|int
*/
function um_current_user_can( $cap, $user_id ) {
if ( ! is_user_logged_in() )
return false;
@@ -286,7 +368,8 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
um_fetch_user( get_current_user_id() );
switch( $cap ) {
$current_user_roles = UM()->roles()->get_all_user_roles( $user_id );
switch( $cap ) {
case 'edit':
if ( get_current_user_id() == $user_id && um_user( 'can_edit_profile' ) )
$return = 1;
@@ -294,13 +377,15 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
$return = 0;
elseif ( get_current_user_id() == $user_id && ! um_user( 'can_edit_profile') )
$return = 0;
elseif ( um_user( 'can_edit_roles' ) && ! in_array( UM()->roles()->um_get_user_role( $user_id ), um_user( 'can_edit_roles' ) ) )
elseif ( um_user( 'can_edit_roles' ) && count( array_intersect( $current_user_roles, um_user( 'can_edit_roles' ) ) ) <= 0 )
$return = 0;
break;
case 'delete':
if ( ! um_user( 'can_delete_everyone' ) ) $return = 0;
elseif ( um_user( 'can_delete_roles' ) && ! in_array( UM()->roles()->um_get_user_role( $user_id ), um_user( 'can_delete_roles' ) ) ) $return = 0;
if ( ! um_user( 'can_delete_everyone' ) )
$return = 0;
elseif ( um_user( 'can_delete_roles' ) && count( array_intersect( $current_user_roles, um_user( 'can_delete_roles' ) ) ) <= 0 )
$return = 0;
break;
}
@@ -322,8 +407,7 @@ if ( ! class_exists( 'Roles_Capabilities' ) ) {
return false;
$user_id = get_current_user_id();
$role = $this->um_get_user_role( $user_id );
$role = UM()->roles()->get_priority_user_role( $user_id );
$permissions = $this->role_data( $role );
$permissions = apply_filters( 'um_user_permissions_filter', $permissions, $user_id );
+217 -141
View File
@@ -10,23 +10,27 @@ if ( ! class_exists( 'Shortcodes' ) ) {
function __construct() {
$this->message_mode = false;
$this->custom_message = '';
$this->loop = array();
add_shortcode( 'ultimatemember', array( &$this, 'ultimatemember' ) );
add_shortcode('um_loggedin', array(&$this, 'um_loggedin'));
add_shortcode('um_loggedout', array(&$this, 'um_loggedout'));
add_shortcode('um_show_content', array(&$this, 'um_shortcode_show_content_for_role') );
add_shortcode('ultimatemember_searchform', array(&$this, 'ultimatemember_searchform') );
add_shortcode( 'um_loggedin', array( &$this, 'um_loggedin' ) );
add_shortcode( 'um_loggedout', array( &$this, 'um_loggedout' ) );
add_shortcode( 'um_show_content', array( &$this, 'um_shortcode_show_content_for_role' ) );
add_shortcode( 'ultimatemember_searchform', array( &$this, 'ultimatemember_searchform' ) );
add_filter('body_class', array(&$this, 'body_class'), 0);
add_filter( 'body_class', array( &$this, 'body_class' ), 0 );
$base_uri = apply_filters('um_emoji_base_uri', 'https://s.w.org/images/core/emoji/');
add_filter( 'um_shortcode_args_filter', array( &$this, 'display_logout_form' ), 99 );
add_filter( 'um_shortcode_args_filter', array( &$this, 'parse_shortcode_args' ), 99 );
$this->emoji[':)'] = $base_uri . '72x72/1f604.png';
$this->emoji[':smiley:'] = $base_uri . '72x72/1f603.png';
$base_uri = apply_filters( 'um_emoji_base_uri', 'https://s.w.org/images/core/emoji/' );
$this->emoji[':)'] = $base_uri . '72x72/1f604.png';
$this->emoji[':smiley:'] = $base_uri . '72x72/1f603.png';
$this->emoji[':D'] = $base_uri . '72x72/1f600.png';
$this->emoji[':$'] = $base_uri . '72x72/1f60a.png';
$this->emoji[':relaxed:'] = $base_uri . '72x72/263a.png';
@@ -86,6 +90,59 @@ if ( ! class_exists( 'Shortcodes' ) ) {
}
/**
* Conditional logout form
*
* @param array $args
*
* @return array
*/
function display_logout_form( $args ) {
if ( is_user_logged_in() && isset( $args['mode'] ) && $args['mode'] == 'login' ) {
if ( get_current_user_id() != um_user( 'ID' ) ) {
um_fetch_user( get_current_user_id() );
}
$args['template'] = 'logout';
}
return $args;
}
/**
* Filter shortcode args
*
* @param array $args
*
* @return array
*/
function parse_shortcode_args( $args ) {
if ( $this->message_mode == true ) {
if ( ! empty( $_REQUEST['um_role'] ) ) {
$args['template'] = 'message';
$roleID = esc_attr( $_REQUEST['um_role'] );
$role = UM()->roles()->role_data( $roleID );
if ( ! empty( $role ) && ! empty( $role["status"] ) ) {
$message_key = $role["status"] . '_message';
$this->custom_message = ! empty( $role[ $message_key ] ) ? $role[ $message_key ] : '';
}
}
}
foreach ( $args as $k => $v ) {
$args[ $k ] = maybe_unserialize( $args[ $k ] );
}
return $args;
}
/***
*** @emoji support
*/
@@ -203,14 +260,19 @@ if ( ! class_exists( 'Shortcodes' ) ) {
return $classes;
}
/***
*** @Logged-in only content
*/
function um_loggedin($args = array(), $content = "") {
/**
* Logged-in only content
*
* @param array $args
* @param string $content
*
* @return string
*/
function um_loggedin( $args = array(), $content = "" ) {
ob_start();
$defaults = array(
'lock_text' => __('This content has been restricted to logged in users only. Please <a href="{login_referrer}">login</a> to view this content.', 'ultimate-member'),
'lock_text' => __( 'This content has been restricted to logged in users only. Please <a href="{login_referrer}">login</a> to view this content.', 'ultimate-member' ),
'show_lock' => 'yes',
);
@@ -229,8 +291,7 @@ if ( ! class_exists( 'Shortcodes' ) ) {
echo do_shortcode( $this->convert_locker_tags( wpautop( $content ) ) );
}
$output = ob_get_contents();
ob_end_clean();
$output = ob_get_clean();
return $output;
}
@@ -320,9 +381,11 @@ if ( ! class_exists( 'Shortcodes' ) ) {
}
// 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() ) ) {
return;
if ( $mode == 'profile' && um_profile_id() ) {
$current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() );
if ( ! empty( $args['role'] ) && ! in_array( $args['role'], $current_user_roles ) ) {
return '';
}
}
// start loading the template here
@@ -488,136 +551,149 @@ if ( ! class_exists( 'Shortcodes' ) ) {
}
/***
*** @Get Shortcode for given form ID
*/
function get_shortcode($post_id) {
$shortcode = '[ultimatemember form_id=' . $post_id . ']';
return $shortcode;
}
/***
*** @convert access lock tags
*/
function convert_locker_tags($str) {
$str = um_convert_tags($str);
return $str;
}
/***
*** @convert user tags in a string
*/
function convert_user_tags($str) {
$value = '';
$pattern_array = array(
'{first_name}',
'{last_name}',
'{display_name}',
'{user_avatar_small}',
'{username}',
);
$pattern_array = apply_filters('um_allowed_user_tags_patterns', $pattern_array);
$matches = false;
foreach ($pattern_array as $pattern) {
if (preg_match($pattern, $str)) {
$usermeta = str_replace('{', '', $pattern);
$usermeta = str_replace('}', '', $usermeta);
if ($usermeta == 'user_avatar_small') {
$value = get_avatar(um_user('ID'), 40);
} elseif (um_user($usermeta)) {
$value = um_user($usermeta);
}
if ($usermeta == 'username') {
$value = um_user('user_login');
}
$value = apply_filters("um_profile_tag_hook__{$usermeta}", $value, um_user('ID'));
if ($value) {
$str = preg_replace('/' . $pattern . '/', $value, $str);
}
}
}
return $str;
}
/**
* Shortcode: Show custom content to specific role
*
* Show content to specific roles
* [um_show_content roles='member'] <!-- insert content here --> [/um_show_content]
* You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets']
*
* Hide content from specific roles
* [um_show_content not='contributors'] <!-- insert content here --> [/um_show_content]
* You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets']
*
* @param array $atts
* @param string $content
* @return string
*/
function um_shortcode_show_content_for_role( $atts = array() , $content = '' ) {
global $user_ID;
if( ! is_user_logged_in() ) {
return;
}
$a = shortcode_atts( array(
'roles' => '',
'not' => '',
'is_profile' => false,
), $atts );
if( $a['is_profile'] ){
um_fetch_user( um_profile_id() );
}else{
um_fetch_user( $user_ID );
}
/**
* Get Shortcode for given form ID
*
* @param $post_id
*
* @return string
*/
function get_shortcode( $post_id ) {
$shortcode = '[ultimatemember form_id=' . $post_id . ']';
return $shortcode;
}
$current_user_role = um_user( 'role' );
if( isset( $a['not'] ) && ! empty( $a['not'] ) && isset( $a['roles'] ) && ! empty( $a['roles'] ) ){
return do_shortcode( $content );
}
if( isset( $a['not'] ) && ! empty( $a['not'] ) ){
$not_in_roles = explode(",", $a['not'] );
if( is_array( $not_in_roles ) && ! in_array( $current_user_role, $not_in_roles ) ){
return do_shortcode( $content );
}
}else{
$roles = explode(",", $a['roles'] );
if(is_array( $roles ) && in_array( $current_user_role, $roles ) ){
return do_shortcode( $content );
}
/**
* Convert access lock tags
*
* @param $str
*
* @return mixed|string
*/
function convert_locker_tags( $str ) {
return um_convert_tags( $str, array(), false );
}
}
/**
* Convert user tags in a string
*
* @param $str
*
* @return mixed
*/
function convert_user_tags( $str ) {
return '';
}
$pattern_array = array(
'{first_name}',
'{last_name}',
'{display_name}',
'{user_avatar_small}',
'{username}',
);
public function ultimatemember_searchform($args = array(), $content = "") {
$pattern_array = apply_filters( 'um_allowed_user_tags_patterns', $pattern_array );
//$matches = false;
foreach ( $pattern_array as $pattern ) {
$value = '';
if ( preg_match( $pattern, $str ) ) {
$usermeta = str_replace( '{', '', $pattern );
$usermeta = str_replace( '}', '', $usermeta );
if ( $usermeta == 'user_avatar_small' ) {
$value = get_avatar( um_user( 'ID' ), 40 );
} elseif ( um_user( $usermeta ) ) {
$value = um_user( $usermeta );
}
if ( $usermeta == 'username' ) {
$value = um_user( 'user_login' );
}
$value = apply_filters( "um_profile_tag_hook__{$usermeta}", $value, um_user( 'ID' ) );
if ( $value ) {
$str = preg_replace( '/' . $pattern . '/', $value, $str );
}
}
}
return $str;
}
/**
* Shortcode: Show custom content to specific role
*
* Show content to specific roles
* [um_show_content roles='member'] <!-- insert content here --> [/um_show_content]
* You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets']
*
* Hide content from specific roles
* [um_show_content not='contributors'] <!-- insert content here --> [/um_show_content]
* You can add multiple target roles, just use ',' e.g. [um_show_content roles='member,candidates,pets']
*
* @param array $atts
* @param string $content
* @return string
*/
function um_shortcode_show_content_for_role( $atts = array() , $content = '' ) {
global $user_ID;
if ( ! is_user_logged_in() ) {
return;
}
$a = shortcode_atts( array(
'roles' => '',
'not' => '',
'is_profile' => false,
), $atts );
if ( $a['is_profile'] ) {
um_fetch_user( um_profile_id() );
} else {
um_fetch_user( $user_ID );
}
$current_user_roles = um_user( 'roles' );
if ( ! empty( $a['not'] ) && ! empty( $a['roles'] ) ) {
return do_shortcode( $content );
}
if ( ! empty( $a['not'] ) ) {
$not_in_roles = explode( ",", $a['not'] );
if ( is_array( $not_in_roles ) && count( array_intersect( $current_user_roles, $not_in_roles ) ) <= 0 ) {
return do_shortcode( $content );
}
} else {
$roles = explode( ",", $a['roles'] );
if ( is_array( $roles ) && count( array_intersect( $current_user_roles, $roles ) ) > 0 ) {
return do_shortcode( $content );
}
}
return '';
}
/**
* @param array $args
* @param string $content
*
* @return string
*/
public function ultimatemember_searchform( $args = array(), $content = "" ) {
// turn off buffer
ob_start();
+29 -3
View File
@@ -15,8 +15,34 @@ if ( ! class_exists( 'Tracking' ) ) {
add_action( 'admin_notices', array( $this, 'admin_notices' ), 10 );
add_action( 'um_admin_do_action__opt_into_tracking', array( $this, 'um_admin_do_action__opt_into_tracking' ) );
add_action( 'um_admin_do_action__opt_out_of_tracking', array( $this, 'um_admin_do_action__opt_out_of_tracking' ) );
}
/***
*** @Opt-in tracking
***/
function um_admin_do_action__opt_into_tracking( $action ) {
UM()->options()->update( 'um_allow_tracking', 1 );
update_option( 'um_tracking_notice', 1 );
$this->send_checkin(true);
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
/***
*** @Opt-out of tracking
***/
function um_admin_do_action__opt_out_of_tracking( $action ) {
UM()->options()->update( 'um_allow_tracking', 0 );
update_option('um_tracking_notice', 1 );
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
/***
*** @setup info array
***/
@@ -145,12 +171,12 @@ if ( ! class_exists( 'Tracking' ) ) {
echo '<div class="updated um-admin-notice"><p>';
echo __( 'Allow Ultimate Member to track plugin usage? Opt-in to tracking and our newsletter and we will immediately e-mail you a 20% discount which you can use to purchase our core extensions bundle. No sensitive data is tracked.', 'ultimate-member' );
printf( __( 'Thanks for installing <strong>%s</strong>! The core plugin is free but we also sell extensions which allow us to continue developing and supporting the plugin full time. If you subscribe to our mailing list (no spam) we will email you a 20%% discount code which you can use to purchase the <a href="%s" target="_blank">extensions bundle</a>.', 'ultimate-member' ), ultimatemember_plugin_name, 'https://ultimatemember.com/core-extensions-bundle/' );
echo '</p>';
echo '<p><a href="' . esc_url( $optin_url ) . '" class="button button-primary">' . __( 'Allow tracking', 'ultimate-member' ) . '</a>';
echo '&nbsp;<a href="' . esc_url( $optout_url ) . '" class="button-secondary">' . __( 'Do not allow tracking', 'ultimate-member' ) . '</a></p></div>';
echo '<p><a href="' . esc_url( $optin_url ) . '" class="button button-primary">' . __( 'Subscribe to mailing list', 'ultimate-member' ) . '</a>';
echo '&nbsp;<a href="' . esc_url( $optout_url ) . '" class="button-secondary">' . __( 'No thanks', 'ultimate-member' ) . '</a></p></div>';
}
+12 -3
View File
@@ -84,6 +84,7 @@ if ( ! class_exists( 'User' ) ) {
if ( 'rejected' == $status ) {
wp_logout();
session_unset();
exit( wp_redirect( um_get_core_page( 'login' ) ) );
}
@@ -258,13 +259,17 @@ if ( ! class_exists( 'User' ) ) {
$duplicate_id = get_option( "um_duplicate_name_{$duplicate_slug_hash}" );
if ( ! empty( $duplicate_id ) && $duplicate_id != $user_id )
$full_name = $full_name . ' ' . $user_id;
$full_name = trim( $full_name . ' ' . $user_id );
$user_in_url = UM()->permalinks()->profile_slug( $full_name, $first_name, $last_name );
}
update_user_meta( $user_id, "um_user_profile_url_slug_{$permalink_base}", $user_in_url );
if ( empty ( $user_in_url )) {
$user_in_url = $user_id;
}
return UM()->permalinks()->profile_permalink( $user_in_url );
}
@@ -379,7 +384,8 @@ if ( ! class_exists( 'User' ) ) {
if ( ! current_user_can( 'edit_user', $userdata->ID ) )
return $content;
$user_role = UM()->roles()->um_get_user_role( $userdata->ID );
//$user_role = UM()->roles()->um_get_user_role( $userdata->ID );
$user_role = UM()->roles()->get_um_user_role( $userdata->ID );
if ( $user_role && ! empty( $userdata->roles ) && count( $userdata->roles ) == 1 )
$style = 'style="display:none;"';
@@ -469,6 +475,7 @@ if ( ! class_exists( 'User' ) ) {
delete_option( "um_cache_userdata_{$user_id}" );
}
/**
* @function set()
*
@@ -580,9 +587,11 @@ if ( ! class_exists( 'User' ) ) {
}
// add permissions
$user_role = UM()->roles()->um_get_user_role( $this->id );
//$user_role = UM()->roles()->um_get_user_role( $this->id );
$user_role = UM()->roles()->get_priority_user_role( $this->id );
//$this->profile['role'] = ( strpos( $user_role, 'um_' ) === 0 ) ? str_replace( 'um_', '', $user_role ) : $user_role;
$this->profile['role'] = $user_role;
$this->profile['roles'] = UM()->roles()->get_all_user_roles( $this->id );
$role_meta = UM()->roles()->role_data( $user_role );
$role_meta = apply_filters( 'um_user_permissions_filter', $role_meta, $this->id );
+2 -1
View File
@@ -142,7 +142,8 @@ if ( ! defined( 'ABSPATH' ) ) exit;
foreach ( $fields as $key => $array ) {
if ( isset( $array['public'] ) && -2 == $array['public'] && ! empty( $array['roles'] ) && is_user_logged_in() ) {
if ( ! in_array( um_user( 'role' ), $array['roles'] ) ) {
$current_user_roles = um_user( 'roles' );
if ( count( array_intersect( $current_user_roles, $array['roles'] ) ) <= 0 ) {
continue;
}
}
+16 -14
View File
@@ -166,11 +166,12 @@ if ( ! defined( 'ABSPATH' ) ) exit;
um_store_lastlogin_timestamp( $user->ID );
}
/***
*** @login user
***/
add_action('um_user_login', 'um_user_login', 10);
function um_user_login($args){
/**
* Login user process
*
* @param array $args
*/
function um_user_login( $args ) {
extract( $args );
$rememberme = ( isset( $args['rememberme'] ) && 1 == $args['rememberme'] && isset( $_REQUEST['rememberme'] ) ) ? 1 : 0;
@@ -179,30 +180,29 @@ if ( ! defined( 'ABSPATH' ) ) exit;
wp_die( __('This action has been prevented for security measures.','ultimate-member') );
}
UM()->user()->auto_login( um_user('ID'), $rememberme );
UM()->user()->auto_login( um_user( 'ID' ), $rememberme );
// Hook that runs after successful login and before user is redirected
do_action('um_on_login_before_redirect', um_user('ID') );
do_action( 'um_on_login_before_redirect', um_user( 'ID' ) );
// Priority redirect
if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
exit( wp_redirect( $args['redirect_to'] ) );
if ( ! empty( $args['redirect_to'] ) ) {
exit( wp_redirect( $args['redirect_to'] ) );
}
$role_data = UM()->roles()->role_data( um_user( 'role' ) );
// Role redirect
if ( empty( $role_data['after_login'] ) )
$after_login = um_user( 'after_login' );
if ( empty( $after_login ) )
exit( wp_redirect( um_user_profile_url() ) );
switch( $role_data['after_login'] ) {
switch( $after_login ) {
case 'redirect_admin':
exit( wp_redirect( admin_url() ) );
break;
case 'redirect_url':
exit( wp_redirect( $role_data['login_redirect_url'] ) );
exit( wp_redirect( um_user( 'login_redirect_url' ) ) );
break;
case 'refresh':
@@ -216,6 +216,8 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}
}
add_action( 'um_user_login', 'um_user_login', 10 );
/***
*** @form processing
+6 -7
View File
@@ -19,17 +19,16 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}
$search_filters = apply_filters('um_frontend_member_search_filters',$search_filters);
if ( $args['search'] == 1 && is_array( $search_filters ) ) { // search on
if ( isset( $args['roles_can_search'] ) && ! empty( $args['roles_can_search'] ) && ! in_array( um_user( 'role' ), $args['roles_can_search'] ) ) {
$current_user_roles = um_user( 'roles' );
if ( ! empty( $args['roles_can_search'] ) && count( array_intersect( $current_user_roles, $args['roles_can_search'] ) ) <= 0 ) {
return;
}
$count = count( $search_filters );
?>
$count = count( $search_filters ); ?>
<div class="um-search um-search-<?php echo $count; ?>">
<form method="get" action="" />
+9 -1
View File
@@ -66,15 +66,23 @@ if ( ! defined( 'ABSPATH' ) ) exit;
add_action( 'send_password_change_email','um_send_password_change_email', 10, 1 );
function um_send_password_change_email( $args ) {
if ( ! is_array( $args ) )
return false;
/**
* @var $user_id
*/
extract( $args );
if ( ! isset( $user_id ) )
return false;
um_fetch_user( $user_id );
UM()->user()->password_changed();
um_reset_user();
return false;
}
+38 -3
View File
@@ -114,16 +114,18 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! in_array( $args['submitted']['role'], $exclude_roles ) ) {
$to_update['role'] = $args['submitted']['role'];
}
$args['roles_before_upgrade'] = UM()->roles()->get_all_user_roles( um_user( 'ID' ) );
}
do_action( 'um_user_pre_updating_profile', $to_update );
$to_update = apply_filters( 'um_user_pre_updating_profile_array', $to_update );
if (is_array( $to_update )) {
UM()->user()->update_profile( $to_update );
do_action( 'um_after_user_updated', um_user( 'ID' ) );
if ( is_array( $to_update ) ) {
UM()->user()->update_profile( $to_update );
do_action( 'um_after_user_updated', um_user( 'ID' ), $args, $to_update );
}
$files = apply_filters( 'um_user_pre_updating_files_array', $files );
@@ -145,6 +147,39 @@ if ( ! defined( 'ABSPATH' ) ) exit;
}
/**
* Leave roles for User, which are not in the list of update profile (are default WP or 3rd plugins roles)
*
* @param $user_id
* @param $args
* @param $to_update
*/
function um_restore_default_roles( $user_id, $args, $to_update ) {
if ( ! empty( $args['submitted']['role'] ) ) {
$wp_user = new WP_User( $user_id );
$role_keys = array_map( function( $item ) {
return 'um_' . $item;
}, get_option( 'um_roles' ) );
$leave_roles = array_diff( $args['roles_before_upgrade'], array_merge( $role_keys, array( 'subscriber' ) ) );
if ( UM()->roles()->is_role_custom( $to_update['role'] ) ) {
$wp_user->remove_role( $to_update['role'] );
$roles = array_merge( $leave_roles, array( $to_update['role'] ) );
} else {
$roles = array_merge( array( $to_update['role'] ), $leave_roles );
}
foreach ( $roles as $role_k ) {
$wp_user->add_role( $role_k );
}
}
}
add_action( 'um_after_user_updated', 'um_restore_default_roles', 10, 3 );
/***
*** @if editing another user
***/
+1
View File
@@ -124,6 +124,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
$url = UM()->permalinks()->get_current_url();
$url = add_query_arg( 'message', esc_attr( $status ), $url );
//add only priority role to URL
$url = add_query_arg( 'um_role', esc_attr( um_user( 'role' ) ), $url );
$url = add_query_arg( 'um_form_id', esc_attr( $args['form_id'] ), $url );
+37 -66
View File
@@ -3,82 +3,53 @@
if ( ! defined( 'ABSPATH' ) ) exit;
/***
*** @sync with WP role
***/
add_action('um_after_user_role_is_updated','um_setup_synced_wp_role', 50, 2);
function um_setup_synced_wp_role( $user_id, $role ) {
$meta = UM()->roles()->role_data( $role );
$meta = apply_filters('um_user_permissions_filter', $meta, $user_id );
$wp_user_object = new WP_User( $user_id );
if ( isset( $meta['synced_role'] ) && $meta['synced_role'] ) {
$wp_user_object->add_role( $meta['synced_role'] );
}elseif( ! $wp_user_object->roles ) { // Fallback user default role if nothing set
$wp_user_object->add_role( 'subscriber' );
}
}
/***
*** @remove previously synced WP role
***/
add_action('um_when_role_is_set', 'um_remove_prev_synced_wp_role');
function um_remove_prev_synced_wp_role( $user_id ) {
um_fetch_user( $user_id );
$meta = UM()->roles()->role_data( um_user( 'role' ) );
if ( isset( $meta['synced_role'] ) && $meta['synced_role'] ) {
$wp_user_object = new WP_User( $user_id );
$wp_user_object->remove_role( $meta['synced_role'] );
}
/**
* Clean user temp uploads
*
* @param $user_id
* @param $post_array
*/
function um_remove_unused_uploads( $user_id, $post_array ) {
um_fetch_user( $user_id );
$user_meta_keys = UM()->user()->profile;
$_array = array();
foreach ( UM()->builtin()->custom_fields as $_field ) {
if ( $_field['type'] == 'file' && ! empty( $user_meta_keys[ $_field['metakey'] ] ) )
$_array[] = $user_meta_keys[ $_field['metakey'] ];
}
$_array = array_merge( $_array, $post_array );
/**
* Clean user temp uploads
*
* @param $user_id
* @param $post_array
*/
function um_remove_unused_uploads( $user_id, $post_array ) {
um_fetch_user( $user_id );
$files = glob( um_user_uploads_dir() . '*', GLOB_BRACE );
$error = array();
if ( file_exists( um_user_uploads_dir() ) && $files && isset( $_array ) && is_array( $_array ) ) {
foreach ( $files as $file ) {
$str = basename( $file );
$user_meta_keys = UM()->user()->profile;
$_array = array();
foreach ( UM()->builtin()->custom_fields as $_field ) {
if ( $_field['type'] == 'file' && ! empty( $user_meta_keys[ $_field['metakey'] ] ) )
$_array[] = $user_meta_keys[ $_field['metakey'] ];
}
$_array = array_merge( $_array, $post_array );
$files = glob( um_user_uploads_dir() . '*', GLOB_BRACE );
$error = array();
if ( file_exists( um_user_uploads_dir() ) && $files && isset( $_array ) && is_array( $_array ) ) {
foreach ( $files as $file ) {
$str = basename( $file );
if ( ! strstr( $str, 'profile_photo' ) && ! strstr( $str, 'cover_photo' ) &&
! strstr( $str, 'stream_photo' ) && ! preg_grep( '/' . $str . '/', $_array ) ) {
$error[] = $str;
unlink( $file );
}
if ( ! strstr( $str, 'profile_photo' ) && ! strstr( $str, 'cover_photo' ) &&
! strstr( $str, 'stream_photo' ) && ! preg_grep( '/' . $str . '/', $_array ) ) {
$error[] = $str;
unlink( $file );
}
}
}
add_action( 'um_after_user_upload','um_remove_unused_uploads', 10, 2 );
}
add_action( 'um_after_user_upload','um_remove_unused_uploads', 10, 2 );
/***
*** @adds main links to a logout widget
***/
add_action('um_logout_user_links', 'um_logout_user_links', 100 );
function um_logout_user_links( $args ) {
/**
* Adds main links to a logout widget
*
* @param $args
*/
function um_logout_user_links( $args ) {
?>
<li><a href="<?php echo um_get_core_page('account'); ?>"><?php _e('Your account','ultimate-member'); ?></a></li>
<li><a href="<?php echo esc_url( add_query_arg('redirect_to', UM()->permalinks()->get_current_url(true), um_get_core_page('logout') ) ); ?>"><?php _e('Logout','ultimate-member'); ?></a></li>
<li><a href="<?php echo um_get_core_page( 'account' ); ?>"><?php _e( 'Your account', 'ultimate-member' ); ?></a></li>
<li><a href="<?php echo esc_url( add_query_arg( 'redirect_to', UM()->permalinks()->get_current_url( true ), um_get_core_page( 'logout' ) ) ); ?>"><?php _e('Logout','ultimate-member'); ?></a></li>
<?php
}
}
add_action( 'um_logout_user_links', 'um_logout_user_links', 100 );
-48
View File
@@ -1,48 +0,0 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/***
*** @conditional logout form
***/
add_filter('um_shortcode_args_filter', 'um_display_logout_form', 99);
function um_display_logout_form( $args ) {
if ( is_user_logged_in() && isset( $args['mode'] ) && $args['mode'] == 'login' ) {
if ( get_current_user_id() != um_user('ID' ) ) {
um_fetch_user( get_current_user_id() );
}
$args['template'] = 'logout';
}
return $args;
}
/***
*** @filter for shortcode args
***/
add_filter('um_shortcode_args_filter', 'um_shortcode_args_filter', 99);
function um_shortcode_args_filter( $args ) {
if ( UM()->shortcodes()->message_mode == true ) {
$args['template'] = 'message';
$roleID = esc_attr( $_REQUEST['um_role'] );
$role = UM()->roles()->role_data( $roleID );
$status = $role["status"];
$message = $role["{$status}_message"];
UM()->shortcodes()->custom_message = $message;
}
foreach( $args as $k => $v ) {
$args[$k] = maybe_unserialize( $args[$k] );
}
return $args;
}
+1 -1
View File
@@ -256,7 +256,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
$value = str_replace('https://https://','https://',$value);
$value = str_replace('http://https://','https://',$value);
$value = UM()->shortcodes()->emotize( $value );
//$value = UM()->shortcodes()->emotize( $value );
return $value;
}
+13 -10
View File
@@ -33,9 +33,14 @@ if ( ! defined( 'ABSPATH' ) ) exit;
return $query_args;
}
/***
*** @Remove users we do not need to show in directory
***/
/**
* Remove users we do not need to show in directory
*
* @param $query_args
* @param $args
*
* @return mixed
*/
function um_remove_special_users_from_list( $query_args, $args ) {
extract( $args );
@@ -69,13 +74,11 @@ if ( ! defined( 'ABSPATH' ) ) exit;
if ( UM()->roles()->um_user_can( 'can_view_all' ) && UM()->roles()->um_user_can( 'can_view_roles' ) ) {
$permissions = UM()->roles()->role_data( um_user( 'role' ) );
if ( ! empty( $permissions['can_view_roles'] ) )
$roles = maybe_unserialize( $permissions['can_view_roles'] );
$roles = um_user( 'can_view_roles' );
$roles = maybe_unserialize( $roles );
if ( isset( $roles ) && is_array( $roles ) ) {
if ( ! empty( $roles ) ) {
$query_args['meta_query'][] = array(
'key' => 'role',
'value' => $roles,
@@ -83,8 +86,8 @@ if ( ! defined( 'ABSPATH' ) ) exit;
);
}
}
}
return $query_args;
}
+80 -73
View File
@@ -3,81 +3,88 @@
if ( ! defined( 'ABSPATH' ) ) exit;
/***
*** @add dynamic profile headers
***/
add_filter( 'wp_nav_menu_items', 'um_add_custom_message_to_menu', 10, 2 );
function um_add_custom_message_to_menu( $items, $args ) {
// this feature required logged in user
if ( !is_user_logged_in() )
return $items;
/**
* Add dynamic profile headers
*
* @param $items
* @param $args
*
* @return mixed
*/
function um_add_custom_message_to_menu( $items, $args ) {
// this feature required logged in user
if ( ! is_user_logged_in() )
return $items;
um_fetch_user( get_current_user_id() );
$items = UM()->shortcodes()->convert_user_tags( $items );
um_reset_user();
return $items;
}
add_filter( 'wp_nav_menu_items', 'um_add_custom_message_to_menu', 10, 2 );
/***
*** @conditional menu items
***/
if ( ! is_admin() ) {
add_filter( 'wp_get_nav_menu_items', 'um_conditional_nav_menu', 9999, 3 );
function um_conditional_nav_menu( $items, $menu, $args ) {
$hide_children_of = array();
um_fetch_user( get_current_user_id() );
$items = UM()->shortcodes()->convert_user_tags( $items );
foreach ( $items as $key => $item ) {
$mode = get_post_meta( $item->ID, 'menu-item-um_nav_public', true );
$roles = get_post_meta( $item->ID, 'menu-item-um_nav_roles', true );
$visible = true;
// hide any item that is the child of a hidden item
if ( in_array( $item->menu_item_parent, $hide_children_of ) ) {
$visible = false;
$hide_children_of[] = $item->ID; // for nested menus
}
if ( isset( $mode ) && $visible ) {
switch( $mode ) {
case 2:
if ( is_user_logged_in() && ! empty( $roles ) ) {
$current_user_roles = um_user( 'roles' );
$visible = ( count( array_intersect( $current_user_roles, (array)$roles ) ) > 0 ) ? true : false;
} else {
$visible = is_user_logged_in() ? true : false;
}
break;
case 1:
$visible = ! is_user_logged_in() ? true : false;
break;
}
}
// add filter to work with plugins that don't use traditional roles
$visible = apply_filters( 'um_nav_menu_roles_item_visibility', $visible, $item );
// unset non-visible item
if ( ! $visible ) {
$hide_children_of[] = $item->ID; // store ID of item
unset( $items[ $key ] ) ;
}
}
um_reset_user();
return $items;
}
/***
*** @conditional menu items
***/
if ( ! is_admin() ) {
add_filter( 'wp_get_nav_menu_items', 'um_conditional_nav_menu', 9999, 3 );
function um_conditional_nav_menu( $items, $menu, $args ) {
$hide_children_of = array();
um_fetch_user( get_current_user_id() );
foreach( $items as $key => $item ) {
$mode = get_post_meta( $item->ID, 'menu-item-um_nav_public', true );
$roles = get_post_meta( $item->ID, 'menu-item-um_nav_roles', true );
$visible = true;
// hide any item that is the child of a hidden item
if ( in_array( $item->menu_item_parent, $hide_children_of ) ) {
$visible = false;
$hide_children_of[] = $item->ID; // for nested menus
}
if ( isset( $mode ) && $visible ) {
switch( $mode ) {
case 2:
if ( is_user_logged_in() && ! empty( $roles ) ) {
$visible = in_array( um_user( 'role' ), (array)$roles ) ? true : false;
} else {
$visible = is_user_logged_in() ? true : false;
}
break;
case 1:
$visible = ! is_user_logged_in() ? true : false;
break;
}
}
// add filter to work with plugins that don't use traditional roles
$visible = apply_filters( 'um_nav_menu_roles_item_visibility', $visible, $item );
// unset non-visible item
if ( ! $visible ) {
$hide_children_of[] = $item->ID; // store ID of item
unset( $items[$key] ) ;
}
}
um_reset_user();
return $items;
}
}
}
-160
View File
@@ -1,160 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'UM_Menu_Item_Custom_Fields_Editor' ) ) :
class UM_Menu_Item_Custom_Fields_Editor {
protected static $fields = array();
/**
* Initialize plugin
*/
public static function init() {
add_action( 'wp_nav_menu_item_custom_fields', array( __CLASS__, '_fields' ), 1, 4 );
add_action( 'wp_update_nav_menu_item', array( __CLASS__, '_save' ), 10, 3 );
add_filter( 'manage_nav-menus_columns', array( __CLASS__, '_columns' ), 99 );
self::$fields = array(
'um_nav_public' => __( 'Display Mode'),
'um_nav_roles' => __('By Role')
);
}
public static function _save( $menu_id, $menu_item_db_id, $menu_item_args ) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
foreach ( self::$fields as $_key => $label ) {
if( $_key == 'um_nav_roles' ){
$key = sprintf( 'menu-item-%s', $_key );
// Sanitize
if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) {
// Do some checks here...
$value = $_POST[ $key ][ $menu_item_db_id ];
}
else {
$value = null;
}
}else{
$key = sprintf( 'menu-item-%s', $_key );
// Sanitize
if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) {
// Do some checks here...
$value = $_POST[ $key ][ $menu_item_db_id ];
}
else {
$value = null;
}
}
// Update
if ( ! is_null( $value ) ) {
update_post_meta( $menu_item_db_id, $key, $value );
}
else {
delete_post_meta( $menu_item_db_id, $key );
}
}
}
public static function _fields( $id, $item, $depth, $args ) {
?>
<div class="um-nav-edit">
<div class="clear"></div>
<h4 style="margin-bottom: 0.6em;"><?php _e( "Ultimate Member Menu Settings", 'ultimate-member' ) ?></h4>
<?php foreach ( self::$fields as $_key => $label ) {
$key = sprintf('menu-item-%s', $_key);
$id = sprintf('edit-%s-%s', $key, $item->ID);
$name = sprintf('%s[%s]', $key, $item->ID);
$value = get_post_meta($item->ID, $key, true);
$role_name = sprintf('%s[%s][]', $key, $item->ID);
$class = sprintf('field-%s', $_key); ?>
<?php if ( $_key == 'um_nav_public' ) { ?>
<p class="description description-wide um-nav-mode">
<label for="<?php echo $id ?>">
<?php _e( "Who can see this menu link?", 'ultimate-member' ); ?><br/>
<select id="<?php echo $id ?>" name="<?php echo $name ?>" style="width:100%;">
<option value="0" <?php selected(!isset($value) || $value == ''); ?>>
<?php _e( 'Everyone', 'ultimate-member' ) ?>
</option>
<option value="1" <?php selected(1, $value); ?>>
<?php _e( 'Logged Out Users', 'ultimate-member' ) ?>
</option>
<option value="2" <?php selected(2, $value); ?>>
<?php _e( 'Logged In Users', 'ultimate-member' ) ?>
</option>
</select>
</label>
</p>
<?php }
if ( $_key == 'um_nav_roles' ) { ?>
<p class="description description-wide um-nav-roles">
<?php _e( "Select the member roles that can see this link", 'ultimate-member' ) ?><br />
<?php $options = UM()->roles()->get_roles();
$i = 0;
$html = '';
$columns = 2;
while ( $i < $columns ) {
$per_page = ceil( count( $options ) / $columns );
$section_fields_per_page = array_slice( $options, $i*$per_page, $per_page );
$html .= '<span class="um-form-fields-section" style="width:' . floor( 100 / $columns ) . '% !important;">';
foreach ( $section_fields_per_page as $k => $title ) {
$id_attr = ' id="' . $id . '_' . $k . '" ';
$for_attr = ' for="' . $id . '_' . $k . '" ';
$name_attr = ' name="' . $role_name . '" ';
$html .= "<label $for_attr>
<input type=\"checkbox\" " . checked( ( is_array( $value ) && in_array( $k, $value ) ) || ( isset( $value ) && $k == $value ), true, false ) . "$id_attr $name_attr value=\"" . $k . "\">
<span>$title</span>
</label>";
}
$html .= '</span>';
$i++;
}
echo $html; ?>
</p>
<?php }
} ?>
<div class="clear"></div>
</div>
<?php
}
public static function _columns( $columns ) {
$columns = array_merge( $columns, self::$fields );
return $columns;
}
}
endif;
UM_Menu_Item_Custom_Fields_Editor::init();
@@ -1,37 +0,0 @@
<?php
/**
* This is template for NavMenu Walker Class which extends from latest parents
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( '{{{%um_navmenu_walker%}}}' ) ) :
class {{{%um_navmenu_walker%}}} extends {{{%parent_walker%}}} {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$item_output = '';
parent::start_el( $item_output, $item, $depth, $args, $id );
if( $new_fields = $this->get_fields( $item, $depth, $args, $id ) ){
//$item_output = preg_replace('/(?=<div[^>]+class="[^"]*submitbox)/', $new_fields, $item_output);
$item_output = preg_replace('/(?=<(fieldset|p)[^>]+class="[^"]*field-move)/', $new_fields, $item_output);
}
$output .= $item_output;
}
public function get_fields( $item, $depth, $args = array(), $id = 0 ) {
ob_start();
if( isset( $item->ID ) ){
$id = esc_attr( $item->ID );
}
do_action( 'wp_nav_menu_item_custom_fields', $id, $item, $depth, $args );
return ob_get_clean();
}
}
endif;
-34
View File
@@ -1,34 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'UM_Menu_Item_Custom_Fields_Walker' ) ) :
class UM_Menu_Item_Custom_Fields_Walker extends Walker_Nav_Menu_Edit {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$item_output = '';
parent::start_el( $item_output, $item, $depth, $args, $id );
if( $new_fields = $this->get_fields( $item, $depth, $args, $id ) ){
//$item_output = preg_replace('/(?=<div[^>]+class="[^"]*submitbox)/', $new_fields, $item_output);
$item_output = preg_replace('/(?=<(fieldset|p)[^>]+class="[^"]*field-move)/', $new_fields, $item_output);
}
$output .= $item_output;
}
public function get_fields( $item, $depth, $args = array(), $id = 0 ) {
ob_start();
if( isset( $item->ID ) ){
$id = esc_attr( $item->ID );
}
do_action( 'wp_nav_menu_item_custom_fields', $id, $item, $depth, $args );
return ob_get_clean();
}
}
endif;
+183 -45
View File
@@ -1,58 +1,196 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'UM_Menu_Item_Custom_Fields' ) ) :
if ( ! class_exists( 'UM_Menu_Item_Custom_Fields_Editor' ) ) {
class UM_Menu_Item_Custom_Fields {
/**
*
*/
public static function load() {
add_filter( 'wp_edit_nav_menu_walker', array( __CLASS__, '_filter_walker' ), 999 );
}
class UM_Menu_Item_Custom_Fields_Editor {
/**
* @var array
*/
protected static $fields = array();
/**
* @param $walker
* @return string
*/
public static function _filter_walker( $walker ) {
$um_walker = 'UM_Menu_Item_Custom_Fields_Walker';
/**
* Initialize plugin
*/
public static function init() {
if ( UM()->options()->get( 'menu_item_workaround' ) ) {
//hard rewrite workaround with conflicted themes/plugins
$walker = 'Walker_Nav_Menu_Edit';
}
$walker_filename = dirname( __FILE__ ) . '/um-navmenu-walker.php';
$walker_template = file_get_contents( dirname( __FILE__ ) . '/um-navmenu-walker-template.php' );
$current_walker_content = file_get_contents( $walker_filename );
if ( strpos( $current_walker_content, $um_walker ) === false ||
strpos( $current_walker_content, $walker ) === false ) {
$walker_template = str_replace(
array(
'{{{%um_navmenu_walker%}}}',
'{{{%parent_walker%}}}'
),
array(
$um_walker,
$walker
),
$walker_template
self::$fields = array(
'um_nav_public' => __( 'Display Mode' ),
'um_nav_roles' => __( 'By Role' )
);
$fp = fopen( $walker_filename, 'w+' );
fwrite( $fp, $walker_template );
fclose( $fp );
add_action( 'wp_update_nav_menu_item', array( __CLASS__, '_save' ), 10, 3 );
//add_filter( 'manage_nav-menus_columns', array( __CLASS__, '_columns' ), 99 );
add_action( 'load-nav-menus.php', array( __CLASS__, 'enqueue_nav_menus_scripts' ) );
add_action( 'admin_footer-nav-menus.php', array( __CLASS__, '_wp_template' ) );
}
require_once $walker_filename;
return $um_walker;
/**
* @param $menu_id
* @param $menu_item_db_id
* @param $menu_item_args
*/
public static function _save( $menu_id, $menu_item_db_id, $menu_item_args ) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
return;
}
foreach ( self::$fields as $_key => $label ) {
if ( $_key == 'um_nav_roles' ) {
$key = sprintf( 'menu-item-%s', $_key );
// Sanitize
if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) {
// Do some checks here...
$value = $_POST[ $key ][ $menu_item_db_id ];
} else {
$value = null;
}
} else {
$key = sprintf( 'menu-item-%s', $_key );
// Sanitize
if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) {
// Do some checks here...
$value = $_POST[ $key ][ $menu_item_db_id ];
} else {
$value = null;
}
}
// Update
if ( ! is_null( $value ) ) {
update_post_meta( $menu_item_db_id, $key, $value );
} else {
delete_post_meta( $menu_item_db_id, $key );
}
}
}
/**
* @param $columns
*
* @return array
*/
public static function _columns( $columns ) {
$columns = array_merge( $columns, self::$fields );
return $columns;
}
/**
*
*/
public static function enqueue_nav_menus_scripts() {
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) );
}
/**
*
*/
public static function admin_enqueue_scripts() {
UM()->admin_enqueue()->load_nav_manus_scripts();
$menus = get_posts( 'post_type=nav_menu_item&numberposts=-1' );
$menu_restriction_data = array();
foreach ( $menus as $data ) {
$_nav_roles_meta = get_post_meta( $data->ID, 'menu-item-um_nav_roles', true );
$um_nav_roles = array();
if ( $_nav_roles_meta ) {
foreach ( $_nav_roles_meta as $key => $value ) {
if ( is_int( $key ) ) {
$um_nav_roles[] = $value;
}
}
}
$menu_restriction_data[ $data->ID ] = array(
'um_nav_public' => get_post_meta( $data->ID, 'menu-item-um_nav_public', true ),
'um_nav_roles' => $um_nav_roles,
);
}
wp_localize_script( 'um_admin_nav_manus', 'um_menu_restriction_data', $menu_restriction_data );
}
/**
*
*/
public static function _wp_template() {
?>
<script type="text/html" id="tmpl-um-nav-menus-fields">
<div class="um-nav-edit">
<div class="clear"></div>
<h4 style="margin-bottom: 0.6em;"><?php _e( "Ultimate Member Menu Settings", 'ultimate-member' ) ?></h4>
<p class="description description-wide um-nav-mode">
<label for="edit-menu-item-um_nav_public-{{data.menuItemID}}">
<?php _e( "Who can see this menu link?", 'ultimate-member' ); ?><br/>
<select id="edit-menu-item-um_nav_public-{{data.menuItemID}}"
name="menu-item-um_nav_public[{{data.menuItemID}}]" style="width:100%;">
<option value="0" <# if( data.restriction_data.um_nav_public == '0' ){ #>selected="selected"<# } #>>
<?php _e( 'Everyone', 'ultimate-member' ) ?>
</option>
<option value="1" <# if( data.restriction_data.um_nav_public == '1' ){ #>selected="selected"<# } #>>
<?php _e( 'Logged Out Users', 'ultimate-member' ) ?>
</option>
<option value="2" <# if( data.restriction_data.um_nav_public == '2' ){ #>selected="selected"<# } #>>
<?php _e( 'Logged In Users', 'ultimate-member' ) ?>
</option>
</select>
</label>
</p>
<p class="description description-wide um-nav-roles" <# if( data.restriction_data.um_nav_public == '2' ){ #>style="display: block;"<# } #>>
<?php _e( "Select the member roles that can see this link", 'ultimate-member' ) ?><br/>
<?php $options = UM()->roles()->get_roles();
$i = 0;
$html = '';
$columns = 2;
while ( $i < $columns ) {
$per_page = ceil( count( $options ) / $columns );
$section_fields_per_page = array_slice( $options, $i * $per_page, $per_page );
$html .= '<span class="um-form-fields-section" style="width:' . floor( 100 / $columns ) . '% !important;">';
foreach ( $section_fields_per_page as $k => $title ) {
$id_attr = ' id="edit-menu-item-um_nav_roles-{{data.menuItemID}}_' . $k . '" ';
$for_attr = ' for="edit-menu-item-um_nav_roles-{{data.menuItemID}}_' . $k . '" ';
$html .= "<label $for_attr>
<input type='checkbox' {$id_attr} name='menu-item-um_nav_roles[{{data.menuItemID}}][]' value='{$k}' <# if( _.contains( data.restriction_data.um_nav_roles,'{$k}' ) ){ #>checked='checked'<# } #> />
<span>{$title}</span>
</label>";
}
$html .= '</span>';
$i++;
}
echo $html; ?>
</p>
<div class="clear"></div>
</div>
</script>
<?php
}
}
}
add_action( 'wp_loaded', array( 'UM_Menu_Item_Custom_Fields', 'load' ), 9 );
endif;
require_once dirname( __FILE__ ) . '/um-navmenu-walker-edit.php';
UM_Menu_Item_Custom_Fields_Editor::init();
+39 -24
View File
@@ -87,10 +87,11 @@ function um_clean_user_basename( $value ) {
*
* @param $content
* @param array $args
* @param bool $with_kses
*
* @return mixed|string
*/
function um_convert_tags( $content, $args = array() ) {
function um_convert_tags( $content, $args = array(), $with_kses = true ) {
$search = array(
'{display_name}',
'{first_name}',
@@ -137,9 +138,12 @@ function um_convert_tags( $content, $args = array() ) {
$replace = apply_filters( 'um_template_tags_replaces_hook', $replace );
$content = wp_kses_decode_entities( str_replace( $search, $replace, $content ) );
$content = str_replace( $search, $replace, $content );
if ( $with_kses ) {
$content = wp_kses_decode_entities( $content );
}
if (isset( $args['tags'] ) && isset( $args['tags_replace'] )) {
if ( isset( $args['tags'] ) && isset( $args['tags_replace'] ) ) {
$content = str_replace( $args['tags'], $args['tags_replace'], $content );
}
@@ -509,7 +513,7 @@ function um_filtered_value( $key, $data = false ) {
$value = apply_filters( "um_profile_field_filter_hook__", $value, $data, $type );
$value = apply_filters( "um_profile_field_filter_hook__{$key}", $value, $data );
$value = apply_filters( "um_profile_field_filter_hook__{$type}", $value, $data );
$value = UM()->shortcodes()->emotize( $value );
return $value;
}
@@ -667,9 +671,17 @@ function um_is_core_page( $page ) {
if (isset( $post->ID ) && isset( UM()->config()->permalinks[$page] ) && $post->ID == UM()->config()->permalinks[$page])
return true;
if (isset( $post->ID ) && get_post_meta( $post->ID, '_um_wpml_' . $page, true ) == 1)
return true;
if ( UM()->external_integrations()->is_wpml_active() ) {
global $sitepress;
if ( UM()->config()->permalinks[$page] == wpml_object_id_filter( $post->ID, 'page', true, $sitepress->get_default_language() ) ) {
return true;
}
}
if (isset( $post->ID )) {
$_icl_lang_duplicate_of = get_post_meta( $post->ID, '_icl_lang_duplicate_of', true );
@@ -984,23 +996,27 @@ function um_is_on_edit_profile() {
*/
function um_can_view_field( $data ) {
if (!isset( UM()->fields()->set_mode ))
if ( ! isset( UM()->fields()->set_mode ) ) {
UM()->fields()->set_mode = '';
}
if (isset( $data['public'] ) && UM()->fields()->set_mode != 'register') {
if ( isset( $data['public'] ) && UM()->fields()->set_mode != 'register' ) {
if (!is_user_logged_in() && $data['public'] != '1') return false;
if ( ! is_user_logged_in() && $data['public'] != '1' ) {
return false;
}
if (is_user_logged_in()) {
if ( is_user_logged_in() ) {
$current_user_roles = um_user( 'roles' );
if ($data['public'] == '-3' && !um_is_user_himself() && !in_array( UM()->roles()->um_get_user_role( get_current_user_id() ), $data['roles'] ))
if ( $data['public'] == '-3' && ! um_is_user_himself() && count( array_intersect( $current_user_roles, $data['roles'] ) ) <= 0 )
return false;
if (!um_is_user_himself() && $data['public'] == '-1' && !UM()->roles()->um_user_can( 'can_edit_everyone' ))
if ( ! um_is_user_himself() && $data['public'] == '-1' && ! UM()->roles()->um_user_can( 'can_edit_everyone' ) )
return false;
if ($data['public'] == '-2' && $data['roles'])
if (!in_array( UM()->roles()->um_get_user_role( get_current_user_id() ), $data['roles'] ))
if ( $data['public'] == '-2' && $data['roles'] )
if ( count( array_intersect( $current_user_roles, $data['roles'] ) ) <= 0 )
return false;
}
@@ -1018,30 +1034,29 @@ function um_can_view_field( $data ) {
* @return bool
*/
function um_can_view_profile( $user_id ) {
if (!um_user( 'can_view_all' ) && $user_id != get_current_user_id() && is_user_logged_in()) return false;
if ( ! um_user( 'can_view_all' ) && $user_id != get_current_user_id() && is_user_logged_in() ) {
return false;
}
if (UM()->roles()->um_current_user_can( 'edit', $user_id )) {
if ( UM()->roles()->um_current_user_can( 'edit', $user_id ) ) {
return true;
}
if (!is_user_logged_in()) {
if (UM()->user()->is_private_profile( $user_id )) {
return false;
} else {
return true;
}
if ( ! is_user_logged_in() ) {
return ! UM()->user()->is_private_profile( $user_id );
}
if (!um_user( 'can_access_private_profile' ) && UM()->user()->is_private_profile( $user_id )) return false;
if ( ! um_user( 'can_access_private_profile' ) && UM()->user()->is_private_profile( $user_id ) ) {
return false;
}
if (UM()->roles()->um_user_can( 'can_view_roles' ) && $user_id != get_current_user_id()) {
if (!in_array( UM()->roles()->um_get_user_role( $user_id ), UM()->roles()->um_user_can( 'can_view_roles' ) )) {
if ( UM()->roles()->um_user_can( 'can_view_roles' ) && $user_id != get_current_user_id() ) {
if ( count( array_intersect( UM()->roles()->get_all_user_roles( $user_id ), UM()->roles()->um_user_can( 'can_view_roles' ) ) ) <= 0 ) {
return false;
}
}
return true;
}
File diff suppressed because it is too large Load Diff
+20 -25
View File
@@ -65,38 +65,33 @@
} // end if
} // end foreach
} // end if $show_tagline
?>
<?php if ( $show_userinfo ) { ?>
<div class="um-member-meta-main">
if ( ! empty( $show_userinfo ) ) { ?>
<div class="um-member-meta-main">
<?php if ( $userinfo_animate ) { ?>
<div class="um-member-more"><a href="#"><i class="um-faicon-angle-down"></i></a></div>
<div class="um-member-more"><a href="#"><i class="um-faicon-angle-down"></i></a></div>
<?php } ?>
<div class="um-member-meta <?php if ( !$userinfo_animate ) { echo 'no-animate'; } ?>">
<div class="um-member-meta <?php if ( ! $userinfo_animate ) { echo 'no-animate'; } ?>">
<?php foreach( $reveal_fields as $key ) {
if ( $key /*&& um_filtered_value( $key )*/ ) {
$value = um_filtered_value( $key );
if ( ! $value )
continue;
?>
<?php um_fetch_user( $member );
foreach ( $reveal_fields as $key ) {
if ( $key ) {
$value = um_filtered_value( $key );
if ( ! $value )
continue; ?>
<div class="um-member-metaline um-member-metaline-<?php echo $key; ?>"><span><strong><?php echo UM()->fields()->get_label( $key ); ?>:</strong> <?php echo $value; ?></span></div>
<?php
}
}
?>
<?php if ( $show_social ) { ?>
<div class="um-member-connect">
<?php UM()->fields()->show_social_urls(); ?>
<div class="um-member-metaline um-member-metaline-<?php echo $key; ?>"><span><strong><?php echo UM()->fields()->get_label( $key ); ?>:</strong> <?php echo $value; ?></span></div>
</div>
<?php }
}
if ( $show_social ) { ?>
<div class="um-member-connect">
<?php UM()->fields()->show_social_urls(); ?>
</div>
<?php } ?>
</div>
+1 -1
View File
@@ -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
Version: 2.0.1
Author: Ultimate Member
Author URI: http://ultimatemember.com/
Text Domain: ultimate-member