- fixed integration with User Tags extension (remove some hardcode, changed to hooks);

- fixed 2.0 upgrades for User roles meta data;
- clear/review code;
This commit is contained in:
nikitozzzzzzz
2017-09-06 09:03:24 +03:00
parent 31de1e49ce
commit 2921707a65
9 changed files with 309 additions and 102 deletions
@@ -150,6 +150,8 @@ a.um-delete{ color: #a00; }
max-width: 300px;
font-size: 12px;
border-radius: 5px;
border: none !important;
text-shadow: none !important;
}
.um_tooltip.dashicons,
+1 -7
View File
@@ -147,13 +147,7 @@ if ( ! class_exists( 'Admin_Metabox' ) ) {
//restrict content metabox
$all_taxonomies = get_taxonomies( array( 'public' => true ) );
$tax_types = um_get_option( 'restricted_access_taxonomy_metabox' );
$exclude_taxonomies = array(
'nav_menu',
'link_category',
'post_format',
'um_user_tag',
'um_hashtag',
);
$exclude_taxonomies = UM()->excluded_taxonomies();
foreach ( $all_taxonomies as $key => $taxonomy ) {
if ( in_array( $key, $exclude_taxonomies ) || empty( $tax_types[$key] ) )
+1 -7
View File
@@ -176,13 +176,7 @@ if ( ! class_exists( 'Admin_Settings' ) ) {
$all_post_types = get_post_types( array( 'public' => true ) );
$all_taxonomies = get_taxonomies( array( 'public' => true ) );
$exclude_taxonomies = array(
'nav_menu',
'link_category',
'post_format',
'um_user_tag',
'um_hashtag',
);
$exclude_taxonomies = UM()->excluded_taxonomies();
foreach ( $all_taxonomies as $key => $taxonomy ) {
if( in_array( $key , $exclude_taxonomies ) )
+286 -7
View File
@@ -960,6 +960,19 @@ if ( ! empty( $um_roles ) ) {
$role_metadata = array();
if ( ! empty( $all_role_metadata ) ) {
foreach( $all_role_metadata as $metadata ) {
if ( '_um_can_edit_roles' == $metadata['meta_key'] || '_um_can_delete_roles' == $metadata['meta_key']
|| '_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'];
}
}
@@ -1048,13 +1061,7 @@ if ( ! empty( $posts ) ) {
$all_taxonomies = get_taxonomies( array( 'public' => true ) );
$exclude_taxonomies = array(
'nav_menu',
'link_category',
'post_format',
'um_user_tag',
'um_hashtag',
);
$exclude_taxonomies = UM()->excluded_taxonomies();
foreach ( $all_taxonomies as $key => $taxonomy ) {
if ( in_array( $key , $exclude_taxonomies ) )
@@ -1135,6 +1142,36 @@ foreach ( $forms as $form_id ) {
}
}
//for metadata for all UM Member Directories
//also update for forms metadata where "member" or "admin"
$member_directories = get_posts( array(
'post_type' => 'um_directory',
'numberposts' => -1,
'fields' => 'ids'
) );
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 ) {
return 'um_' . $item;
}, $directory_roles );
update_post_meta( $directory_id, '_um_roles', $directory_roles );
}
$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 ) {
return 'um_' . $item;
}, $um_roles_can_search );
update_post_meta( $directory_id, '_um_roles', $um_roles_can_search );
}
}
/**
* Transferring email templates to new logic
@@ -1195,3 +1232,245 @@ foreach ( $menus as $menu ) {
update_post_meta( $menu->ID, 'menu-item-um_nav_roles', $menu_roles );
}
$profile_tab_main_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_main_roles );
um_update_option( 'profile_tab_main_roles', $profile_tab_main_roles );
}
$profile_tab_posts_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_posts_roles );
um_update_option( 'profile_tab_posts_roles', $profile_tab_posts_roles );
}
$profile_tab_comments_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_comments_roles );
um_update_option( 'profile_tab_comments_roles', $profile_tab_comments_roles );
}
$profile_tab_activity_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_activity_roles );
um_update_option( 'profile_tab_activity_roles', $profile_tab_activity_roles );
}
$profile_tab_messages_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_messages_roles );
um_update_option( 'profile_tab_messages_roles', $profile_tab_messages_roles );
}
$profile_tab_reviews_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_reviews_roles );
um_update_option( 'profile_tab_reviews_roles', $profile_tab_reviews_roles );
}
$profile_tab_purchases_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_purchases_roles );
um_update_option( 'profile_tab_purchases_roles', $profile_tab_purchases_roles );
}
$profile_tab_product_reviews = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_product_reviews );
um_update_option( 'profile_tab_product-reviews_roles', $profile_tab_product_reviews );
}
$profile_tab_forums_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_forums_roles );
um_update_option( 'profile_tab_forums_roles', $profile_tab_forums_roles );
}
$profile_tab_friends_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $profile_tab_friends_roles );
um_update_option( 'profile_tab_friends_roles', $profile_tab_friends_roles );
}
$register_role = um_get_option( 'register_role' );
if ( ! empty( $register_role ) ) {
$register_role = 'um_' . $register_role;
um_update_option( 'register_role', $register_role );
}
$woo_oncomplete_role = um_get_option( 'woo_oncomplete_role' );
if ( ! empty( $woo_oncomplete_role ) ) {
$woo_oncomplete_role = 'um_' . $woo_oncomplete_role;
um_update_option( 'woo_oncomplete_role', $woo_oncomplete_role );
}
$woo_oncomplete_except_roles = um_get_option( '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 ) {
return 'um_' . $item;
}, $woo_oncomplete_except_roles );
um_update_option( 'woo_oncomplete_except_roles', $woo_oncomplete_except_roles );
}
//for metadata for all bbPress forums
//also update for forms metadata where "member" or "admin"
$wc_products = get_posts( array(
'post_type' => 'product',
'numberposts' => -1,
'fields' => 'ids'
) );
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;
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;
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;
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;
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;
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;
update_post_meta( $product_id, '_um_woo_product_downgrade_cancelled_role', $woo_product_downgrade_cancelled_role );
}
}
$bb_forums = get_posts( array(
'post_type' => 'forum',
'numberposts' => -1,
'fields' => 'ids'
) );
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 ) {
return 'um_' . $item;
}, $bbpress_can_topic );
update_post_meta( $forum_id, '_um_bbpress_can_topic', $bbpress_can_topic );
}
$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 ) {
return 'um_' . $item;
}, $bbpress_can_reply );
update_post_meta( $forum_id, '_um_bbpress_can_reply', $bbpress_can_reply );
}
}
$mc_lists = get_posts( array(
'post_type' => 'um_mailchimp',
'numberposts' => -1,
'fields' => 'ids'
) );
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 ) {
return 'um_' . $item;
}, $um_roles );
update_post_meta( $list_id, '_um_roles', $um_roles );
}
}
$um_social_login = get_posts( array(
'post_type' => 'um_social_login',
'numberposts' => -1,
'fields' => 'ids'
) );
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;
update_post_meta( $social_login_id, '_um_assigned_role', $assigned_role );
}
}
+7 -38
View File
@@ -177,45 +177,14 @@ if ( ! class_exists( 'UM_Functions' ) ) {
}
function excluded_taxonomies() {
$taxes = array(
'nav_menu',
'link_category',
'post_format',
);
/*
* redirect
*/
function redirect( $url ) {
if ( headers_sent() || empty( $url ) ) {
$this->cc_js_redirect( $url );
} else {
wp_redirect( $url );
}
exit;
}
/*
* JS redirect
*/
function cc_js_redirect( $url ) {
//for blank redirects
if ( '' == $url ) {
$url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
}
$funtext="echo \"<script data-cfasync='false' type='text/javascript'>window.location = '" . $url . "'</script>\";";
register_shutdown_function( create_function( '', $funtext ) );
if ( 1 < ob_get_level() ) {
while ( ob_get_level() > 1 ) {
ob_end_clean();
}
}
?>
<script data-cfasync="false" type="text/javascript">
window.location = '<?php echo $url; ?>';
</script>
<?php
exit;
return apply_filters( 'um_excluded_taxonomies', $taxes );
}
}
+2 -9
View File
@@ -79,15 +79,8 @@ if ( ! class_exists( 'Members' ) ) {
// additional filter for search field attributes
$attrs = apply_filters("um_search_field_{$filter}", $attrs);
if ( UM()->builtin()->is_dropdown_field( $filter, $attrs ) ) {
$type = 'select';
} else if ( 'user_tags' == $attrs['type'] ) {
$attrs['options'] = apply_filters('um_multiselect_options_user_tags', array(), $attrs);
$attrs['custom'] = 1;
$type = 'select';
} else {
$type = 'text';
}
$type = UM()->builtin()->is_dropdown_field( $filter, $attrs ) ? 'select' : 'text';
$type = apply_filters( 'um_search_field_type', $type, $attrs );
// filter all search fields
$attrs = apply_filters( 'um_search_fields', $attrs );
+2 -4
View File
@@ -203,14 +203,12 @@ function um_submit_account_errors_hook( $args ) {
$url = UM()->permalinks()->get_current_url( true );
$url = add_query_arg( 'updated', 'account', $url );
UM()->redirect( $url );
exit;
um_js_redirect( $url );
}
}
}
UM()->redirect( $url );
exit;
um_js_redirect( $url );
}
+3 -4
View File
@@ -220,10 +220,6 @@
UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) );
}
if ( defined('um_user_tags_path') && isset( $array['type'] ) && $array['type'] == 'user_tags' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) {
UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) );
}
if ( isset( $array['type'] ) && $array['type'] == 'radio' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) && !in_array($key, array('role_radio','role_select') ) ) {
UM()->form()->add_error($key, sprintf(__('%s is required.','ultimate-member'), $array['title'] ) );
}
@@ -238,6 +234,9 @@
}
}
do_action( 'um_add_error_on_form_submit_validation', $array, $key, $args );
if ( isset( $args[$key] ) ) {
if ( isset( $array['required'] ) && $array['required'] == 1 ) {
+5 -26
View File
@@ -754,39 +754,18 @@
*** @Check whether item in dropdown is selected in query-url
***/
function um_select_if_in_query_params( $filter, $val ) {
/*if ( isset( $_REQUEST['um_search'] ) ) {
$query = UM()->permalinks()->get_query_array();
if ( isset( $query[$filter] ) && $val == $query[$filter] )
echo 'selected="selected"';
}*/
$selected = false;
if ( isset( $_REQUEST['um_search'] ) ) {
$query = UM()->permalinks()->get_query_array();
if ( ! is_numeric( $query[$filter] ) ) {
$tags = get_option( 'um_user_tags_filters' );
if ( isset( $query[ $filter ] ) && $val == $query[ $filter ] )
$selected = true;
if ( $tags ) {
$tags = array_unique( array_values( $tags ) );
if ( in_array( $filter, $tags ) ) {
$term = get_term_by( 'slug', $query[$filter], 'um_user_tag' );
if ( ! is_wp_error( $term ) ) {
if ( isset( $query[$filter] ) && $val == $term->term_id ) {
echo 'selected="selected"';
}
}
}
} else {
if ( isset( $query[$filter] ) && $val == $query[$filter] )
echo 'selected="selected"';
}
} else {
if ( isset( $query[$filter] ) && $val == $query[$filter] )
echo 'selected="selected"';
}
$selected = apply_filters( 'um_selected_if_in_query_params', $selected, $filter, $val );
}
echo '';
echo $selected ? 'selected="selected"' : '';
}
/***