2018-04-03 15:04:14 +03:00
|
|
|
<?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() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-11-21 14:01:18 +02:00
|
|
|
/**
|
|
|
|
|
* Check wp-admin nonce
|
|
|
|
|
*
|
|
|
|
|
* @param bool $action
|
|
|
|
|
*/
|
|
|
|
|
function check_ajax_nonce( $action = false ) {
|
2018-12-07 15:26:42 +02:00
|
|
|
$nonce = isset( $_REQUEST['nonce'] ) ? $_REQUEST['nonce'] : '';
|
2018-11-21 14:01:18 +02:00
|
|
|
$action = empty( $action ) ? 'um-admin-nonce' : $action;
|
|
|
|
|
|
|
|
|
|
if ( ! wp_verify_nonce( $nonce, $action ) ) {
|
|
|
|
|
wp_send_json_error( esc_js( __( 'Wrong Nonce', 'ultimate-member' ) ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-04-03 15:04:14 +03:00
|
|
|
/**
|
|
|
|
|
* Boolean check if we're viewing UM backend
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2018-04-04 16:17:03 +03:00
|
|
|
function is_um_screen() {
|
2018-04-03 15:04:14 +03:00
|
|
|
global $current_screen;
|
|
|
|
|
$screen_id = $current_screen->id;
|
2018-04-04 15:12:30 +03:00
|
|
|
|
|
|
|
|
if ( strstr( $screen_id, 'ultimatemember') ||
|
|
|
|
|
strstr( $screen_id, 'um_') ||
|
|
|
|
|
strstr( $screen_id, 'user' ) ||
|
|
|
|
|
strstr( $screen_id, 'profile' ) ||
|
|
|
|
|
$screen_id == 'nav-menus' ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->is_plugin_post_type() ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->is_restricted_entity() ) {
|
2018-04-03 15:04:14 +03:00
|
|
|
return true;
|
2018-04-04 15:12:30 +03:00
|
|
|
}
|
|
|
|
|
|
2018-04-03 15:04:14 +03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if current page load UM post type
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function is_plugin_post_type() {
|
2018-04-04 15:12:30 +03:00
|
|
|
$cpt = UM()->cpt_list();
|
|
|
|
|
|
2018-04-03 15:04:14 +03:00
|
|
|
if ( isset( $_REQUEST['post_type'] ) ) {
|
|
|
|
|
$post_type = $_REQUEST['post_type'];
|
2018-04-04 15:12:30 +03:00
|
|
|
if ( in_array( $post_type, $cpt ) ) {
|
2018-04-03 15:04:14 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) {
|
|
|
|
|
$post_type = get_post_type();
|
2018-04-04 15:12:30 +03:00
|
|
|
if ( in_array( $post_type, $cpt ) ) {
|
2018-04-03 15:04:14 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-04 15:12:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If page now show content with restricted post/taxonomy
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function is_restricted_entity() {
|
|
|
|
|
$restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
|
|
|
|
|
$restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
|
|
|
|
|
|
|
|
|
|
global $typenow, $taxnow;
|
|
|
|
|
if ( ! empty( $typenow ) && ! empty( $restricted_posts[ $typenow ] ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! empty( $taxnow ) && ! empty( $restricted_taxonomies[ $taxnow ] ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-03 15:04:14 +03:00
|
|
|
}
|
|
|
|
|
}
|