| 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 |
public function module_init($sm){ |
| 23 |
add_filter( 'set_url_scheme', array( $this, 'set_url_scheme' ), 20, 3 ); |
| 24 |
add_action( 'admin_menu', array($this, 'action_admin_menu'), 3 ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Change Upload BaseURL when CDN Used. |
| 29 |
* |
| 30 |
* @param $data |
| 31 |
* @return mixed |
| 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'); |
| 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 |
} |
| 45 |
catch(Exception $e){} |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Change Upload BaseURL when CDN Used. |
| 51 |
* |
| 52 |
* @param $data |
| 53 |
* @return mixed |
| 54 |
*/ |
| 55 |
public function set_url_scheme( $url, $scheme, $orig_scheme ) { |
| 56 |
$position = strpos($url, 'so-css/'); |
| 57 |
if( $position !== false ){ |
| 58 |
$upload_data = wp_upload_dir(); |
| 59 |
$name = substr($url, $position); |
| 60 |
// We need to get the absolute path before adding the bucket dir to name. |
| 61 |
$absolutePath = $upload_data['basedir'] . '/' . $name; |
| 62 |
$name = apply_filters('wp_stateless_file_name', $name); |
| 63 |
do_action( 'sm:sync::syncFile', $name, $absolutePath); |
| 64 |
// echo "do_action( 'sm:sync::syncFile', $name, $absolutePath);\n"; |
| 65 |
$url = ud_get_stateless_media()->get_gs_host() . '/' . $name; |
| 66 |
} |
| 67 |
return $url; |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|