*/ protected function input_properties(): array { return array( 'id' => array( 'type' => 'integer', 'description' => __( 'Snippet id. Omit to clear the recorded error for every snippet.', 'acrossai-abilities-manager' ), ), ); } /** * @since 0.0.34 * @return array */ protected function required_input(): array { return array(); } /** * @since 0.0.34 * @return array */ protected function output_properties(): array { return array( 'cleared' => array( 'type' => 'integer' ), 'cleared_ids' => array( 'type' => 'array', 'items' => array( 'type' => 'integer' ), ), ); } /** * @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 ) { if ( isset( $input['id'] ) ) { $snippet = Snippet_Repository::find( (int) $input['id'] ); if ( is_wp_error( $snippet ) ) { return $snippet; } /* * reset_last_error(), never set_last_error(''). The setter returns early unless it is * handed an array with a 'message' key (class-wpcode-snippet.php), so clearing through * it is a silent no-op that would report success having changed nothing. The reset also * clears WPCode's aggregated error state, which the meta delete alone does not. */ $snippet->reset_last_error(); if ( '' !== Snippet_Repository::last_error( $snippet ) ) { return new WP_Error( 'clear_failed', sprintf( /* translators: %d: snippet id. */ __( 'The recorded error for snippet %d is still present after clearing it.', 'acrossai-abilities-manager' ), (int) $snippet->get_id() ) ); } return array( 'cleared' => 1, 'cleared_ids' => array( (int) $snippet->get_id() ), ); } $posts = get_posts( array( 'post_type' => Snippet_Repository::POST_TYPE, 'post_status' => array( 'publish', 'draft' ), 'numberposts' => -1, 'suppress_filters' => false, ) ); $cleared = array(); foreach ( $posts as $post ) { $snippet = new WPCode_Snippet( $post ); if ( '' === Snippet_Repository::last_error( $snippet ) ) { continue; } $snippet->reset_last_error(); $cleared[] = (int) $snippet->get_id(); } return array( 'cleared' => count( $cleared ), 'cleared_ids' => $cleared, ); } }