Skip to content

Commit

Permalink
Merge pull request #1 from udx/develop-alexey
Browse files Browse the repository at this point in the history
Develop alexey
  • Loading branch information
balexey88 authored Nov 27, 2023
2 parents ed4fd9c + d1f4857 commit dcf62de
Show file tree
Hide file tree
Showing 25 changed files with 3,501 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: composer test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
.DS_Store
.vscode
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# wp-stateless-siteorigin-css-addon
WP-Stateless - SiteOrigin CSS Addon
# WP-Stateless - SiteOrigin CSS Addon

Provides compatibility between the [SiteOrigin CSS](https://wordpress.org/plugins/so-css/) and the [WP-Stateless](https://wordpress.org/plugins/wp-stateless/) plugins.

### Features

* Sync CSS files generated by SiteOrigin CSS plugin with Google Cloud Storage.

### Notes

* Tested with SiteOrigin CSS plugin version 1.5.9

### Support, Feedback, & Contribute

We welcome community involvement via the [GitHub repository](https://github.com/udx/wp-stateless-siteorigin-css-addon).

### Frequently Asked Questions

<details>
<summary>Where can I submit feature requests or bug reports?</summary>

We encourage community feedback and discussion through issues on the [GitHub repository](https://github.com/udx/wp-stateless-siteorigin-css-addon/issues).
</details>

<details>
<summary>Can I test new features before they are released?</summary>

To ensure new releases cause as little disruption as possible, we rely on early adopters who assist us by testing out new features before they are released. [Please contact us](https://udx.io/) if you are interested in becoming an early adopter.
</details>

<details>
<summary>Who maintains this plugin?</summary>

[UDX](https://udx.io/) maintains this plugin by continuing development through its own staff, reviewing pull requests, testing, and steering the overall release schedule. UDX is located in Durham, North Carolina, and provides WordPress engineering and hosting services to clients throughout the United States.
</details>
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
== Changelog ==
= 0.0.1 =
* Initial public release.
3 changes: 3 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### 0.0.1

- Initial public release.
69 changes: 69 additions & 0 deletions class-siteorigin-css.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Compatibility Plugin Name: SiteOrigin CSS
* Compatibility Plugin URI: https://wordpress.org/plugins/so-css/
*
* Compatibility Description: Ensures compatibility with CSS files generated by SiteOrigin.
*
*/

namespace WPSL\SiteOriginCSS;

use wpCloud\StatelessMedia\Compatibility;

class SiteOriginCSS extends Compatibility {
protected $id = 'so-css';
protected $title = 'SiteOrigin CSS';
protected $constant = 'WP_STATELESS_COMPATIBILITY_SOCSS';
protected $description = 'Ensures compatibility with CSS files generated by SiteOrigin.';
protected $plugin_file = 'so-css/so-css.php';

/**
* @param $sm
*/
public function module_init($sm) {
add_filter('set_url_scheme', array($this, 'set_url_scheme'), 20, 3);
add_action('admin_menu', array($this, 'action_admin_menu'), 3);
}

/**
* Change Upload BaseURL when CDN Used.
* @param $url
* @param $scheme
* @param $orig_scheme
* @return string
*/
public function set_url_scheme($url, $scheme, $orig_scheme) {
$position = strpos($url, 'so-css/');
if ($position !== false) {
$upload_data = wp_upload_dir();
$name = substr($url, $position);
// We need to get the absolute path before adding the bucket dir to name.
$absolutePath = $upload_data['basedir'] . '/' . $name;
$name = apply_filters('wp_stateless_file_name', $name, 0);
do_action('sm:sync::syncFile', $name, $absolutePath);
// echo "do_action( 'sm:sync::syncFile', $name, $absolutePath);\n";
$url = ud_get_stateless_media()->get_gs_host() . '/' . $name;
}
return $url;
}

/**
* Change Upload BaseURL when CDN Used.
*/
public function action_admin_menu() {
if (current_user_can('edit_theme_options') && isset($_POST['siteorigin_custom_css_save'])) {
try {
$prefix = apply_filters('wp_stateless_file_name', 'so-css', 0);
do_action('sm:sync::deleteFiles', $prefix);
// die();
// $object_list = ud_get_stateless_media()->get_client()->list_objects("prefix=$prefix");
// $files_array = $object_list->getItems();
// foreach ($files_array as $file) {
// do_action( 'sm:sync::deleteFile', $file->name );
// }
} catch (Exception $e) {
}
}
}
}
31 changes: 31 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "udx/wp-stateless-siteorigin-css-addon",
"description": "Ensures compatibility with SiteOrigin CSS",
"type": "wordpress-plugin",
"license": "MIT",
"authors": [
{
"name": "UDX",
"email": "[email protected]"
}
],
"minimum-stability": "stable",
"require-dev": {
"phpunit/phpunit": "^9.5",
"brain/monkey": "2.*"
},
"autoload": {
"files": [
"class-siteorigin-css.php"
]
},
"scripts": {
"test": [
"@composer install",
"./vendor/bin/phpunit --prepend tests/prepend.php tests/ --testdox"
]
},
"scripts-descriptions": {
"test": "Run all tests."
}
}
Loading

0 comments on commit dcf62de

Please sign in to comment.