| 1 |
<?php |
| 2 |
/** |
| 3 |
* MCP Tool — Get Breadcrumb Path |
| 4 |
* |
| 5 |
* Returns the resolved breadcrumb trail for a given post or page. |
| 6 |
* |
| 7 |
* @package MetaSync |
| 8 |
* @subpackage MCP_Server/Tools |
| 9 |
* @since 2.9.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
class MCP_Tool_Get_Breadcrumb_Path extends MCP_Tool_Base { |
| 17 |
|
| 18 |
/** |
| 19 |
* @inheritDoc |
| 20 |
*/ |
| 21 |
public function get_name() { |
| 22 |
return 'wordpress_get_breadcrumb_path'; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* @inheritDoc |
| 27 |
*/ |
| 28 |
public function get_description() { |
| 29 |
return 'Get the resolved breadcrumb trail for a post or page'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @inheritDoc |
| 34 |
*/ |
| 35 |
public function get_input_schema() { |
| 36 |
return array( |
| 37 |
'type' => 'object', |
| 38 |
'properties' => array( |
| 39 |
'post_id' => array( |
| 40 |
'type' => 'integer', |
| 41 |
'description' => 'The post ID to resolve the breadcrumb trail for', |
| 42 |
), |
| 43 |
), |
| 44 |
'required' => array('post_id'), |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @inheritDoc |
| 50 |
*/ |
| 51 |
public function execute($params) { |
| 52 |
$this->validate_params($params); |
| 53 |
$this->require_capability('edit_posts'); |
| 54 |
|
| 55 |
$post_id = intval($params['post_id']); |
| 56 |
$this->check_post_permission($post_id); |
| 57 |
$this->verify_post_exists($post_id); |
| 58 |
|
| 59 |
$breadcrumbs = new Metasync_Breadcrumbs(); |
| 60 |
$trail = $breadcrumbs->resolve_breadcrumb_trail($post_id); |
| 61 |
|
| 62 |
if (!function_exists('is_plugin_active')) { |
| 63 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 64 |
} |
| 65 |
|
| 66 |
$payload = array( |
| 67 |
'post_id' => $post_id, |
| 68 |
'trail' => $trail, |
| 69 |
'trail_count' => count($trail), |
| 70 |
'custom_label' => get_post_meta($post_id, '_metasync_breadcrumb_title', true), |
| 71 |
); |
| 72 |
|
| 73 |
if (is_plugin_active('wordpress-seo/wp-seo.php') || |
| 74 |
is_plugin_active('wordpress-seo-premium/wp-seo-premium.php')) { |
| 75 |
$payload['yoast_label'] = get_post_meta($post_id, '_yoast_wpseo_bctitle', true); |
| 76 |
} |
| 77 |
|
| 78 |
if (is_plugin_active('seo-by-rank-math/rank-math.php') || |
| 79 |
is_plugin_active('seo-by-rankmath/rank-math.php')) { |
| 80 |
$payload['rankmath_label'] = get_post_meta($post_id, 'rank_math_breadcrumb_title', true); |
| 81 |
} |
| 82 |
|
| 83 |
return $this->success($payload); |
| 84 |
} |
| 85 |
} |
| 86 |
|