/**
  * Constructor     
  */
 function __construct()
 {
     $current_tab = isset($_GET['tab']) ? $_GET['tab'] : '';
     $tabs = learn_press_settings_tabs_array();
     if (!$current_tab && $tabs) {
         $tab_keys = array_keys($tabs);
         $current_tab = reset($tab_keys);
         $this->tab = array('id' => $current_tab, 'text' => $tabs[$current_tab]);
     } else {
         $this->tab = array('id' => null, 'text' => null);
     }
     $current_section = !empty($_REQUEST['section']) ? $_REQUEST['section'] : '';
     $sections = $this->get_sections();
     if ($sections) {
         $array_keys = array_keys($sections);
         if (!$current_section) {
             $current_section = reset($array_keys);
         }
         if (!empty($sections[$current_section])) {
             $this->section = array('id' => $current_section, 'text' => $sections[$current_section]);
         } else {
             $this->section = array('id' => null, 'text' => '');
         }
     } else {
         $this->section = array('id' => null, 'text' => '');
     }
     add_action('learn_press_sections_' . $this->id, array($this, 'output_sections'));
     add_action('learn_press_settings_' . $this->id, array($this, 'output'));
     add_action('learn_press_settings_save_' . $this->id, array($this, 'save'));
 }
Example #2
0
 /**
  * Redirect to admin settings page
  */
 function _redirect()
 {
     $page = isset($_GET['page']) ? $_GET['page'] : '';
     if ('learn_press_settings' == $page) {
         $current_tab = isset($_GET['tab']) ? $_GET['tab'] : '';
         $tabs = learn_press_settings_tabs_array();
         if (!$current_tab || $tabs && empty($tabs[$current_tab])) {
             if ($tabs) {
                 $tab_keys = array_keys($tabs);
                 $current_tab = reset($tab_keys);
                 wp_redirect(admin_url('options-general.php?page=learn_press_settings&tab=' . $current_tab));
                 exit;
             }
         }
     }
 }
 /**
  * Constructor
  */
 function __construct()
 {
     if (strtolower(current_filter()) == 'activate_learnpress/learnpress.php') {
         return;
     }
     $current_tab = isset($_GET['tab']) ? $_GET['tab'] : '';
     $tabs = learn_press_settings_tabs_array();
     if (!$current_tab && $tabs) {
         $tab_keys = array_keys($tabs);
         $current_tab = reset($tab_keys);
         $this->tab = array('id' => $current_tab, 'text' => $tabs[$current_tab]);
     } else {
         $this->tab = array('id' => null, 'text' => null);
     }
     $current_section = !empty($_REQUEST['section']) ? $_REQUEST['section'] : '';
     $sections = $this->get_sections();
     /**
      * Find current section by detect request
      */
     if ($sections) {
         $array_keys = array_keys($sections);
         if (!$current_section) {
             $current_section = reset($array_keys);
         }
         if (!empty($sections[$current_section])) {
             $this->section = $sections[$current_section];
         } else {
             $this->section = array('id' => null, 'title' => '');
         }
     } else {
         $this->section = array('id' => null, 'title' => '');
     }
     if ($sections = $this->get_sections()) {
         foreach ($sections as $id => $text) {
             $callback = apply_filters('learn_press_section_callback_' . $this->id . '_' . $id, array($this, 'output_section_' . $id));
             if (is_callable($callback)) {
                 add_action('learn_press_section_' . $this->id . '_' . $id, $callback);
             }
         }
     }
     // hooks
     add_action('learn_press_sections_' . $this->id, array($this, 'output_sections'));
     add_action('learn_press_settings_' . $this->id, array($this, 'output'));
     add_action('learn_press_settings_save_' . $this->id, array($this, 'save'));
 }
Example #4
0
/**
 * Setting page
 */
