| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class LP_Settings_Mcp |
| 4 |
* |
| 5 |
* @package LearnPress/Admin/Classes/Settings |
| 6 |
* @version 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
use LearnPress\Helpers\Config; |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
class LP_Settings_Mcp extends LP_Abstract_Settings_Page { |
| 14 |
/** |
| 15 |
* Construct. |
| 16 |
*/ |
| 17 |
public function __construct() { |
| 18 |
$this->id = 'mcp'; |
| 19 |
$this->text = esc_html__( 'MCP', 'learnpress' ); |
| 20 |
|
| 21 |
parent::__construct(); |
| 22 |
} |
| 23 |
|
| 24 |
public function get_settings( $section = '', $tab = '' ) { |
| 25 |
return Config::instance()->get( 'mcp', 'settings' ); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Render MCP unavailable notice. |
| 30 |
* |
| 31 |
* @return void |
| 32 |
*/ |
| 33 |
protected function render_mcp_unavailable_notice(): void { |
| 34 |
$learn_more = sprintf( |
| 35 |
'<a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s</a>', |
| 36 |
esc_url( 'https://learnpresslms.com/docs/learnpress-developer-documentation/model-context-protocol-mcp-integration/' ), |
| 37 |
esc_html__( 'Learn more', 'learnpress' ) |
| 38 |
); |
| 39 |
|
| 40 |
$message = sprintf( |
| 41 |
'%1$s %2$s', |
| 42 |
esc_html__( 'This feature requires WordPress 7.0+ or WordPress 6.9+ with the MCP Adapter plugin activated.', 'learnpress' ), |
| 43 |
$learn_more |
| 44 |
); |
| 45 |
?> |
| 46 |
<div class="notice notice-warning inline"> |
| 47 |
<p><?php echo wp_kses_post( $message ); ?></p> |
| 48 |
</div> |
| 49 |
<?php |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Render MCP settings and API keys on one page (no sub-tabs). |
| 54 |
* |
| 55 |
* @param string $section |
| 56 |
* @param string $tab |
| 57 |
* |
| 58 |
* @return void |
| 59 |
*/ |
| 60 |
public function admin_page_settings( $section = null, $tab = '' ) { |
| 61 |
parent::admin_page_settings( $section, $tab ); |
| 62 |
|
| 63 |
if ( 'yes' === LP_Settings::get_option( 'enable_mcp_integration', 'no' ) && class_exists( 'LP_Admin_MCP_API_Keys' ) ) { |
| 64 |
LP_Admin_MCP_API_Keys::instance()->render_page(); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Save MCP settings when MCP support is available. |
| 70 |
* |
| 71 |
* @param string $section |
| 72 |
* @param string $tab |
| 73 |
* |
| 74 |
* @return void |
| 75 |
*/ |
| 76 |
public function save_settings( $section = null, $tab = '' ) { |
| 77 |
parent::save_settings( $section, $tab ); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
return new LP_Settings_Mcp(); |
| 82 |
|