array( 'type' => 'integer', 'minimum' => 1 ), 'taxonomy' => array( 'type' => 'string' ), 'term_id' => array( 'type' => 'integer', 'minimum' => 0, 'description' => __( 'Term to make primary, or 0 to clear. Must be a term the post already has.', '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' ) ), 'cleared' => array( 'type' => 'boolean' ), ); } protected function required_input(): array { return array( 'post_id', 'taxonomy', 'term_id' ); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $result = Post_Meta_Repository::update_primary_term( isset( $input['post_id'] ) ? absint( $input['post_id'] ) : 0, isset( $input['taxonomy'] ) ? sanitize_key( (string) $input['taxonomy'] ) : '', isset( $input['term_id'] ) ? absint( $input['term_id'] ) : 0 ); if ( is_wp_error( $result ) ) { return $result; } $result['message'] = $result['cleared'] ? sprintf( /* translators: 1: taxonomy name, 2: post id */ __( 'Cleared the primary %1$s for post %2$d.', 'acrossai-abilities-manager' ), $result['taxonomy'], $result['post_id'] ) : sprintf( /* translators: 1: taxonomy name, 2: post id */ __( 'Set the primary %1$s for post %2$d.', 'acrossai-abilities-manager' ), $result['taxonomy'], $result['post_id'] ); return $result; } }