MS_View_Settings_Edit

Renders Membership Plugin Settings.

Defined (1)

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

/app/view/settings/class-ms-view-settings-edit.php  
  1. class MS_View_Settings_Edit extends MS_View { 
  2.  
  3. /** 
  4. * Overrides parent's to_html() method. 
  5. * Creates an output buffer, outputs the HTML and grabs the buffer content before releasing it. 
  6. * Creates a wrapper 'ms-wrap' HTML element to contain content and navigation. The content inside 
  7. * the navigation gets loaded with dynamic method calls. 
  8. * e.g. if key is 'settings' then render_settings() gets called, if 'bob' then render_bob(). 
  9. * @todo Could use callback functions to call dynamic methods from within the helper, thus 
  10. * creating the navigation with a single method call and passing method pointers in the $tabs array. 
  11. * @since 1.0.0 
  12. * @return object 
  13. */ 
  14. public function to_html() { 
  15. $this->check_simulation(); 
  16.  
  17. // Setup navigation tabs. 
  18. $tabs = $this->data['tabs']; 
  19. $desc = array(); 
  20.  
  21. ob_start(); 
  22. // Render tabbed interface. 
  23. ?> 
  24. <div class="ms-wrap wrap"> 
  25. <?php 
  26. $desc = $this->advanced_forms( $desc ); 
  27.  
  28. MS_Helper_Html::settings_header( 
  29. array( 
  30. 'title' => __( 'Membership 2 Settings', 'membership2' ),  
  31. 'title_icon_class' => 'wpmui-fa wpmui-fa-cog',  
  32. 'desc' => $desc,  
  33. ); 
  34. $active_tab = MS_Helper_Html::html_admin_vertical_tabs( $tabs ); 
  35.  
  36. // Call the appropriate form to render. 
  37. $tab_name = str_replace( '-', '_', $active_tab ); 
  38. $callback_name = 'render_tab_' . $tab_name; 
  39. $render_callback = apply_filters( 
  40. 'ms_view_settings_edit_render_callback',  
  41. array( $this, $callback_name ),  
  42. $active_tab,  
  43. $this->data 
  44. ); 
  45. ?> 
  46. <div class="ms-settings ms-settings-<?php echo esc_attr( $tab_name ); ?>"> 
  47. <?php 
  48. $html = call_user_func( $render_callback ); 
  49. $html = apply_filters( 'ms_view_settings_' . $callback_name, $html ); 
  50. echo $html; 
  51. ?> 
  52. </div> 
  53. </div> 
  54. <?php 
  55. $this->render_settings_footer( $tab_name ); 
  56.  
  57. $html = ob_get_clean(); 
  58.  
  59. return $html; 
  60.  
  61. /** ====================================================================== * 
  62. * ADVANCED-FORMS 
  63. * ====================================================================== */ 
  64.  
  65. /** 
  66. * Display advanced setting forms that can be triggered via an URL param. 
  67. * @since 1.0.0 
  68. * @param array $desc Array of items to display in the settings header. 
  69. * @return array New Array of items to display. Might include a HTML form. 
  70. */ 
  71. protected function advanced_forms( $desc ) { 
  72. // A "Reset" button that can be added via URL param 
  73. // Intentionally not translated (purpose is dev/testing) 
  74. if ( ! empty( $_GET['reset'] ) ) { 
  75. $reset_url = MS_Controller_Plugin::get_admin_url( 
  76. 'settings',  
  77. array( 'reset' => 1 ) 
  78. ); 
  79. $reset_url = esc_url_raw( 
  80. add_query_arg( 
  81. MS_Model_Upgrade::get_token( 'reset' ),  
  82. $reset_url 
  83. ); 
  84. $cancel_url = esc_url_raw( remove_query_arg( 'reset' ) ); 
  85.  
  86. $desc[] = sprintf( 
  87. '<div class="error" style="width:600px;margin:20px auto;text-align:center"><p><b>%1$s</b></p><hr />%2$s</div>',  
  88. 'Careful: This will completely erase all your Membership2 settings and details!',  
  89. sprintf( 
  90. '<form method="POST" action="%s" style="padding:20px 0">' . 
  91. '<label style="line-height:28px">' . 
  92. '<input type="checkbox" name="confirm" value="yes" /> Yes, reset everything!' . 
  93. '</label><p>' . 
  94. '<button class="button-primary">Do it!</button> ' . 
  95. '<a href="%s" class="button">Cancel</a>' . 
  96. '</p></form>',  
  97. $reset_url,  
  98. $cancel_url 
  99. ); 
  100.  
  101. // A "Resore" button that can be added via URL param 
  102. // Intentionally not translated (purpose is dev/testing) 
  103. if ( ! empty( $_GET['restore'] ) ) { 
  104. $restore_url = MS_Controller_Plugin::get_admin_url( 
  105. 'settings',  
  106. array( 'restore' => 1 ) 
  107. ); 
  108. $restore_url = esc_url_raw( 
  109. add_query_arg( 
  110. MS_Model_Upgrade::get_token( 'restore' ),  
  111. $restore_url 
  112. ); 
  113. $cancel_url = esc_url_raw( remove_query_arg( 'restore' ) ); 
  114. $options = array(); 
  115. $files = lib3()->updates->plugin( 'membership2' ); 
  116. $files = lib3()->updates->list_files( 'json' ); 
  117. foreach ( $files as $file ) { 
  118. $parts = explode( '-', $file ); 
  119. if ( 3 == count( $parts ) ) { 
  120. $version = str_replace( 'upgrade_', '', $parts[0] ); 
  121. $version = str_replace( '_', '.', $version ); 
  122. $date = substr( $parts[1], 0, 4 ) . '-' . substr( $parts[1], 4, 2 ) . '-' . substr( $parts[1], 6, 2 ); 
  123. $time = substr( $parts[2], 0, 2 ) . ':' . substr( $parts[2], 2, 2 ) . ':' . substr( $parts[2], 4, 2 ); 
  124. $label = sprintf( 
  125. '%2$s (%3$s) - Upgrade to %1$s',  
  126. $version,  
  127. $date,  
  128. $time 
  129. ); 
  130. } else { 
  131. $label = $file; 
  132. $options[$label] = sprintf( 
  133. '<option value="%1$s">%2$s</option>',  
  134. $file,  
  135. $label 
  136. ); 
  137. krsort( $options ); 
  138.  
  139. $desc[] = sprintf( 
  140. '<div class="error" style="width:600px;margin:20px auto;text-align:center"><p><b>%1$s</b></p><hr />%2$s</div>',  
  141. 'Careful: This will overwrite and replace existing data with old data from the Snapshot!',  
  142. sprintf( 
  143. '<form method="POST" action="%s" style="padding:20px 0">' . 
  144. '<label style="line-height:28px">Snapshot:</label><p>' . 
  145. '<select name="restore_snapshot">' . implode( '', $options ) . '</select>' . 
  146. '</p><label style="line-height:28px">' . 
  147. '<input type="checkbox" name="confirm" value="yes" /> Yes, overwrite data!' . 
  148. '</label><p>' . 
  149. '<button class="button-primary">Do it!</button> ' . 
  150. '<a href="%s" class="button">Cancel</a>' . 
  151. '</p></form>',  
  152. $restore_url,  
  153. $cancel_url 
  154. ); 
  155.  
  156. return $desc; 
  157.  
  158.  
  159. /** ====================================================================== * 
  160. * SETTINGS-FOOTER 
  161. * ====================================================================== */ 
  162.  
  163. /** 
  164. * Display a footer below the Settings box. 
  165. * The footer will show information on the next scheduled cron jobs and also 
  166. * allow the user to run these jobs instantly. 
  167. * @since 1.0.0 
  168. * @param string $tab_name Name of the currently open settings-tab. 
  169. */ 
  170. protected function render_settings_footer( $tab_name ) { 
  171. if ( 'general' != $tab_name ) { return; } 
  172.  
  173. $status_stamp = wp_next_scheduled( 'ms_cron_check_membership_status' ) - time(); 
  174. $email_stamp = wp_next_scheduled( 'ms_cron_process_communications' ) - time(); 
  175.  
  176. if ( $status_stamp > 0 ) { 
  177. $status_delay = sprintf( 
  178. __( 'in %s hrs %s min', 'membership2' ),  
  179. floor( ($status_stamp - 1) / 3600 ),  
  180. date( 'i', $status_stamp ) 
  181. ); 
  182. } else { 
  183. $status_delay = __( '(now...)', 'membership2' ); 
  184.  
  185. if ( $email_stamp > 0 ) { 
  186. $email_delay = sprintf( 
  187. __( 'in %s hrs %s min', 'membership2' ),  
  188. floor( ($email_stamp - 1) / 3600 ),  
  189. date( 'i', $email_stamp ) 
  190. ); 
  191. } else { 
  192. $email_delay = __( '(now...)', 'membership2' ); 
  193.  
  194. $status_url = esc_url_raw( 
  195. add_query_arg( array( 'run_cron' => 'ms_cron_check_membership_status' ) ) 
  196. ); 
  197. $email_url = esc_url_raw( 
  198. add_query_arg( array( 'run_cron' => 'ms_cron_process_communications' ) ) 
  199. ); 
  200. $lbl_run = __( 'Run now!', 'membership2' ); 
  201.  
  202. echo '<div class="cf ms-settings-footer"><div class="ms-tab-container"> </div>'; 
  203. echo '<div>'; 
  204.  
  205. if ( MS_Plugin::get_modifier( 'MS_LOCK_SUBSCRIPTIONS' ) ) { 
  206. _e( 'Membership Status Checks are disabled.', 'membership2' ); 
  207. echo ' '; 
  208. } else { 
  209. printf( 
  210. __( 'Check Membership Status changes %s.' ) . ' ',  
  211. '<a href="' . $status_url . '" title="' . $lbl_run . '">' . $status_delay . '</a>' 
  212. ); 
  213.  
  214. if ( MS_Plugin::get_modifier( 'MS_STOP_EMAILS' ) ) { 
  215. _e( 'Sending Email Responses is disabled.', 'membership2' ); 
  216. } else { 
  217. $count = MS_Model_Communication::get_queue_count(); 
  218. if ( ! $count ) { 
  219. $msg = __( 'No pending Email Responses found', 'membership2' ); 
  220. } elseif ( 1 == $count ) { 
  221. $msg = __( 'Send 1 pending Email Response %1$s', 'membership2' ); 
  222. } else { 
  223. $msg = __( 'Send %2$s pending Email Responses %1$s', 'membership2' ); 
  224.  
  225. printf( 
  226. $msg,  
  227. '<a href="' . $email_url . '"title="' . $lbl_run . '">' . $email_delay . '</a>',  
  228. $count 
  229. ); 
  230.  
  231. echo '</div></div>'; 
  232.  
  233. /** ====================================================================== * 
  234. * GENERAL 
  235. * ====================================================================== */ 
  236.  
  237. public function render_tab_general() { 
  238. $tab = MS_Factory::create( 'MS_View_Settings_Page_General' ); 
  239. $tab->data = $this->data; 
  240.  
  241. return $tab->to_html(); 
  242.  
  243. /** ====================================================================== * 
  244. * PAYMENT 
  245. * ====================================================================== */ 
  246.  
  247. public function render_tab_payment() { 
  248. $tab = MS_Factory::create( 'MS_View_Settings_Page_Payment' ); 
  249. $tab->data = $this->data; 
  250.  
  251. return $tab->to_html(); 
  252.  
  253. /** ====================================================================== * 
  254. * PROTECTION MESSAGE 
  255. * ====================================================================== */ 
  256.  
  257. public function render_tab_messages() { 
  258. $tab = MS_Factory::create( 'MS_View_Settings_Page_Messages' ); 
  259. $tab->data = $this->data; 
  260.  
  261. return $tab->to_html(); 
  262.  
  263. /** ====================================================================== * 
  264. * AUTOMATED MESSAGES 
  265. * ====================================================================== */ 
  266.  
  267. public function render_tab_emails() { 
  268. $tab = MS_Factory::create( 'MS_View_Settings_Page_Communications' ); 
  269. $tab->data = $this->data; 
  270.  
  271. return $tab->to_html(); 
  272.  
  273. /** ====================================================================== * 
  274. * IMPORT 
  275. * ====================================================================== */ 
  276.  
  277. public function render_tab_import() { 
  278. $tab = MS_Factory::create( 'MS_View_Settings_Page_Import' ); 
  279. $tab->data = $this->data; 
  280.  
  281. return $tab->to_html(); 
  282.