*/ protected function input_properties(): array { return array( 'id' => array( 'type' => 'integer', 'description' => __( 'Snippet id.', 'acrossai-abilities-manager' ), ), 'location' => array( 'type' => 'string', 'enum' => Snippet_Repository::LOCATIONS, 'description' => __( 'Where the snippet should be inserted.', 'acrossai-abilities-manager' ), ), 'auto_insert' => array( 'type' => 'boolean', 'default' => true, 'description' => __( 'Whether WPCode inserts the snippet automatically at that location. Set false to keep the location but render the snippet only via its shortcode.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.34 * @return array */ protected function required_input(): array { return array( 'id', 'location' ); } /** * @since 0.0.34 * @return array */ protected function output_properties(): array { return array( 'snippet' => array( 'type' => 'object', 'additionalProperties' => true ), 'in_cache' => array( 'type' => 'boolean' ), 'safe_mode' => array( 'type' => 'boolean' ), ); } /** * @since 0.0.34 * @return array */ protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true ); } /** * @since 0.0.34 * @param array $input Input. * @return array|WP_Error */ protected function run( array $input ) { $snippet = Snippet_Repository::find( (int) ( $input['id'] ?? 0 ) ); if ( is_wp_error( $snippet ) ) { return $snippet; } $placed = Snippet_Repository::place( $snippet, (string) ( $input['location'] ?? '' ), ! array_key_exists( 'auto_insert', $input ) || (bool) $input['auto_insert'] ); if ( is_wp_error( $placed ) ) { return $placed; } return array( 'snippet' => $placed, 'in_cache' => $placed['in_cache'], 'safe_mode' => WPCode_Guard::safe_mode(), ); } }