!!! IMPORTANT 2.0 version before upgrade please run full backup of your site !!!

- new code structure, optimized for next development;
  - created spl_autoloader for remove includes;
  - UM classes with namespaces;
  - deprecated global $ultimatemember; variable (use UM() instead);
- new UM/WP roles logic;
- new settings class and logic (deprecated Redux framework, deprecated some old options, added some new options);
- new dependencies class for extensions;
- WP native styles for backend fields;
- new upgrades and license activations for extensions;
- new logic form backend forms and fields;
- created uninstall.php file for delete permanently all UM settings;
- optimized registration/upgrade profile process;

Deprecated Hooks:

um_new_user_registration_plain
um_user_registration_extra_hook
um_add_user_frontend
um_post_registration_global_hook
um_admin_extend_directory_options_general (was action...will be filter)
This commit is contained in:
nikitozzzzzzz
2017-07-26 14:57:52 +03:00
parent 6b85436a12
commit 9e53314c3a
635 changed files with 30753 additions and 83847 deletions
+681
View File
@@ -0,0 +1,681 @@
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Builder' ) ) {
class Admin_Builder {
var $form_id;
function __construct() {
}
/***
*** @update the builder area
***/
function update_builder() {
if ( !is_user_logged_in() || !current_user_can('manage_options') ) die('Please login as administrator');
extract($_POST);
ob_start();
$this->form_id = $_POST['form_id'];
$this->show_builder();
$output = ob_get_contents();
ob_end_clean();
if(is_array($output)){ print_r($output); }else{ echo $output; } die;
}
/***
*** @sort array function
***/
function array_sort_by_column( $arr, $col, $dir = SORT_ASC ) {
$sort_col = array();
foreach ( $arr as $key => $row ) {
if ( ! empty( $row[$col] ) )
$sort_col[$key] = $row[$col];
}
if ( ! empty( $sort_col ) )
array_multisort( $sort_col, $dir, $arr );
return $arr;
}
/***
*** @get fields in row
***/
function get_fields_by_row( $row_id ) {
if( empty( $this->global_fields) || ! is_array( $this->global_fields ) ){
$this->global_fields = array();
}
foreach( $this->global_fields as $key => $array ) {
if ( !isset( $array['in_row'] ) || ( isset( $array['in_row'] ) && $array['in_row'] == $row_id ) ) {
$results[$key] = $array;
unset( $this->global_fields[$key] );
}
}
return ( isset ( $results ) ) ? $results : '';
}
/***
*** @get fields by sub row
***/
function get_fields_in_subrow( $row_fields, $subrow_id ) {
if ( !is_array( $row_fields ) ) return '';
foreach( $row_fields as $key => $array ) {
if ( !isset( $array['in_sub_row'] ) || ( isset( $array['in_sub_row'] ) && $array['in_sub_row'] == $subrow_id ) ) {
$results[$key] = $array;
unset( $this->global_fields[$key] );
}
}
return ( isset ( $results ) ) ? $results : '';
}
/***
*** @Display the builder
***/
function show_builder() {
$fields = UM()->query()->get_attr( 'custom_fields', $this->form_id );
if ( !isset( $fields ) || empty( $fields ) ) { ?>
<div class="um-admin-drag-row">
<!-- Master Row Actions -->
<div class="um-admin-drag-row-icons">
<a href="#" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php _e('Add Row','ultimate-member'); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a>
<a href="#" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php _e('Edit Row','ultimate-member'); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo $this->form_id; ?>" data-arg3="_um_row_1"><i class="um-faicon-pencil"></i></a>
<span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span>
</div><div class="um-admin-clear"></div>
<div class="um-admin-drag-rowsubs">
<div class="um-admin-drag-rowsub">
<!-- Column Layout -->
<div class="um-admin-drag-ctrls columns">
<a href="#" class="active" data-cols="1"></a>
<a href="#" data-cols="2"></a>
<a href="#" data-cols="3"></a>
</div>
<!-- Sub Row Actions -->
<div class="um-admin-drag-rowsub-icons">
<span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span>
</div><div class="um-admin-clear"></div>
<!-- Columns -->
<div class="um-admin-drag-col">
</div>
<div class="um-admin-drag-col-dynamic"></div>
<div class="um-admin-clear"></div>
</div>
</div>
</div>
<?php
} else {
if( empty( $fields) || ! is_array( $fields ) ){
$this->global_fields = array();
}else{
$this->global_fields = $fields;
}
foreach( $this->global_fields as $key => $array ) {
if ( $array['type'] == 'row' ) {
$rows[$key] = $array;
unset( $this->global_fields[ $key ] ); // not needed now
}
}
if ( !isset( $rows ) ){
$rows = array( '_um_row_1' => array(
'type' => 'row',
'id' => '_um_row_1',
'sub_rows' => 1,
'cols' => 1
)
);
}
foreach ( $rows as $row_id => $array ) {
?>
<div class="um-admin-drag-row" data-original="<?php echo $row_id; ?>">
<!-- Master Row Actions -->
<div class="um-admin-drag-row-icons">
<a href="#" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php _e('Add Row','ultimate-member'); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a>
<a href="#" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php _e('Edit Row','ultimate-member'); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo $this->form_id; ?>" data-arg3="<?php echo $row_id; ?>"><i class="um-faicon-pencil"></i></a>
<span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span>
<?php if ( $row_id != '_um_row_1' ) {?>
<a href="#" class="um-admin-tipsy-n" title="<?php _e('Delete Row','ultimate-member'); ?>" data-remove_element="um-admin-drag-row"><i class="um-faicon-trash-o"></i></a>
<?php } ?>
</div><div class="um-admin-clear"></div>
<div class="um-admin-drag-rowsubs">
<?php
$row_fields = $this->get_fields_by_row( $row_id );
$sub_rows = ( isset( $array['sub_rows'] ) ) ? $array['sub_rows'] : 1;
for( $c = 0; $c < $sub_rows; $c++ ) {
$subrow_fields = $this->get_fields_in_subrow( $row_fields, $c );
?>
<div class="um-admin-drag-rowsub">
<!-- Column Layout -->
<div class="um-admin-drag-ctrls columns">
<?php
if ( !isset( $array['cols'] ) ){
$col_num = 1;
} else {
$col_split = explode(':', $array['cols'] );
$col_num = $col_split[$c];
}
for ( $i = 1; $i <= 3; $i++ ) {
echo '<a href="#" data-cols="'.$i.'" ';
if ( $col_num == $i ) echo 'class="active"';
echo '></a>';
}
?>
</div>
<!-- Sub Row Actions -->
<div class="um-admin-drag-rowsub-icons">
<span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span>
<?php if ( $c > 0 ) { ?><a href="#" class="um-admin-tipsy-n" title="Delete Row" data-remove_element="um-admin-drag-rowsub"><i class="um-faicon-trash-o"></i></a><?php } ?>
</div><div class="um-admin-clear"></div>
<!-- Columns -->
<div class="um-admin-drag-col">
<?php
if ( is_array( $subrow_fields ) ) {
$subrow_fields = $this->array_sort_by_column( $subrow_fields, 'position');
foreach( $subrow_fields as $key => $keyarray ) {
extract( $keyarray );
?>
<div class="um-admin-drag-fld um-admin-delete-area um-field-type-<?php echo $type; ?> <?php echo $key; ?>" data-group="<?php echo (isset($keyarray['in_group'])) ? $keyarray['in_group'] : ''; ?>" data-key="<?php echo $key; ?>" data-column="<?php echo ( isset($keyarray['in_column']) ) ? $keyarray['in_column'] : 1; ?>">
<div class="um-admin-drag-fld-title um-field-type-<?php echo $type; ?>">
<?php if ( $type == 'group' ) { ?>
<i class="um-icon-plus"></i>
<?php } else if ( isset($keyarray['icon']) && !empty( $keyarray['icon'] ) ) { ?>
<i class="<?php echo $keyarray['icon']; ?>"></i>
<?php } ?><?php echo $title; ?></div>
<?php $field_name = isset( UM()->builtin()->core_fields[$type]['name'] ) ? UM()->builtin()->core_fields[$type]['name'] : ''; ?>
<div class="um-admin-drag-fld-type um-field-type-<?php echo $type; ?>"><?php echo $field_name; ?></div>
<div class="um-admin-drag-fld-icons um-field-type-<?php echo $type; ?>">
<a href="#" class="um-admin-tipsy-n" title="Edit" data-modal="UM_edit_field" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="<?php echo $type; ?>" data-arg2="<?php echo $this->form_id; ?>" data-arg3="<?php echo $key; ?>"><i class="um-faicon-pencil"></i></a>
<a href="#" class="um-admin-tipsy-n um_admin_duplicate_field" title="Duplicate" data-silent_action="um_admin_duplicate_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-files-o"></i></a>
<?php if ( $type == 'group' ) { ?>
<a href="#" class="um-admin-tipsy-n" title="Delete Group" data-remove_element="um-admin-drag-fld.um-field-type-group" data-silent_action="um_admin_remove_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-trash-o"></i></a>
<?php } else { ?>
<a href="#" class="um-admin-tipsy-n" title="Delete" data-silent_action="um_admin_remove_field" data-arg1="<?php echo $key; ?>" data-arg2="<?php echo $this->form_id; ?>"><i class="um-faicon-trash-o"></i></a>
<?php } ?>
</div><div class="um-admin-clear"></div>
<?php if ( $type == 'group' ) { ?>
<div class="um-admin-drag-group">
</div>
<?php } ?>
</div>
<?php
} // end foreach
} // end if
?>
</div>
<div class="um-admin-drag-col-dynamic"></div>
<div class="um-admin-clear"></div>
</div>
<?php } ?>
</div>
</div>
<?php
} // rows loop
} // if fields exist
}
function update_field() {
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) )
die( __('Please login as administrator','ultimate-member') );
$output['error'] = null;
$array = array(
'field_type' => $_POST['_type'],
'form_id' => $_POST['post_id'],
'args' => UM()->builtin()->get_core_field_attrs( $_POST['_type'] ),
'post' => $_POST
);
$array = apply_filters("um_admin_pre_save_fields_hook", $array );
$output['error'] = apply_filters( 'um_admin_field_update_error_handling', $output['error'], $array );
extract( $array['post'] );
if ( empty( $output['error'] ) ){
$save = array();
$save[ $_metakey ] = null;
foreach( $array['post'] as $key => $val){
if ( substr( $key, 0, 1) === '_' && $val != '' ) { // field attribute
$new_key = ltrim ($key,'_');
if ( $new_key == 'options' ) {
//$save[ $_metakey ][$new_key] = explode(PHP_EOL, $val);
$save[ $_metakey ][$new_key] = preg_split('/[\r\n]+/', $val, -1, PREG_SPLIT_NO_EMPTY);
} else {
$save[ $_metakey ][$new_key] = $val;
}
} else if ( strstr( $key, 'um_editor' ) ) {
$save[ $_metakey ]['content'] = $val;
}
}
$field_ID = $_metakey;
$field_args = $save[ $_metakey ];
$field_args = apply_filters("um_admin_pre_save_field_to_form", $field_args );
UM()->fields()->update_field( $field_ID, $field_args, $post_id );
$field_args = apply_filters("um_admin_pre_save_field_to_db", $field_args );
if ( ! isset( $array['args']['form_only'] ) ) {
if ( ! isset( UM()->builtin()->predefined_fields[ $field_ID ] ) ) {
UM()->fields()->globally_update_field( $field_ID, $field_args );
}
}
}
$output = json_encode( $output );
if ( is_array( $output ) ) {
print_r( $output );
} else {
echo $output;
}
die;
}
function dynamic_modal_content() {
$metabox = UM()->metabox();
if ( !is_user_logged_in() || !current_user_can('manage_options') ) die( __('Please login as administrator','ultimate-member') );
extract($_POST);
switch ( $act_id ) {
default:
ob_start();
do_action('um_admin_ajax_modal_content__hook', $act_id );
do_action("um_admin_ajax_modal_content__hook_{$act_id}");
$output = ob_get_contents();
ob_end_clean();
break;
case 'um_admin_fonticon_selector':
ob_start();
?>
<div class="um-admin-metabox">
<p class="_icon_search"><input type="text" name="_icon_search" id="_icon_search" value="" placeholder="<?php _e('Search Icons...','ultimate-member'); ?>" /></p>
</div>
<div class="um-admin-icons">
<?php foreach( UM()->fonticons()->all as $icon ) { ?>
<span data-code="<?php echo $icon; ?>" title="<?php echo $icon; ?>" class="um-admin-tipsy-n"><i class="<?php echo $icon; ?>"></i></span>
<?php } ?>
</div><div class="um-admin-clear"></div>
<?php
$output = ob_get_contents();
ob_end_clean();
break;
case 'um_admin_show_fields':
ob_start();
$form_fields = UM()->query()->get_attr( 'custom_fields', $arg2 );
$form_fields = array_values( array_filter( array_keys( $form_fields ) ) );
//$form_fields = array_keys( $form_fields );
?>
<h4><?php _e('Setup New Field','ultimate-member'); ?></h4>
<div class="um-admin-btns">
<?php
if ( UM()->builtin()->core_fields ) {
foreach ( UM()->builtin()->core_fields as $field_type => $array ) {
if ( isset( $array['in_fields'] ) && $array['in_fields'] == false ) { } else {
?>
<a href="#" class="button" data-modal="UM_add_field" data-modal-size="normal" data-dynamic-content="um_admin_new_field_popup" data-arg1="<?php echo $field_type; ?>" data-arg2="<?php echo $arg2 ?>"><?php echo $array['name']; ?></a>
<?php } } } ?>
</div>
<h4><?php _e('Predefined Fields','ultimate-member'); ?></h4>
<div class="um-admin-btns">
<?php
if ( UM()->builtin()->predefined_fields ) {
foreach ( UM()->builtin()->predefined_fields as $field_key => $array ) {
if ( !isset( $array['account_only'] ) && !isset( $array['private_use'] ) ) {?>
<a href="#" class="button" <?php disabled( in_array( $field_key, $form_fields, true ) ) ?> data-silent_action="um_admin_add_field_from_predefined" data-arg1="<?php echo $field_key; ?>" data-arg2="<?php echo $arg2; ?>"><?php echo um_trim_string( stripslashes( $array['title'] ), 20 ); ?></a>
<?php } } } else { echo '<p>' . __('None','ultimate-member') . '</p>'; } ?>
</div>
<h4><?php _e('Custom Fields','ultimate-member'); ?></h4>
<div class="um-admin-btns">
<?php
if ( UM()->builtin()->custom_fields ) {
foreach ( UM()->builtin()->custom_fields as $field_key => $array ) {
?>
<a href="#" class="button with-icon" <?php disabled( in_array( $field_key, $form_fields, true ) ) ?> data-silent_action="um_admin_add_field_from_list" data-arg1="<?php echo $field_key; ?>" data-arg2="<?php echo $arg2; ?>"><?php echo um_trim_string( stripslashes( $array['title'] ), 20 ); ?> <small>(<?php echo ucfirst( $array['type']); ?>)</small><span class="remove"></span></a>
<?php } } else { echo '<p>' . __('You did not create any custom fields', 'ultimate-member') . '</p>'; } ?>
</div>
<?php
$output = ob_get_contents();
ob_end_clean();
break;
case 'um_admin_edit_field_popup':
ob_start();
$args = UM()->builtin()->get_core_field_attrs( $arg1 );
$form_fields = UM()->query()->get_attr( 'custom_fields', $arg2 );
$metabox->set_field_type = $arg1;
$metabox->in_edit = true;
$metabox->edit_array = $form_fields[ $arg3 ];
if ( !isset( $metabox->edit_array['metakey'] ) ){
$metabox->edit_array['metakey'] = $metabox->edit_array['id'];
}
if ( !isset( $metabox->edit_array['position'] ) ){
$metabox->edit_array['position'] = $metabox->edit_array['id'];
}
extract( $args );
if ( !isset( $col1 ) ) {
echo '<p>'. __('This field type is not setup correcty.', 'ultimate-member') . '</p>';
} else {
?>
<?php if ( isset( $metabox->edit_array['in_group'] ) ) { ?>
<input type="hidden" name="_in_row" id="_in_row" value="<?php echo $metabox->edit_array['in_row']; ?>" />
<input type="hidden" name="_in_sub_row" id="_in_sub_row" value="<?php echo $metabox->edit_array['in_sub_row']; ?>" />
<input type="hidden" name="_in_column" id="_in_column" value="<?php echo $metabox->edit_array['in_column']; ?>" />
<input type="hidden" name="_in_group" id="_in_group" value="<?php echo $metabox->edit_array['in_group']; ?>" />
<?php } ?>
<input type="hidden" name="_type" id="_type" value="<?php echo $arg1; ?>" />
<input type="hidden" name="post_id" id="post_id" value="<?php echo $arg2; ?>" />
<input type="hidden" name="edit_mode" id="edit_mode" value="true" />
<input type="hidden" name="_metakey" id="_metakey" value="<?php echo $metabox->edit_array['metakey']; ?>" />
<input type="hidden" name="_position" id="_position" value="<?php echo $metabox->edit_array['position']; ?>" />
<?php if ( isset( $args['mce_content'] ) ) { ?><div class="dynamic-mce-content"><?php echo $metabox->edit_array['content']; ?></div><?php } ?>
<?php do_action('um_admin_field_modal_header'); ?>
<div class="um-admin-half">
<?php if ( isset( $col1 ) ) { foreach( $col1 as $opt ) $metabox->field_input ( $opt, null, $metabox->edit_array ); } ?>
</div>
<div class="um-admin-half um-admin-right">
<?php if ( isset( $col2 ) ) { foreach( $col2 as $opt ) $metabox->field_input ( $opt, null, $metabox->edit_array ); } ?>
</div><div class="um-admin-clear"></div>
<?php if ( isset( $col3 ) ) { foreach( $col3 as $opt ) $metabox->field_input ( $opt, null, $metabox->edit_array ); } ?>
<div class="um-admin-clear"></div>
<?php if ( isset( $col_full ) ) {foreach( $col_full as $opt ) $metabox->field_input ( $opt, null, $metabox->edit_array ); } ?>
<?php do_action('um_admin_field_modal_footer', $arg2, $args, $metabox->in_edit, (isset( $metabox->edit_array ) ) ? $metabox->edit_array : '' ); ?>
<?php
}
$output = ob_get_contents();
ob_end_clean();
break;
case 'um_admin_new_field_popup':
ob_start();
$args = UM()->builtin()->get_core_field_attrs( $arg1 );
$metabox->set_field_type = $arg1;
extract( $args );
if ( !isset( $col1 ) ) {
echo '<p>'. __('This field type is not setup correcty.', 'ultimate-member') . '</p>';
} else {
?>
<?php if ( $in_column ) { ?>
<input type="hidden" name="_in_row" id="_in_row" value="_um_row_<?php echo $in_row + 1; ?>" />
<input type="hidden" name="_in_sub_row" id="_in_sub_row" value="<?php echo $in_sub_row; ?>" />
<input type="hidden" name="_in_column" id="_in_column" value="<?php echo $in_column; ?>" />
<input type="hidden" name="_in_group" id="_in_group" value="<?php echo $in_group; ?>" />
<?php } ?>
<input type="hidden" name="_type" id="_type" value="<?php echo $arg1; ?>" />
<input type="hidden" name="post_id" id="post_id" value="<?php echo $arg2; ?>" />
<?php do_action('um_admin_field_modal_header'); ?>
<div class="um-admin-half">
<?php if ( isset( $col1 ) ) { foreach( $col1 as $opt ) $metabox->field_input ( $opt ); } ?>
</div>
<div class="um-admin-half um-admin-right">
<?php if ( isset( $col2 ) ) { foreach( $col2 as $opt ) $metabox->field_input ( $opt ); } ?>
</div><div class="um-admin-clear"></div>
<?php if ( isset( $col3 ) ) { foreach( $col3 as $opt ) $metabox->field_input ( $opt ); } ?>
<div class="um-admin-clear"></div>
<?php if ( isset( $col_full ) ) {foreach( $col_full as $opt ) $metabox->field_input ( $opt ); } ?>
<?php do_action('um_admin_field_modal_footer', $arg2, $args, $metabox->in_edit, (isset( $metabox->edit_array ) ) ? $metabox->edit_array : '' ); ?>
<?php
}
$output = ob_get_contents();
ob_end_clean();
break;
case 'um_admin_preview_form':
$mode = UM()->query()->get_attr('mode', $arg1 );
if ( $mode == 'profile' ) {
UM()->fields()->editing = true;
}
$output = do_shortcode('[ultimatemember form_id='.$arg1.']');
break;
case 'um_admin_review_registration':
//$user_id = $arg1;
um_fetch_user( $arg1 );
UM()->user()->preview = true;
$output = um_user_submitted_registration( true );
um_reset_user();
break;
}
if ( is_array( $output ) ) {
print_r( $output );
} else {
echo $output;
}
die;
}
/**
* Retrieves dropdown/multi-select options from a callback function
*/
function populate_dropdown_options(){
$arr_options = array();
if( ! current_user_can('manage_options') ){
wp_die( __( 'This is not possible for security reasons.','ultimate-member') );
}
$um_callback_func = $_POST['um_option_callback'];
if( empty( $um_callback_func ) ){
$arr_options['status'] = 'empty';
$arr_options['function_name'] = $um_callback_func;
$arr_options['function_exists'] = function_exists( $um_callback_func );
}
$arr_options['data'] = array();
if( function_exists( $um_callback_func ) ){
$arr_options['data'] = call_user_func( $um_callback_func );
}
wp_send_json( $arr_options );
}
}
}
+121
View File
@@ -0,0 +1,121 @@
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Columns' ) ) {
class Admin_Columns {
function __construct() {
$this->slug = 'ultimatemember';
add_filter('manage_edit-um_form_columns', array(&$this, 'manage_edit_um_form_columns') );
add_action('manage_um_form_posts_custom_column', array(&$this, 'manage_um_form_posts_custom_column'), 10, 3);
add_filter('manage_edit-um_directory_columns', array(&$this, 'manage_edit_um_directory_columns') );
add_action('manage_um_directory_posts_custom_column', array(&$this, 'manage_um_directory_posts_custom_column'), 10, 3);
add_filter('post_row_actions', array(&$this, 'post_row_actions'), 99, 2);
}
/***
*** @custom row actions
***/
function post_row_actions( $actions, $post ) {
//check for your post type
if ( $post->post_type == "um_form" ) {
$actions['um_duplicate'] = '<a href="' . $this->duplicate_uri( $post->ID ) . '">' . __('Duplicate','ultimate-member') . '</a>';
}
return $actions;
}
/***
*** @duplicate a form
***/
function duplicate_uri( $id ) {
$url = add_query_arg('um_adm_action', 'duplicate_form', admin_url('edit.php?post_type=um_form') );
$url = add_query_arg('post_id', $id, $url);
return $url;
}
/***
*** @Custom columns for Form
***/
function manage_edit_um_form_columns( $columns ) {
$new_columns['cb'] = '<input type="checkbox" />';
$new_columns['title'] = __( 'Title', 'ulitmatemember' );
$new_columns['id'] = __('ID', 'ulitmatemember' );
$new_columns['mode'] = __( 'Type', 'ulitmatemember' );
$new_columns['shortcode'] = __( 'Shortcode', 'ulitmatemember' );
$new_columns['date'] = __( 'Date', 'ulitmatemember' );
return $new_columns;
}
/***
*** @Custom columns for Directory
***/
function manage_edit_um_directory_columns( $columns ) {
$new_columns['cb'] = '<input type="checkbox" />';
$new_columns['title'] = __( 'Title', 'ultimate-member' );
$new_columns['id'] = __( 'ID', 'ultimate-member' );
$new_columns['shortcode'] = __( 'Shortcode', 'ultimate-member' );
$new_columns['date'] = __( 'Date', 'ultimate-member' );
return $new_columns;
}
/***
*** @Display cusom columns for Form
***/
function manage_um_form_posts_custom_column( $column_name, $id ) {
switch ( $column_name ) {
case 'id':
echo '<span class="um-admin-number">'.$id.'</span>';
break;
case 'shortcode':
echo UM()->shortcodes()->get_shortcode( $id );
break;
case 'mode':
$mode = UM()->query()->get_attr( 'mode', $id );
echo UM()->form()->display_form_type( $mode, $id );
break;
}
}
/***
*** @Display cusom columns for Directory
***/
function manage_um_directory_posts_custom_column($column_name, $id) {
global $wpdb;
switch ($column_name) {
case 'id':
echo '<span class="um-admin-number">'.$id.'</span>';
break;
case 'shortcode':
echo UM()->shortcodes()->get_shortcode( $id );
break;
}
}
}
}
@@ -0,0 +1,216 @@
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_DragDrop' ) ) {
class Admin_DragDrop {
function __construct() {
add_action( 'admin_footer', array( &$this, 'load_field_order' ), 9 );
}
/***
*** @update order of fields
***/
function update_order() {
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) )
die( 'Please login as administrator' );
extract( $_POST );
$fields = UM()->query()->get_attr( 'custom_fields', $form_id );
$this->row_data = get_option( 'um_form_rowdata_' . $form_id, array() );
$this->exist_rows = array();
if ( ! empty( $fields ) ) {
foreach ( $fields as $key => $array ) {
if ( $array['type'] == 'row' ) {
$this->row_data[$key] = $array;
unset( $fields[$key] );
}
}
} else {
$fields = array();
}
foreach ( $_POST as $key => $value ) {
// adding rows
if ( 0 === strpos( $key, '_um_row_' ) ) {
$update_args = null;
$row_id = str_replace( '_um_row_', '', $key );
$row_array = array(
'type' => 'row',
'id' => $value,
'sub_rows' => $_POST[ '_um_rowsub_'.$row_id .'_rows' ],
'cols' => $_POST[ '_um_rowcols_'.$row_id .'_cols' ],
'origin' => $_POST[ '_um_roworigin_'.$row_id . '_val' ],
);
$row_args = $row_array;
if ( isset( $this->row_data[ $row_array['origin'] ] ) ) {
foreach( $this->row_data[ $row_array['origin'] ] as $k => $v ){
if ( $k != 'position' && $k != 'metakey' ) {
$update_args[$k] = $v;
}
}
if ( isset( $update_args ) ) {
$row_args = array_merge( $update_args, $row_array );
}
$this->exist_rows[] = $key;
}
$fields[$key] = $row_args;
}
// change field position
if ( 0 === strpos( $key, 'um_position_' ) ) {
$field_key = str_replace('um_position_','',$key);
if ( isset( $fields[$field_key] ) ) {
$fields[$field_key]['position'] = $value;
}
}
// change field master row
if ( 0 === strpos( $key, 'um_row_' ) ) {
$field_key = str_replace('um_row_','',$key);
if ( isset( $fields[$field_key] ) ) {
$fields[$field_key]['in_row'] = $value;
}
}
// change field sub row
if ( 0 === strpos( $key, 'um_subrow_' ) ) {
$field_key = str_replace('um_subrow_','',$key);
if ( isset( $fields[$field_key] ) ) {
$fields[$field_key]['in_sub_row'] = $value;
}
}
// change field column
if ( 0 === strpos( $key, 'um_col_' ) ) {
$field_key = str_replace('um_col_','',$key);
if ( isset( $fields[$field_key] ) ) {
$fields[$field_key]['in_column'] = $value;
}
}
// add field to group
if ( 0 === strpos( $key, 'um_group_' ) ) {
$field_key = str_replace('um_group_','',$key);
if ( isset( $fields[$field_key] ) ) {
$fields[$field_key]['in_group'] = $value;
}
}
}
foreach ( $this->row_data as $k => $v ) {
if ( ! in_array( $k, $this->exist_rows ) )
unset( $this->row_data[$k] );
}
update_option( 'um_existing_rows_' . $form_id, $this->exist_rows );
update_option( 'um_form_rowdata_' . $form_id , $this->row_data );
UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
}
/***
*** @load form to maintain form order
***/
function load_field_order() {
$screen = get_current_screen();
if ( ! isset( $screen->id ) || $screen->id != 'um_form' ) return;
?>
<div class="um-col-demon-settings" data-in_row="" data-in_sub_row="" data-in_column="" data-in_group=""></div>
<div class="um-col-demon-row" style="display:none;">
<div class="um-admin-drag-row-icons">
<a href="#" class="um-admin-drag-rowsub-add um-admin-tipsy-n" title="<?php _e('Add Row','ultimate-member'); ?>" data-row_action="add_subrow"><i class="um-icon-plus"></i></a>
<a href="#" class="um-admin-drag-row-edit um-admin-tipsy-n" title="<?php _e('Edit Row','ultimate-member'); ?>" data-modal="UM_edit_row" data-modal-size="normal" data-dynamic-content="um_admin_edit_field_popup" data-arg1="row" data-arg2="<?php echo get_the_ID(); ?>"><i class="um-faicon-pencil"></i></a>
<span class="um-admin-drag-row-start"><i class="um-icon-arrow-move"></i></span>
<a href="#" class="um-admin-tipsy-n" title="<?php _e('Delete Row','ultimate-member'); ?>" data-remove_element="um-admin-drag-row"><i class="um-faicon-trash-o"></i></a>
</div><div class="um-admin-clear"></div>
<div class="um-admin-drag-rowsubs">
<div class="um-admin-drag-rowsub">
<div class="um-admin-drag-ctrls columns">
<a href="#" class="active" data-cols="1"></a>
<a href="#" data-cols="2"></a>
<a href="#" data-cols="3"></a>
</div>
<div class="um-admin-drag-rowsub-icons">
<span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span>
<a href="#" class="um-admin-tipsy-n" title="<?php _e('Delete Row','ultimate-member'); ?>" data-remove_element="um-admin-drag-rowsub"><i class="um-faicon-trash-o"></i></a>
</div><div class="um-admin-clear"></div>
<div class="um-admin-drag-col">
</div>
<div class="um-admin-drag-col-dynamic"></div>
<div class="um-admin-clear"></div>
</div>
</div>
</div>
<div class="um-col-demon-subrow" style="display:none;">
<div class="um-admin-drag-ctrls columns">
<a href="#" class="active" data-cols="1"></a>
<a href="#" data-cols="2"></a>
<a href="#" data-cols="3"></a>
</div>
<div class="um-admin-drag-rowsub-icons">
<span class="um-admin-drag-rowsub-start"><i class="um-icon-arrow-move"></i></span>
<a href="#" class="um-admin-tipsy-n" title="<?php _e('Delete Row','ultimate-member'); ?>" data-remove_element="um-admin-drag-rowsub"><i class="um-faicon-trash-o"></i></a>
</div><div class="um-admin-clear"></div>
<div class="um-admin-drag-col">
</div>
<div class="um-admin-drag-col-dynamic"></div>
<div class="um-admin-clear"></div>
</div>
<form action="" method="post" class="um_update_order">
<input type="hidden" name="form_id" id="form_id" value="<?php echo get_the_ID(); ?>" />
<div class="um_update_order_fields">
</div>
</form>
<?php
}
}
}
+390
View File
@@ -0,0 +1,390 @@
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Enqueue' ) ) {
class Admin_Enqueue {
var $js_url;
var $css_url;
function __construct() {
$this->slug = 'ultimatemember';
$this->js_url = um_url . 'includes/admin/assets/js/';
$this->css_url = um_url . 'includes/admin/assets/css/';
add_action('admin_head', array(&$this, 'admin_head'), 9);
add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts') );
add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ), 999 );
add_filter('enter_title_here', array(&$this, 'enter_title_here') );
add_action( 'load-user-new.php', array( &$this, 'enqueue_role_wrapper' ) );
add_action( 'load-user-edit.php', array( &$this, 'enqueue_role_wrapper' ) );
}
function enqueue_role_wrapper() {
add_action( 'admin_enqueue_scripts', array( &$this, 'load_role_wrapper' ) );
}
/**
* Load js for Add/Edit User form
*/
function load_role_wrapper() {
wp_register_script( 'um_admin_role_wrapper', $this->js_url . 'um-admin-role-wrapper.js', '', '', true );
wp_enqueue_script( 'um_admin_role_wrapper' );
$localize_data = get_option( 'um_roles' );
wp_localize_script( 'um_admin_settings', 'um_roles', $localize_data );
}
/***
*** @enter title placeholder
***/
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() ){
?>
<style type="text/css">
.um-admin.post-type-<?php echo get_post_type(); ?> div#slugdiv,
.um-admin.post-type-<?php echo get_post_type(); ?> div#minor-publishing,
.um-admin.post-type-<?php echo get_post_type(); ?> div#screen-meta-links
{display:none}
</style>
<?php
}
}
/***
*** @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
***/
function load_form() {
wp_register_style( 'um_admin_form', $this->css_url . 'um-admin-form.css' );
wp_enqueue_style( 'um_admin_form' );
wp_register_script( 'um_admin_form', $this->js_url . 'um-admin-form.js', '', '', true );
wp_enqueue_script( 'um_admin_form' );
}
/***
*** @Load Form
***/
function load_forms() {
wp_register_style( 'um_admin_forms', $this->css_url . 'um-admin-forms.css' );
wp_enqueue_style( 'um_admin_forms' );
wp_register_script( 'um_admin_forms', $this->js_url . 'um-admin-forms.js', '', '', true );
wp_enqueue_script( 'um_admin_forms' );
$localize_data = array(
'texts' => array(
'remove' => __( 'Remove', 'ultimate-member' ),
'select' => __( 'Select', 'ultimate-member' )
)
);
wp_localize_script( 'um_admin_forms', 'php_data', $localize_data );
}
/***
*** @Load dashboard
***/
function load_dashboard() {
wp_register_style( 'um_admin_dashboard', $this->css_url . 'um-admin-dashboard.css' );
wp_enqueue_style( 'um_admin_dashboard' );
wp_register_script( 'um_admin_dashboard', $this->js_url . 'um-admin-dashboard.js', '', '', true );
wp_enqueue_script( 'um_admin_dashboard' );
}
/***
*** @Load settings
***/
function load_settings() {
wp_register_style( 'um_admin_settings', $this->css_url . 'um-admin-settings.css' );
wp_enqueue_style( 'um_admin_settings' );
wp_register_script( 'um_admin_settings', $this->js_url . 'um-admin-settings.js', '', '', true );
wp_enqueue_script( 'um_admin_settings' );
$localize_data = array(
'texts' => array(
'remove' => __( 'Remove', 'ultimate-member' ),
'select' => __( 'Select', 'ultimate-member' )
)
);
wp_localize_script( 'um_admin_settings', 'php_data', $localize_data );
}
/***
*** @Load modal
***/
function load_modal() {
wp_register_style( 'um_admin_modal', $this->css_url . 'um-admin-modal.css' );
wp_enqueue_style( 'um_admin_modal' );
wp_register_script( 'um_admin_modal', $this->js_url . 'um-admin-modal.js', '', '', true );
wp_enqueue_script( 'um_admin_modal' );
$localize_data = array(
'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'dynamic_modal_content' ),
'dropdown_ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'populate_dropdown_options' ),
);
wp_localize_script( 'um_admin_modal', 'um_admin_modal_data', $localize_data );
}
/***
*** @Field Processing
***/
function load_field() {
wp_register_script( 'um_admin_field', $this->js_url . 'um-admin-field.js', '', '', true );
wp_enqueue_script( 'um_admin_field' );
$localize_data = array(
'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'update_field' ),
'do_ajax_url' => UM()->get_ajax_route( 'um\core\Fields', 'do_ajax_action' ),
);
wp_localize_script( 'um_admin_field', 'um_admin_field_data', $localize_data );
}
/***
*** @Load Builder
***/
function load_builder() {
wp_register_script( 'um_admin_builder', $this->js_url . 'um-admin-builder.js', '', '', true );
wp_enqueue_script( 'um_admin_builder' );
$localize_data = array(
'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_Builder', 'update_builder' ),
);
wp_localize_script( 'um_admin_builder', 'um_admin_builder_data', $localize_data );
wp_register_script( 'um_admin_dragdrop', $this->js_url . 'um-admin-dragdrop.js', '', '', true );
wp_enqueue_script( 'um_admin_dragdrop' );
$localize_data = array(
'ajax_url' => UM()->get_ajax_route( 'um\admin\core\Admin_DragDrop', 'update_order' ),
);
wp_localize_script( 'um_admin_dragdrop', 'um_admin_dragdrop_data', $localize_data );
wp_register_style( 'um_admin_builder', $this->css_url . 'um-admin-builder.css' );
wp_enqueue_style( 'um_admin_builder' );
}
/***
*** @Load core WP styles/scripts
***/
function load_core_wp() {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'jquery-ui-draggable' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-ui-tooltip' );
}
/***
*** @Load Admin Styles
***/
function load_css() {
wp_register_style( 'um_admin_menu', $this->css_url . 'um-admin-menu.css' );
wp_enqueue_style( 'um_admin_menu' );
wp_register_style( 'um_admin_columns', $this->css_url . 'um-admin-columns.css' );
wp_enqueue_style( 'um_admin_columns' );
wp_register_style( 'um_admin_misc', $this->css_url . 'um-admin-misc.css' );
wp_enqueue_style( 'um_admin_misc' );
if ( get_post_type() != 'shop_order' ) {
wp_register_style( 'um_admin_select2', $this->css_url . 'um-admin-select2.css' );
wp_enqueue_style( 'um_admin_select2' );
}
}
/***
*** @Load global css
***/
function load_global_css() {
wp_register_style( 'um_admin_global', $this->css_url . 'um-admin-global.css' );
wp_enqueue_style( 'um_admin_global' );
}
/***
*** @Load jQuery custom code
***/
function load_custom_scripts() {
wp_register_script( 'um_admin_scripts', $this->js_url . 'um-admin-scripts.js', '', '', true );
wp_enqueue_script( 'um_admin_scripts' );
}
/***
*** @Load AJAX
***/
function load_ajax_js() {
wp_register_script( 'um_admin_ajax', $this->js_url . 'um-admin-ajax.js', '', '', true );
wp_enqueue_script( 'um_admin_ajax' );
$localize_data = array(
'ajax_url' => UM()->get_ajax_route( 'um\core\Fields', 'do_ajax_action' ),
);
wp_localize_script( 'um_admin_ajax', 'um_admin_ajax_data', $localize_data );
}
/***
*** @Boolean check if we're viewing UM backend
***/
function is_UM_admin() {
global $current_screen;
$screen_id = $current_screen->id;
if ( strstr( $screen_id, 'ultimatemember' ) || strstr( $screen_id, 'um_' ) || strstr( $screen_id, 'user' ) || strstr( $screen_id, 'profile' ) || $screen_id == 'nav-menus' ) return true;
global $post;
if ( isset( $post->post_type ) ) return true;
global $tax;
if ( isset( $tax->name ) ) return true;
return false;
}
/***
*** @Adds class to our admin pages
***/
function admin_body_class($classes){
if ( $this->is_UM_admin() ) {
return "$classes um-admin";
}
return $classes;
}
/***
*** @Enqueue scripts and styles
***/
function admin_enqueue_scripts() {
if ( $this->is_UM_admin() ) {
if ( get_post_type() != 'shop_order' ) {
UM()->enqueue()->wp_enqueue_scripts();
}
$this->load_global_css();
$this->load_form();
$this->load_forms();
$this->load_modal();
$this->load_dashboard();
$this->load_settings();
$this->load_field();
$this->load_builder();
$this->load_css();
$this->load_core_wp();
$this->load_ajax_js();
$this->load_custom_scripts();
if ( is_rtl() ) {
wp_register_style( 'um_admin_rtl', $this->css_url . 'um-admin-rtl.css' );
wp_enqueue_style( 'um_admin_rtl' );
}
} else {
$this->load_global_css();
}
}
}
}
+890
View File
@@ -0,0 +1,890 @@
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Forms' ) ) {
class Admin_Forms {
var $form_data;
/**
* Admin_Forms constructor.
* @param bool $form_data
*/
function __construct( $form_data = false ) {
if ( $form_data )
$this->form_data = $form_data;
}
/**
* Render form
*
*
* @param bool $echo
* @return string
*/
function render_form( $echo = true ) {
if ( empty( $this->form_data['fields'] ) )
return '';
$class = 'form-table um-form-table ' . ( ! empty( $this->form_data['class'] ) ? $this->form_data['class'] : '' );
$class_attr = ' class="' . $class . '" ';
ob_start();
foreach ( $this->form_data['fields'] as $field_data ) {
if ( isset( $field_data['type'] ) && 'hidden' == $field_data['type'] )
echo $this->render_form_row( $field_data );
}
if ( empty( $this->form_data['without_wrapper'] ) ) { ?>
<table <?php echo $class_attr ?>>
<tbody>
<?php }
foreach ( $this->form_data['fields'] as $field_data ) {
if ( isset( $field_data['type'] ) && 'hidden' != $field_data['type'] )
echo $this->render_form_row( $field_data );
}
if ( empty( $this->form_data['without_wrapper'] ) ) { ?>
</tbody>
</table>
<?php }
if ( $echo ) {
ob_get_flush();
return '';
} else {
return ob_get_clean();
}
}
function render_form_row( $data ) {
if ( empty( $data['type'] ) )
return '';
$conditional = ! empty( $data['conditional'] ) ? 'data-conditional="' . esc_attr( json_encode( $data['conditional'] ) ) . '"' : '';
$prefix_attr = ! empty( $this->form_data['prefix_id'] ) ? ' data-prefix="' . $this->form_data['prefix_id'] . '" ' : '';
$html = '';
if ( $data['type'] != 'hidden' ) {
if ( ! empty( $this->form_data['div_line'] ) ) {
if ( strpos( $this->form_data['class'], 'um-top-label' ) !== false ) {
$html .= '<div class="form-field um-forms-line" ' . $conditional . $prefix_attr . '>' . $this->render_field_label( $data );
if ( method_exists( $this, 'render_' . $data['type'] ) ) {
$html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data );
} else {
$html .= apply_filters( 'um_render_field_type_' . $data['type'], '', $data, $this->form_data );
}
if ( ! empty( $data['description'] ) )
$html .= '<p class="description">' . $data['description'] . '</p>';
$html .= '</div>';
} else {
if ( ! empty( $data['without_label'] ) ) {
$html .= '<div class="form-field um-forms-line" ' . $conditional . $prefix_attr . '>';
if ( method_exists( $this, 'render_' . $data['type'] ) ) {
$html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data );
} else {
$html .= apply_filters( 'um_render_field_type_' . $data['type'], '', $data, $this->form_data );
}
if ( ! empty( $data['description'] ) )
$html .= '<p class="description">' . $data['description'] . '</p>';
$html .= '</div>';
} else {
$html .= '<div class="form-field um-forms-line" ' . $conditional . $prefix_attr . '>' . $this->render_field_label( $data );
if ( method_exists( $this, 'render_' . $data['type'] ) ) {
$html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data );
} else {
$html .= apply_filters( 'um_render_field_type_' . $data['type'], '', $data, $this->form_data );
}
if ( ! empty( $data['description'] ) )
$html .= '<p class="description">' . $data['description'] . '</p>';
$html .= '</div>';
}
}
} else {
if ( strpos( $this->form_data['class'], 'um-top-label' ) !== false ) {
$html .= '<tr class="um-forms-line" ' . $conditional . $prefix_attr . '>
<td>' . $this->render_field_label( $data );
if ( method_exists( $this, 'render_' . $data['type'] ) ) {
$html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data );
} else {
$html .= apply_filters( 'um_render_field_type_' . $data['type'], '', $data, $this->form_data );
}
if ( ! empty( $data['description'] ) )
$html .= '<div class="um-admin-clear"></div><p class="description">' . $data['description'] . '</p>';
$html .= '</td></tr>';
} else {
if ( ! empty( $data['without_label'] ) ) {
$html .= '<tr class="um-forms-line" ' . $conditional . $prefix_attr . '>
<td colspan="2">';
if ( method_exists( $this, 'render_' . $data['type'] ) ) {
$html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data );
} else {
$html .= apply_filters( 'um_render_field_type_' . $data['type'], '', $data, $this->form_data );
}
if ( ! empty( $data['description'] ) )
$html .= '<div class="um-admin-clear"></div><p class="description">' . $data['description'] . '</p>';
$html .= '</td></tr>';
} else {
$html .= '<tr class="um-forms-line" ' . $conditional . $prefix_attr . '>
<th>' . $this->render_field_label( $data ) . '</th>
<td>';
if ( method_exists( $this, 'render_' . $data['type'] ) ) {
$html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data );
} else {
$html .= apply_filters( 'um_render_field_type_' . $data['type'], '', $data, $this->form_data );
}
if ( ! empty( $data['description'] ) )
$html .= '<div class="um-admin-clear"></div><p class="description">' . $data['description'] . '</p>';
$html .= '</td></tr>';
}
}
}
} else {
if ( method_exists( $this, 'render_' . $data['type'] ) ) {
$html .= call_user_func( array( &$this, 'render_' . $data['type'] ), $data );
} else {
$html .= apply_filters( 'um_render_field_type_' . $data['type'], '', $data, $this->form_data );
}
}
return $html;
}
function render_field_label( $data ) {
if ( empty( $data['label'] ) )
return false;
$id = ! empty( $data['id1'] ) ? $data['id1'] : $data['id'];
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $id;
$for_attr = ' for="' . $id . '" ';
$label = $data['label'];
$tooltip = ! empty( $data['tooltip'] ) ? UM()->tooltip( $data['tooltip'], false, false ) : '';
return "<label $for_attr>$label $tooltip</label>";
}
function render_hidden( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$id_attr = ' id="' . $id . '" ';
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id']
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$value_attr = ' value="' . $value . '" ';
$html = "<input type=\"hidden\" $id_attr $class_attr $name_attr $data_attr $value_attr />";
return $html;
}
function render_text( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$id_attr = ' id="' . $id . '" ';
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id']
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : '';
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$value_attr = ' value="' . $value . '" ';
$html = "<input type=\"text\" $id_attr $class_attr $name_attr $data_attr $value_attr $placeholder_attr />";
return $html;
}
function render_color( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$id_attr = ' id="' . $id . '" ';
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? ' um-' . $field_data['size'] . '-field ' : ' um-long-field ';
$class .= ' um-admin-colorpicker ';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id']
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : '';
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$value_attr = ' value="' . $value . '" ';
$html = "<input type=\"text\" $id_attr $class_attr $name_attr $data_attr $value_attr $placeholder_attr />";
return $html;
}
function render_icon( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$id_attr = ' id="' . $id . '" ';
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$value_attr = ' value="' . $value . '" ';
$html = '<a href="#" class="button" data-modal="UM_fonticons" data-modal-size="normal" data-dynamic-content="um_admin_fonticon_selector" data-arg1="" data-arg2="" data-back="">' . __( 'Choose Icon', 'ultimate-member' ) . '</a>
<span class="um-admin-icon-value">';
if ( ! empty( $value ) ) {
$html .= '<i class="' . $value . '"></i>';
} else {
$html .= __( 'No Icon', 'ultimate-member' );
}
$html .= '</span><input type="hidden" ' . $name_attr . ' ' . $id_attr . ' ' . $value_attr . ' />';
if ( get_post_meta( get_the_ID(), '_um_icon', true ) ) {
$html .= '<span class="um-admin-icon-clear show"><i class="um-icon-android-cancel"></i></span>';
} else {
$html .= '<span class="um-admin-icon-clear"><i class="um-icon-android-cancel"></i></span>';
}
$html .= '</span>';
return $html;
}
function render_datepicker( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$id_attr = ' id="' . $id . '" ';
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id']
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : '';
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$value_attr = ' value="' . $value . '" ';
$html = "<input type=\"date\" $id_attr $class_attr $name_attr $data_attr $value_attr $placeholder_attr />";
return $html;
}
function render_inline_texts( $field_data ) {
if ( empty( $field_data['id1'] ) )
return false;
$i = 1;
$fields = array();
while( ! empty( $field_data['id' . $i] ) ) {
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'. $i];
$id_attr = ' id="' . $id . '" ';
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id'. $i]
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$placeholder_attr = ! empty( $field_data['placeholder'] ) ? ' placeholder="' . $field_data['placeholder'] . '"' : '';
$name = $field_data['id'. $i];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'. $i] ) ? $field_data['default'. $i] : '';
$value = isset( $field_data['value'. $i] ) ? $field_data['value'. $i] : $default;
$value_attr = ' value="' . $value . '" ';
$fields[$i] = "<input type=\"text\" $id_attr $class_attr $name_attr $data_attr $value_attr $placeholder_attr style=\"display:inline;\"/>";
$i++;
}
$html = vsprintf( $field_data['mask'], $fields );
return $html;
}
function render_textarea( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$id_attr = ' id="' . $id . '" ';
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id']
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$rows = ! empty( $field_data['args']['textarea_rows'] ) ? ' rows="' . $field_data['args']['textarea_rows'] . '" ' : '';
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$html = "<textarea $id_attr $class_attr $name_attr $data_attr $rows>$value</textarea>";
return $html;
}
function render_wp_editor( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field';
$data = array(
'field_id' => $field_data['id']
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
ob_start();
wp_editor( $value,
$id,
array(
'textarea_name' => $name,
'textarea_rows' => 20,
'editor_height' => 425,
'wpautop' => false,
'media_buttons' => false,
'editor_class' => $class
)
);
$html = ob_get_clean();
return $html;
}
function render_checkbox( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$id_attr = ' id="' . $id . '" ';
$id_attr_hidden = ' id="' . $id . '_hidden" ';
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id']
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = ( '' !== $field_data['value'] ) ? $field_data['value'] : $default;
/*$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$value = ! empty( $field_data['value'] ) ? $field_data['value'] : 0;
*/
$html = "<input type=\"hidden\" $id_attr_hidden $name_attr value=\"0\" />
<input type=\"checkbox\" $id_attr $class_attr $name_attr $data_attr " . checked( $value, true, false ) . " value=\"1\" />";
return $html;
}
function render_select( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$multiple = ! empty( $field_data['multi'] ) ? 'multiple' : '';
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$id_attr = ' id="' . $id . '" ';
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id']
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name = $name . ( ! empty( $field_data['multi'] ) ? '[]' : '' );
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$options = '';
foreach ( $field_data['options'] as $key=>$option ) {
if ( ! empty( $field_data['multi'] ) ) {
if ( ! is_array( $value ) && empty( $value ) )
$value = array();
$options .= '<option value="' . $key . '" ' . selected( in_array( $key, $value ), true, false ) . '>' . $option . '</option>';
} else {
$options .= '<option value="' . $key . '" ' . selected( (string)$key == $value, true, false ) . '>' . $option . '</option>';
}
}
$html = "<select $multiple $id_attr $name_attr $class_attr $data_attr>$options</select>";
return $html;
}
function render_multi_selects( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id'],
'id_attr' => $id
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name = "{$name}[]";
$name_attr = ' name="' . $name . '" ';
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$values = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$options = '';
foreach ( $field_data['options'] as $key=>$option ) {
$options .= '<option value="' . $key . '">' . $option . '</option>';
}
$html = "<select class=\"um-hidden-multi-selects\" $data_attr>$options</select>";
$html .= "<ul class=\"um-multi-selects-list\" $data_attr>";
if ( ! empty( $values ) ) {
foreach ( $values as $k=>$value ) {
$id_attr = ' id="' . $id . '-' . $k . '" ';
$options = '';
foreach ( $field_data['options'] as $key=>$option ) {
$options .= '<option value="' . $key . '" ' . selected( $key == $value, true, false ) . '>' . $option . '</option>';
}
$html .= "<li class=\"um-multi-selects-option-line\"><span class=\"um-field-wrapper\">
<select $id_attr $name_attr $class_attr $data_attr>$options</select></span>
<span class=\"um-field-control\"><a href=\"javascript:void(0);\" class=\"um-select-delete\">" . __( 'Remove', 'ultimate-member' ) . "</a></span></li>";
}
} elseif ( ! empty( $field_data['show_default_number'] ) && is_numeric( $field_data['show_default_number'] ) && $field_data['show_default_number'] > 0 ) {
$i = 0;
while( $i < $field_data['show_default_number'] ) {
$id_attr = ' id="' . $id . '-' . $i . '" ';
$options = '';
foreach ( $field_data['options'] as $key=>$option ) {
$options .= '<option value="' . $key . '">' . $option . '</option>';
}
$html .= "<li class=\"um-multi-selects-option-line\"><span class=\"um-field-wrapper\">
<select $id_attr $name_attr $class_attr $data_attr>$options</select></span>
<span class=\"um-field-control\"><a href=\"javascript:void(0);\" class=\"um-select-delete\">" . __( 'Remove', 'ultimate-member' ) . "</a></span></li>";
$i++;
}
}
$html .= "</ul><a href=\"javascript:void(0);\" class=\"button button-primary um-multi-selects-add-option\" data-name=\"$name\">{$field_data['add_text']}</a>";
return $html;
}
function render_multi_checkbox( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$values = ( '' !== $field_data['value'] ) ? $field_data['value'] : $default;
$i = 0;
$html = '';
$columns = ( ! empty( $field_data['columns'] ) && is_numeric( $field_data['columns'] ) ) ? $field_data['columns'] : 1;
while ( $i < $columns ) {
$per_page = ceil( count( $field_data['options'] ) / $columns );
$section_fields_per_page = array_slice( $field_data['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="' . $name . '[' . $k . ']" ';
$html .= "<label $for_attr>
<input type=\"checkbox\" " . checked( in_array( $k, $values ), true, false ) . "$id_attr $name_attr value=\"1\" $class_attr>
<span>$title</span>
</label>";
}
$html .= '</span>';
$i++;
}
return $html;
}
function render_multi_text( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$size = ! empty( $field_data['size'] ) ? 'um-' . $field_data['size'] . '-field' : 'um-long-field';
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class_attr = ' class="um-forms-field ' . $class . '" ';
$data = array(
'field_id' => $field_data['id'],
'id_attr' => $id
);
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$name = "{$name}[]";
$name_attr = ' name="' . $name . '" ';
//$values = ! empty( $field_data['value'] ) ? $field_data['value'] : ( ! empty( $field_data['default'] ) ? $field_data['default'] : '' );
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$values = isset( $field_data['value'] ) ? $field_data['value'] : $default;
$html = "<input type=\"text\" class=\"um-hidden-multi-text\" $data_attr />";
$html .= "<ul class=\"um-multi-text-list\" $data_attr>";
if ( ! empty( $values ) ) {
foreach ( $values as $k=>$value ) {
$id_attr = ' id="' . $id . '-' . $k . '" ';
$html .= "<li class=\"um-multi-text-option-line {$size}\"><span class=\"um-field-wrapper\">
<input type=\"text\" $id_attr $name_attr $class_attr $data_attr value=\"$value\" /></span>
<span class=\"um-field-control\"><a href=\"javascript:void(0);\" class=\"um-text-delete\">" . __( 'Remove', 'ultimate-member' ) . "</a></span></li>";
}
} elseif ( ! empty( $field_data['show_default_number'] ) && is_numeric( $field_data['show_default_number'] ) && $field_data['show_default_number'] > 0 ) {
$i = 0;
while( $i < $field_data['show_default_number'] ) {
$id_attr = ' id="' . $id . '-' . $i . '" ';
$html .= "<li class=\"um-multi-text-option-line {$size}\"><span class=\"um-field-wrapper\">
<input type=\"text\" $id_attr $name_attr $class_attr $data_attr value=\"\" /></span>
<span class=\"um-field-control\"><a href=\"javascript:void(0);\" class=\"um-text-delete\">" . __( 'Remove', 'ultimate-member' ) . "</a></span></li>";
$i++;
}
}
$html .= "</ul><a href=\"javascript:void(0);\" class=\"button button-primary um-multi-text-add-option\" data-name=\"$name\">{$field_data['add_text']}</a>";
return $html;
}
function render_media( $field_data ) {
if ( empty( $field_data['id'] ) )
return false;
$id = ( ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] : '' ) . '_' . $field_data['id'];
$class = ! empty( $field_data['class'] ) ? $field_data['class'] : '';
$class .= ! empty( $field_data['size'] ) ? $field_data['size'] : 'um-long-field';
$class_attr = ' class="um-forms-field um-media-upload-data-url ' . $class . '"';
$data = array(
'field_id' => $field_data['id'],
);
if ( ! empty( $field_data['default']['url'] ) )
$data['default'] = esc_attr( $field_data['default']['url'] );
$data_attr = '';
foreach ( $data as $key => $value ) {
$data_attr .= " data-{$key}=\"{$value}\" ";
}
$name = $field_data['id'];
$name = ! empty( $this->form_data['prefix_id'] ) ? $this->form_data['prefix_id'] . '[' . $name . ']' : $name;
$default = isset( $field_data['default'] ) ? $field_data['default'] : '';
$value = ! empty( $field_data['value'] ) ? $field_data['value'] : $default;
$upload_frame_title = ! empty( $field_data['upload_frame_title'] ) ? $field_data['upload_frame_title'] : __( 'Select media', 'ultimate-member' );
$image_id = ! empty( $value['id'] ) ? $value['id'] : '';
$image_width = ! empty( $value['width'] ) ? $value['width'] : '';
$image_height = ! empty( $value['height'] ) ? $value['height'] : '';
$image_thumbnail = ! empty( $value['thumbnail'] ) ? $value['thumbnail'] : '';
$image_url = ! empty( $value['url'] ) ? $value['url'] : '';
$html = "<div class=\"um-media-upload\">" .
"<input type=\"hidden\" class=\"um-media-upload-data-id\" name=\"{$name}[id]\" id=\"{$id}_id\" value=\"$image_id\">" .
"<input type=\"hidden\" class=\"um-media-upload-data-width\" name=\"{$name}[width]\" id=\"{$id}_width\" value=\"$image_width\">" .
"<input type=\"hidden\" class=\"um-media-upload-data-height\" name=\"{$name}[height]\" id=\"{$id}_height\" value=\"$image_height\">" .
"<input type=\"hidden\" class=\"um-media-upload-data-thumbnail\" name=\"{$name}[thumbnail]\" id=\"{$id}_thumbnail\" value=\"$image_thumbnail\">" .
"<input type=\"hidden\" $class_attr name=\"{$name}[url]\" id=\"{$id}_url\" value=\"$image_url\" $data_attr>";
if ( ! isset( $field_data['preview'] ) || $field_data['preview'] !== false ) {
$html .= '<img src="' . $image_url . '" alt="" class="icon_preview"><div style="clear:both;"></div>';
}
if ( ! empty( $field_data['url'] ) ) {
$html .= '<input type="text" class="um-media-upload-url" readonly value="' . $image_url . '" /><div style="clear:both;"></div>';
}
$html .= '<input type="button" class="um-set-image button button-primary" value="' . __( 'Select', 'ultimate-member' ) . '" data-upload_frame="' . $upload_frame_title . '" />
<input type="button" class="um-clear-image button" value="' . __( 'Clear', 'ultimate-member' ) . '" /></div>';
return $html;
}
}
}
@@ -0,0 +1,121 @@
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Functions' ) ) {
class Admin_Functions {
function __construct() {
$this->slug = 'ultimatemember';
add_action('parent_file', array(&$this, 'parent_file'), 9);
add_filter('gettext', array(&$this, 'gettext'), 10, 4);
add_filter('post_updated_messages', array(&$this, 'post_updated_messages') );
}
/***
*** @updated post messages
***/
function post_updated_messages($messages) {
global $post, $post_ID;
$post_type = get_post_type( $post_ID );
if ($post_type == 'um_form') {
$messages['um_form'] = array(
0 => '',
1 => __('Form updated.'),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Form updated.'),
5 => isset($_GET['revision']) ? __('Form restored to revision.') : false,
6 => __('Form created.'),
7 => __('Form saved.'),
8 => __('Form submitted.'),
9 => __('Form scheduled.'),
10=> __('Form draft updated.'),
);
}
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
***/
function gettext($translation, $text, $domain) {
global $post;
//$screen = get_current_screen();
if ( isset( $post->post_type ) && $this->is_plugin_post_type() ) {
$translations = get_translations_for_domain( $domain);
if ( $text == 'Publish') {
return $translations->translate( 'Create' );
}
if ( $text == 'Move to Trash') {
return $translations->translate( 'Delete' );
}
}
return $translation;
}
/***
*** @Fix parent file for correct highlighting
***/
function parent_file($parent_file){
global $current_screen;
$screen_id = $current_screen->id;
if ( strstr($screen_id, 'um_') ) {
$parent_file = $this->slug;
}
return $parent_file;
}
}
}
+321
View File
@@ -0,0 +1,321 @@
<?php
namespace um\admin\core;
use \RecursiveDirectoryIterator;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Menu' ) ) {
class Admin_Menu {
var $about_tabs = array();
function __construct() {
$this->slug = 'ultimatemember';
$this->about_tabs['about'] = 'About';
$this->about_tabs['start'] = 'Getting Started';
add_action('admin_menu', array(&$this, 'primary_admin_menu'), 0);
add_action('admin_menu', array(&$this, 'secondary_menu_items'), 1000);
add_action('admin_menu', array(&$this, 'extension_menu'), 9999);
add_action( 'admin_head', array( $this, 'menu_order_count' ) );
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1000 );
}
/**
* Change the admin footer text on UM admin pages
*/
public function admin_footer_text( $footer_text ) {
$current_screen = get_current_screen();
// Add the dashboard pages
$um_pages[] = 'toplevel_page_ultimatemember';
$um_pages[] = 'admin_page_ultimatemember-about';
$um_pages[] = 'ultimate-member_page_um_options';
$um_pages[] = 'edit-um_form';
$um_pages[] = 'edit-um_role';
$um_pages[] = 'edit-um_directory';
$um_pages[] = 'ultimate-member_page_ultimatemember-extensions';
if ( isset( $current_screen->id ) && in_array( $current_screen->id, $um_pages ) ) {
// Change the footer text
if ( ! get_option( 'um_admin_footer_text_rated' ) ) {
$footer_text = sprintf( __( 'If you like Ultimate Member please consider leaving a %s&#9733;&#9733;&#9733;&#9733;&#9733;%s review. It will help us to grow the plugin and make it more popular. Thank you.', 'ultimate-member' ), '<a href="https://wordpress.org/support/plugin/ultimate-member/reviews/?filter=5" target="_blank" class="um-admin-rating-link" data-rated="' . __( 'Thanks :)', 'ultimate-member' ) . '">', '</a>' );
$footer_text .= "<script type='text/javascript'>
jQuery('a.um-admin-rating-link').click(function() {
jQuery.post( '" . UM()->get_ajax_route( get_class( $this ), 'ultimatemember_rated' ) . "', {} );
jQuery(this).parent().text( jQuery(this).data( 'rated' ) );
});
</script>";
}
}
return $footer_text;
}
/**
* When user clicks the review link in backend
*/
function ultimatemember_rated() {
update_option('um_admin_footer_text_rated', 1 );
die();
}
/**
* Manage order of admin menu items
*/
public function menu_order_count() {
global $menu, $submenu;
if ( ! current_user_can( 'list_users' ) )
return;
$count = UM()->user()->get_pending_users_count();
if ( is_array( $menu ) ) {
foreach ( $menu as $key => $menu_item ) {
if ( 0 === strpos( $menu_item[0], _x( 'Users', 'Admin menu name' ) ) ) {
$menu[ $key ][0] .= ' <span class="update-plugins count-'.$count.'"><span class="processing-count">'.$count.'</span></span>';
}
}
}
if ( is_array( $submenu ) ) {
foreach ( $submenu['users.php'] as $key => $menu_item ) {
if ( 0 === strpos( $menu_item[0], _x( 'All Users', 'Admin menu name' ) ) ) {
$submenu['users.php'][ $key ][0] .= ' <span class="update-plugins count-'.$count.'"><span class="processing-count">'.$count.'</span></span>';
}
}
}
}
/***
*** @setup admin menu
***/
function primary_admin_menu() {
$this->pagehook = add_menu_page( __('Ultimate Member', $this->slug), __('Ultimate Member', $this->slug), 'manage_options', $this->slug, array(&$this, 'admin_page'), 'dashicons-admin-users', '42.78578');
add_action( 'load-' . $this->pagehook, array( &$this, 'on_load_page' ) );
add_submenu_page( $this->slug, __('Dashboard', $this->slug), __('Dashboard', $this->slug), 'manage_options', $this->slug, array(&$this, 'admin_page') );
foreach( $this->about_tabs as $k => $tab ) {
add_submenu_page( '_'. $k . '_um', sprintf(__('%s | Ultimate Member', $this->slug), $tab), sprintf(__('%s | Ultimate Member', $this->slug), $tab), 'manage_options', $this->slug . '-' . $k, array(&$this, 'admin_page') );
}
}
/***
*** @secondary admin menu (after settings)
***/
function secondary_menu_items() {
add_submenu_page( $this->slug, __('Forms', $this->slug), __('Forms', $this->slug), 'manage_options', 'edit.php?post_type=um_form', '', '' );
add_submenu_page( $this->slug, __( 'User Roles', 'ultimate-member' ), __( 'User Roles', 'ultimate-member' ), 'manage_options', 'um_roles', array( &$this, 'um_roles_pages' ) );
if ( um_get_option('members_page' ) || !get_option('um_options') ){
add_submenu_page( $this->slug, __('Member Directories', $this->slug), __('Member Directories', $this->slug), 'manage_options', 'edit.php?post_type=um_directory', '', '' );
}
do_action('um_extend_admin_menu');
}
function um_roles_pages() {
if ( empty( $_GET['tab'] ) ) {
include_once um_path . 'includes/admin/core/list-tables/roles-list-table.php';
} elseif ( $_GET['tab'] == 'add' || $_GET['tab'] == 'edit' ) {
include_once um_path . 'includes/admin/templates/role/role-edit.php';
} else {
um_js_redirect( add_query_arg( array( 'page' => 'um_roles' ), get_admin_url( 'admin.php' ) ) );
}
}
/***
*** @extension menu
***/
function extension_menu() {
add_submenu_page( $this->slug, __('Extensions', $this->slug), '<span style="color: #00B9EB">' .__('Extensions', $this->slug) . '</span>', 'manage_options', $this->slug . '-extensions', array(&$this, 'admin_page') );
}
/***
*** @load metabox stuff
***/
function on_load_page() {
wp_enqueue_script('common');
wp_enqueue_script('wp-lists');
wp_enqueue_script('postbox');
/** custom metaboxes for dashboard defined here **/
add_meta_box('um-metaboxes-contentbox-1', __('Users Overview','ultimate-member'), array(&$this, 'users_overview'), $this->pagehook, 'core', 'core');
add_meta_box('um-metaboxes-mainbox-1', __('Latest from our blog','ultimate-member'), array(&$this, 'um_news'), $this->pagehook, 'normal', 'core');
add_meta_box('um-metaboxes-sidebox-1', __('Purge Temp Files','ultimate-member'), array(&$this, 'purge_temp'), $this->pagehook, 'side', 'core');
add_meta_box('um-metaboxes-sidebox-2', __('User Cache','ultimate-member'), array(&$this, 'user_cache'), $this->pagehook, 'side', 'core');
if ( $this->language_avaialable_not_installed() ) {
add_meta_box('um-metaboxes-sidebox-2', __('Language','ultimate-member'), array(&$this, 'dl_language'), $this->pagehook, 'side', 'core');
} else if ( $this->language_avaialable_installed() ) {
add_meta_box('um-metaboxes-sidebox-2', __('Language','ultimate-member'), array(&$this, 'up_language'), $this->pagehook, 'side', 'core');
} else if ( $this->language_not_available() ) {
add_meta_box('um-metaboxes-sidebox-2', __('Language','ultimate-member'), array(&$this, 'ct_language'), $this->pagehook, 'side', 'core');
}
}
function up_language() {
$locale = get_option('WPLANG');
include_once UM()->admin()->templates_path . 'dashboard/language-update.php';
}
function dl_language() {
$locale = get_option('WPLANG');
include_once UM()->admin()->templates_path . 'dashboard/language-download.php';
}
function ct_language() {
$locale = get_option('WPLANG');
include_once UM()->admin()->templates_path . 'dashboard/language-contrib.php';
}
function um_news() {
include_once UM()->admin()->templates_path . 'dashboard/feed.php';
}
function users_overview() {
include_once UM()->admin()->templates_path . 'dashboard/users.php';
}
function purge_temp() {
include_once UM()->admin()->templates_path . 'dashboard/purge.php';
}
function user_cache() {
include_once UM()->admin()->templates_path . 'dashboard/cache.php';
}
/***
*** @language not available
***/
function language_not_available() {
$locale = get_option('WPLANG');
if ( $locale && !strstr($locale, 'en_') && !isset( UM()->available_languages[$locale] ) && !file_exists( WP_LANG_DIR . '/plugins/ultimatemember-' . $locale . '.mo' ) )
return true;
return false;
}
/***
*** @language available but not installed
***/
function language_avaialable_not_installed() {
$locale = get_option('WPLANG');
if ( $locale && isset( UM()->available_languages[$locale] ) && !file_exists( WP_LANG_DIR . '/plugins/ultimatemember-' . $locale . '.mo' ) )
return true;
return false;
}
/***
*** @language available and installed
***/
function language_avaialable_installed() {
$locale = get_option('WPLANG');
if ( $locale && isset( UM()->available_languages[$locale] ) && file_exists( WP_LANG_DIR . '/plugins/ultimatemember-' . $locale . '.mo' ) )
return true;
return false;
}
/***
*** @get a directory size
***/
function dir_size( $directory ) {
if ( $directory == 'temp' ) {
$directory = UM()->files()->upload_temp;
$size = 0;
foreach( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $directory ) ) as $file ) {
$size+=$file->getSize();
}
return round ( $size / 1048576, 2);
}
return 0;
}
/***
*** @which admin page to show?
***/
function admin_page() {
$page = $_REQUEST['page'];
if ( $page == 'ultimatemember' && ! isset( $_REQUEST['um-addon'] ) ) {
?>
<div id="um-metaboxes-general" class="wrap">
<h2>Ultimate Member <sup><?php echo ultimatemember_version; ?></sup></h2>
<?php wp_nonce_field('um-metaboxes-general'); ?>
<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>
<input type="hidden" name="action" value="save_um_metaboxes_general" />
<div id="dashboard-widgets-wrap">
<div id="dashboard-widgets" class="metabox-holder um-metabox-holder">
<div id="postbox-container-1" class="postbox-container"><?php do_meta_boxes($this->pagehook,'core',null); ?></div>
<div id="postbox-container-2" class="postbox-container"><?php do_meta_boxes($this->pagehook,'normal',null); ?></div>
<div id="postbox-container-3" class="postbox-container"><?php do_meta_boxes($this->pagehook,'side',null); ?></div>
</div>
</div>
</div><div class="um-admin-clear"></div>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function($) {
// postboxes setup
postboxes.add_postbox_toggles('<?php echo $this->pagehook; ?>');
});
//]]>
</script>
<?php
} else if ( $page == 'ultimatemember-extensions' ) {
include_once UM()->admin()->templates_path . 'extensions.php';
} else if ( $page == 'ultimatemember-about' ) {
include_once UM()->admin()->templates_path . 'welcome/about.php';
} else if ( $page == 'ultimatemember-start' ) {
include_once UM()->admin()->templates_path . 'welcome/start.php';
}
}
}
}
File diff suppressed because it is too large Load Diff
+220
View File
@@ -0,0 +1,220 @@
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Notices' ) ) {
class Admin_Notices {
function __construct() {
add_action('admin_init', array(&$this, 'create_languages_folder') );
add_action('admin_notices', array(&$this, 'main_notices'), 1);
add_action('admin_notices', array(&$this, 'localize_note'), 2);
add_action('admin_notices', array(&$this, 'show_update_messages'), 10);
}
/***
*** @to store plugin languages
***/
function create_languages_folder() {
$path = UM()->files()->upload_basedir;
$path = str_replace('/uploads/ultimatemember','',$path);
$path = $path . '/languages/plugins/';
$path = str_replace('//','/',$path);
if ( !file_exists( $path ) ) {
$old = umask(0);
@mkdir( $path, 0777, true);
umask($old);
}
}
/***
*** @show main notices
***/
function main_notices() {
if ( ! defined( 'DOING_AJAX' ) ) {
$hide_exif_notice = get_option( 'um_hide_exif_notice' );
if ( !extension_loaded('exif') && !$hide_exif_notice ) {
echo '<div class="updated" style="border-color: #0085ba;"><p>';
echo sprintf(__( 'Exif is not enabled on your server. Mobile photo uploads will not be rotated correctly until you enable the exif extension. <a href="%s">Hide this notice</a>', 'ultimate-member' ), add_query_arg('um_adm_action', 'um_hide_exif_notice') );
echo '</p></div>';
}
// Regarding page setup
$pages = UM()->config()->permalinks;
if ( $pages && is_array( $pages ) ) {
$err = false;
foreach( $pages as $slug => $page_id ) {
$page = get_post( $page_id );
if ( !isset( $page->ID ) && in_array( $slug, array( 'user','account','members','register','login','logout','password-reset' ) ) ) {
$err = true;
}
}
if ( $err ) {
echo '<div class="updated" style="border-color: #0085ba;"><p>' . __('One or more of your Ultimate Member pages are not correctly setup. Please visit <strong>Ultimate Member > Settings</strong> to re-assign your missing pages.','ultimate-member') . '</p></div>';
}
if ( isset( $pages['user'] ) ) {
$test = get_post( $pages['user'] );
if ( isset( $test->post_parent ) && $test->post_parent > 0 ) {
echo '<div class="updated" style="border-color: #0085ba;"><p>' . __('Ultimate Member Setup Error: User page can not be a child page.','ultimate-member') . '</p></div>';
}
}
if ( isset( $pages['account'] ) ) {
$test = get_post( $pages['account'] );
if ( isset( $test->post_parent ) && $test->post_parent > 0 ) {
echo '<div class="updated" style="border-color: #0085ba;"><p>' . __('Ultimate Member Setup Error: Account page can not be a child page.','ultimate-member') . '</p></div>';
}
}
}
do_action('um_admin_after_main_notices');
}
}
/***
*** @localization notice
***/
function localize_note() {
$locale = get_option('WPLANG');
if ( !$locale ) return;
if ( strstr( $locale, 'en_' ) ) return; // really, english!
if ( file_exists( WP_LANG_DIR . '/plugins/ultimatemember-' . $locale . '.mo' ) ) return;
if ( isset( UM()->available_languages[ $locale ] ) ) {
$download_uri = add_query_arg('um_adm_action', 'um_language_downloader');
$hide_locale_notice = get_option('um_hide_locale_notice');
if ( !$hide_locale_notice ) {
echo '<div class="updated" style="border-color: #0085ba;"><p>';
echo sprintf(__('Your site language is <strong>%1$s</strong>. Good news! Ultimate Member is already available in <strong>%2$s language</strong>. <a href="%3$s">Download the translation</a> files and start using the plugin in your language now. <a href="%4$s">Hide this notice</a>','ultimate-member'), $locale, UM()->available_languages[$locale], $download_uri, add_query_arg('um_adm_action', 'um_hide_locale_notice') );
echo '</p></div>';
}
} else {
$hide_locale_notice = get_option('um_hide_locale_notice');
if ( !$hide_locale_notice ) {
echo '<div class="updated" style="border-color: #0085ba;"><p>';
echo sprintf(__('Ultimate Member has not yet been translated to your langeuage: <strong>%1$s</strong>. If you have translated the plugin you need put these files <code>ultimatemember-%1$s.po and ultimatemember-%1$s.mo</code> in <strong>/wp-content/languages/plugins/</strong> for the plugin to be translated in your language. <a href="%2$s">Hide this notice</a>','ultimate-member'), $locale, add_query_arg('um_adm_action', 'um_hide_locale_notice') );
echo '</p></div>';
}
}
}
/***
*** @updating users
***/
function show_update_messages(){
if ( !isset($_REQUEST['update']) ) return;
$update = $_REQUEST['update'];
switch($update) {
case 'confirm_delete':
$confirm_uri = admin_url('users.php?' . http_build_query(array(
'um_adm_action' => 'delete_users',
'user' => array_map('intval', (array) $_REQUEST['user']),
'confirm' => 1
)));
$users = '';
if( isset( $_REQUEST['user'] ) ){
foreach( $_REQUEST['user'] as $user_id ) {
$user = get_userdata( $user_id );
$users .= '#' . $user_id . ': ' . $user->user_login . '<br />';
}
}
$ignore = admin_url('users.php');
$messages[0]['err_content'] = sprintf(__('Are you sure you want to delete the selected user(s)? The following users will be deleted: <p>%s</p> <strong>This cannot be undone!</strong>','ultimate-member'), $users);
$messages[0]['err_content'] .= '<p><a href="'. esc_html( $confirm_uri ) .'" class="button-primary">' . __('Remove','ultimate-member') . '</a>&nbsp;&nbsp;<a href="'.$ignore.'" class="button">' . __('Undo','ultimate-member') . '</a></p>';
break;
case 'language_updated':
$messages[0]['content'] = __('Your translation files have been updated successfully.','ultimate-member');
break;
case 'purged_temp':
$messages[0]['content'] = __('Your temp uploads directory is now clean.','ultimate-member');
break;
case 'cleared_cache':
$messages[0]['content'] = __('Your user cache is now removed.','ultimate-member');
break;
case 'form_duplicated':
$messages[0]['content'] = __('The form has been duplicated successfully.','ultimate-member');
break;
case 'user_updated':
$messages[0]['content'] = __('User has been updated.','ultimate-member');
break;
case 'users_updated':
$messages[0]['content'] = __('Users have been updated.','ultimate-member');
break;
case 'users_role_updated':
$messages[0]['content'] = __('Changed roles.','ultimate-member');
break;
case 'err_users_updated':
$messages[0]['err_content'] = __('Super administrators cannot be modified.','ultimate-member');
$messages[1]['content'] = __('Other users have been updated.','ultimate-member');
}
if ( !empty( $messages ) ) {
foreach( $messages as $message ) {
if ( isset($message['err_content'])) {
echo '<div class="error"><p>' . $message['err_content'] . '</p></div>';
} else {
echo '<div class="updated" style="border-color: #0085ba;"><p>' . $message['content'] . '</p></div>';
}
}
}
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,73 @@
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Upgrade' ) ) {
/**
* This class handles all functions that changes data structures and moving files
*/
class Admin_Upgrade {
var $update_versions;
var $packages_dir;
function __construct() {
$this->packages_dir = plugin_dir_path( __FILE__ ).'packages/';
$um_last_version_upgrade = get_option( 'um_last_version_upgrade' );
if ( ! $um_last_version_upgrade || version_compare( $um_last_version_upgrade, ultimatemember_version, '<' ) )
add_action( 'admin_init', array( $this, 'packages' ), 10 );
}
/**
* Load packages
*/
public function packages() {
$this->set_update_versions();
$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;
foreach ( $this->update_versions as $update_version ) {
if ( version_compare( $update_version, $um_last_version_upgrade, '<=' ) )
continue;
if ( version_compare( $update_version, ultimatemember_version, '>' ) )
continue;
$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 );
}
}
}
/**
* Parse packages dir for packages files
*/
function set_update_versions() {
$update_versions = array();
$handle = opendir( $this->packages_dir );
while ( false !== ( $filename = readdir( $handle ) ) ) {
if ( $filename != '.' && $filename != '..' )
$update_versions[] = preg_replace( '/(.*?)\.php/i', '$1', $filename );
}
closedir( $handle );
sort( $update_versions );
$this->update_versions = $update_versions;
}
}
}
+295
View File
@@ -0,0 +1,295 @@
<?php
namespace um\admin\core;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Users' ) ) {
class Admin_Users {
function __construct() {
$this->custom_role = 'um_role';
add_action( 'restrict_manage_users', array( &$this, 'restrict_manage_users' ) );
add_filter( 'user_row_actions', array( &$this, 'user_row_actions' ), 10, 2 );
add_filter( 'pre_user_query', array( &$this, 'sort_by_newest' ) );
add_filter( 'pre_user_query', array( &$this, 'filter_users_by_status' ) );
add_filter( 'views_users', array( &$this, 'add_status_links' ) );
add_action( 'admin_init', array( &$this, 'um_bulk_users_edit' ), 9 );
}
/**
* Add UM Bulk actions to Users List Table
*
*/
function restrict_manage_users() { ?>
<div style="float:right;margin:0 4px">
<label class="screen-reader-text" for="um_bulk_action"><?php _e( 'UM Action', 'ultimate-member' ); ?></label>
<select name="um_bulk_action[]" id="um_bulk_action" class="" style="width: 200px">
<option value="0"><?php _e( 'UM Action', 'ultimate-member' ); ?></option>
<?php echo $this->get_bulk_admin_actions(); ?>
</select>
<input name="um_bulkedit" id="um_bulkedit" class="button" value="<?php _e( 'Apply', 'ultimate-member' ); ?>" type="submit" />
</div>
<?php if ( ! empty( $_REQUEST['status'] ) ) { ?>
<input type="hidden" name="status" id="um_status" value="<?php echo esc_attr( $_REQUEST['status'] );?>"/>
<?php }
}
/**
* Get UM bulk actions HTML
*
* @return string
*/
function get_bulk_admin_actions() {
$actions = apply_filters( 'um_admin_bulk_user_actions_hook', array(
'um_approve_membership' => array(
'label' => __( 'Approve Membership', 'ultimate-member' )
),
'um_reject_membership' => array(
'label' => __( 'Reject Membership', 'ultimate-member' )
),
'um_put_as_pending' => array(
'label' => __( 'Put as Pending Review', 'ultimate-member' )
),
'um_resend_activation' => array(
'label' => __( 'Resend Activation E-mail', 'ultimate-member' )
),
'um_deactivate' => array(
'label' => __( 'Deactivate', 'ultimate-member' )
),
'um_reenable' => array(
'label' => __( 'Reactivate', 'ultimate-member' )
)
) );
$output = '';
foreach ( $actions as $id => $action_data ) {
$output .= '<option value="' . $id . '" '. disabled( isset( $arr['disabled'] ), true, false ) . '>' . $action_data['label'] . '</option>';
}
return $output;
}
/**
* Custom row actions for users page
*
* @param array $actions
* @param $user_object \WP_User
* @return array
*/
function user_row_actions( $actions, $user_object ) {
$user_id = $user_object->ID;
$actions['frontend_profile'] = "<a class='' href='" . UM()->user()->get_profile_url( $user_id ) . "'>" . __( 'View profile', 'ultimate-member' ) . "</a>";
$submitted = get_user_meta( $user_id, 'submitted', true );
if ( ! empty( $submitted ) )
$actions['view_info'] = '<a href="#" data-modal="UM_preview_registration" data-modal-size="smaller" data-dynamic-content="um_admin_review_registration" data-arg1="' . $user_id . '" data-arg2="edit_registration">' . __( 'Info', 'ultimate-member' ) . '</a>';
$actions = apply_filters( 'um_admin_user_row_actions', $actions, $user_id );
return $actions;
}
/**
* Change default sorting at WP Users list table
*
* @param $query
* @return mixed
*/
function sort_by_newest( $query ) {
global $pagenow;
if ( is_admin() && $pagenow == 'users.php' ) {
if ( ! isset( $_REQUEST['orderby'] ) ) {
$query->query_vars["order"] = 'desc';
$query->query_orderby = " ORDER BY user_registered " . ( $query->query_vars["order"] == "desc" ? "desc " : "asc " ); //set sort order
}
}
return $query;
}
/**
* Filter WP users by UM Status
*
* @param $query
* @return mixed
*/
function filter_users_by_status( $query ) {
global $wpdb, $pagenow;
if ( is_admin() && $pagenow == 'users.php' && ! empty( $_GET['status'] ) ) {
$status = urldecode( $_GET['status'] );
if ( $status == 'needs-verification' ) {
$query->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = '_um_verified'
AND {$wpdb->usermeta}.meta_value = 'pending')",
$query->query_where
);
} else {
$query->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = 'account_status'
AND {$wpdb->usermeta}.meta_value = '{$status}')",
$query->query_where
);
}
}
return $query;
}
/**
* Add status links to WP Users List Table
*
* @param $views
* @return array|mixed|void
*/
function add_status_links( $views ) {
remove_filter( 'pre_user_query', array( &$this, 'filter_users_by_status' ) );
$old_views = $views;
$views = array();
if ( ! isset( $_REQUEST['role'] ) && ! isset( $_REQUEST['status'] ) ) {
$views['all'] = '<a href="' . admin_url( 'users.php' ) . '" class="current">All <span class="count">(' . UM()->query()->count_users() . ')</span></a>';
} else {
$views['all'] = '<a href="' . admin_url( 'users.php' ) . '">All <span class="count">(' . UM()->query()->count_users() . ')</span></a>';
}
$status = array(
'approved' => __( 'Approved', 'ultimate-member' ),
'awaiting_admin_review' => __( 'Pending review', 'ultimate-member' ),
'awaiting_email_confirmation' => __( 'Waiting e-mail confirmation', 'ultimate-member' ),
'inactive' => __( 'Inactive', 'ultimate-member' ),
'rejected' => __( 'Rejected', 'ultimate-member' )
);
UM()->query()->count_users_by_status( 'unassigned' );
foreach ( $status as $k => $v ) {
if ( isset( $_REQUEST['status'] ) && $_REQUEST['status'] == $k ) {
$current = 'class="current"';
} else {
$current = '';
}
$views[$k] = '<a href="' . admin_url( 'users.php' ) . '?status=' . $k . '" ' . $current . '>'. $v . ' <span class="count">('.UM()->query()->count_users_by_status( $k ).')</span></a>';
}
$views = apply_filters( 'um_admin_views_users', $views );
// remove all filters
unset( $old_views['all'] );
// add separator
$views['subsep'] = '<span></span>';
// merge views
foreach ( $old_views as $key => $view ) {
$views[ $key ] = $view;
}
return $views;
}
/***
*** @Bulk user editing actions
***/
function um_bulk_users_edit() {
$admin_err = 0;
// bulk edit users
if ( ! empty( $_REQUEST['users'] ) && ! empty( $_REQUEST['um_bulkedit'] ) && ! empty( $_REQUEST['um_bulk_action'] ) ) {
if ( ! current_user_can( 'edit_users' ) )
wp_die( __( 'You do not have enough permissions to do that.', 'ultimate-member' ) );
check_admin_referer( 'bulk-users' );
$users = $_REQUEST['users'];
$bulk_action = current( array_filter( $_REQUEST['um_bulk_action'] ) );
foreach ( $users as $user_id ) {
UM()->user()->set( $user_id );
if ( ! um_user( 'super_admin' ) ) {
do_action( "um_admin_user_action_hook", $bulk_action );
do_action( "um_admin_user_action_{$bulk_action}_hook" );
} else {
$admin_err = 1;
}
}
// Finished. redirect now
if ( $admin_err == 0 ) {
$uri = $this->set_redirect_uri( admin_url( 'users.php' ) );
$uri = add_query_arg( 'update', 'users_updated', $uri );
wp_redirect( $uri );
exit;
} else {
wp_redirect( admin_url( 'users.php?update=err_users_updated' ) );
exit;
}
} else if ( ! empty( $_REQUEST['um_bulkedit'] ) ) {
$uri = $this->set_redirect_uri( admin_url( 'users.php' ) );
wp_redirect( $uri );
exit;
}
}
/**
* Sets redirect URI after bulk action
*
* @param string $uri
* @return string
*/
function set_redirect_uri( $uri ) {
if ( ! empty( $_REQUEST['s'] ) )
$uri = add_query_arg( 's', $_REQUEST['s'], $uri );
if ( ! empty( $_REQUEST['status'] ) )
$uri = add_query_arg( 'status', $_REQUEST['status'], $uri );
return $uri;
}
}
}
@@ -0,0 +1,192 @@
<?php
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'] ) );
} else {
$redirect = get_admin_url(). 'admin.php?page=ultimatemember';
}
//remove extra query arg
if ( !empty( $_GET['_wp_http_referer'] ) ) {
do_action( 'wp_client_redirect', remove_query_arg( array( '_wp_http_referer', '_wpnonce'), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
exit;
}
$order_by = 'u.user_registered';
if ( isset( $_GET['orderby'] ) ) {
switch( $_GET['orderby'] ) {
case 'username' :
$order_by = 'u.user_login';
break;
case 'nickname' :
$order_by = 'u.user_nicename';
break;
case 'email' :
$order_by = 'u.user_email';
break;
}
}
$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' );
class UM_Emails_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();
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' );
parent::__construct( $args );
}
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 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 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 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 set_actions( $args = array() ) {
$this->actions = $args;
return $this;
}
function get_actions() {
return $this->actions;
}
function set_bulk_actions( $args = array() ) {
$this->bulk_actions = $args;
return $this;
}
function get_bulk_actions() {
return $this->bulk_actions;
}
function column_email( $item ) {
$active = um_get_option( $item['key'] . '_on' );
if ( $active === '' )
$active = ! empty( $item['default_active'] );
return '<span class="dashicons um-notification-status ' . ( ! empty( $active ) ? 'um-notification-is-active dashicons-yes' : 'dashicons-no-alt' ) . '"></span><a href="' . add_query_arg( array( 'email' => $item['key'] ) ) . '"><strong>'. $item['title'] . '</strong></a>';
}
function column_recipients( $item ) {
if ( $item['recipient'] == 'admin' )
return um_get_option( 'admin_email' );
else
return __( 'Member', 'ultimate-member' );
}
function column_configure( $item ) {
return '<a class="button um-email-configure" href="' . add_query_arg( array( 'email' => $item['key'] ) ) . '"><span class="dashicons dashicons-admin-generic"></span></a>';
}
function wpc_set_pagination_args( $attr = array() ) {
$this->set_pagination_args( $attr );
}
}
$ListTable = new UM_Emails_List_Table( array(
'singular' => __( 'Email Notification', 'ultimate-member' ),
'plural' => __( 'Email Notifications', 'ultimate-member' ),
'ajax' => false
));
$per_page = 20;
$paged = $ListTable->get_pagenum();
$ListTable->set_columns( array(
'email' => __( 'Email', 'ultimate-member' ),
'recipients' => __( 'Recipient(s)', 'ultimate-member' ),
'configure' => '',
) );
$emails = UM()->config()->email_notifications;
$ListTable->prepare_items();
$ListTable->items = $emails;
$ListTable->wpc_set_pagination_args( array( 'total_items' => count( $emails ), 'per_page' => $per_page ) ); ?>
<form action="" method="get" name="um-settings-emails" id="um-settings-emails">
<input type="hidden" name="page" value="um_options" />
<input type="hidden" name="tab" value="email" />
<?php if ( ! empty( $_GET['section'] ) ) { ?>
<input type="hidden" name="section" value="<?php echo $_GET['section'] ?>" />
<?php }
$ListTable->display(); ?>
</form>
@@ -0,0 +1,366 @@
<?php
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'] ) );
} else {
$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'];
}
if ( ! count( $role_keys ) )
um_js_redirect( $redirect );
$um_roles = get_option( 'um_roles' );
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;
}
delete_option( "um_role_{$role_key}_meta" );
$role_keys[$k] = 'um_' . $role_key;
}
//set for users with deleted roles role "Subscriber"
$args = array(
'blog_id' => get_current_blog_id(),
'role__in' => $role_keys,
'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 ( $role_keys 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' ) );
}
}
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 );
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;
}
delete_option( "um_role_{$role_key}_meta" );
}
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'] ) ) );
$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' );
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();
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' );
parent::__construct( $args );
}
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 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 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 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 set_actions( $args = array() ) {
$this->actions = $args;
return $this;
}
function get_actions() {
return $this->actions;
}
function set_bulk_actions( $args = array() ) {
$this->bulk_actions = $args;
return $this;
}
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_title( $item ) {
$actions = array();
$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( $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'] . '">'. ( ! empty( $item['_um_is_custom'] ) ? 'UM ' : '' ) . $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_core( $item ) {
if ( ! empty( $item['_um_is_custom'] ) ) {
echo '<span class="um-adm-ico um-admin-tipsy-n" title="' . __( 'UM Custom Role', 'ultimate-member' ) . '"><i class="um-faicon-check"></i></span>';
} else {
echo '&mdash;';
}
}
function column_admin_access( $item ) {
if ( ! empty( $item['_um_can_access_wpadmin'] ) ) {
echo '<span class="um-adm-ico um-admin-tipsy-n" title="' . __( 'This role can access the WordPress backend', 'ultimate-member' ).'"><i class="um-faicon-check"></i></span>';
} else {
echo __( 'No', 'ultimate-member' );
}
}
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
));
$per_page = 20;
$paged = $ListTable->get_pagenum();
$ListTable->set_bulk_actions( array(
'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' ),
) );
$ListTable->set_sortable_columns( array(
'title' => 'title'
) );
$users_count = count_users();
$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 ) {
$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;
$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 );
}
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'];
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;
}
$ListTable->prepare_items();
$ListTable->items = $roles;
$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>
<?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>
</div>
+27
View File
@@ -0,0 +1,27 @@
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* This populates all existing UM users with meta_key `last_login` as `user_registered` if the meta key doesn't exist.
* Target Version: 1.3.39
*/
global $wpdb;
$wpdb->query('INSERT INTO '.$wpdb->usermeta.'(user_id, meta_key, meta_value)
SELECT uu.ID, "_um_last_login", uu.user_registered
FROM '.$wpdb->users.' AS uu
WHERE
uu.ID NOT IN(
SELECT user_id FROM '.$wpdb->usermeta.'
WHERE meta_key = "_um_last_login"
GROUP BY user_id
)'
);
?>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,87 @@
<?php
/***
*** @Put status handler in modal
***/
add_action('um_admin_field_modal_header', 'um_admin_add_message_handlers');
function um_admin_add_message_handlers(){ ?><div class="um-admin-error-block"></div><div class="um-admin-success-block"></div> <?php }
/***
*** @Footer of modal
***/
add_action('um_admin_field_modal_footer', 'um_admin_add_conditional_support', 10, 4);
function um_admin_add_conditional_support( $form_id, $field_args, $in_edit, $edit_array ){
$metabox = UM()->metabox();
if ( isset( $field_args['conditional_support'] ) && $field_args['conditional_support'] == 0 )
return;
?>
<div class="um-admin-btn-toggle">
<?php if ( $in_edit ) { $metabox->in_edit = true; $metabox->edit_array = $edit_array; ?>
<a href="#"><i class="um-icon-plus"></i><?php _e('Manage conditional fields support'); ?></a> <?php UM()->tooltip( __( 'Here you can setup conditional logic to show/hide this field based on specific fields value or conditions', 'ultimate-member' ) ); ?>
<?php } else { ?>
<a href="#"><i class="um-icon-plus"></i><?php _e('Add conditional fields support'); ?></a> <?php UM()->tooltip( __( 'Here you can setup conditional logic to show/hide this field based on specific fields value or conditions', 'ultimate-member' ) ); ?>
<?php } ?>
<div class="um-admin-btn-content">
<p class="um-admin-reset-conditions"><a href="#" class="button button-primary"><?php _e('Reset all rules','ultimate-member'); ?></a></p>
<div class="um-admin-clear"></div>
<?php
if ( isset( $edit_array['conditions'] ) ){
foreach( $edit_array['conditions'] as $k => $arr ) {
if ( $k == 0 ) $k = '';
?>
<div class="um-admin-cur-condition">
<?php $metabox->field_input( '_conditional_action' . $k, $form_id ); ?>
<?php $metabox->field_input( '_conditional_field' . $k , $form_id ); ?>
<?php $metabox->field_input( '_conditional_operator' . $k, $form_id ); ?>
<?php $metabox->field_input( '_conditional_value' . $k, $form_id ); ?>
<?php if ( $k == '' ) { ?>
<p><a href="#" class="um-admin-new-condition button um-admin-tipsy-n" title="Add new condition"><i class="um-icon-plus" style="margin-right:0!important"></i></a></p>
<?php } else { ?>
<p><a href="#" class="um-admin-remove-condition button um-admin-tipsy-n" title="Remove condition"><i class="um-icon-close" style="margin-right:0!important"></i></a></p>
<?php } ?>
<div class="um-admin-clear"></div>
</div>
<?php
}
} else {
?>
<div class="um-admin-cur-condition">
<?php $metabox->field_input( '_conditional_action', $form_id ); ?>
<?php $metabox->field_input( '_conditional_field', $form_id ); ?>
<?php $metabox->field_input( '_conditional_operator', $form_id ); ?>
<?php $metabox->field_input( '_conditional_value', $form_id ); ?>
<p><a href="#" class="um-admin-new-condition button um-admin-tipsy-n" title="Add new condition"><i class="um-icon-plus" style="margin-right:0!important"></i></a></p>
<div class="um-admin-clear"></div>
</div>
<?php } ?>
</div>
</div>
<?php
}
@@ -0,0 +1,43 @@
<?php
/***
*** @Does an action to user asap
***/
add_action('um_admin_user_action_hook', 'um_admin_user_action_hook');
function um_admin_user_action_hook( $action ){
switch ( $action ) {
default:
do_action("um_admin_custom_hook_{$action}", UM()->user()->id );
break;
case 'um_put_as_pending':
UM()->user()->pending();
break;
case 'um_approve_membership':
case 'um_reenable':
UM()->user()->approve();
break;
case 'um_reject_membership':
UM()->user()->reject();
break;
case 'um_resend_activation':
UM()->user()->email_pending();
break;
case 'um_deactivate':
UM()->user()->deactivate();
break;
case 'um_delete':
if ( is_admin() )
wp_die('This action is not allowed in backend.','ultimate-member');
UM()->user()->delete();
break;
}
}
+226
View File
@@ -0,0 +1,226 @@
<?php
/**
*
* Add access settings to category
*
**/
/***
*** @add option for WPML
***/
add_filter( 'um_admin_access_settings_fields', 'um_admin_wpml_post_options', 10, 2 );
function um_admin_wpml_post_options( $fields, $data ) {
global $post;
if ( ! function_exists('icl_get_current_language') )
return $fields;
if ( empty( $post->post_type ) || $post->post_type != 'page' )
return $fields;
$fields[] = array(
'id' => '_um_wpml_user',
'type' => 'checkbox',
'label' => __( 'This is a translation of UM profile page?', 'ultimate-member' ),
'value' => ! empty( $data['_um_wpml_user'] ) ? $data['_um_wpml_user'] : 0
);
$fields[] = array(
'id' => '_um_wpml_account',
'type' => 'checkbox',
'label' => __( 'This is a translation of UM account page?', 'ultimate-member' ),
'value' => ! empty( $data['_um_wpml_account'] ) ? $data['_um_wpml_account'] : 0
);
return $fields;
}
/***
*** @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 $wpdb;
if ( !is_admin() || !current_user_can('manage_options') ) die();
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'um_cache_userdata_%'" );
$url = admin_url('admin.php?page=ultimatemember');
$url = add_query_arg('update','cleared_cache',$url);
exit( wp_redirect($url) );
}
/***
*** @purge temp
***/
add_action('um_admin_do_action__purge_temp', 'um_admin_do_action__purge_temp');
function um_admin_do_action__purge_temp( $action ){
if ( !is_admin() || !current_user_can('manage_options') ) die();
UM()->files()->remove_dir( UM()->files()->upload_temp );
$url = remove_query_arg('um_adm_action', UM()->permalinks()->get_current_url() );
$url = add_query_arg('update','purged_temp',$url);
exit( wp_redirect($url) );
}
/***
*** @duplicate form
***/
add_action('um_admin_do_action__duplicate_form', 'um_admin_do_action__duplicate_form');
function um_admin_do_action__duplicate_form( $action ) {
if ( !is_admin() || !current_user_can('manage_options') ) die();
if ( !isset($_REQUEST['post_id']) || !is_numeric( $_REQUEST['post_id'] ) ) die();
$post_id = $_REQUEST['post_id'];
$n = array(
'post_type' => 'um_form',
'post_title' => sprintf( __( 'Duplicate of %s', 'ultimate-member' ), get_the_title( $post_id ) ),
'post_status' => 'publish',
'post_author' => get_current_user_id(),
);
$n_id = wp_insert_post( $n );
$n_fields = get_post_custom( $post_id );
foreach ( $n_fields as $key => $value ) {
if ( $key == '_um_custom_fields' ) {
$the_value = unserialize( $value[0] );
} else {
$the_value = $value[0];
}
update_post_meta( $n_id, $key, $the_value );
}
delete_post_meta($n_id, '_um_core');
$url = admin_url('edit.php?post_type=um_form');
$url = add_query_arg('update','form_duplicated',$url);
exit( wp_redirect( $url ) );
}
/***
*** @download a language remotely
***/
add_action('um_admin_do_action__um_language_downloader', 'um_admin_do_action__um_language_downloader');
function um_admin_do_action__um_language_downloader( $action ){
if ( !is_admin() || !current_user_can('manage_options') ) die();
$locale = get_option('WPLANG');
if ( !$locale ) return;
if ( !isset( UM()->available_languages[$locale] ) ) return;
$path = UM()->files()->upload_basedir;
$path = str_replace('/uploads/ultimatemember','',$path);
$path = $path . '/languages/plugins/';
$path = str_replace('//','/',$path);
$remote = 'https://ultimatemember.com/wp-content/languages/plugins/ultimatemember-' . $locale . '.po';
$remote2 = 'https://ultimatemember.com/wp-content/languages/plugins/ultimatemember-' . $locale . '.mo';
$remote_tmp = download_url( $remote, $timeout = 300 );
copy( $remote_tmp, $path . 'ultimatemember-' . $locale . '.po' );
unlink( $remote_tmp );
$remote2_tmp = download_url( $remote2, $timeout = 300 );
copy( $remote2_tmp, $path . 'ultimatemember-' . $locale . '.mo' );
unlink( $remote2_tmp );
$url = remove_query_arg('um_adm_action', UM()->permalinks()->get_current_url() );
$url = add_query_arg('update','language_updated',$url);
exit( wp_redirect($url) );
}
/***
*** @Action to hide notices in admin
***/
add_action('um_admin_do_action__um_hide_locale_notice', 'um_admin_do_action__hide_notice');
add_action('um_admin_do_action__um_can_register_notice', 'um_admin_do_action__hide_notice');
add_action('um_admin_do_action__um_hide_exif_notice', 'um_admin_do_action__hide_notice');
function um_admin_do_action__hide_notice( $action ){
if ( !is_admin() || !current_user_can('manage_options') ) die();
update_option( $action, 1 );
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_update_option( '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_update_option( 'um_allow_tracking', 0 );
update_option('um_tracking_notice', 1 );
exit( wp_redirect( remove_query_arg('um_adm_action') ) );
}
/***
*** @various user actions
***/
add_action('um_admin_do_action__user_action', 'um_admin_do_action__user_action');
function um_admin_do_action__user_action( $action ){
if ( !is_admin() || !current_user_can( 'edit_users' ) ) die();
if ( !isset( $_REQUEST['sub'] ) ) die();
if ( !isset($_REQUEST['user_id']) ) die();
um_fetch_user( $_REQUEST['user_id'] );
$subaction = $_REQUEST['sub'];
do_action("um_admin_user_action_hook", $subaction);
do_action("um_admin_user_action_{$subaction}_hook");
um_reset_user();
wp_redirect( add_query_arg( 'update', 'user_updated', admin_url('?page=ultimatemember') ) );
exit;
}
/***
*** @Add any custom links to plugin page
***/
$prefix = is_network_admin() ? 'network_admin_' : '';
add_filter( "{$prefix}plugin_action_links_" . um_plugin, 'ultimatemember_plugin_links' );
function ultimatemember_plugin_links( $links ) {
$more_links[] = '<a href="http://docs.ultimatemember.com/">' . __('Docs','ultimate-member') . '</a>';
$more_links[] = '<a href="'.admin_url().'admin.php?page=um_options">' . __('Settings','ultimate-member') . '</a>';
$links = $more_links + $links;
return $links;
}
@@ -0,0 +1,128 @@
<?php
/***
*** @modify field args just before it is saved into form
***/
add_filter('um_admin_pre_save_field_to_form', 'um_admin_pre_save_field_to_form', 1 );
function um_admin_pre_save_field_to_form( $array ){
unset( $array['conditions'] );
if ( isset($array['conditional_field']) && !empty( $array['conditional_action'] ) && !empty( $array['conditional_operator'] ) ) {
$array['conditions'][] = array( $array['conditional_action'], $array['conditional_field'], $array['conditional_operator'], $array['conditional_value'] );
}
if ( isset($array['conditional_field1']) && !empty( $array['conditional_action1'] ) && !empty( $array['conditional_operator1'] ) ) {
$array['conditions'][] = array( $array['conditional_action1'], $array['conditional_field1'], $array['conditional_operator1'], $array['conditional_value1'] );
}
if ( isset($array['conditional_field2']) && !empty( $array['conditional_action2'] ) && !empty( $array['conditional_operator2'] ) ) {
$array['conditions'][] = array( $array['conditional_action2'], $array['conditional_field2'], $array['conditional_operator2'], $array['conditional_value2'] );
}
if ( isset($array['conditional_field3']) && !empty( $array['conditional_action3'] ) && !empty( $array['conditional_operator3'] ) ) {
$array['conditions'][] = array( $array['conditional_action3'], $array['conditional_field3'], $array['conditional_operator3'], $array['conditional_value3'] );
}
if ( isset($array['conditional_field4']) && !empty( $array['conditional_action4'] ) && !empty( $array['conditional_operator4'] ) ) {
$array['conditions'][] = array( $array['conditional_action4'], $array['conditional_field4'], $array['conditional_operator4'], $array['conditional_value4'] );
}
return $array;
}
/***
*** @Some fields may require extra fields before saving
***/
add_filter('um_admin_pre_save_fields_hook', 'um_admin_pre_save_fields_hook', 1 );
function um_admin_pre_save_fields_hook( $array ){
extract( $array );
$fields_without_metakey = array('block','shortcode','spacing','divider','group');
$fields_without_metakey = apply_filters('um_fields_without_metakey', $fields_without_metakey );
$fields = UM()->query()->get_attr('custom_fields', $form_id);
$count = 1;
if ( isset( $fields ) && !empty( $fields) ) $count = count($fields)+1;
// set unique meta key
if ( in_array( $field_type, $fields_without_metakey ) && !isset($array['post']['_metakey']) ) {
$array['post']['_metakey'] = "um_{$field_type}_{$form_id}_{$count}";
}
// set position
if ( !isset( $array['post']['_position'] ) ) {
$array['post']['_position'] = $count;
}
return $array;
}
/***
*** @Apply a filter to handle errors for field updating in backend
***/
add_filter('um_admin_field_update_error_handling', 'um_admin_field_update_error_handling', 1, 2 );
function um_admin_field_update_error_handling( $errors, $array ){
extract( $array );
$field_attr = UM()->builtin()->get_core_field_attrs( $field_type );
if ( isset( $field_attr['validate'] ) ) {
$validate = $field_attr['validate'];
foreach ( $validate as $post_input => $arr ) {
$mode = $arr['mode'];
switch ( $mode ) {
case 'numeric':
if ( !empty( $array['post'][$post_input] ) && !is_numeric( $array['post'][$post_input] ) ){
$errors[$post_input] = $validate[$post_input]['error'];
}
break;
case 'unique':
if ( !isset( $array['post']['edit_mode'] ) ) {
if ( UM()->builtin()->unique_field_err( $array['post'][$post_input] ) ) {
$errors[$post_input] = UM()->builtin()->unique_field_err( $array['post'][$post_input] );
}
}
break;
case 'required':
if ( $array['post'][$post_input] == '' )
$errors[$post_input] = $validate[$post_input]['error'];
break;
case 'range-start':
if ( UM()->builtin()->date_range_start_err( $array['post'][$post_input] ) && $array['post']['_range'] == 'date_range' )
$errors[$post_input] = UM()->builtin()->date_range_start_err( $array['post'][$post_input] );
break;
case 'range-end':
if ( UM()->builtin()->date_range_end_err( $array['post'][$post_input], $array['post']['_range_start'] ) && $array['post']['_range'] == 'date_range' )
$errors[$post_input] = UM()->builtin()->date_range_end_err( $array['post'][$post_input], $array['post']['_range_start'] );
break;
}
}
}
return $errors;
}
/***
*** @Filter validation types on loop
****/
add_filter('um_builtin_validation_types_continue_loop', 'um_builtin_validation_types_continue_loop', 1, 4);
function um_builtin_validation_types_continue_loop( $break, $key, $form_id, $field_array ){
// show unique username validation only for user_login field
if ( isset( $field_array['metakey'] ) && $field_array['metakey'] == 'user_login' && $key !== 'unique_username' ){
return false;
}
return $break;
}