| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Page Builder by SiteOrigin |
| 4 |
* Plugin URI: https://wordpress.org/plugins/easy-digital-downloads/ |
| 5 |
* |
| 6 |
* Compatibility Description: add support for siteorigin generated CSS files |
| 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 CSS files'; |
| 17 |
protected $constant = 'WP_STATELESS_COMPATIBILITY_SO_CSS'; |
| 18 |
protected $description = 'Add support for siteorigin generated CSS files'; |
| 19 |
|
| 20 |
public function __construct(){ |
| 21 |
$this->init(); |
| 22 |
} |
| 23 |
|
| 24 |
public function module_init($sm){ |
| 25 |
add_filter( 'set_url_scheme', array( $this, 'set_url_scheme' ), 20, 3 ); |
| 26 |
add_filter( 'pre_set_transient_sow:cleared', array( $this, 'clear_file_cache' ), 20, 3 ); |
| 27 |
add_filter( 'siteorigin_widgets_sanitize_instance', array($this, 'delete_file'), 10, 3); |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* Change Upload BaseURL when CDN Used. |
| 35 |
* |
| 36 |
* @param $data |
| 37 |
* @return mixed |
| 38 |
*/ |
| 39 |
public function set_url_scheme( $url, $scheme, $orig_scheme ) { |
| 40 |
$position = strpos($url, 'siteorigin-widgets/'); |
| 41 |
if( $position !== false ){ |
| 42 |
$upload_data = wp_upload_dir(); |
| 43 |
$name = substr($url, $position); |
| 44 |
$absolutePath = $upload_data['basedir'] . '/' . $name; |
| 45 |
do_action( 'sm:sync::syncFile', $name, $absolutePath); |
| 46 |
$url = ud_get_stateless_media()->get_gs_host() . '/' . $name; |
| 47 |
} |
| 48 |
return $url; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Clear all SO CSS files from GCS after expired. 7 days |
| 53 |
*/ |
| 54 |
public function clear_file_cache($value, $expiration, $transient){ |
| 55 |
do_action( 'sm:sync::deleteFiles', 'siteorigin-widgets/' ); |
| 56 |
return $value; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Remove single file from GCS |
| 61 |
*/ |
| 62 |
public function delete_file($new_instance, $form_options, $so_widget){ |
| 63 |
$new_instance = $so_widget->modify_instance($new_instance); |
| 64 |
$style = $so_widget->get_style_name($new_instance); |
| 65 |
$hash = $so_widget->get_style_hash( $new_instance ); |
| 66 |
$name = $so_widget->id_base.'-'.$style.'-'.$hash; |
| 67 |
|
| 68 |
$file = '/siteorigin-widgets/' . $name . '.css'; |
| 69 |
do_action( 'sm:sync::deleteFile', $file ); |
| 70 |
return $new_instance; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
|