PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / classes / image / image-db-update.php

image-db-update.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.7, at classes/image/image-db-update.php

34 lines 655 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Classes\Image;
4
5 use WP_Query;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class Image_DB_Update {
12 public static function update_posts_table_urls( string $old_url, string $new_url ) {
13 $query = new WP_Query( [
14 'post_type' => 'any',
15 'post_status' => 'any',
16 's' => $old_url,
17 'search_columns' => [ 'post_content' ],
18 ] );
19
20 if ( ! $query->post_count ) {
21 return;
22 }
23
24 foreach ( $query->posts as $post ) {
25 $new_content = str_replace( $old_url, $new_url, $post->post_content );
26
27 wp_update_post([
28 'ID' => $post->ID,
29 'post_content' => $new_content,
30 ]);
31 }
32 }
33 }
34