register( 'integrations_detect', array( 'description' => 'Detect active integrations: ACF, SEO plugins, cache plugins.', 'domain' => 'integrations', 'capability' => 'manage_options', 'inputSchema' => array( 'type' => 'object', 'properties' => array() ), ), function () { return array( 'acf' => class_exists( 'ACF' ), 'seo' => array( 'yoast' => defined( 'WPSEO_VERSION' ), 'rank_math' => defined( 'RANK_MATH_VERSION' ), ), 'cache' => array( 'wp_rocket' => defined( 'WP_ROCKET_VERSION' ), 'litespeed' => defined( 'LSCWP_V' ), 'w3tc' => defined( 'W3TC' ), ), 'forms' => array( 'wpforms' => class_exists( 'WPForms' ), 'gravity_forms' => class_exists( 'GFForms' ), 'cf7' => defined( 'WPCF7_VERSION' ), ), ); } ); if ( class_exists( 'ACF' ) ) { $registry->register( 'acf_field_groups_list', array( 'description' => 'List ACF field groups.', 'domain' => 'integrations', 'capability' => 'manage_options', 'inputSchema' => array( 'type' => 'object', 'properties' => array() ), ), function () { $groups = function_exists( 'acf_get_field_groups' ) ? acf_get_field_groups() : array(); $items = array(); foreach ( $groups as $group ) { $items[] = array( 'key' => $group['key'] ?? '', 'title' => $group['title'] ?? '', 'id' => $group['ID'] ?? 0, ); } return array( 'field_groups' => $items ); } ); $registry->register( 'acf_fields_get', array( 'description' => 'Get ACF field values for a post.', 'domain' => 'integrations', 'capability' => 'edit_posts', 'inputSchema' => array( 'type' => 'object', 'properties' => array( 'post_id' => array( 'type' => 'integer' ) ), 'required' => array( 'post_id' ), ), ), function ( $args ) { $post_id = absint( $args['post_id'] ); $allowed = Agentdesk_Security::can_edit_post( $post_id ); if ( is_wp_error( $allowed ) ) { return $allowed; } if ( ! function_exists( 'get_fields' ) ) { return new WP_Error( 'agentdesk_acf_unavailable', 'ACF get_fields not available' ); } return array( 'post_id' => $post_id, 'fields' => get_fields( $post_id ) ); } ); } $registry->register( 'seo_meta_get', array( 'description' => 'Get SEO meta title and description for a post (Yoast or Rank Math).', 'domain' => 'integrations', 'capability' => 'edit_posts', 'inputSchema' => array( 'type' => 'object', 'properties' => array( 'post_id' => array( 'type' => 'integer' ) ), 'required' => array( 'post_id' ), ), ), function ( $args ) { $post_id = absint( $args['post_id'] ); $allowed = Agentdesk_Security::can_edit_post( $post_id ); if ( is_wp_error( $allowed ) ) { return $allowed; } $meta = array( 'post_id' => $post_id, 'provider' => null ); if ( defined( 'WPSEO_VERSION' ) ) { $meta['provider'] = 'yoast'; $meta['title'] = get_post_meta( $post_id, '_yoast_wpseo_title', true ); $meta['description'] = get_post_meta( $post_id, '_yoast_wpseo_metadesc', true ); } elseif ( defined( 'RANK_MATH_VERSION' ) ) { $meta['provider'] = 'rank_math'; $meta['title'] = get_post_meta( $post_id, 'rank_math_title', true ); $meta['description'] = get_post_meta( $post_id, 'rank_math_description', true ); } else { return new WP_Error( 'agentdesk_no_seo_plugin', 'No supported SEO plugin detected' ); } return $meta; } ); $registry->register( 'seo_meta_update', array( 'description' => 'Update SEO meta title and description (Yoast or Rank Math).', 'domain' => 'integrations', 'capability' => 'edit_posts', 'inputSchema' => array( 'type' => 'object', 'properties' => array( 'post_id' => array( 'type' => 'integer' ), 'title' => array( 'type' => 'string' ), 'description' => array( 'type' => 'string' ), ), 'required' => array( 'post_id' ), ), ), function ( $args ) { $post_id = absint( $args['post_id'] ); $allowed = Agentdesk_Security::can_edit_post( $post_id ); if ( is_wp_error( $allowed ) ) { return $allowed; } if ( defined( 'WPSEO_VERSION' ) ) { if ( isset( $args['title'] ) ) { update_post_meta( $post_id, '_yoast_wpseo_title', sanitize_text_field( $args['title'] ) ); } if ( isset( $args['description'] ) ) { update_post_meta( $post_id, '_yoast_wpseo_metadesc', sanitize_textarea_field( $args['description'] ) ); } return array( 'updated' => true, 'provider' => 'yoast' ); } if ( defined( 'RANK_MATH_VERSION' ) ) { if ( isset( $args['title'] ) ) { update_post_meta( $post_id, 'rank_math_title', sanitize_text_field( $args['title'] ) ); } if ( isset( $args['description'] ) ) { update_post_meta( $post_id, 'rank_math_description', sanitize_textarea_field( $args['description'] ) ); } return array( 'updated' => true, 'provider' => 'rank_math' ); } return new WP_Error( 'agentdesk_no_seo_plugin', 'No supported SEO plugin detected' ); } ); $registry->register( 'cache_flush', array( 'description' => 'Flush cache for detected cache plugin or WordPress object cache.', 'domain' => 'integrations', 'capability' => 'manage_options', 'inputSchema' => array( 'type' => 'object', 'properties' => array() ), ), function () { $flushed = array(); if ( function_exists( 'rocket_clean_domain' ) ) { rocket_clean_domain(); $flushed[] = 'wp_rocket'; } if ( class_exists( 'LiteSpeed_Cache_API' ) ) { LiteSpeed_Cache_API::purge_all(); $flushed[] = 'litespeed'; } if ( function_exists( 'w3tc_flush_all' ) ) { w3tc_flush_all(); $flushed[] = 'w3tc'; } wp_cache_flush(); $flushed[] = 'object_cache'; return array( 'flushed' => $flushed ); } ); } );