PluginProbe
WP-Stateless – Google Cloud Storage / 3.0.3
WP-Stateless – Google Cloud Storage v3.0.3
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / lib / classes / compatibility / siteorigin-widget-bundle.php

siteorigin-widget-bundle.php in WP-Stateless – Google Cloud Storage 3.0.3, at lib/classes/compatibility/siteorigin-widget-bundle.php

89 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Page Builder by SiteOrigin
4 * Plugin URI: https://wordpress.org/plugins/so-widgets-bundle/
5 *
6 * Compatibility Description: Ensures compatibility with CSS files generated by SiteOrigin.
7 *
8 */
9
10 namespace wpCloud\StatelessMedia {
11
12 if( !class_exists( 'wpCloud\StatelessMedia\SOWidgetCSS' ) ) {
13
14 class SOWidgetCSS extends ICompatibility {
15 protected $id = 'so-widget-css';
16 protected $title = 'SiteOrigin Widget Bundle';
17 protected $constant = 'WP_STATELESS_COMPATIBILITY_SOWB';
18 protected $description = 'Enabled support for CSS files generated by SiteOrigin Widgets Bundle.';
19 protected $plugin_file = 'so-widgets-bundle/so-widgets-bundle.php';
20 protected $non_library_sync = true;
21
22 /**
23 * @param $sm
24 */
25 public function module_init( $sm ) {
26 add_filter( 'set_url_scheme', array( $this, 'set_url_scheme' ), 20, 3 );
27 add_filter( 'pre_set_transient_sow:cleared', array( $this, 'clear_file_cache' ), 20, 3 );
28 add_filter( 'siteorigin_widgets_sanitize_instance', array( $this, 'delete_file' ), 10, 3 );
29 // Manual sync from Sync tab.
30 do_action( 'sm:sync::register_dir', '/siteorigin-widgets/' );
31 }
32
33 /**
34 * Change Upload BaseURL when CDN Used.
35 * @param $url
36 * @param $scheme
37 * @param $orig_scheme
38 * @return string
39 */
40 public function set_url_scheme( $url, $scheme, $orig_scheme ) {
41 $position = strpos( $url, 'siteorigin-widgets/' );
42 if( $position !== false ) {
43 $upload_data = wp_upload_dir();
44 $name = substr( $url, $position );
45 $absolutePath = $upload_data[ 'basedir' ] . '/' . $name;
46 $name = apply_filters( 'wp_stateless_file_name', $name, 0 );
47 do_action( 'sm:sync::syncFile', $name, $absolutePath );
48 $url = ud_get_stateless_media()->get_gs_host() . '/' . $name;
49 }
50 return $url;
51 }
52
53 /**
54 * Clear all SO CSS files from GCS after expired. 7 days
55 * @param $value
56 * @param $expiration
57 * @param $transient
58 * @return mixed
59 */
60 public function clear_file_cache( $value, $expiration, $transient ) {
61 do_action( 'sm:sync::deleteFiles', 'siteorigin-widgets/' );
62 return $value;
63 }
64
65 /**
66 * Remove single file from GCS
67 * @param $new_instance
68 * @param $form_options
69 * @param $so_widget
70 * @return mixed
71 */
72 public function delete_file( $new_instance, $form_options, $so_widget ) {
73 $new_instance = $so_widget->modify_instance( $new_instance );
74 $style = $so_widget->get_style_name( $new_instance );
75 $hash = $so_widget->get_style_hash( $new_instance );
76 $name = $so_widget->id_base . '-' . $style . '-' . $hash;
77
78 $file = 'siteorigin-widgets/' . $name . '.css';
79 do_action( 'sm:sync::deleteFile', $file );
80 return $new_instance;
81 }
82
83
84 }
85
86 }
87
88 }
89