UM_Admin_Access

The Ultimate Member UM Admin Access class.

Defined (1)

The class is defined in the following location(s).

/admin/core/um-admin-access.php  
  1. class UM_Admin_Access { 
  2.  
  3. function __construct() { 
  4.  
  5. $this->slug = 'ultimatemember'; 
  6.  
  7. add_action( 'load-post.php', array(&$this, 'add_metabox'), 9 ); 
  8. add_action( 'load-post-new.php', array(&$this, 'add_metabox'), 9 ); 
  9.  
  10.  
  11. /*** 
  12. *** @add a helper tooltip 
  13. ***/ 
  14. function tooltip( $text, $e = false ) { 
  15.  
  16. ?> 
  17.  
  18. <span class="um-admin-tip"> 
  19. <?php if ($e == 'e' ) { ?> 
  20. <span class="um-admin-tipsy-e" title="<?php echo $text; ?>"><i class="dashicons dashicons-editor-help"></i></span> 
  21. <?php } else { ?> 
  22. <span class="um-admin-tipsy-w" title="<?php echo $text; ?>"><i class="dashicons dashicons-editor-help"></i></span> 
  23. <?php } ?> 
  24. </span> 
  25.  
  26. <?php 
  27.  
  28.  
  29. /*** 
  30. *** @Checks core post type 
  31. ***/ 
  32. function core_post_type( $post_type ) { 
  33.  
  34.  
  35. if ( strstr($post_type, 'um_') ) 
  36. return true; 
  37.  
  38. if ( $post_type == 'shop_order' ) 
  39. return true; 
  40.  
  41. if ( !class_exists('UM_bbPress_API') && in_array($post_type, array('forum', 'topic', 'reply')) ) 
  42. return true; 
  43.  
  44. return false; 
  45.  
  46. /*** 
  47. *** @Init the metaboxes 
  48. ***/ 
  49. function add_metabox() { 
  50. global $current_screen; 
  51.  
  52. add_action( 'add_meta_boxes', array(&$this, 'add_metabox_form'), 1 ); 
  53. add_action( 'save_post', array(&$this, 'save_metabox_form'), 10, 2 ); 
  54.  
  55.  
  56. /*** 
  57. *** @load a form metabox 
  58. ***/ 
  59. function load_metabox_form( $object, $box ) { 
  60. global $ultimatemember, $post; 
  61.  
  62. $box['id'] = str_replace('um-admin-access-', '', $box['id']); 
  63.  
  64. if ( $box['id'] == 'builder' ) { 
  65. $UM_Builder = new UM_Admin_Builder(); 
  66. $UM_Builder->form_id = get_the_ID(); 
  67.  
  68. preg_match('#\{.*?\}#s', $box['id'], $matches); 
  69.  
  70. if ( isset($matches[0]) ) { 
  71. $path = $matches[0]; 
  72. $box['id'] = preg_replace('~(\\{[^}]+\\})~', '', $box['id'] ); 
  73. } else { 
  74. $path = um_path; 
  75.  
  76. $path = str_replace('{', '', $path ); 
  77. $path = str_replace('}', '', $path ); 
  78.  
  79. include_once $path . 'admin/templates/access/'. $box['id'] . '.php'; 
  80. wp_nonce_field( basename( __FILE__ ), 'um_admin_save_metabox_access_nonce' ); 
  81.  
  82. /*** 
  83. *** @add form metabox 
  84. ***/ 
  85. function add_metabox_form() { 
  86. global $ultimatemember; 
  87.  
  88. if ( um_get_option('access_widget_admin_only') && !current_user_can( 'edit_users' ) ) return; 
  89.  
  90. $types = $ultimatemember->query->get_post_types; 
  91. foreach($types as $post_type) { 
  92.  
  93. if ( !$this->core_post_type( $post_type ) ) { 
  94.  
  95. $current_screen = get_current_screen(); 
  96.  
  97. if( ! in_array( $current_screen->id, array("upload", "media", "attachment") ) ) { 
  98. add_meta_box('um-admin-access-settings', __('Ultimate Member'), array(&$this, 'load_metabox_form'), $post_type, 'side', 'default'); 
  99.  
  100.  
  101. do_action('um_admin_custom_access_metaboxes'); 
  102.  
  103.  
  104.  
  105. /*** 
  106. *** @save form metabox 
  107. ***/ 
  108. function save_metabox_form( $post_id, $post ) { 
  109. global $wpdb; 
  110.  
  111. // validate nonce 
  112. if ( !isset( $_POST['um_admin_save_metabox_access_nonce'] ) || !wp_verify_nonce( $_POST['um_admin_save_metabox_access_nonce'], basename( __FILE__ ) ) ) return $post_id; 
  113.  
  114. // validate user 
  115. $post_type = get_post_type_object( $post->post_type ); 
  116. if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; 
  117.  
  118. // save 
  119. $multi_choice_keys = apply_filters('um_admin_multi_choice_keys', array() ); 
  120. if ( $multi_choice_keys ) { 
  121. foreach( $multi_choice_keys as $k ) { 
  122. delete_post_meta( $post_id, $k ); 
  123. foreach( $_POST as $k => $v ) { 
  124. if (strstr($k, '_um_')) { 
  125. update_post_meta( $post_id, $k, $v); 
  126.  
  127.