- added PHPDocs;

- small fixes and code optimization;
This commit is contained in:
nikitozzzzzzz
2018-03-19 16:31:49 +02:00
parent 70e33dcacf
commit 68a18b02e9
55 changed files with 8603 additions and 8097 deletions
+1 -1
View File
@@ -156,7 +156,7 @@ if ( ! class_exists( 'Admin_Columns' ) ) {
$page_id = UM()->options()->get( UM()->options()->get_core_page_id( $page_key ) );
if ( $page_id == $post->ID ) {
$post_states['um_core_page_' . $page_key] = sprintf( 'UM %s', $page_value['title'] );
$post_states[ 'um_core_page_' . $page_key ] = sprintf( 'UM %s', $page_value['title'] );
}
}
@@ -5,6 +5,12 @@ namespace um\admin\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Forms_Settings' ) ) {
/**
* Class Admin_Forms_Settings
* @package um\admin\core
*/
class Admin_Forms_Settings extends Admin_Forms {
/**
+100 -71
View File
@@ -5,82 +5,111 @@ namespace um\admin\core;
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.'),
);
}
return $messages;
}
/***
*** @gettext filters
***/
function gettext($translation, $text, $domain) {
global $post;
//$screen = get_current_screen();
if ( isset( $post->post_type ) && UM()->admin()->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' );
}
}
/**
* Class Admin_Functions
* @package um\admin\core
*/
class Admin_Functions {
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;
}
/**
* Admin_Functions constructor.
*/
function __construct() {
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
*
* @param array $messages
*
* @return array
*/
function post_updated_messages( $messages ) {
global $post_ID;
$post_type = get_post_type( $post_ID );
if ( $post_type == 'um_form' ) {
$messages['um_form'] = array(
0 => '',
1 => __( 'Form updated.', 'ultimate-member' ),
2 => __( 'Custom field updated.', 'ultimate-member' ),
3 => __( 'Custom field deleted.', 'ultimate-member' ),
4 => __( 'Form updated.', 'ultimate-member' ),
5 => isset( $_GET['revision'] ) ? __( 'Form restored to revision.', 'ultimate-member' ) : false,
6 => __( 'Form created.', 'ultimate-member' ),
7 => __( 'Form saved.', 'ultimate-member' ),
8 => __( 'Form submitted.', 'ultimate-member' ),
9 => __( 'Form scheduled.', 'ultimate-member' ),
10 => __( 'Form draft updated.', 'ultimate-member' ),
);
}
return $messages;
}
/**
* Gettext filters
*
* @param $translation
* @param $text
* @param $domain
*
* @return string
*/
function gettext( $translation, $text, $domain ) {
global $post;
if ( isset( $post->post_type ) && UM()->admin()->is_plugin_post_type() ) {
$translations = get_translations_for_domain( $domain );
if ( $text == 'Publish' ) {
return $translations->translate( 'Create' );
} elseif ( $text == 'Move to Trash' ) {
return $translations->translate( 'Delete' );
}
}
return $translation;
}
/**
* Fix parent file for correct highlighting
*
* @param $parent_file
*
* @return string
*/
function parent_file( $parent_file ) {
global $current_screen;
$screen_id = $current_screen->id;
if ( strstr( $screen_id, 'um_' ) ) {
$parent_file = 'ultimatemember';
}
return $parent_file;
}
}
/**
* Boolean check if we're viewing UM backend
*
* @todo global for all admin classes
* @return bool
*/
function is_UM_admin_screen() {
global $current_screen;
$screen_id = $current_screen->id;
if ( is_admin() && ( strstr( $screen_id, 'ultimatemember') || strstr( $screen_id, 'um_') || strstr($screen_id, 'user') || strstr($screen_id, 'profile') ) )
return true;
return false;
}
}
}
+371 -298
View File
@@ -7,312 +7,385 @@ use \RecursiveDirectoryIterator;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Menu' ) ) {
class Admin_Menu {
function __construct() {
$this->slug = 'ultimatemember';
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[] = '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') );
}
/***
*** @secondary admin menu (after settings)
***/
function secondary_menu_items() {
add_submenu_page( $this->slug, __( 'Forms', 'ultimate-member' ), __( 'Forms', 'ultimate-member' ), '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()->options()->get( 'members_page' ) ) {
add_submenu_page( $this->slug, __( 'Member Directories', 'ultimate-member' ), __( 'Member Directories', 'ultimate-member' ), 'manage_options', 'edit.php?post_type=um_directory', '' );
}
/**
* UM hook
*
* @type action
* @title um_extend_admin_menu
* @description Extend UM menu
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_extend_admin_menu', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_extend_admin_menu', 'my_extend_admin_menu', 10 );
* function my_extend_admin_menu() {
* // your code here
* }
* ?>
*/
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;
}
/**
* Class Admin_Menu
* @package um\admin\core
*/
class Admin_Menu {
/**
* @var string
*/
var $pagehook;
/**
* Admin_Menu constructor.
*/
function __construct() {
$this->slug = 'ultimatemember';
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 );
}
/***
*** @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;
}
/**
* Change the admin footer text on UM admin pages
*
* @param $footer_text
*
* @return string
*/
public function admin_footer_text( $footer_text ) {
$current_screen = get_current_screen();
// Add the dashboard pages
$um_pages[] = 'toplevel_page_ultimatemember';
$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' ) ) {
ob_start(); ?>
<a href="https://wordpress.org/support/plugin/ultimate-member/reviews/?filter=5" target="_blank" class="um-admin-rating-link" data-rated="<?php esc_attr_e( 'Thanks :)', 'ultimate-member' ) ?>">
&#9733;&#9733;&#9733;&#9733;&#9733;
</a>
<?php $link = ob_get_clean();
ob_start();
printf( __( 'If you like Ultimate Member please consider leaving a %s review. It will help us to grow the plugin and make it more popular. Thank you.', 'ultimate-member' ), $link ) ?>
<script type="text/javascript">
jQuery( 'a.um-admin-rating-link' ).click(function() {
jQuery.post(
'<?php echo UM()->get_ajax_route( get_class( $this ), 'ultimatemember_rated' ) ?>',
{}
);
jQuery(this).parent().text( jQuery( this ).data( 'rated' ) );
});
</script>
<?php $footer_text = ob_get_clean();
}
}
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', 'ultimate-member' ), __( 'Ultimate Member', 'ultimate-member' ), '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', 'ultimate-member' ), __( 'Dashboard', 'ultimate-member' ), 'manage_options', $this->slug, array( &$this, 'admin_page' ) );
}
/**
* Secondary admin menu (after settings)
*/
function secondary_menu_items() {
add_submenu_page( $this->slug, __( 'Forms', 'ultimate-member' ), __( 'Forms', 'ultimate-member' ), '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()->options()->get( 'members_page' ) ) {
add_submenu_page( $this->slug, __( 'Member Directories', 'ultimate-member' ), __( 'Member Directories', 'ultimate-member' ), 'manage_options', 'edit.php?post_type=um_directory', '' );
}
/**
* UM hook
*
* @type action
* @title um_extend_admin_menu
* @description Extend UM menu
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_extend_admin_menu', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_extend_admin_menu', 'my_extend_admin_menu', 10 );
* function my_extend_admin_menu() {
* // your code here
* }
* ?>
*/
do_action( 'um_extend_admin_menu' );
}
/**
* Role page menu callback
*/
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', 'ultimate-member' ), '<span style="color: #00B9EB">' .__( 'Extensions', 'ultimate-member' ) . '</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
*
* @return bool
*/
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
*
* @return bool
*/
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
*
* @return bool
*/
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
*
* @param $directory
*
* @return float|int
*/
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() {
/***
*** @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">
$page = $_REQUEST['page'];
if ( $page == 'ultimatemember' && ! isset( $_REQUEST['um-addon'] ) ) {
<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 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>
<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 } elseif ( $page == 'ultimatemember-extensions' ) {
include_once UM()->admin()->templates_path . 'extensions.php';
<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
} elseif ( $page == 'ultimatemember-extensions' ) {
include_once UM()->admin()->templates_path . 'extensions.php';
}
}
}
}
}
File diff suppressed because it is too large Load Diff
+171 -163
View File
@@ -5,234 +5,242 @@ namespace um\admin\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Admin_Notices' ) ) {
class Admin_Notices {
function __construct() {
add_action('admin_init', array(&$this, 'create_languages_folder') );
/**
* Class Admin_Notices
* @package um\admin\core
*/
class Admin_Notices {
add_action('admin_notices', array(&$this, 'main_notices'), 1);
add_action('admin_notices', array(&$this, 'localize_note'), 2);
/**
* Admin_Notices constructor.
*/
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 );
}
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 );
/***
*** @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);
}
}
if ( ! file_exists( $path ) ) {
$old = umask(0);
@mkdir( $path, 0777, true );
umask( $old );
}
}
/**
* Show main notices
*/
function main_notices() {
function main_notices() {
if ( ! defined( 'DOING_AJAX' ) ) {
if ( ! defined( 'DOING_AJAX' ) ) {
$hide_exif_notice = get_option( 'um_hide_exif_notice' );
$hide_exif_notice = get_option( 'um_hide_exif_notice' );
if ( !extension_loaded('exif') && !$hide_exif_notice ) {
if ( !extension_loaded('exif') && !$hide_exif_notice ) {
echo '<div class="updated" style="border-color: #0085ba;"><p>';
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 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>';
echo '</p></div>';
}
}
// Regarding page setup
$pages = UM()->config()->permalinks;
if ( $pages && is_array( $pages ) ) {
// Regarding page setup
$pages = UM()->config()->permalinks;
if ( $pages && is_array( $pages ) ) {
$err = false;
$err = false;
foreach( $pages as $slug => $page_id ) {
foreach( $pages as $slug => $page_id ) {
$page = get_post( $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 ( !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 ( $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['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>';
}
}
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>';
}
}
}
}
/**
* UM hook
*
* @type action
* @title um_admin_after_main_notices
* @description Insert some content after main admin notices
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_after_main_notices', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_admin_after_main_notices', 'my_admin_after_main_notices', 10 );
* function my_admin_after_main_notices() {
* // your code here
* }
* ?>
*/
do_action( 'um_admin_after_main_notices' );
}
/**
* UM hook
*
* @type action
* @title um_admin_after_main_notices
* @description Insert some content after main admin notices
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_after_main_notices', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_admin_after_main_notices', 'my_admin_after_main_notices', 10 );
* function my_admin_after_main_notices() {
* // your code here
* }
* ?>
*/
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;
/**
* Localization notice
*/
function localize_note() {
$locale = get_option( 'WPLANG' );
if ( ! $locale || strstr( $locale, 'en_' ) ) {
return;
}
if ( file_exists( WP_LANG_DIR . '/plugins/ultimatemember-' . $locale . '.mo' ) ) {
return;
}
if ( isset( UM()->available_languages[ $locale ] ) ) {
$hide_locale_notice = get_option( 'um_hide_locale_notice' );
if ( $hide_locale_notice ) {
return;
}
$download_uri = add_query_arg('um_adm_action', 'um_language_downloader');
if ( isset( UM()->available_languages[ $locale ] ) ) {
$hide_locale_notice = get_option('um_hide_locale_notice');
if ( !$hide_locale_notice ) {
echo '<div class="updated" style="border-color: #0085ba;"><p>';
$download_uri = add_query_arg( 'um_adm_action', 'um_language_downloader' );
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 '<div class="updated" style="border-color: #0085ba;"><p>';
echo '</p></div>';
}
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 {
} else {
$hide_locale_notice = get_option('um_hide_locale_notice');
if ( !$hide_locale_notice ) {
echo '<div class="updated" style="border-color: #0085ba;"><p>';
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 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>';
echo '</p></div>';
}
}
}
}
}
/***
*** @updating users
***/
function show_update_messages(){
/**
* Updating users
*/
function show_update_messages() {
if ( !isset($_REQUEST['update']) ) return;
if ( ! isset( $_REQUEST['update'] ) ) {
return;
}
$update = $_REQUEST['update'];
switch($update) {
$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 = '';
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 />';
}
}
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');
$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>';
$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;
break;
case 'language_updated':
$messages[0]['content'] = __('Your translation files have been updated successfully.','ultimate-member');
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 '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 '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 '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 '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_updated':
$messages[0]['content'] = __( 'Users have been updated.', 'ultimate-member' );
break;
case 'users_role_updated':
$messages[0]['content'] = __('Changed roles.','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');
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>';
}
}
}
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
+57 -38
View File
@@ -5,22 +5,41 @@ namespace um\admin\core;
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' . DIRECTORY_SEPARATOR;
/**
* Class Admin_Upgrade
*
* This class handles all functions that changes data structures and moving files
*
* @package um\admin\core
*/
class Admin_Upgrade {
$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 );
}
/**
* @var
*/
var $update_versions;
/**
* @var string
*/
var $packages_dir;
/**
* Admin_Upgrade constructor.
*/
function __construct() {
$this->packages_dir = plugin_dir_path( __FILE__ ) . 'packages' . DIRECTORY_SEPARATOR;
$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 );
}
/**
@@ -54,35 +73,35 @@ if ( ! class_exists( 'Admin_Upgrade' ) ) {
}
/**
* Parse packages dir for packages files
*/
function set_update_versions() {
$update_versions = array();
$handle = opendir( $this->packages_dir );
if ( $handle ) {
while ( false !== ( $filename = readdir( $handle ) ) ) {
if ( $filename != '.' && $filename != '..' )
$update_versions[] = preg_replace( '/(.*?)\.php/i', '$1', $filename );
}
closedir( $handle );
/**
* Parse packages dir for packages files
*/
function set_update_versions() {
$update_versions = array();
$handle = opendir( $this->packages_dir );
if ( $handle ) {
while ( false !== ( $filename = readdir( $handle ) ) ) {
if ( $filename != '.' && $filename != '..' )
$update_versions[] = preg_replace( '/(.*?)\.php/i', '$1', $filename );
}
closedir( $handle );
usort( $update_versions, array( &$this, 'version_compare_sort' ) );
usort( $update_versions, array( &$this, 'version_compare_sort' ) );
$this->update_versions = $update_versions;
}
}
$this->update_versions = $update_versions;
}
}
/**
* Sort versions by version compare function
* @param $a
* @param $b
* @return mixed
*/
function version_compare_sort( $a, $b ) {
return version_compare( $a, $b );
}
/**
* Sort versions by version compare function
* @param $a
* @param $b
* @return mixed
*/
function version_compare_sort( $a, $b ) {
return version_compare( $a, $b );
}
}
}
}
+334 -324
View File
@@ -5,392 +5,402 @@ namespace um\admin\core;
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 }
}
/**
* Class Admin_Users
* @package um\admin\core
*/
class Admin_Users {
/**
* Get UM bulk actions HTML
*
* @return string
*/
function get_bulk_admin_actions() {
/**
* Admin_Users constructor.
*/
function __construct() {
/**
* UM hook
*
* @type filter
* @title um_admin_bulk_user_actions_hook
* @description Admin Users List Table bulk actions
* @input_vars
* [{"var":"$actions","type":"array","desc":"User List Table bulk actions"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_bulk_user_actions_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_admin_bulk_user_actions_hook', 'my_admin_bulk_user_actions', 10, 1 );
* function my_admin_bulk_user_actions( $actions ) {
* // your code here
* $actions['my-custom-bulk'] = array(
* 'label' => 'My Custom Bulk Action'
* );
* return $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' )
)
) );
$this->custom_role = 'um_role';
$output = '';
foreach ( $actions as $id => $action_data ) {
$output .= '<option value="' . $id . '" '. disabled( isset( $arr['disabled'] ), true, false ) . '>' . $action_data['label'] . '</option>';
}
return $output;
}
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 );
}
/**
* 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;
/**
* 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 }
}
$actions['frontend_profile'] = "<a class='' href='" . um_user_profile_url( $user_id ) . "'>" . __( 'View profile', 'ultimate-member' ) . "</a>";
/**
* Get UM bulk actions HTML
*
* @return string
*/
function get_bulk_admin_actions() {
$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>';
/**
* UM hook
*
* @type filter
* @title um_admin_bulk_user_actions_hook
* @description Admin Users List Table bulk actions
* @input_vars
* [{"var":"$actions","type":"array","desc":"User List Table bulk actions"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_bulk_user_actions_hook', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_admin_bulk_user_actions_hook', 'my_admin_bulk_user_actions', 10, 1 );
* function my_admin_bulk_user_actions( $actions ) {
* // your code here
* $actions['my-custom-bulk'] = array(
* 'label' => 'My Custom Bulk Action'
* );
* return $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' )
)
) );
/**
* UM hook
*
* @type filter
* @title um_admin_user_row_actions
* @description Admin views array
* @input_vars
* [{"var":"$actions","type":"array","desc":"User List Table actions"},
* {"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_user_row_actions', 'function_name', 10, 2 );
* @example
* <?php
* add_filter( 'um_admin_user_row_actions', 'my_admin_user_row_actions', 10, 2 );
* function my_admin_user_row_actions( $actions, $user_id ) {
* // your code here
* return $actions;
* }
* ?>
*/
$actions = apply_filters( 'um_admin_user_row_actions', $actions, $user_id );
return $actions;
}
$output = '';
foreach ( $actions as $id => $action_data ) {
$output .= '<option value="' . $id . '" '. disabled( isset( $arr['disabled'] ), true, false ) . '>' . $action_data['label'] . '</option>';
}
return $output;
}
/**
* 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;
}
/**
* 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;
/**
* Filter WP users by UM Status
*
* @param $query
* @return mixed
*/
function filter_users_by_status( $query ) {
global $wpdb, $pagenow;
$actions['frontend_profile'] = "<a class='' href='" . um_user_profile_url( $user_id ) . "'>" . __( 'View profile', 'ultimate-member' ) . "</a>";
if ( is_admin() && $pagenow == 'users.php' && ! empty( $_GET['status'] ) ) {
$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>';
$status = urldecode( $_GET['status'] );
/**
* UM hook
*
* @type filter
* @title um_admin_user_row_actions
* @description Admin views array
* @input_vars
* [{"var":"$actions","type":"array","desc":"User List Table actions"},
* {"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_user_row_actions', 'function_name', 10, 2 );
* @example
* <?php
* add_filter( 'um_admin_user_row_actions', 'my_admin_user_row_actions', 10, 2 );
* function my_admin_user_row_actions( $actions, $user_id ) {
* // your code here
* return $actions;
* }
* ?>
*/
$actions = apply_filters( 'um_admin_user_row_actions', $actions, $user_id );
if ( $status == 'needs-verification' ) {
$query->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
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 (
$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
);
}
$query->query_where
);
}
}
}
return $query;
}
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' ) );
/**
* 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();
$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>';
}
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' )
);
$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' );
UM()->query()->count_users_by_status( 'unassigned' );
foreach ( $status as $k => $v ) {
if ( isset( $_REQUEST['status'] ) && $_REQUEST['status'] == $k ) {
$current = 'class="current"';
} else {
$current = '';
}
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[$k] = '<a href="' . admin_url( 'users.php' ) . '?status=' . $k . '" ' . $current . '>'. $v . ' <span class="count">('.UM()->query()->count_users_by_status( $k ).')</span></a>';
}
/**
* UM hook
*
* @type filter
* @title um_admin_views_users
* @description Admin views array
* @input_vars
* [{"var":"$views","type":"array","desc":"User Views"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_views_users', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_admin_views_users', 'my_admin_views_users', 10, 1 );
* function my_admin_views_users( $views ) {
* // your code here
* return $views;
* }
* ?>
*/
$views = apply_filters( 'um_admin_views_users', $views );
/**
* UM hook
*
* @type filter
* @title um_admin_views_users
* @description Admin views array
* @input_vars
* [{"var":"$views","type":"array","desc":"User Views"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_views_users', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_admin_views_users', 'my_admin_views_users', 10, 1 );
* function my_admin_views_users( $views ) {
* // your code here
* return $views;
* }
* ?>
*/
$views = apply_filters( 'um_admin_views_users', $views );
// remove all filters
unset( $old_views['all'] );
// remove all filters
unset( $old_views['all'] );
// add separator
$views['subsep'] = '<span></span>';
// add separator
$views['subsep'] = '<span></span>';
// merge views
foreach ( $old_views as $key => $view ) {
$views[ $key ] = $view;
}
// merge views
foreach ( $old_views as $key => $view ) {
$views[ $key ] = $view;
}
return $views;
}
return $views;
}
/***
*** @Bulk user editing actions
***/
function um_bulk_users_edit() {
$admin_err = 0;
/**
* 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'] ) ) {
// 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' ) );
if ( ! current_user_can( 'edit_users' ) )
wp_die( __( 'You do not have enough permissions to do that.', 'ultimate-member' ) );
check_admin_referer( 'bulk-users' );
check_admin_referer( 'bulk-users' );
$users = $_REQUEST['users'];
$bulk_action = current( array_filter( $_REQUEST['um_bulk_action'] ) );
$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' ) ) {
foreach ( $users as $user_id ) {
UM()->user()->set( $user_id );
if ( ! um_user( 'super_admin' ) ) {
/**
* UM hook
*
* @type action
* @title um_admin_user_action_hook
* @description Action on bulk user action
* @input_vars
* [{"var":"$bulk_action","type":"string","desc":"Bulk Action"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_user_action_hook{$action}', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_admin_user_action_hook', 'my_admin_user_action', 10, 1 );
* function my_admin_user_action( $bulk_action ) {
* // your code here
* }
* ?>
*/
do_action( "um_admin_user_action_hook", $bulk_action );
/**
* UM hook
*
* @type action
* @title um_admin_user_action_hook
* @description Action on bulk user action
* @input_vars
* [{"var":"$bulk_action","type":"string","desc":"Bulk Action"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_user_action_hook{$action}', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_admin_user_action_hook', 'my_admin_user_action', 10, 1 );
* function my_admin_user_action( $bulk_action ) {
* // your code here
* }
* ?>
*/
do_action( "um_admin_user_action_hook", $bulk_action );
/**
* UM hook
*
* @type action
* @title um_admin_user_action_{$bulk_action}_hook
* @description Action on bulk user action
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_user_action_{$bulk_action}_hook', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_admin_user_action_{$bulk_action}_hook', 'my_admin_user_action', 10 );
* function my_admin_user_action() {
* // your code here
* }
* ?>
*/
do_action( "um_admin_user_action_{$bulk_action}_hook" );
/**
* UM hook
*
* @type action
* @title um_admin_user_action_{$bulk_action}_hook
* @description Action on bulk user action
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_user_action_{$bulk_action}_hook', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_admin_user_action_{$bulk_action}_hook', 'my_admin_user_action', 10 );
* function my_admin_user_action() {
* // your code here
* }
* ?>
*/
do_action( "um_admin_user_action_{$bulk_action}_hook" );
} else {
$admin_err = 1;
}
}
} else {
$admin_err = 1;
}
}
// Finished. redirect now
if ( $admin_err == 0 ) {
// Finished. redirect now
if ( $admin_err == 0 ) {
$uri = $this->set_redirect_uri( admin_url( 'users.php' ) );
$uri = add_query_arg( 'update', 'users_updated', $uri );
$uri = $this->set_redirect_uri( admin_url( 'users.php' ) );
$uri = add_query_arg( 'update', 'users_updated', $uri );
wp_redirect( $uri );
wp_redirect( $uri );
exit;
} else {
wp_redirect( admin_url( 'users.php?update=err_users_updated' ) );
exit;
}
exit;
} else {
wp_redirect( admin_url( 'users.php?update=err_users_updated' ) );
exit;
}
} else if ( ! empty( $_REQUEST['um_bulkedit'] ) ) {
} else if ( ! empty( $_REQUEST['um_bulkedit'] ) ) {
$uri = $this->set_redirect_uri( admin_url( 'users.php' ) );
wp_redirect( $uri );
exit;
$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 ) {
/**
* 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['s'] ) )
$uri = add_query_arg( 's', $_REQUEST['s'], $uri );
if ( ! empty( $_REQUEST['status'] ) )
$uri = add_query_arg( 'status', $_REQUEST['status'], $uri );
if ( ! empty( $_REQUEST['status'] ) )
$uri = add_query_arg( 'status', $_REQUEST['status'], $uri );
return $uri;
return $uri;
}
}
}
}
}
+82 -77
View File
@@ -3,88 +3,93 @@
if ( ! defined( 'ABSPATH' ) ) exit;
/***
*** @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();
/**
* Put status handler in modal
*/
function um_admin_add_message_handlers() {
?>
<div class="um-admin-error-block"></div>
<div class="um-admin-success-block"></div>
<?php
}
add_action( 'um_admin_field_modal_header', 'um_admin_add_message_handlers' );
if ( isset( $field_args['conditional_support'] ) && $field_args['conditional_support'] == 0 )
return;
/**
* Footer of modal
*
* @param $form_id
* @param $field_args
* @param $in_edit
* @param $edit_array
*/
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">
?>
<div class="um-admin-btn-toggle">
<?php if ( $in_edit ) { $metabox->in_edit = true; $metabox->edit_array = $edit_array; ?>
<?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 { ?>
<?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 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>
</div>
<?php
}
<?php
}
add_action( 'um_admin_field_modal_footer', 'um_admin_add_conditional_support', 10, 4 );
+138 -111
View File
@@ -3,100 +3,114 @@
if ( ! defined( 'ABSPATH' ) ) exit;
/***
*** @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['conditional_value'] = ! empty( $array['conditional_value'] ) ? $array['conditional_value'] : '';
$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['conditional_value1'] = ! empty( $array['conditional_value1'] ) ? $array['conditional_value1'] : '';
$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['conditional_value2'] = ! empty( $array['conditional_value2'] ) ? $array['conditional_value2'] : '';
$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['conditional_value3'] = ! empty( $array['conditional_value3'] ) ? $array['conditional_value3'] : '';
$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['conditional_value4'] = ! empty( $array['conditional_value4'] ) ? $array['conditional_value4'] : '';
$array['conditions'][] = array( $array['conditional_action4'], $array['conditional_field4'], $array['conditional_operator4'], $array['conditional_value4'] );
}
return $array;
/**
* Modify field args just before it is saved into form
*
* @param $array
*
* @return mixed
*/
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['conditional_value'] = ! empty( $array['conditional_value'] ) ? $array['conditional_value'] : '';
$array['conditions'][] = array( $array['conditional_action'], $array['conditional_field'], $array['conditional_operator'], $array['conditional_value'] );
}
/***
*** @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 );
/**
* UM hook
*
* @type filter
* @title um_fields_without_metakey
* @description Field Types without meta key
* @input_vars
* [{"var":"$types","type":"array","desc":"Field Types"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_fields_without_metakey', 'my_fields_without_metakey', 10, 1 );
* function my_fields_without_metakey( $types ) {
* // your code here
* return $types;
* }
* ?>
*/
$fields_without_metakey = apply_filters( 'um_fields_without_metakey', array(
'block',
'shortcode',
'spacing',
'divider',
'group'
) );
$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;
if ( isset($array['conditional_field1']) && !empty( $array['conditional_action1'] ) && !empty( $array['conditional_operator1'] ) ) {
$array['conditional_value1'] = ! empty( $array['conditional_value1'] ) ? $array['conditional_value1'] : '';
$array['conditions'][] = array( $array['conditional_action1'], $array['conditional_field1'], $array['conditional_operator1'], $array['conditional_value1'] );
}
/***
*** @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 );
if ( isset($array['conditional_field2']) && !empty( $array['conditional_action2'] ) && !empty( $array['conditional_operator2'] ) ) {
$array['conditional_value2'] = ! empty( $array['conditional_value2'] ) ? $array['conditional_value2'] : '';
$array['conditions'][] = array( $array['conditional_action2'], $array['conditional_field2'], $array['conditional_operator2'], $array['conditional_value2'] );
}
$field_attr = UM()->builtin()->get_core_field_attrs( $field_type );
if ( isset($array['conditional_field3']) && !empty( $array['conditional_action3'] ) && !empty( $array['conditional_operator3'] ) ) {
$array['conditional_value3'] = ! empty( $array['conditional_value3'] ) ? $array['conditional_value3'] : '';
$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['conditional_value4'] = ! empty( $array['conditional_value4'] ) ? $array['conditional_value4'] : '';
$array['conditions'][] = array( $array['conditional_action4'], $array['conditional_field4'], $array['conditional_operator4'], $array['conditional_value4'] );
}
return $array;
}
add_filter('um_admin_pre_save_field_to_form', 'um_admin_pre_save_field_to_form', 1 );
/**
* Some fields may require extra fields before saving
*
* @param $array
*
* @return mixed
*/
function um_admin_pre_save_fields_hook( $array ) {
extract( $array );
/**
* UM hook
*
* @type filter
* @title um_fields_without_metakey
* @description Field Types without meta key
* @input_vars
* [{"var":"$types","type":"array","desc":"Field Types"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_fields_without_metakey', 'my_fields_without_metakey', 10, 1 );
* function my_fields_without_metakey( $types ) {
* // your code here
* return $types;
* }
* ?>
*/
$fields_without_metakey = apply_filters( 'um_fields_without_metakey', array(
'block',
'shortcode',
'spacing',
'divider',
'group'
) );
$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;
}
add_filter('um_admin_pre_save_fields_hook', 'um_admin_pre_save_fields_hook', 1 );
/**
* Apply a filter to handle errors for field updating in backend
*
* @param $errors
* @param $array
*
* @return mixed
*/
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'] ) ) {
@@ -145,29 +159,42 @@ if ( ! defined( 'ABSPATH' ) ) exit;
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;
}
add_filter('um_admin_field_update_error_handling', 'um_admin_field_update_error_handling', 1, 2 );
/**
* Filter validation types on loop
*
* @param $break
* @param $key
* @param $form_id
* @param $field_array
*
* @return bool
*/
function um_builtin_validation_types_continue_loop( $break, $key, $form_id, $field_array ) {
add_filter( 'um_restrict_content_hide_metabox', 'um_hide_metabox_restrict_content_shop', 10, 1 );
function um_hide_metabox_restrict_content_shop( $hide ) {
if ( function_exists( 'wc_get_page_id' ) && ! empty( $_GET['post'] ) &&
$_GET['post'] == wc_get_page_id( 'shop' ) ) {
return true;
}
return $hide;
// 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;
}
add_filter( 'um_builtin_validation_types_continue_loop', 'um_builtin_validation_types_continue_loop', 1, 4 );
/**
* @param $hide
*
* @return bool
*/
function um_hide_metabox_restrict_content_shop( $hide ) {
if ( function_exists( 'wc_get_page_id' ) && ! empty( $_GET['post'] ) &&
$_GET['post'] == wc_get_page_id( 'shop' ) ) {
return true;
}
return $hide;
}
add_filter( 'um_restrict_content_hide_metabox', 'um_hide_metabox_restrict_content_shop', 10, 1 );