Skip to content

Instantly share code, notes, and snippets.

@alexclst
Created December 9, 2023 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexclst/c1b2ef21f4d30ff03e761266dbe094e0 to your computer and use it in GitHub Desktop.
Save alexclst/c1b2ef21f4d30ff03e761266dbe094e0 to your computer and use it in GitHub Desktop.
WP MU plugin to force WP-SCSS plugin to run with desired settings, which can be changed in this file when you download it for installation.
<?php
/**
* Plugin Name: SCSS Compile
* Description: Makes sure SCSS compilation is ready.
* Author: Tenseg LLC
* Author URI: https://www.tenseg.net
* Text Domain: tg-scss-compile
* Version: 1.0.0
*
* @package tg-scss-compile
*/
class TG_SCSS_Compile {
/**
* Settings
*
* @var array of settings
*/
private $settings = [
'base_compiling_folder' => 'Child Theme',
'scss_dir' => '/assets/scss/',
'css_dir' => '/assets/css/',
'compiling_options' => 'expanded',
'sourcemap_options' => 'SOURCE_MAP_INLINE',
'errors' => 'show',
];
/**
* Class constructor
*/
public function __construct() {
add_action( 'plugins_loaded', [$this, 'scss_compiler_loader'] );
add_filter( 'plugin_action_links', [$this, 'disable_plugin_actions'], 10, 4 );
add_filter( 'default_option_wpscss_options', [$this, 'force_scss_settings'], 10, 2 );
add_filter( 'option_wpscss_options', [$this, 'force_scss_settings'], 10, 2 );
}
/**
* Forces the SCSS Compiler to be on.
*
* Called by action: plugins_loaded
*
* @return void
*/
public function scss_compiler_loader() {
// check for the toolkit
if ( file_exists( WP_PLUGIN_DIR . '/wp-scss/wp-scss.php' ) ) {
require_once WP_PLUGIN_DIR . '/wp-scss/wp-scss.php';
} else {
add_action( 'admin_notices', function () {
echo "<div class='error'><p>Please install WP-SCSS plugin.</p></div>";
} );
}
}
/**
* Turn off plugin actions for the toolkit.
*
* @param array $actions
* @param string $plugin_file
* @param array $plugin_data
* @param string $context
* @return array
*/
public function disable_plugin_actions( $actions, $plugin_file, $plugin_data, $context ) {
if ( str_starts_with( $plugin_file, 'wp-scss' ) ) {
return [];
}
return $actions;
}
/**
* Force the SCSS settings.
*
* Called by filter: option_pmpro_gateway_environment
* Called by filter: default_option_pmpro_gateway_environment
*
* @param mixed $value the option's value
* @param string $option the option's name
* @return mixed the option's value
*/
function force_scss_settings( $value, $option ) {
return $this->settings;
}
}
$tg_scss_compile = new TG_SCSS_Compile();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment