array( 'type' => 'integer', 'minimum' => 1 ), 'taxonomy' => array( 'type' => 'string', 'description' => __( 'Taxonomy name, e.g. category or product_cat.', 'acrossai-abilities-manager' ) ), ); } protected function output_properties(): array { return array( 'post_id' => array( 'type' => 'integer' ), 'taxonomy' => array( 'type' => 'string' ), 'primary_term' => array( 'type' => array( 'object', 'null' ) ), 'assigned' => array( 'type' => 'array' ), ); } protected function required_input(): array { return array( 'post_id', 'taxonomy' ); } protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $result = Post_Meta_Repository::get_primary_term( isset( $input['post_id'] ) ? absint( $input['post_id'] ) : 0, isset( $input['taxonomy'] ) ? sanitize_key( (string) $input['taxonomy'] ) : '' ); if ( is_wp_error( $result ) ) { return $result; } $result['message'] = null === $result['primary_term'] ? sprintf( /* translators: 1: taxonomy name, 2: post id */ __( 'No primary %1$s is set for post %2$d.', 'acrossai-abilities-manager' ), $result['taxonomy'], $result['post_id'] ) : sprintf( /* translators: 1: term name, 2: taxonomy name, 3: post id */ __( '"%1$s" is the primary %2$s for post %3$d.', 'acrossai-abilities-manager' ), $result['primary_term']['name'], $result['taxonomy'], $result['post_id'] ); return $result; } }