| 1 |
<?php |
| 2 |
|
| 3 |
use LearnPress\Helpers\Config; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class LP_Settings_Permalink |
| 7 |
* |
| 8 |
* @author ThimPress |
| 9 |
* @package LearnPress/Admin/Settings |
| 10 |
* @since 4.1.7.3.2 |
| 11 |
* @version 1.0.0 |
| 12 |
*/ |
| 13 |
class LP_Settings_Permalink extends LP_Abstract_Settings_Page { |
| 14 |
/** |
| 15 |
* Construct |
| 16 |
*/ |
| 17 |
public function __construct() { |
| 18 |
$this->id = 'permalink'; |
| 19 |
$this->text = esc_html__( 'Permalinks', 'learnpress' ); |
| 20 |
|
| 21 |
parent::__construct(); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Return fields for settings page. |
| 26 |
* |
| 27 |
* @param string $section |
| 28 |
* @param string $tab |
| 29 |
* |
| 30 |
* @return mixed |
| 31 |
*/ |
| 32 |
public function get_settings( $section = '', $tab = '' ) { |
| 33 |
return Config::instance()->get( 'permalink', 'settings' ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* @since 4.3.2.3 |
| 38 |
* |
| 39 |
* move from LP_Settings_Courses class to here |
| 40 |
*/ |
| 41 |
public function save() { |
| 42 |
$course_permalink = trim( LP_Request::get_param( 'learn_press_course_base' ) ); |
| 43 |
if ( ! $course_permalink ) { |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
if ( $course_permalink == 'custom' ) { |
| 48 |
$course_permalink = trim( LP_Request::get_param( 'course_permalink_structure' ), '/' ); |
| 49 |
|
| 50 |
if ( '%course_category%' == $course_permalink ) { |
| 51 |
$course_permalink = _x( 'courses', 'slug', 'learnpress' ) . '/' . $course_permalink; |
| 52 |
} |
| 53 |
|
| 54 |
$course_permalink = '/' . $course_permalink; |
| 55 |
update_option( 'learn_press_course_base_type', 'custom' ); |
| 56 |
} else { |
| 57 |
delete_option( 'learn_press_course_base_type' ); |
| 58 |
} |
| 59 |
|
| 60 |
$course_base = untrailingslashit( $course_permalink ); |
| 61 |
|
| 62 |
update_option( 'learn_press_course_base', $course_base ); |
| 63 |
//$courses_page_id = learn_press_get_page_id( 'courses' ); |
| 64 |
//$courses_permalink = ( $courses_page_id > 0 && get_post( $courses_page_id ) ) ? get_page_uri( $courses_page_id ) : _x( 'courses', 'default-slug', 'learnpress' ); |
| 65 |
|
| 66 |
/*if ( $courses_page_id && trim( $course_base, '/' ) === $courses_permalink ) { |
| 67 |
update_option( 'learn_press_use_verbose_page_rules', 'yes' ); |
| 68 |
} else { |
| 69 |
delete_option( 'learn_press_use_verbose_page_rules' ); |
| 70 |
}*/ |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
return new LP_Settings_Permalink(); |
| 75 |
|