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. // A "Fix subscriptions" button that can be added via URL param 
  157. // Intentionally not translated (purpose is dev/testing) 
  158. if ( ! empty( $_GET['fixsub'] ) ) { 
  159. $fix_url = MS_Controller_Plugin::get_admin_url( 
  160. 'settings',  
  161. array( 'fixsub' => 1 ) 
  162. ); 
  163. $fix_url = esc_url_raw( 
  164. add_query_arg( 
  165. MS_Model_Upgrade::get_token( 'fixsub' ),  
  166. $fix_url 
  167. ); 
  168. $cancel_url = esc_url_raw( remove_query_arg( 'fixsub' ) ); 
  169.  
  170. $desc[] = sprintf( 
  171. '<div class="error" style="width:600px;margin:20px auto;text-align:center"><p><b>%1$s</b></p><hr />%2$s</div>',  
  172. 'Careful: This might change the subscription status of some members!',  
  173. sprintf( 
  174. '<form method="POST" action="%s" style="padding:20px 0">' . 
  175. '<label style="line-height:28px">' . 
  176. '<input type="checkbox" name="confirm" value="yes" /> Yes, fix subscriptions!' . 
  177. '</label><p>' . 
  178. '<button class="button-primary">Do it!</button> ' . 
  179. '<a href="%s" class="button">Cancel</a>' . 
  180. '</p></form>',  
  181. $fix_url,  
  182. $cancel_url 
  183. ); 
  184.  
  185. return $desc; 
  186.  
  187.  
  188. /** ====================================================================== * 
  189. * SETTINGS-FOOTER 
  190. * ====================================================================== */ 
  191.  
  192. /** 
  193. * Display a footer below the Settings box. 
  194. * The footer will show information on the next scheduled cron jobs and also 
  195. * allow the user to run these jobs instantly. 
  196. * @since 1.0.0 
  197. * @param string $tab_name Name of the currently open settings-tab. 
  198. */ 
  199. protected function render_settings_footer( $tab_name ) { 
  200. if ( 'general' != $tab_name ) { return; } 
  201.  
  202. $status_stamp = wp_next_scheduled( 'ms_cron_check_membership_status' ) - time(); 
  203. $email_stamp = wp_next_scheduled( 'ms_cron_process_communications' ) - time(); 
  204.  
  205. if ( $status_stamp > 0 ) { 
  206. $status_delay = sprintf( 
  207. __( 'in %s hrs %s min', 'membership2' ),  
  208. floor( ($status_stamp - 1) / 3600 ),  
  209. date( 'i', $status_stamp ) 
  210. ); 
  211. } else { 
  212. $status_delay = __( '(now...)', 'membership2' ); 
  213.  
  214. if ( $email_stamp > 0 ) { 
  215. $email_delay = sprintf( 
  216. __( 'in %s hrs %s min', 'membership2' ),  
  217. floor( ($email_stamp - 1) / 3600 ),  
  218. date( 'i', $email_stamp ) 
  219. ); 
  220. } else { 
  221. $email_delay = __( '(now...)', 'membership2' ); 
  222.  
  223. $status_url = esc_url_raw( 
  224. add_query_arg( array( 'run_cron' => 'ms_cron_check_membership_status' ) ) 
  225. ); 
  226. $email_url = esc_url_raw( 
  227. add_query_arg( array( 'run_cron' => 'ms_cron_process_communications' ) ) 
  228. ); 
  229. $lbl_run = __( 'Run now!', 'membership2' ); 
  230.  
  231. echo '<div class="cf ms-settings-footer"><div class="ms-tab-container"> </div>'; 
  232. echo '<div>'; 
  233.  
  234. if ( MS_Plugin::get_modifier( 'MS_LOCK_SUBSCRIPTIONS' ) ) { 
  235. _e( 'Membership Status Checks are disabled.', 'membership2' ); 
  236. echo ' '; 
  237. } else { 
  238. printf( 
  239. __( 'Check Membership Status changes %s.' ) . ' ',  
  240. '<a href="' . $status_url . '" title="' . $lbl_run . '">' . $status_delay . '</a>' 
  241. ); 
  242.  
  243. if ( MS_Plugin::get_modifier( 'MS_STOP_EMAILS' ) ) { 
  244. _e( 'Sending Email Responses is disabled.', 'membership2' ); 
  245. } else { 
  246. $count = MS_Model_Communication::get_queue_count(); 
  247. if ( ! $count ) { 
  248. $msg = __( 'No pending Email Responses found', 'membership2' ); 
  249. } elseif ( 1 == $count ) { 
  250. $msg = __( 'Send 1 pending Email Response %1$s', 'membership2' ); 
  251. } else { 
  252. $msg = __( 'Send %2$s pending Email Responses %1$s', 'membership2' ); 
  253.  
  254. printf( 
  255. $msg,  
  256. '<a href="' . $email_url . '"title="' . $lbl_run . '">' . $email_delay . '</a>',  
  257. $count 
  258. ); 
  259.  
  260. echo '</div></div>'; 
  261.  
  262. /** ====================================================================== * 
  263. * GENERAL 
  264. * ====================================================================== */ 
  265.  
  266. public function render_tab_general() { 
  267. $tab = MS_Factory::create( 'MS_View_Settings_Page_General' ); 
  268. $tab->data = $this->data; 
  269.  
  270. return $tab->to_html(); 
  271.  
  272. /** ====================================================================== * 
  273. * PAYMENT 
  274. * ====================================================================== */ 
  275.  
  276. public function render_tab_payment() { 
  277. $tab = MS_Factory::create( 'MS_View_Settings_Page_Payment' ); 
  278. $tab->data = $this->data; 
  279.  
  280. return $tab->to_html(); 
  281.  
  282. /** ====================================================================== * 
  283. * PROTECTION MESSAGE 
  284. * ====================================================================== */ 
  285.  
  286. public function render_tab_messages() { 
  287. $tab = MS_Factory::create( 'MS_View_Settings_Page_Messages' ); 
  288. $tab->data = $this->data; 
  289.  
  290. return $tab->to_html(); 
  291.  
  292. /** ====================================================================== * 
  293. * AUTOMATED MESSAGES 
  294. * ====================================================================== */ 
  295.  
  296. public function render_tab_emails() { 
  297. $tab = MS_Factory::create( 'MS_View_Settings_Page_Communications' ); 
  298. $tab->data = $this->data; 
  299.  
  300. return $tab->to_html(); 
  301.  
  302. /** ====================================================================== * 
  303. * IMPORT 
  304. * ====================================================================== */ 
  305.  
  306. public function render_tab_import() { 
  307. $tab = MS_Factory::create( 'MS_View_Settings_Page_Import' ); 
  308. $tab->data = $this->data; 
  309.  
  310. return $tab->to_html(); 
  311.