← All changes
|
inc/admin/settings/class-lp-settings-advanced.php
+165
-39
4.3.8
→
4.4.8
View file →
| @@ -1,39 +1,165 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Class LP_Settings_Profile | |
| 4 | - * | |
| 5 | - * @author ThimPress | |
| 6 | - * @package LearnPress/Admin/Classes/Settings | |
| 7 | - * @version 4.0.0 | |
| 8 | - */ | |
| 9 | - | |
| 10 | -use LearnPress\Helpers\Config; | |
| 11 | - | |
| 12 | -defined( 'ABSPATH' ) || exit; | |
| 13 | - | |
| 14 | -class LP_Settings_Advanced extends LP_Abstract_Settings_Page { | |
| 15 | - | |
| 16 | - public function __construct() { | |
| 17 | - $this->id = 'advanced'; | |
| 18 | - $this->text = esc_html__( 'Advanced', 'learnpress' ); | |
| 19 | - | |
| 20 | - parent::__construct(); | |
| 21 | - } | |
| 22 | - | |
| 23 | - public function get_settings( $section = '', $tab = '' ) { | |
| 24 | - return Config::instance()->get( 'advanced', 'settings' ); | |
| 25 | - } | |
| 26 | - | |
| 27 | - /** | |
| 28 | - * Get sections for advanced settings. | |
| 29 | - * | |
| 30 | - * @return array<string, string> | |
| 31 | - */ | |
| 32 | - public function get_sections() { | |
| 33 | - return array( | |
| 34 | - 'general' => esc_html__( 'General', 'learnpress' ), | |
| 35 | - ); | |
| 36 | - } | |
| 37 | -} | |
| 38 | - | |
| 39 | -return new LP_Settings_Advanced(); | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Class LP_Settings_Advanced | |
| 4 | + * | |
| 5 | + * @author ThimPress | |
| 6 | + * @package LearnPress/Admin/Classes/Settings | |
| 7 | + * @version 4.0.0 | |
| 8 | + */ | |
| 9 | + | |
| 10 | +use LearnPress\Helpers\Config; | |
| 11 | +use LearnPress\Helpers\Template; | |
| 12 | + | |
| 13 | +defined( 'ABSPATH' ) || exit; | |
| 14 | + | |
| 15 | +class LP_Settings_Advanced extends LP_Abstract_Settings_Page { | |
| 16 | + | |
| 17 | + public function __construct() { | |
| 18 | + $this->id = 'advanced'; | |
| 19 | + $this->text = esc_html__( 'Advanced', 'learnpress' ); | |
| 20 | + | |
| 21 | + parent::__construct(); | |
| 22 | + } | |
| 23 | + | |
| 24 | + public function get_settings( $section = '', $tab = '' ) { | |
| 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' ) | |
| 95 | + ), | |
| 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' | |
| 103 | + ); | |
| 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 | + } | |
| 164 | +} | |
| 165 | +return new LP_Settings_Advanced(); | |