| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) || exit(); |
| 3 |
|
| 4 |
/** |
| 5 |
* Class LP_Submenu_Settings |
| 6 |
*/ |
| 7 |
class LP_Submenu_Settings extends LP_Abstract_Submenu { |
| 8 |
/** |
| 9 |
* @var LP_Abstract_Settings_Page[] |
| 10 |
*/ |
| 11 |
protected $tabs = array(); |
| 12 |
|
| 13 |
/** |
| 14 |
* LP_Submenu_Settings constructor. |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
$this->id = 'learn-press-settings'; |
| 18 |
$this->menu_title = esc_html__( 'Settings', 'learnpress' ); |
| 19 |
$this->page_title = esc_html__( 'LearnPress Settings', 'learnpress' ); |
| 20 |
$this->priority = 30; |
| 21 |
|
| 22 |
$this->tabs = apply_filters( |
| 23 |
'learn-press/admin/settings-tabs-array', |
| 24 |
array( |
| 25 |
'general' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-general.php', |
| 26 |
'courses' => new LP_Settings_Courses(), |
| 27 |
'profile' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-profile.php', |
| 28 |
'payments' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-payments.php', |
| 29 |
'emails' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-emails.php', |
| 30 |
'advanced' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-advanced.php', |
| 31 |
) |
| 32 |
); |
| 33 |
|
| 34 |
add_action( 'learn-press/admin/page-content-settings', array( $this, 'page_contents' ) ); |
| 35 |
add_action( 'learn-press/admin/page-' . $this->_get_page() . '/section-content', array( $this, 'section_content' ) ); |
| 36 |
|
| 37 |
/** Save metabox in LP4 */ |
| 38 |
add_action( 'admin_init', array( $this, 'save_settings' ) ); |
| 39 |
|
| 40 |
parent::__construct(); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Display menu content |
| 45 |
*/ |
| 46 |
public function page_content() { |
| 47 |
parent::page_content(); |
| 48 |
} |
| 49 |
|
| 50 |
public function page_contents() { |
| 51 |
$active_tab = $this->get_active_tab(); |
| 52 |
|
| 53 |
$this->tabs[ $active_tab ]->admin_page_settings( $this->get_active_section(), $this->get_sections() ); |
| 54 |
?> |
| 55 |
|
| 56 |
<input type="hidden" name="lp-settings-nonce" value="<?php echo wp_create_nonce( 'lp-settings' ); ?>"> |
| 57 |
<p class="lp-admin-settings-buttons"> |
| 58 |
<button class="button button-primary"><?php esc_html_e( 'Save settings', 'learnpress' ); ?></button> |
| 59 |
</p> |
| 60 |
|
| 61 |
<?php |
| 62 |
} |
| 63 |
|
| 64 |
public function section_content( $section ) { |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Update metabox setting |
| 69 |
* |
| 70 |
* @return void |
| 71 |
* @version 4.0.0 |
| 72 |
* @author ThimPress <nhamdv> |
| 73 |
*/ |
| 74 |
public function save_settings() { |
| 75 |
if ( ! is_admin() || ! isset( $_GET['page'] ) || 'learn-press-settings' !== $_GET['page'] ) { |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
$nonce = learn_press_get_request( 'lp-settings-nonce' ); |
| 80 |
|
| 81 |
if ( ! wp_verify_nonce( $nonce, 'lp-settings' ) ) { |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
$active_tab = $this->get_active_tab(); |
| 86 |
|
| 87 |
$this->tabs[ $active_tab ]->save_settings( $this->get_active_section(), $this->get_sections() ); |
| 88 |
|
| 89 |
// flush_rewrite_rules(); |
| 90 |
|
| 91 |
do_action( 'learn-press/update-settings/updated', $this ); |
| 92 |
|
| 93 |
// Filter redirect |
| 94 |
$redirect = apply_filters( 'learn-press/update-settings/redirect', esc_url_raw( add_query_arg( 'settings-updated', 'yes' ) ), $this ); |
| 95 |
|
| 96 |
if ( $redirect ) { |
| 97 |
wp_redirect( $redirect ); |
| 98 |
exit(); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
public function save() { |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
return new LP_Submenu_Settings(); |
| 107 |
|