MS_View_Protection

Render Accessible Content page.

Defined (1)

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

/app/view/class-ms-view-protection.php  
  1. class MS_View_Protection extends MS_View { 
  2.  
  3. /** 
  4. * Create view output. 
  5. * @since 1.0.0 
  6. * @return string 
  7. */ 
  8. public function to_html() { 
  9. $this->check_simulation(); 
  10. $this->check_network(); 
  11.  
  12. $desc = array( 
  13. __( 'Choose Pages, Categories etc. that you want to make <strong>unavailable</strong> to visitors, and non-members.', 'membership2' ),  
  14. ); 
  15.  
  16. ob_start(); 
  17. // Render tabbed interface. 
  18. ?> 
  19. <div class="ms-wrap wrap ms-wrap-membership2"> 
  20. <?php 
  21. MS_Helper_Html::settings_header( 
  22. array( 
  23. 'title' => __( 'Set-up Protection Rules', 'membership2' ),  
  24. 'desc' => $desc,  
  25. ); 
  26.  
  27. // Display a filter to switch between individual memberships. 
  28. $this->membership_filter(); 
  29.  
  30. // In network-wide protection mode allow user to select a site. 
  31. $this->site_filter(); 
  32.  
  33. $active_tab = $this->data['active_tab']; 
  34. MS_Helper_Html::html_admin_vertical_tabs( $this->data['tabs'], $active_tab ); 
  35.  
  36. // Call the appropriate form to render. 
  37. $callback_name = 'render_tab_' . str_replace( '-', '_', $active_tab ); 
  38. $render_callback = array( $this, $callback_name ); 
  39. $render_callback = apply_filters( 
  40. 'ms_view_protectedcontent_define-' . $active_tab,  
  41. $render_callback,  
  42. $this->data 
  43. ); 
  44.  
  45. if ( is_callable( $render_callback ) ) { 
  46. $html = call_user_func( $render_callback ); 
  47. } else { 
  48. // This is to notify devs that a file/hook is missing or wrong. 
  49. $html = '<div class="ms-settings">' . 
  50. '<div class="error below-h2"><p>' . 
  51. '<em>No View defined by hook "ms_view_protectedcontent_define-' . $active_tab . '"</em>' . 
  52. '</p></div>' . 
  53. '</div>'; 
  54.  
  55. $html = apply_filters( 
  56. 'ms_view_membership_protected_' . $active_tab,  
  57. $html 
  58. ); 
  59. echo $html; 
  60. ?> 
  61. </div> 
  62. <?php 
  63.  
  64. $html = ob_get_clean(); 
  65.  
  66. return apply_filters( 
  67. 'ms_view_membership_protectedcontent_to_html',  
  68. $html,  
  69. $this 
  70. ); 
  71.  
  72. /** 
  73. * Display a filter to select the current membership. 
  74. * @since 1.0.0 
  75. */ 
  76. protected function membership_filter() { 
  77. $memberships = MS_Model_Membership::get_membership_names( 
  78. array( 'active' => true ) 
  79. ); 
  80. $url = esc_url_raw( 
  81. remove_query_arg( array( 'membership_id', 'paged' ) ) 
  82. ); 
  83. $links = array(); 
  84.  
  85. $links['all'] = array( 
  86. 'label' => __( 'All', 'membership2' ),  
  87. 'url' => $url,  
  88. ); 
  89.  
  90. foreach ( $memberships as $id => $name ) { 
  91. if ( empty( $name ) ) { 
  92. $name = __( '(No Name)', 'membership2' ); 
  93.  
  94. $links['ms-' . $id] = array( 
  95. 'label' => esc_html( $name ),  
  96. 'url' => esc_url_raw( 
  97. add_query_arg( array( 'membership_id' => $id ), $url ) 
  98. ),  
  99. ); 
  100.  
  101. ?> 
  102. <div class="wp-filter"> 
  103. <ul class="filter-links"> 
  104. <?php foreach ( $links as $key => $item ) : 
  105. $is_current = MS_Helper_Utility::is_current_url( $item['url'] ); 
  106. $class = ( $is_current ? 'current' : '' ); 
  107. ?> 
  108. <li> 
  109. <a href="<?php echo esc_url( $item['url'] ); ?>" class="<?php echo esc_attr( $class ); ?>"> 
  110. <?php echo esc_html( $item['label'] ); ?> 
  111. </a> 
  112. </li> 
  113. <?php endforeach; ?> 
  114. </ul> 
  115. </div> 
  116. <?php 
  117.  
  118. /** 
  119. * When network-wide protection is enabled then allow the user to choose the 
  120. * source-site of the content. 
  121. * Protection options can only be changed on a site-by-site base. So if the 
  122. * user has 3 sites he can protect all pages on all sites but has to select 
  123. * each site individually here. 
  124. * @since 1.0.0 
  125. */ 
  126. protected function site_filter() { 
  127. if ( ! MS_Plugin::is_network_wide() ) { 
  128. return false; 
  129.  
  130. $sites = MS_Helper_Settings::get_blogs(); 
  131. $site_options = array(); 
  132. $current_blog_id = MS_Factory::current_blog_id(); 
  133. $admin_script = 'admin.php?'. $_SERVER['QUERY_STRING']; 
  134.  
  135. foreach ( $sites as $blog_id => $title ) { 
  136. $key = get_admin_url( $blog_id, $admin_script ); 
  137.  
  138. if ( $current_blog_id == $blog_id ) { 
  139. $current_value = $key; 
  140.  
  141. $site_options[ $key ] = $title; 
  142.  
  143. $site_list = array( 
  144. 'id' => 'select-site',  
  145. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  146. 'value' => $current_value,  
  147. 'field_options' => $site_options,  
  148. ); 
  149.  
  150. ?> 
  151. <div class="ms-tab-container"> 
  152. <label class="ms-tab-link" for="select-site"> 
  153. <?php _e( 'Select Site', 'membership2' ); ?> 
  154. </label> 
  155. </div> 
  156. <div> 
  157. <?php lib3()->html->element( $site_list ); ?> 
  158. </div> 
  159. <?php 
  160.