Нет описания

class-admin-functions.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace um\admin;
  3. // Exit if accessed directly.
  4. if ( ! defined( 'ABSPATH' ) ) exit;
  5. if ( ! class_exists( 'um\admin\Admin_Functions' ) ) {
  6. /**
  7. * Class Admin_Functions
  8. * @package um\admin\core
  9. */
  10. class Admin_Functions {
  11. /**
  12. * Admin_Functions constructor.
  13. */
  14. function __construct() {
  15. }
  16. /**
  17. * Check wp-admin nonce
  18. *
  19. * @param bool $action
  20. */
  21. function check_ajax_nonce( $action = false ) {
  22. $nonce = isset( $_REQUEST['nonce'] ) ? sanitize_text_field( $_REQUEST['nonce'] ) : '';
  23. $action = empty( $action ) ? 'um-admin-nonce' : $action;
  24. if ( ! wp_verify_nonce( $nonce, $action ) ) {
  25. wp_send_json_error( esc_js( __( 'Wrong Nonce', 'ultimate-member' ) ) );
  26. }
  27. }
  28. /**
  29. * Boolean check if we're viewing UM backend
  30. *
  31. * @return bool
  32. */
  33. function is_um_screen() {
  34. global $current_screen;
  35. $is_um_screen = false;
  36. if ( ! empty( $current_screen ) ) {
  37. $screen_id = $current_screen->id;
  38. if ( strstr( $screen_id, 'ultimatemember' ) ||
  39. strstr( $screen_id, 'um_' ) ||
  40. strstr( $screen_id, 'user' ) ||
  41. strstr( $screen_id, 'profile' ) ||
  42. $screen_id == 'nav-menus' ) {
  43. $is_um_screen = true;
  44. }
  45. }
  46. if ( $this->is_plugin_post_type() ) {
  47. $is_um_screen = true;
  48. }
  49. if ( $this->is_restricted_entity() ) {
  50. $is_um_screen = true;
  51. }
  52. return apply_filters( 'um_is_ultimatememeber_admin_screen', $is_um_screen );
  53. }
  54. /**
  55. * Check if current page load UM post type
  56. *
  57. * @return bool
  58. */
  59. function is_plugin_post_type() {
  60. $cpt = UM()->cpt_list();
  61. if ( isset( $_REQUEST['post_type'] ) ) {
  62. $post_type = sanitize_key( $_REQUEST['post_type'] );
  63. if ( in_array( $post_type, $cpt ) ) {
  64. return true;
  65. }
  66. } elseif ( isset( $_REQUEST['action'] ) && sanitize_key( $_REQUEST['action'] ) == 'edit' ) {
  67. $post_type = get_post_type();
  68. if ( in_array( $post_type, $cpt ) ) {
  69. return true;
  70. }
  71. }
  72. return false;
  73. }
  74. /**
  75. * If page now show content with restricted post/taxonomy
  76. *
  77. * @return bool
  78. */
  79. function is_restricted_entity() {
  80. $restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
  81. $restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
  82. global $typenow, $taxnow;
  83. if ( ! empty( $typenow ) && ! empty( $restricted_posts[ $typenow ] ) ) {
  84. return true;
  85. }
  86. if ( ! empty( $taxnow ) && ! empty( $restricted_taxonomies[ $taxnow ] ) ) {
  87. return true;
  88. }
  89. return false;
  90. }
  91. }
  92. }