← All changes
|
inc/admin/settings/class-lp-settings-advanced.php
+140
-86
4.2.0
→
4.4.8
View file →
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Class LP_Settings_Profile | |
| 3 | + * Class LP_Settings_Advanced | |
| 4 | 4 | * |
| 5 | 5 | * @author ThimPress |
| 6 | 6 | * @package LearnPress/Admin/Classes/Settings |
| 7 | 7 | * @version 4.0.0 |
| @@ -6,8 +6,11 @@ | ||
| 6 | 6 | * @package LearnPress/Admin/Classes/Settings |
| 7 | 7 | * @version 4.0.0 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | +use LearnPress\Helpers\Config; | |
| 11 | +use LearnPress\Helpers\Template; | |
| 12 | + | |
| 10 | 13 | defined( 'ABSPATH' ) || exit; |
| 11 | 14 | |
| 12 | 15 | class LP_Settings_Advanced extends LP_Abstract_Settings_Page { |
| 13 | 16 | |
| @@ -18,94 +21,145 @@ | ||
| 18 | 21 | parent::__construct(); |
| 19 | 22 | } |
| 20 | 23 | |
| 21 | 24 | public function get_settings( $section = '', $tab = '' ) { |
| 22 | - return apply_filters( | |
| 23 | - 'learn_press_advanced_settings', | |
| 24 | - array( | |
| 25 | - array( | |
| 26 | - 'type' => 'title', | |
| 27 | - 'title' => esc_html__( 'Style', 'learnpress' ), | |
| 28 | - 'id' => 'lp_metabox_setting_advanced', | |
| 25 | + | |
| 26 | + return parent::get_settings( $section, $tab ); | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Settings fields for the general section. | |
| 31 | + * | |
| 32 | + * @return mixed | |
| 33 | + */ | |
| 34 | + public function get_settings_general() { | |
| 35 | + | |
| 36 | + return Config::instance()->get( 'advanced', 'settings' ); | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Settings fields for the MCP section. | |
| 41 | + * | |
| 42 | + * @return mixed | |
| 43 | + */ | |
| 44 | + public function get_settings_mcp() { | |
| 45 | + | |
| 46 | + if ( ! self::is_mcp_available() ) { | |
| 47 | + return array(); | |
| 48 | + } | |
| 49 | + return Config::instance()->get( 'mcp', 'settings' ); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Settings fields for the Webhook section. | |
| 54 | + * | |
| 55 | + * @return mixed | |
| 56 | + */ | |
| 57 | + public function get_settings_webhook() { | |
| 58 | + | |
| 59 | + return Config::instance()->get( 'webhook', 'settings' ); | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 63 | + * Check whether MCP capabilities are available in current WordPress runtime. | |
| 64 | + * | |
| 65 | + * @return bool | |
| 66 | + */ | |
| 67 | + public static function is_mcp_available(): bool { | |
| 68 | + | |
| 69 | + return learn_press_is_mcp_available(); | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Backward-compatible alias for MCP availability checks. | |
| 74 | + * | |
| 75 | + * @return bool | |
| 76 | + */ | |
| 77 | + public static function is_mcp_adapter_active(): bool { | |
| 78 | + | |
| 79 | + return self::is_mcp_available(); | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Render MCP unavailable notice. | |
| 84 | + * | |
| 85 | + * @return void | |
| 86 | + */ | |
| 87 | + protected function render_mcp_unavailable_notice(): void { | |
| 88 | + Template::print_message( | |
| 89 | + sprintf( | |
| 90 | + 'This feature requires the %s and WP from 6.9+. Please install and activate it to access the settings. %s', | |
| 91 | + sprintf( | |
| 92 | + '<a href="%s">%s</a>', | |
| 93 | + esc_url_raw( 'https://github.com/wordpress/mcp-adapter/' ), | |
| 94 | + esc_html__( 'MCP Adapter plugin', 'learnpress' ) | |
| 29 | 95 | ), |
| 30 | - array( | |
| 31 | - 'title' => esc_html__( 'Primary color', 'learnpress' ), | |
| 32 | - 'desc' => sprintf( __( 'Default: %s', 'learnpress' ), '<code>#ffb606</code>' ), | |
| 33 | - 'id' => 'primary_color', | |
| 34 | - 'type' => 'color', | |
| 35 | - 'css' => 'width:6em;', | |
| 36 | - 'default' => '#ffb606', | |
| 37 | - 'autoload' => false, | |
| 38 | - 'desc_tip' => true, | |
| 39 | - ), | |
| 40 | - array( | |
| 41 | - 'title' => esc_html__( 'Secondary color', 'learnpress' ), | |
| 42 | - 'desc' => sprintf( __( 'Default: %s', 'learnpress' ), '<code>#442e66</code>' ), | |
| 43 | - 'id' => 'secondary_color', | |
| 44 | - 'type' => 'color', | |
| 45 | - 'css' => 'width:6em;', | |
| 46 | - 'default' => '#442e66', | |
| 47 | - 'autoload' => false, | |
| 48 | - 'desc_tip' => true, | |
| 49 | - ), | |
| 50 | - array( | |
| 51 | - 'type' => 'sectionend', | |
| 52 | - 'id' => 'lp_metabox_setting_advanced', | |
| 53 | - ), | |
| 54 | - array( | |
| 55 | - 'type' => 'title', | |
| 56 | - 'title' => esc_html__( 'Other', 'learnpress' ), | |
| 57 | - 'id' => 'lp_metabox_advanced_other', | |
| 58 | - ), | |
| 59 | - array( | |
| 60 | - 'title' => esc_html__( 'Enable gutenberg', 'learnpress' ), | |
| 61 | - 'id' => 'enable_gutenberg_course', | |
| 62 | - 'default' => 'no', | |
| 63 | - 'type' => 'checkbox', | |
| 64 | - 'checkboxgroup' => 'start', | |
| 65 | - 'desc' => esc_html__( 'Course', 'learnpress' ), | |
| 66 | - ), | |
| 67 | - array( | |
| 68 | - 'id' => 'enable_gutenberg_lesson', | |
| 69 | - 'default' => 'no', | |
| 70 | - 'type' => 'checkbox', | |
| 71 | - 'checkboxgroup' => '', | |
| 72 | - 'desc' => esc_html__( 'Lesson', 'learnpress' ), | |
| 73 | - ), | |
| 74 | - array( | |
| 75 | - 'id' => 'enable_gutenberg_quiz', | |
| 76 | - 'default' => 'no', | |
| 77 | - 'type' => 'checkbox', | |
| 78 | - 'checkboxgroup' => '', | |
| 79 | - 'desc' => esc_html__( 'Quiz', 'learnpress' ), | |
| 80 | - ), | |
| 81 | - array( | |
| 82 | - 'id' => 'enable_gutenberg_question', | |
| 83 | - 'default' => 'no', | |
| 84 | - 'type' => 'checkbox', | |
| 85 | - 'checkboxgroup' => 'end', | |
| 86 | - 'desc' => esc_html__( 'Question', 'learnpress' ), | |
| 87 | - ), | |
| 88 | - array( | |
| 89 | - 'title' => esc_html__( 'Debug Mode', 'learnpress' ), | |
| 90 | - 'id' => 'debug', | |
| 91 | - 'default' => 'no', | |
| 92 | - 'type' => 'checkbox', | |
| 93 | - 'desc' => esc_html__( 'Enable debug mode for the developer.', 'learnpress' ), | |
| 94 | - ), | |
| 95 | - array( | |
| 96 | - 'title' => esc_html__( 'Sticky Quiz Paging', 'learnpress' ), | |
| 97 | - 'id' => 'navigation_position', | |
| 98 | - 'default' => 'yes', | |
| 99 | - 'type' => 'checkbox', | |
| 100 | - 'desc' => esc_html__( 'The question\'s navigation position is sticky. If this option is disabled, the question navigation position will be below the quiz content', 'learnpress' ), | |
| 101 | - ), | |
| 102 | - array( | |
| 103 | - 'type' => 'sectionend', | |
| 104 | - 'id' => 'lp_metabox_advanced_other', | |
| 105 | - ), | |
| 106 | - ) | |
| 96 | + sprintf( | |
| 97 | + '<a href="%s">%s</a>', | |
| 98 | + esc_url_raw( 'https://learnpresslms.com/docs/learnpress-developer-documentation/model-context-protocol-mcp-integration/' ), | |
| 99 | + esc_html__( 'Learn more', 'learnpress' ) | |
| 100 | + ) | |
| 101 | + ), | |
| 102 | + 'warning' | |
| 107 | 103 | ); |
| 108 | 104 | } |
| 105 | + | |
| 106 | + /** | |
| 107 | + * Render Advanced settings sections. | |
| 108 | + * | |
| 109 | + * @param string $section | |
| 110 | + * @param string $tab | |
| 111 | + * | |
| 112 | + * @return void | |
| 113 | + */ | |
| 114 | + public function admin_page_settings( $section = null, $tab = '' ) { | |
| 115 | + parent::admin_page_settings( $section, $tab ); | |
| 116 | + | |
| 117 | + if ( 'mcp' === $section ) { | |
| 118 | + if ( ! self::is_mcp_available() ) { | |
| 119 | + $this->render_mcp_unavailable_notice(); | |
| 120 | + return; | |
| 121 | + } | |
| 122 | + //parent::admin_page_settings( $section, $tab ); | |
| 123 | + | |
| 124 | + if ( 'yes' === LP_Settings::get_option( 'enable_mcp_integration', 'no' ) && class_exists( 'LP_Admin_MCP_API_Keys' ) ) { | |
| 125 | + LP_Admin_MCP_API_Keys::instance()->render_page(); | |
| 126 | + } | |
| 127 | + return; | |
| 128 | + } | |
| 129 | + | |
| 130 | + if ( 'webhook' === $section && 'yes' === LP_Settings::get_option( 'enable_webhook_integration', 'no' ) ) { | |
| 131 | + LP_Admin_Webhooks::instance()->render_page(); | |
| 132 | + } | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Save Advanced settings sections. | |
| 137 | + * | |
| 138 | + * @param string $section | |
| 139 | + * @param string $tab | |
| 140 | + * | |
| 141 | + * @return void | |
| 142 | + */ | |
| 143 | + public function save_settings( $section = null, $tab = '' ) { | |
| 144 | + | |
| 145 | + if ( 'mcp' === $section && ! self::is_mcp_available() ) { | |
| 146 | + return; | |
| 147 | + } | |
| 148 | + parent::save_settings( $section, $tab ); | |
| 149 | + } | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Get sections for advanced settings. | |
| 153 | + * | |
| 154 | + * @return array<string, string> | |
| 155 | + */ | |
| 156 | + public function get_sections() { | |
| 157 | + | |
| 158 | + return array( | |
| 159 | + 'general' => esc_html__( 'General', 'learnpress' ), | |
| 160 | + 'mcp' => esc_html__( 'MCP', 'learnpress' ), | |
| 161 | + 'webhook' => esc_html__( 'Webhook', 'learnpress' ), | |
| 162 | + ); | |
| 163 | + } | |
| 109 | 164 | } |
| 110 | - | |
| 111 | 165 | return new LP_Settings_Advanced(); |