id = 'thinkrank/get-faq'; $this->label = __( 'Get ThinkRank FAQ', 'thinkrank' ); $this->description = __( 'Read the FAQ questions and answers on one post, where they are stored (the ThinkRank FAQ block, or the Elementor, Bricks or Beaver module), and whether ThinkRank is publishing FAQPage schema for the post. Call this before update-faq: it reports which builder renders the post, and update-faq can only write posts built with the block editor. Read writable_reason before acting on a post that is not writable, and questions_readable before trusting the question count. Oxygen and Breakdance pages have no ThinkRank FAQ module, so their own accordions are read instead and reported with source oxygen or breakdance; those questions reach FAQPage schema only while the accordion setting in Schema Settings is on, which it is not by default. Note that Google shows FAQ rich results only for well-known, authoritative government and health websites, so for most sites the value of an FAQ is being quotable by answer engines, not a rich result.', 'thinkrank' ); } /** * {@inheritDoc} * * @return array */ public function get_annotations() { return [ 'readonly' => true, 'destructive' => false, 'idempotent' => true, 'priority' => 0.6, 'openWorldHint' => false, ]; } /** * {@inheritDoc} * * @return array */ public function get_input_schema() { return [ 'type' => 'object', 'additionalProperties' => false, 'required' => [ 'post_id' ], 'properties' => [ 'post_id' => [ 'type' => 'integer', 'description' => __( 'Post ID from list-content-items.', 'thinkrank' ), ], ], ]; } /** * {@inheritDoc} * * @return array */ public function get_output_schema() { return [ 'type' => 'object', 'properties' => [ 'post_id' => [ 'type' => 'integer' ], 'post_title' => [ 'type' => 'string' ], 'post_type' => [ 'type' => 'string' ], 'permalink' => [ 'type' => 'string' ], 'edit_url' => [ 'type' => 'string' ], 'builder' => [ 'type' => 'string', 'enum' => $this->builder_enum(), 'description' => __( 'Which page builder renders this post. Anything but "none" means update-faq will refuse it. "none" means the block editor, not "no builder was recognised".', 'thinkrank' ), ], 'writable' => [ 'type' => 'boolean', 'description' => __( 'True when update-faq can write this post. False for builder-rendered posts, where a block would be stored but never shown.', 'thinkrank' ), ], 'writable_reason' => [ 'type' => 'string', 'description' => __( 'Why update-faq will or will not write this post, in a sentence. Read this before deciding what to do with a post that is not writable: a builder ThinkRank has a FAQ module for is a different situation from one it only recognises.', 'thinkrank' ), ], 'questions_readable' => [ 'type' => 'boolean', 'description' => __( 'Whether ThinkRank can read the questions this post stores. False for a builder with no ThinkRank FAQ module, where total and items describe only what is left in the post content and a count of zero does not mean the page has no FAQ.', 'thinkrank' ), ], 'faqpage_emitted' => [ 'type' => 'boolean', 'description' => __( 'Whether ThinkRank currently publishes FAQPage schema for this post. False with questions present means the post is password protected, the content type has Schema off, a producer has its schema toggle off, or another plugin already publishes its own FAQPage here.', 'thinkrank' ), ], 'total' => [ 'type' => 'integer' ], 'items' => [ 'type' => 'array', 'items' => [ 'type' => 'object', 'properties' => $this->item_properties(), ], ], ], ]; } /** * Execute ability. * * @param array $input Ability input payload. * @return array|\WP_Error */ public function execute( $input ) { $input = (array) $input; $post = $this->resolve_post( (int) ( $input['post_id'] ?? 0 ) ); if ( $post instanceof \WP_Error ) { return $post; } $items = FAQ_Content::items( $post ); $builder = FAQ_Content::builder( (int) $post->ID ); return [ 'post_id' => (int) $post->ID, 'post_title' => (string) get_the_title( $post ), 'post_type' => (string) $post->post_type, 'permalink' => (string) get_permalink( $post ), 'edit_url' => (string) get_edit_post_link( $post->ID, 'raw' ), 'builder' => $this->builder_name( $builder ), 'writable' => '' === $builder, 'writable_reason' => $this->writable_reason( $builder ), 'questions_readable' => FAQ_Content::builder_is_readable( $builder ), 'faqpage_emitted' => Schema_Graph::will_emit_faqpage( $post ), 'total' => count( $items ), 'items' => $items, ]; } }