PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.10
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.10
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / admin / custom-folders.php

custom-folders.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.10, at inc/admin/custom-folders.php

86 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
3
4 add_filter( 'upgrader_post_install', 'imagify_sync_theme_plugin_files_on_update', IMAGIFY_INT_MAX, 3 );
5 /**
6 * Sync files right after a theme or plugin has been updated.
7 *
8 * @since 1.7
9 * @author Grégory Viguier
10 *
11 * @param bool $response Installation response.
12 * @param array $hook_extra Extra arguments passed to hooked filters.
13 * @param array $result Installation result data.
14 * @return bool
15 */
16 function imagify_sync_theme_plugin_files_on_update( $response, $hook_extra, $result ) {
17 global $wpdb;
18
19 if ( ( empty( $hook_extra['plugin'] ) && empty( $hook_extra['theme'] ) ) || empty( $result['destination'] ) ) {
20 return $response;
21 }
22
23 $folders_to_sync = get_site_transient( 'imagify_themes_plugins_to_sync' );
24 $folders_to_sync = is_array( $folders_to_sync ) ? $folders_to_sync : array();
25
26 $folders_to_sync[] = $result['destination'];
27
28 set_site_transient( 'imagify_themes_plugins_to_sync', $folders_to_sync, DAY_IN_SECONDS );
29
30 return $response;
31 }
32
33 add_action( 'admin_init', 'imagify_sync_theme_plugin_files_after_update' );
34 /**
35 * Sync files after some themes or plugins have been updated.
36 *
37 * @since 1.7.1.2
38 * @author Grégory Viguier
39 */
40 function imagify_sync_theme_plugin_files_after_update() {
41 global $wpdb;
42
43 $folders_to_sync = get_site_transient( 'imagify_themes_plugins_to_sync' );
44
45 if ( ! $folders_to_sync || ! is_array( $folders_to_sync ) ) {
46 return;
47 }
48
49 delete_site_transient( 'imagify_themes_plugins_to_sync' );
50
51 $folders_db = Imagify_Folders_DB::get_instance();
52 $files_db = Imagify_Files_DB::get_instance();
53
54 if ( ! $folders_db->can_operate() || ! $files_db->can_operate() ) {
55 return;
56 }
57
58 foreach ( $folders_to_sync as $folder_path ) {
59 $folder_path = trailingslashit( $folder_path );
60
61 if ( Imagify_Files_Scan::is_path_forbidden( $folder_path ) ) {
62 // This theme or plugin must not be optimized.
63 continue;
64 }
65
66 // Get the related folder.
67 $placeholder = Imagify_Files_Scan::add_placeholder( $folder_path );
68 $folder = Imagify_Folders_DB::get_instance()->get_in( 'path', $placeholder );
69
70 if ( ! $folder ) {
71 // This theme or plugin is not in the database.
72 continue;
73 }
74
75 // Sync the folder files.
76 Imagify_Custom_Folders::synchronize_files_from_folders( array(
77 $folder['folder_id'] => array(
78 'folder_id' => $folder['folder_id'],
79 'path' => $placeholder,
80 'active' => $folder['active'],
81 'folder_path' => $folder_path,
82 ),
83 ) );
84 }
85 }
86