function learn_press_settings_page()
{
    LP_Assets::enqueue_style('learn-press-admin');
    LP_Assets::enqueue_script('learn-press-admin-settings', LP()->plugin_url('assets/js/admin/settings.js'));
    $current_tab = isset($_GET['tab']) ? $_GET['tab'] : '';
    $tabs = learn_press_settings_tabs_array();
    if (!$current_tab && $tabs) {
        $current_tab = reset(array_keys($tabs));
    }
    $class_name = apply_filters('learn_press_settings_class_' . $current_tab, 'LP_Settings_' . $tabs[$current_tab]);
    if (!class_exists($class_name)) {
        $class_file = apply_filters('learn_press_settings_file_' . $current_tab, LP()->plugin_path('inc/admin/settings/class-lp-settings-' . $current_tab . '.php'));
        if (!file_exists($class_file)) {
            return false;
        }
        include_once $class_file;
        if (!class_exists($class_name)) {
        }
    }
    if (!empty($_POST)) {
        //	 Check if our nonce is set.
        if (!isset($_POST['learn_press_settings_nonce'])) {
            return;
        }
        // Verify that the nonce is valid.
        if (!wp_verify_nonce($_POST['learn_press_settings_nonce'], 'learn_press_settings')) {
            return;
        }
        do_action('learn_press_settings_save_' . $current_tab);
        $section = !empty($_REQUEST['section']) ? '&section=' . $_REQUEST['section'] : '';
        ?>
<script type="text/javascript">window.location.href = '<?php 
        echo admin_url('options-general.php?page=learn_press_settings&tab=' . $current_tab . $section);
        ?>
';</script><?php 
        exit;
        echo '<div class="updated"><p><strong>' . __('Settings saved', 'learn_press') . '</strong></p></div>';
    }
    ?>
	<form method="<?php 
    echo esc_attr(apply_filters('learn_press_settings_form_method_tab_' . $current_tab, 'post'));
    ?>
" id="mainform" action="" enctype="multipart/form-data">
		<div id="icon-themes" class="icon32"><br></div>
		<h2 class="nav-tab-wrapper">
			<?php 
    if ($tabs) {
        foreach ($tabs as $tab => $name) {
            ?>
				<?php 
            $class = $tab == $current_tab ? ' nav-tab-active' : '';
            ?>
				<a class="nav-tab <?php 
            echo $class;
            ?>
" href="?page=learn_press_settings&tab=<?php 
            echo $tab;
            ?>
"><?php 
            echo $name;
            ?>
</a>
			<?php 
        }
    }
    ?>
			<?php 
    do_action('learn_press_settings_tabs');
    ?>
		</h2>
		<?php 
    do_action('learn_press_sections_' . $current_tab);
    do_action('learn_press_settings_' . $current_tab);
    ?>
		<p>
			<button class="button button-primary"><?php 
    _e('Save settings', 'learn_press');
    ?>
</button>
		</p>
		<?php 
    wp_nonce_field('learn_press_settings', 'learn_press_settings_nonce');
    ?>
	</form>
	<?php 
}
Example #5
0
/**
 * Setting page
 */
function learn_press_settings_page()
{
    require_once LPR_PLUGIN_PATH . "/inc/admin/class.lpr-admin-settings.php";
    require_once LPR_PLUGIN_PATH . "/inc/admin/settings/class.lpr-settings-base.php";
    require_once LPR_PLUGIN_PATH . "/inc/admin/settings/class.lpr-settings-general.php";
    require_once LPR_PLUGIN_PATH . "/inc/admin/settings/class.lpr-settings-pages.php";
    require_once LPR_PLUGIN_PATH . "/inc/admin/settings/class.lpr-settings-payment.php";
    require_once LPR_PLUGIN_PATH . "/inc/admin/settings/class.lpr-settings-emails.php";
    $current_tab = isset($_GET['tab']) ? $_GET['tab'] : '';
    $tabs = learn_press_settings_tabs_array();
    if (!empty($_POST)) {
        //	 Check if our nonce is set.
        if (!isset($_POST['learn_press_settings_nonce'])) {
            return;
        }
        // Verify that the nonce is valid.
        if (!wp_verify_nonce($_POST['learn_press_settings_nonce'], 'learn_press_settings')) {
            return;
        }
        do_action('learn_press_settings_save_' . $current_tab);
        echo '<div class="updated"><p><strong>' . __('Settings saved', 'learn_press') . '</strong></p></div>';
    }
    if (!$current_tab && $tabs) {
        $current_tab = reset(array_keys($tabs));
    }
    ?>
    <form method="<?php 
    echo esc_attr(apply_filters('learn_press_settings_form_method_tab_' . $current_tab, 'post'));
    ?>
" id="mainform" action="" enctype="multipart/form-data">
        <div id="icon-themes" class="icon32"><br></div>
        <h2 class="nav-tab-wrapper">
            <?php 
    if ($tabs) {
        foreach ($tabs as $tab => $name) {
            ?>
                <?php 
            $class = $tab == $current_tab ? ' nav-tab-active' : '';
            ?>
                <a class="nav-tab <?php 
            echo $class;
            ?>
" href="?page=learn_press_settings&tab=<?php 
            echo $tab;
            ?>
"><?php 
            echo $name;
            ?>
</a>
            <?php 
        }
    }
    ?>
            <?php 
    do_action('learn_press_settings_tabs');
    ?>
        </h2>
        <?php 
    do_action('learn_press_sections_' . $current_tab);
    do_action('learn_press_settings_' . $current_tab);
    ?>
        <p>
            <button class="button button-primary"><?php 
    _e('Save settings', 'learn_press');
    ?>
</button>
        </p>
        <?php 
    wp_nonce_field('learn_press_settings', 'learn_press_settings_nonce');
    ?>
    </form>
<?php 
}