mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-20 15:13:55 +09:00
Update 1.3.29
This commit is contained in:
@@ -1,14 +1,183 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Add access settings to category
|
||||
*
|
||||
**/
|
||||
|
||||
add_action( 'category_add_form_fields', 'um_category_access_fields_create' );
|
||||
add_action( 'category_edit_form_fields', 'um_category_access_fields_edit' );
|
||||
add_action( 'create_category', 'um_category_access_fields_save' );
|
||||
add_action( 'edited_category', 'um_category_access_fields_save' );
|
||||
|
||||
function um_category_access_fields_create( $term ){
|
||||
global $ultimatemember;
|
||||
|
||||
echo '<div class="form-field term-access-wrap">';
|
||||
echo '<label>' . __('Content Availability','ultimatemember') . '</label>';
|
||||
echo '<label><input type="radio" name="_um_accessible" value="0" checked /> '. __('Content accessible to Everyone','ultimatemember') . '</label>
|
||||
<label><input type="radio" name="_um_accessible" value="1" /> ' . __('Content accessible to Logged Out Users','ultimatemember') . '</label>
|
||||
<label><input type="radio" name="_um_accessible" value="2" /> ' . __('Content accessible to Logged In Users','ultimatemember') . '</label>';
|
||||
echo '<p class="description">Who can see content/posts in this category.</p>';
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="form-field term-roles-wrap">';
|
||||
echo '<label>' . __('Roles who can see the content','ultimatemember') . '</label>';
|
||||
foreach($ultimatemember->query->get_roles() as $role_id => $role) {
|
||||
echo '<label><input type="checkbox" name="_um_roles[]" value="' . $role_id . '" /> ' . $role . '</label>';
|
||||
}
|
||||
echo '<p class="description">' . __('This is applicable only if you allow logged-in users to view the content.','ultimatemember') . '</p>';
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="form-field term-redirect-wrap">';
|
||||
echo '<label>' . __('Content Restriction Redirect URL','ultimatemember') . '</label>';
|
||||
echo '<input type="text" name="_um_redirect" id="_um_redirect" value="" />';
|
||||
echo '<p class="description">' . __('Users who cannot see content will get redirected to that URL.','ultimatemember') . '</p>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
function um_category_access_fields_edit( $term ){
|
||||
global $ultimatemember;
|
||||
|
||||
$termID = $term->term_id;
|
||||
$termMeta = get_option( "category_$termID" );
|
||||
$_um_accessible= (isset( $termMeta['_um_accessible'] ) )? $termMeta['_um_accessible'] : '';
|
||||
$_um_redirect= (isset( $termMeta['_um_redirect'] ) )? $termMeta['_um_redirect'] : '';
|
||||
$_um_roles= (isset( $termMeta['_um_roles'] ) )? $termMeta['_um_roles'] : '';
|
||||
|
||||
echo "<tr class='form-field form-required term-access-wrap'>";
|
||||
echo "<th scope='row'><label>" . __('Content Availability','ultimatemember') . "</label></th>";
|
||||
echo '<td><label><input type="radio" name="_um_accessible" value="0" ' . checked( 0, $_um_accessible, 0 ) . ' /> '. __('Content accessible to Everyone','ultimatemember') . '</label><br />
|
||||
<label><input type="radio" name="_um_accessible" value="1" ' . checked( 1, $_um_accessible, 0 ) . ' /> ' . __('Content accessible to Logged Out Users','ultimatemember') . '</label><br />
|
||||
<label><input type="radio" name="_um_accessible" value="2" ' . checked( 2, $_um_accessible, 0 ) . ' /> ' . __('Content accessible to Logged In Users','ultimatemember') . '</label>';
|
||||
echo '<p class="description">Who can see content/posts in this category.</p>';
|
||||
echo "</td></tr>";
|
||||
|
||||
echo "<tr class='form-field form-required term-roles-wrap'>";
|
||||
echo "<th scope='row'><label>" . __('Roles who can see the content','ultimatemember') . "</label></th>";
|
||||
echo '<td>';
|
||||
foreach($ultimatemember->query->get_roles() as $role_id => $role) {
|
||||
if ( ( isset( $_um_roles ) && is_array( $_um_roles ) && in_array($role_id, $_um_roles ) ) || ( isset( $_um_roles ) && $role_id == $_um_roles ) ) {
|
||||
$checked = 'checked';
|
||||
} else {
|
||||
$checked = '';
|
||||
}
|
||||
echo '<label><input type="checkbox" name="_um_roles[]" value="' . $role_id . '" ' . $checked . ' /> ' . $role . '</label> ';
|
||||
}
|
||||
echo '<p class="description">' . __('Users who cannot see content will get redirected to that URL.','ultimatemember') . '</p>';
|
||||
echo "</td></tr>";
|
||||
|
||||
echo "<tr class='form-field form-required term-redirect-wrap'>";
|
||||
echo "<th scope='row'><label>" . __('Content Restriction Redirect URL','ultimatemember') . "</label></th>";
|
||||
echo '<td>';
|
||||
echo '<input type="text" name="_um_redirect" id="_um_redirect" value="' . $_um_redirect . '" />';
|
||||
echo '<p class="description">' . __('Users who cannot see content will get redirected to that URL.','ultimatemember') . '</p>';
|
||||
echo "</td></tr>";
|
||||
|
||||
}
|
||||
|
||||
function um_category_access_fields_save( $termID ){
|
||||
|
||||
if ( isset( $_POST['_um_accessible'] ) ) {
|
||||
|
||||
// get options from database - if not a array create a new one
|
||||
$termMeta = get_option( "category_$termID" );
|
||||
if ( !is_array( $termMeta ))
|
||||
$termMeta = array();
|
||||
|
||||
// get value and save it into the database - maybe you have to sanitize your values (urls, etc...)
|
||||
$termMeta['_um_accessible'] = isset( $_POST['_um_accessible'] ) ? $_POST['_um_accessible'] : '';
|
||||
$termMeta['_um_redirect'] = isset( $_POST['_um_redirect'] ) ? $_POST['_um_redirect'] : '';
|
||||
$termMeta['_um_roles'] = isset( $_POST['_um_roles'] ) ? $_POST['_um_roles'] : '';
|
||||
|
||||
update_option( "category_$termID", $termMeta );
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
*** @Allow mass syncing for roles
|
||||
***/
|
||||
add_action('um_admin_do_action__mass_role_sync', 'um_admin_do_action__mass_role_sync');
|
||||
function um_admin_do_action__mass_role_sync( $action ){
|
||||
global $ultimatemember;
|
||||
if ( !is_admin() || !current_user_can( 'edit_user' ) ) die();
|
||||
|
||||
if ( !isset($_REQUEST['post']) || !is_numeric( $_REQUEST['post'] ) ) die();
|
||||
|
||||
$post_id = (int) $_REQUEST['post'];
|
||||
|
||||
$post = get_post( $post_id );
|
||||
$slug = $post->post_name;
|
||||
|
||||
if ( $slug != $_REQUEST['um_role'] )
|
||||
die();
|
||||
|
||||
if ( get_post_meta( $post_id, '_um_synced_role', true ) != $_REQUEST['wp_role'] )
|
||||
die();
|
||||
|
||||
if ( $slug == 'admin' ) {
|
||||
$_REQUEST['wp_role'] = 'administrator';
|
||||
update_post_meta( $post_id, '_um_synced_role', 'administrator' );
|
||||
}
|
||||
|
||||
$wp_role = ( $_REQUEST['wp_role'] ) ? $_REQUEST['wp_role'] : 'subscriber';
|
||||
|
||||
$users = get_users( array( 'fields' => array( 'ID' ), 'meta_key' => 'role', 'meta_value' => $slug ) );
|
||||
foreach( $users as $user_id ) {
|
||||
$wp_user_object = new WP_User( $user_id );
|
||||
$wp_user_object->set_role( $wp_role );
|
||||
}
|
||||
|
||||
exit( wp_redirect( admin_url( 'post.php?post=' . $post_id ) . '&action=edit&message=1' ) );
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*** @add option for WPML
|
||||
***/
|
||||
add_action('um_admin_before_access_settings', 'um_admin_wpml_post_options', 10, 1 );
|
||||
function um_admin_wpml_post_options( $instance ) {
|
||||
|
||||
if ( !function_exists('icl_get_current_language') )
|
||||
return;
|
||||
|
||||
?>
|
||||
|
||||
<h4><?php _e('This is a translation of UM profile page?','ultimatemember'); ?></h4>
|
||||
|
||||
<p>
|
||||
<span><?php $instance->ui_on_off( '_um_wpml_user', 0 ); ?></span>
|
||||
</p>
|
||||
|
||||
<h4><?php _e('This is a translation of UM account page?','ultimatemember'); ?></h4>
|
||||
|
||||
<p>
|
||||
<span><?php $instance->ui_on_off( '_um_wpml_account', 0 ); ?></span>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*** @when role is saved
|
||||
***/
|
||||
function um_admin_delete_role_cache($post_id, $post){
|
||||
global $ultimatemember;
|
||||
if(get_post_type( $post_id ) == 'um_role'){
|
||||
global $wpdb, $ultimatemember;
|
||||
if( get_post_type( $post_id ) == 'um_role') {
|
||||
$slug = $post->post_name;
|
||||
delete_option("um_cached_role_{$slug}");
|
||||
|
||||
$is_core = get_post_meta( $post_id, '_um_core', true );
|
||||
if ( $is_core == 'member' || $is_core == 'admin' ) {
|
||||
$slug = $is_core;
|
||||
$where = array( 'ID' => $post_id );
|
||||
$wpdb->update( $wpdb->posts, array( 'post_name' => $slug ), $where );
|
||||
}
|
||||
|
||||
delete_option("um_cached_role_{$slug}");
|
||||
|
||||
// need to remove cache of all users
|
||||
$users = get_users( array( 'fields' => array( 'ID' ), 'meta_key' => 'role', 'meta_value' => $slug ) );
|
||||
foreach( $users as $user ) {
|
||||
@@ -80,6 +249,44 @@
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*** @clear user cache
|
||||
***/
|
||||
add_action('um_admin_do_action__user_cache', 'um_admin_do_action__user_cache');
|
||||
function um_admin_do_action__user_cache( $action ){
|
||||
global $ultimatemember;
|
||||
if ( !is_admin() || !current_user_can('manage_options') ) die();
|
||||
|
||||
$all_options = wp_load_alloptions();
|
||||
foreach( $all_options as $k => $v ) {
|
||||
if ( strstr( $k, 'um_cache_userdata_' ) ) {
|
||||
delete_option( $k );
|
||||
}
|
||||
}
|
||||
|
||||
$url = admin_url('admin.php?page=ultimatemember');
|
||||
$url = add_query_arg('update','cleared_cache',$url);
|
||||
exit( wp_redirect($url) );
|
||||
}
|
||||
|
||||
/***
|
||||
*** @secure passwords
|
||||
***/
|
||||
add_action('um_admin_do_action__um_passwords_secured', 'um_admin_do_action__um_passwords_secured');
|
||||
function um_admin_do_action__um_passwords_secured( $action ){
|
||||
global $ultimatemember;
|
||||
if ( !is_admin() || !current_user_can('manage_options') ) die();
|
||||
|
||||
$users = get_users();
|
||||
foreach( $users as $user ) {
|
||||
delete_user_meta( $user->ID, 'confirm_user_password' );
|
||||
update_user_meta( $user->ID, 'submitted', '' );
|
||||
}
|
||||
|
||||
update_option( 'um_passwords_secured', 1 );
|
||||
exit( wp_redirect( admin_url() ) );
|
||||
}
|
||||
|
||||
/***
|
||||
*** @purge temp
|
||||
***/
|
||||
|
||||
Reference in New Issue
Block a user