*/ do_action( 'um_roles_add_meta_boxes', 'um_role_meta' ); /** * UM hook * * @type action * @title um_roles_add_meta_boxes_um_role_meta * @description Make add meta boxes on add/edit UM Role * @change_log * ["Since: 2.0"] * @usage add_action( 'um_roles_add_meta_boxes_um_role_meta', 'function_name', 10 ); * @example * */ do_action( 'um_roles_add_meta_boxes_um_role_meta' ); $data = array(); $option = array(); global $wp_roles; if ( ! empty( $_GET['id'] ) ) { $data = get_option( "um_role_{$_GET['id']}_meta" ); if ( empty( $data['_um_is_custom'] ) ) $data['name'] = $wp_roles->roles[ $_GET['id'] ]['name']; } if ( ! empty( $_POST['role'] ) ) { $data = $_POST['role']; $id = ''; $redirect = ''; $error = ''; if ( empty( $data['name'] ) ) { $error .= __( 'Title is empty!', 'ultimate-member' ) . '
'; } else { if ( 'add' == $_GET['tab'] ) { if ( preg_match( "/[a-z0-9]+$/i", $data['name'] ) ) { $id = sanitize_title( $data['name'] ); } else { $auto_increment = UM()->options()->get( 'custom_roles_increment' ); $auto_increment = ! empty( $auto_increment ) ? $auto_increment : 1; $id = 'custom_role_' . $auto_increment; } $redirect = add_query_arg( array( 'page'=>'um_roles', 'tab'=>'edit', 'id'=>$id, 'msg'=>'a' ), admin_url( 'admin.php' ) ); } elseif ( 'edit' == $_GET['tab'] && ! empty( $_GET['id'] ) ) { $id = $_GET['id']; $redirect = add_query_arg( array( 'page' => 'um_roles', 'tab'=>'edit', 'id'=>$id, 'msg'=>'u' ), admin_url( 'admin.php' ) ); } } $all_roles = array_keys( get_editable_roles() ); if ( 'add' == $_GET['tab'] ) { if ( in_array( 'um_' . $id, $all_roles ) || in_array( $id, $all_roles ) ) $error .= __( 'Role already exists!', 'ultimate-member' ) . '
'; } if ( '' == $error ) { if ( 'add' == $_GET['tab'] ) { $roles = get_option( 'um_roles' ); $roles[] = $id; update_option( 'um_roles', $roles ); if ( isset( $auto_increment ) ) { $auto_increment++; UM()->options()->update( 'custom_roles_increment', $auto_increment ); } } $role_meta = $data; unset( $role_meta['id'] ); update_option( "um_role_{$id}_meta", $role_meta ); UM()->user()->remove_cache_all_users(); um_js_redirect( $redirect ); } } global $current_screen; $screen_id = $current_screen->id; ?>

' . __( 'User Role Added Successfully.', 'ultimate-member' ) . '

'; break; case 'u': echo '

' . __( 'User Role Updated Successfully.', 'ultimate-member' ) . '

'; break; } } if ( ! empty( $error ) ) { ?>

$data, 'option' => $option ) ); ?>
$data, 'option' => $option ) ); ?>