| @@ -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 |
| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | * @version 4.0.0 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | use LearnPress\Helpers\Config; |
| 11 | +use LearnPress\Helpers\Template; | |
| 11 | 12 | |
| 12 | 13 | defined( 'ABSPATH' ) || exit; |
| 13 | 14 | |
| 14 | 15 | class LP_Settings_Advanced extends LP_Abstract_Settings_Page { |
| @@ -20,20 +21,145 @@ | ||
| 20 | 21 | parent::__construct(); |
| 21 | 22 | } |
| 22 | 23 | |
| 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 | + | |
| 24 | 36 | return Config::instance()->get( 'advanced', 'settings' ); |
| 25 | 37 | } |
| 26 | 38 | |
| 27 | 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 | + /** | |
| 28 | 152 | * Get sections for advanced settings. |
| 29 | 153 | * |
| 30 | 154 | * @return array<string, string> |
| 31 | 155 | */ |
| 32 | 156 | public function get_sections() { |
| 157 | + | |
| 33 | 158 | return array( |
| 34 | 159 | 'general' => esc_html__( 'General', 'learnpress' ), |
| 160 | + 'mcp' => esc_html__( 'MCP', 'learnpress' ), | |
| 161 | + 'webhook' => esc_html__( 'Webhook', 'learnpress' ), | |
| 35 | 162 | ); |
| 36 | 163 | } |
| 37 | 164 | } |
| 38 | - | |
| 39 | 165 | return new LP_Settings_Advanced(); |