PluginProbe
WP-Stateless – Google Cloud Storage / 3.1.0
WP-Stateless – Google Cloud Storage v3.1.0
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-css.php

siteorigin-css.php in WP-Stateless – Google Cloud Storage 3.1.0, at lib/classes/compatibility/siteorigin-css.php

76 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: SiteOrigin CSS
4 * Plugin URI: https://wordpress.org/plugins/so-css/
5 *
6 * Compatibility Description: Ensures compatibility with CSS files generated by SiteOrigin.
7 *
8 * @todo New file don't generate if exist in SyncNonMedia::registered_files list but not in GCS
9 */
10
11 namespace wpCloud\StatelessMedia {
12
13 if( !class_exists( 'wpCloud\StatelessMedia\SOCSS' ) ) {
14
15 class SOCSS extends ICompatibility {
16 protected $id = 'so-css';
17 protected $title = 'SiteOrigin CSS';
18 protected $constant = 'WP_STATELESS_COMPATIBILITY_SOCSS';
19 protected $description = 'Ensures compatibility with CSS files generated by SiteOrigin.';
20 protected $plugin_file = 'so-css/so-css.php';
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_action( 'admin_menu', array( $this, 'action_admin_menu' ), 3 );
28 }
29
30 /**
31 * Change Upload BaseURL when CDN Used.
32 */
33 public function action_admin_menu() {
34 if( current_user_can( 'edit_theme_options' ) && isset( $_POST[ 'siteorigin_custom_css_save' ] ) ) {
35 try {
36 $prefix = apply_filters( 'wp_stateless_file_name', 'so-css', 0 );
37 do_action( 'sm:sync::deleteFiles', $prefix );
38 // die();
39 // $object_list = ud_get_stateless_media()->get_client()->list_objects("prefix=$prefix");
40 // $files_array = $object_list->getItems();
41 // foreach ($files_array as $file) {
42 // do_action( 'sm:sync::deleteFile', $file->name );
43 // }
44 } catch( Exception $e ) {
45 }
46 }
47 }
48
49 /**
50 * Change Upload BaseURL when CDN Used.
51 * @param $url
52 * @param $scheme
53 * @param $orig_scheme
54 * @return string
55 */
56 public function set_url_scheme( $url, $scheme, $orig_scheme ) {
57 $position = strpos( $url, 'so-css/' );
58 if( $position !== false ) {
59 $upload_data = wp_upload_dir();
60 $name = substr( $url, $position );
61 // We need to get the absolute path before adding the bucket dir to name.
62 $absolutePath = $upload_data[ 'basedir' ] . '/' . $name;
63 $name = apply_filters( 'wp_stateless_file_name', $name, 0);
64 do_action( 'sm:sync::syncFile', $name, $absolutePath );
65 // echo "do_action( 'sm:sync::syncFile', $name, $absolutePath);\n";
66 $url = ud_get_stateless_media()->get_gs_host() . '/' . $name;
67 }
68 return $url;
69 }
70
71 }
72
73 }
74
75 }
76