MS_View_Settings_Page_Setup

Displays the Setup form.

Defined (1)

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

/app/view/settings/page/class-ms-view-settings-page-setup.php  
  1. class MS_View_Settings_Page_Setup extends MS_View { 
  2.  
  3. /** 
  4. * Type of form displayed. Used to determine height of the popup. 
  5. * @var string 
  6. */ 
  7. protected $form_type = 'full'; 
  8.  
  9. /** 
  10. * Displays the settings form. 
  11. * @since 1.0.0 
  12. * @return string 
  13. */ 
  14. public function to_html() { 
  15. if ( ! empty( $_REQUEST['full_popup'] ) ) { 
  16. $show_wizard_done = true; 
  17. } else { 
  18. $show_wizard_done = MS_Plugin::instance()->settings->is_first_membership; 
  19.  
  20. if ( $show_wizard_done ) { 
  21. $this->form_type = 'full'; 
  22. $code = $this->html_full_form(); 
  23. } else { 
  24. $this->form_type = 'short'; 
  25. $code = $this->html_short_form(); 
  26.  
  27. return $code; 
  28.  
  29. /** 
  30. * Display the small "completed" form 
  31. * @since 1.0.0 
  32. * @return string HTML Code 
  33. */ 
  34. public function html_short_form() { 
  35. $code = sprintf( 
  36. '<center>%1$s</center>',  
  37. sprintf( 
  38. __( 'You can now go to page %sProtection Rules%s to set up access levels for this Membership.', 'membership2' ),  
  39. sprintf( '<a href="%1$s">', MS_Controller_Plugin::get_admin_url( 'protection' ) ),  
  40. '</a>' 
  41. ); 
  42.  
  43. return $code; 
  44.  
  45. /** 
  46. * Display the full settings form, used either by first membership 
  47. * "completed" popup and also by the general settings tab. 
  48. * @since 1.0.0 
  49. * @return string HTML code 
  50. */ 
  51. public function html_full_form() { 
  52. $fields = $this->prepare_fields(); 
  53.  
  54. ob_start(); 
  55. ?> 
  56. <div class="ms-setup-form"> 
  57. <?php if ( ! MS_Plugin::is_network_wide() ) : ?> 
  58. <div class="ms-setup-nav"> 
  59. <div class="ms-title"> 
  60. <i class="ms-icon dashicons dashicons-menu"></i> 
  61. <?php _e( 'Please select pages you want to appear in your Navigation', 'membership2' ); ?> 
  62. </div> 
  63. <div class="ms-description"> 
  64. <?php 
  65. printf( 
  66. __( 'You can always change those later by going to %1$s in your admin sidebar.', 'membership2' ),  
  67. sprintf( 
  68. '<a href="%1$s" target="_blank">%2$s</a>',  
  69. admin_url( 'nav-menus.php' ),  
  70. __( 'Appearance' ) . ' » ' . __( 'Menus' ) 
  71. ); 
  72. ?> 
  73. </div> 
  74. <?php echo $this->show_menu_controls(); ?> 
  75. </div> 
  76. <?php // Network-wide IS PRO ONLY! ?> 
  77. <?php endif; ?> 
  78. <div class="ms-setup-pages"> 
  79. <div class="ms-title"> 
  80. <i class="ms-icon dashicons dashicons-admin-page"></i> 
  81. <?php _e( 'Membership 2 Pages', 'membership2' ); ?> 
  82. </div> 
  83. <div class="ms-description"> 
  84. <?php _e( 'Set Up Membership 2 Pages that will be displayed on your website.', 'membership2' ); ?> 
  85. </div> 
  86. <?php 
  87.  
  88. if ( is_array( $fields['pages'] ) ) { 
  89. $page_types = array_keys( $fields['pages'] ); 
  90. $page_types_menu = array( 
  91. 'memberships',  
  92. 'register',  
  93. 'account',  
  94. ); 
  95. $page_types_rest = array_diff( $page_types, $page_types_menu ); 
  96. $groups = array( 
  97. 'in-menu' => $page_types_menu,  
  98. 'no-menu' => $page_types_rest,  
  99. ); 
  100.  
  101. $pages_site_id = MS_Model_Pages::get_site_info( 'id' ); 
  102. MS_Factory::select_blog( $pages_site_id ); 
  103.  
  104. foreach ( $groups as $group_key => $group_items ) : 
  105. printf( '<div class="ms-pages-group %1$s">', esc_attr( $group_key ) ); 
  106.  
  107. foreach ( $group_items as $key ) : 
  108. $field = $fields['pages'][$key]; 
  109. ?> 
  110. <div class="ms-settings-page-wrapper"> 
  111. <?php MS_Helper_Html::html_element( $field ); ?> 
  112. <div class="ms-action"> 
  113. <?php 
  114. MS_Helper_Html::html_link( 
  115. array( 
  116. 'id' => 'url_page_' . $field['value'],  
  117. 'url' => '',  
  118. 'value' => __( 'View Page', 'membership2' ),  
  119. 'target' => '_blank',  
  120. 'data_ms' => array( 
  121. 'base' => MS_Helper_Utility::get_home_url( 
  122. $pages_site_id, 'index.php?page_id=' 
  123. ),  
  124. ); 
  125. ?> 
  126. <span> | </span> 
  127. <?php 
  128. MS_Helper_Html::html_link( 
  129. array( 
  130. 'id' => 'edit_url_page_' . $field['value'],  
  131. 'url' => '',  
  132. 'value' => __( 'Edit Page', 'membership2' ),  
  133. 'target' => '_blank',  
  134. 'data_ms' => array( 
  135. 'base' => get_admin_url( 
  136. $pages_site_id, 'post.php?action=edit&post=' 
  137. ),  
  138. ); 
  139. ?> 
  140. </div> 
  141. </div> 
  142. <?php 
  143. endforeach; 
  144.  
  145. echo '</div>'; 
  146. endforeach; 
  147. } else { 
  148. echo $fields['pages']; 
  149.  
  150. MS_Factory::revert_blog(); 
  151. ?> 
  152. </div> 
  153. </div> 
  154. <?php 
  155.  
  156. $html = ob_get_clean(); 
  157.  
  158. return apply_filters( 
  159. 'ms_view_settings_page_setup_to_html',  
  160. $html 
  161. ); 
  162.  
  163. /** 
  164. * Prepare the HTML fields that can be displayed 
  165. * @since 1.0.0 
  166. * @return array 
  167. */ 
  168. protected function prepare_fields() { 
  169. // Prepare the return value. 
  170. $nav = array(); 
  171. $pages = array(); 
  172.  
  173. MS_Model_Pages::create_missing_pages(); 
  174. $page_types = MS_Model_Pages::get_page_types(); 
  175. $page_types_menu = array( 
  176. 'memberships',  
  177. 'register',  
  178. 'account',  
  179. ); 
  180. $page_types_rest = array_diff( $page_types, $page_types_menu ); 
  181.  
  182. // Prepare NAV fields. 
  183. $menu_action = MS_Controller_Pages::AJAX_ACTION_TOGGLE_MENU; 
  184. $menu_nonce = wp_create_nonce( $menu_action ); 
  185. foreach ( $page_types_menu as $type ) { 
  186. $nav_exists = MS_Model_Pages::has_menu( $type ); 
  187. $nav[$type] = array( 
  188. 'type' => MS_Helper_Html::INPUT_TYPE_RADIO_SLIDER,  
  189. 'id' => 'nav_' . $type,  
  190. 'value' => $nav_exists,  
  191. 'title' => $page_types[$type],  
  192. 'ajax_data' => array( 
  193. 'action' => $menu_action,  
  194. 'item' => $type,  
  195. '_wpnonce' => $menu_nonce,  
  196. ),  
  197. ); 
  198.  
  199. $nav['sep'] = array( 
  200. 'type' => MS_Helper_Html::TYPE_HTML_SEPARATOR,  
  201. ); 
  202.  
  203. // Prepare PAGES fields. 
  204. $pages_action = MS_Controller_Pages::AJAX_ACTION_UPDATE_PAGES; 
  205. $pages_nonce = wp_create_nonce( $pages_action ); 
  206.  
  207. foreach ( $page_types as $type => $label ) { 
  208. $page_id = MS_Model_Pages::get_setting( $type ); 
  209. $title = sprintf( 
  210. '<strong>%1$s</strong><span class="lbl-details">: %2$s</span>',  
  211. $label,  
  212. MS_Model_Pages::get_description( $type ) 
  213. ); 
  214.  
  215. $pages[ $type ] = array( 
  216. 'id' => $type,  
  217. 'type' => MS_Helper_Html::INPUT_TYPE_WP_PAGES,  
  218. 'title' => $title,  
  219. 'value' => $page_id,  
  220. 'field_options' => array( 
  221. 'no_item' => __( '- Select a page -', 'membership2' ),  
  222. ),  
  223. 'ajax_data' => array( 
  224. 'field' => $type,  
  225. 'action' => $pages_action,  
  226. '_wpnonce' => $pages_nonce,  
  227. ),  
  228. ); 
  229.  
  230. $fields = array( 
  231. 'nav' => $nav,  
  232. 'pages' => $pages,  
  233. ); 
  234.  
  235. return apply_filters( 
  236. 'ms_view_settings_page_setup_prepare_fields',  
  237. $fields,  
  238. $this 
  239. ); 
  240.  
  241. /** 
  242. * Outputs the HTML code to toggle Membership2 menu items. 
  243. * @since 1.0.0 
  244. * @return string 
  245. */ 
  246. public function show_menu_controls() { 
  247. $code = ''; 
  248. $can_create_nav = MS_Model_Pages::can_edit_menus(); 
  249.  
  250. if ( $can_create_nav ) { 
  251. $fields = $this->prepare_fields(); 
  252. foreach ( $fields['nav'] as $field ) { 
  253. $code .= MS_Helper_Html::html_element( $field, true ); 
  254. } else { 
  255. $button = array( 
  256. 'id' => 'create_menu',  
  257. 'type' => MS_Helper_Html::INPUT_TYPE_BUTTON,  
  258. 'value' => __( 'Okay, create the menu', 'membership2' ),  
  259. 'ajax_data' => array( 
  260. 'action' => MS_Controller_Pages::AJAX_ACTION_CREATE_MENU,  
  261. '_wpnonce' => wp_create_nonce( MS_Controller_Pages::AJAX_ACTION_CREATE_MENU ),  
  262. ); 
  263. $code = sprintf( 
  264. '<div style="padding-left:10px"><p><em>%s</em></p><p>%s</p></div>',  
  265. __( 'Wait! You did not create a menu yet...<br>Let us create it now, so you can choose which pages to display to your visitors!', 'membership2' ),  
  266. MS_Helper_Html::html_element( $button, true ) 
  267. ); 
  268.  
  269. return '<div class="ms-nav-controls">' . $code . '</div>'; 
  270.  
  271. /** 
  272. * Returns the height needed to display this dialog inside a popup without 
  273. * adding scrollbars 
  274. * @since 1.0.0 
  275. * @return int Popup height 
  276. */ 
  277. public function dialog_height() { 
  278. switch ( $this->form_type ) { 
  279. case 'short': 
  280. $height = 200; 
  281. break; 
  282.  
  283. case 'full': 
  284. default: 
  285. if ( MS_Model_Pages::can_edit_menus() ) { 
  286. $height = 412; 
  287. } else { 
  288. $height = 460; 
  289. break; 
  290.  
  291. return $height; 
  292.