mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
- class admin optimization;
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace um\admin;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'um\admin\Admin_Functions' ) ) {
|
||||
|
||||
|
||||
/**
|
||||
* Class Admin_Functions
|
||||
* @package um\admin\core
|
||||
*/
|
||||
class Admin_Functions {
|
||||
|
||||
|
||||
/**
|
||||
* Admin_Functions constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if current page load UM post type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_plugin_post_type() {
|
||||
if ( isset( $_REQUEST['post_type'] ) ) {
|
||||
$post_type = $_REQUEST['post_type'];
|
||||
if ( in_array( $post_type, array( 'um_form','um_directory' ) ) ) {
|
||||
return true;
|
||||
}
|
||||
} elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) {
|
||||
$post_type = get_post_type();
|
||||
if ( in_array( $post_type, array( 'um_form', 'um_directory' ) ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ if ( ! class_exists( 'um\admin\Admin' ) ) {
|
||||
* Class Admin
|
||||
* @package um\admin
|
||||
*/
|
||||
class Admin {
|
||||
class Admin extends Admin_Functions {
|
||||
|
||||
|
||||
/**
|
||||
@@ -24,6 +24,8 @@ if ( ! class_exists( 'um\admin\Admin' ) ) {
|
||||
* Admin constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->templates_path = um_path . 'includes/admin/templates/';
|
||||
|
||||
add_action( 'admin_init', array( &$this, 'admin_init' ), 0 );
|
||||
@@ -39,6 +41,10 @@ if ( ! class_exists( 'um\admin\Admin' ) ) {
|
||||
add_action( 'um_admin_do_action__um_can_register_notice', array( &$this, 'um_hide_notice' ) );
|
||||
add_action( 'um_admin_do_action__um_hide_exif_notice', array( &$this, 'um_hide_notice' ) );
|
||||
add_action( 'um_admin_do_action__user_action', array( &$this, 'user_action' ) );
|
||||
|
||||
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' ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -247,29 +253,6 @@ if ( ! class_exists( 'um\admin\Admin' ) ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if current page load UM post type
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_plugin_post_type() {
|
||||
if ( isset( $_REQUEST['post_type'] ) ) {
|
||||
$post_type = $_REQUEST['post_type'];
|
||||
if ( in_array( $post_type, array( 'um_form','um_directory' ) ) ) {
|
||||
return true;
|
||||
}
|
||||
} elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) {
|
||||
$post_type = get_post_type();
|
||||
if ( in_array( $post_type, array( 'um_form', 'um_directory' ) ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Init admin action/filters + request handlers
|
||||
*/
|
||||
@@ -318,5 +301,77 @@ if ( ! class_exists( 'um\admin\Admin' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 ) && $this->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
<?php
|
||||
namespace um\admin\core;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'um\admin\core\Admin_Functions' ) ) {
|
||||
|
||||
|
||||
/**
|
||||
* Class Admin_Functions
|
||||
* @package um\admin\core
|
||||
*/
|
||||
class Admin_Functions {
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -437,7 +437,6 @@ if ( ! class_exists( 'UM' ) ) {
|
||||
$this->admin_settings();
|
||||
$this->columns();
|
||||
$this->admin_enqueue();
|
||||
$this->functions();
|
||||
$this->metabox();
|
||||
$this->notices();
|
||||
$this->users();
|
||||
@@ -612,19 +611,6 @@ if ( ! class_exists( 'UM' ) ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 2.0
|
||||
*
|
||||
* @return um\admin\core\Admin_Functions()
|
||||
*/
|
||||
function functions() {
|
||||
if ( empty( $this->classes['admin_functions'] ) ) {
|
||||
$this->classes['admin_functions'] = new um\admin\core\Admin_Functions();
|
||||
}
|
||||
return $this->classes['admin_functions'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 2.0
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user