/wp-content/plugins/learnpress/inc/admin/sub-menus/settings.php

https://gitlab.com/gregtyka/lfmawordpress · PHP · 110 lines · 78 code · 19 blank · 13 comment · 14 complexity · fdd6a6c8035544eae02c122962a6167d MD5 · raw file

  1. <?php
  2. /**
  3. * Admin view for settings page display in admin under menu Settings -> LearnPress
  4. *
  5. * @author ThimPress
  6. * @package Admin/Views
  7. * @version 1.0
  8. */
  9. if ( !defined( 'ABSPATH' ) ) {
  10. exit; // Exit if accessed directly
  11. }
  12. /**
  13. * Setting page
  14. */
  15. function learn_press_settings_page() {
  16. LP_Assets::enqueue_style( 'learn-press-admin' );
  17. LP_Assets::enqueue_script( 'learn-press-admin-settings', LP()->plugin_url( 'assets/js/admin/settings.js' ) );
  18. $current_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : '';
  19. $tabs = learn_press_settings_tabs_array();
  20. if ( !$current_tab && $tabs ) {
  21. $keys = array_keys( $tabs );
  22. $current_tab = reset( $keys );
  23. }
  24. // ensure all settings relevant to rewrite rules effect immediately
  25. flush_rewrite_rules();
  26. if ( !empty( $_GET['settings-updated'] ) ) : ?>
  27. <div id="message" class="updated notice is-dismissible">
  28. <p><?php _e( 'LearnPress settings updated.', 'learnpress' ); ?></p>
  29. </div>
  30. <?php endif; ?>
  31. <div class="wrap" id="learn-press-admin-settings">
  32. <div id="learn-press-updating-message" class="error hide-if-js">
  33. <p><?php esc_html_e( 'Settings changed. Updating...', 'learnpress' ); ?></p>
  34. </div>
  35. <div id="learn-press-updated-message" class="updated hide-if-js">
  36. <p><?php esc_html_e( 'Settings updated. Redirecting...', 'learnpress' ); ?></p>
  37. </div>
  38. <form method="<?php echo esc_attr( apply_filters( 'learn_press_settings_form_method_tab_' . $current_tab, 'post' ) ); ?>" id="mainform" action="" enctype="multipart/form-data">
  39. <div id="icon-themes" class="icon32"><br></div>
  40. <h2 class="nav-tab-wrapper">
  41. <?php if ( $tabs ) foreach ( $tabs as $tab => $name ) { ?>
  42. <?php $class = ( $tab == $current_tab ) ? ' nav-tab-active' : ''; ?>
  43. <a class="nav-tab <?php echo $class; ?>" href="?page=learn_press_settings&tab=<?php echo $tab; ?>"><?php echo $name; ?></a>
  44. <?php } ?>
  45. <?php do_action( 'learn_press_settings_tabs' ); ?>
  46. </h2>
  47. <?php
  48. do_action( 'learn_press_sections_' . $current_tab );
  49. do_action( 'learn_press_settings_' . $current_tab );
  50. ?>
  51. <p>
  52. <button class="button button-primary"><?php _e( 'Save settings', 'learnpress' ); ?></button>
  53. </p>
  54. <?php wp_nonce_field( 'learn_press_settings', 'learn_press_settings_nonce' ); ?>
  55. </form>
  56. </div>
  57. <?php
  58. }
  59. function learn_press_admin_update_settings() {
  60. $tabs = learn_press_settings_tabs_array();
  61. $current_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : '';
  62. if ( !$current_tab && $tabs ) {
  63. $keys = array_keys( $tabs );
  64. $current_tab = reset( $keys );
  65. }
  66. $class_name = apply_filters( 'learn_press_settings_class_' . $current_tab, 'LP_Settings_' . $tabs[$current_tab] );
  67. if ( !class_exists( $class_name ) ) {
  68. $class_file = apply_filters( 'learn_press_settings_file_' . $current_tab, LP()->plugin_path( 'inc/admin/settings/class-lp-settings-' . $current_tab . '.php' ) );
  69. if ( !file_exists( $class_file ) ) {
  70. return false;
  71. }
  72. include_once $class_file;
  73. if ( !class_exists( $class_name ) ) {
  74. }
  75. }
  76. if ( !empty( $_POST ) ) {
  77. // Check if our nonce is set.
  78. if ( !isset( $_POST['learn_press_settings_nonce'] ) ) {
  79. return;
  80. }
  81. // Verify that the nonce is valid.
  82. if ( !wp_verify_nonce( $_POST['learn_press_settings_nonce'], 'learn_press_settings' ) ) {
  83. return;
  84. }
  85. do_action( 'learn_press_settings_save_' . $current_tab );
  86. $section = !empty( $_REQUEST['section'] ) ? '&section=' . $_REQUEST['section'] : '';
  87. LP_Admin_Notice::add( '<p><strong>' . __( 'Settings saved', 'learnpress' ) . '</strong></p>' );
  88. wp_redirect( admin_url( 'options-general.php?page=learn_press_settings&tab=' . $current_tab . $section . '&settings-updated=true' ) );
  89. exit();
  90. }
  91. }