GIF94;
| Path : /var/www/wordpress/wp-content/plugins/oxymade/includes/ |
| Current File : /var/www/wordpress/wp-content/plugins/oxymade/includes/helpers.php |
<?php
namespace OxygenCustomElements;
/**
* Enqueue OxyMade assets in Oxygen editor and frontend
* Only if Oxygen 6.0 is installed and active
*/
function enqueue_assets()
{
// Check if Oxygen 6.0 is installed and active
if (!is_oxygen_active()) {
return;
}
// Check if OxyMade color palette is installed
$palette_exists = get_option('oxymade_color_palette', false);
// Always enqueue basic assets, but color picker features will be conditional
// Check toggle settings
$css_enabled = get_option('oxymade_css_enabled', true);
$presets_enabled = get_option('oxymade_presets_enabled', true);
$button_enabled = get_option('oxymade_button_enabled', true);
$colors_enabled = get_option('oxymade_colors_enabled', true);
// Enqueue CSS only if enabled
if ($css_enabled) {
// Enqueue main OxyMade CSS
wp_enqueue_style(
'oxymade-styles',
OXYMADE_PLUGIN_URL . 'assets/css/oxymade.css',
[],
OXYMADE_VERSION
);
// Output framework CSS after Oxygen's header assets
// Oxygen/Breakdance places a placeholder at wp_head priority 1000000, then replaces it with CSS
// Using 1000001 ensures our link tag appears after that placeholder in the final output
if (!is_admin()) {
\add_action('wp_head', function() {
$url = OXYMADE_PLUGIN_URL . 'assets/oxymade-framework.css?ver=' . OXYMADE_VERSION;
echo '<link rel="stylesheet" id="oxymade-framework-styles-css" href="' . esc_url($url) . '" type="text/css" media="all" />' . "\n";
}, 1000001);
}
}
// Spectrum is loaded directly via JavaScript, no PHP enqueue needed
// Enqueue modular scripts only if CSS or colors are enabled
if ($css_enabled || $colors_enabled) {
$dependencies = ['jquery'];
// Enqueue color utilities module
wp_enqueue_script(
'oxymade-color-utils',
OXYMADE_PLUGIN_URL . 'assets/js/modules/color-utils.js',
[],
OXYMADE_VERSION,
true
);
// Enqueue color palette module
wp_enqueue_script(
'oxymade-color-palette',
OXYMADE_PLUGIN_URL . 'assets/js/modules/color-palette.js',
['oxymade-color-utils'],
OXYMADE_VERSION,
false // Load in head for immediate availability
);
// Enqueue spacing picker module
wp_enqueue_script(
'oxymade-spacing-picker',
OXYMADE_PLUGIN_URL . 'assets/js/modules/spacing-picker.js',
['oxymade-color-utils'],
OXYMADE_VERSION,
true
);
// Enqueue input picker module (context-aware right-click)
wp_enqueue_script(
'oxymade-input-picker',
OXYMADE_PLUGIN_URL . 'assets/js/modules/input-picker.js',
['oxymade-color-utils', 'oxymade-spacing-picker'],
OXYMADE_VERSION,
true
);
// Enqueue color panel module
wp_enqueue_script(
'oxymade-color-panel',
OXYMADE_PLUGIN_URL . 'assets/js/modules/color-panel.js',
['oxymade-color-utils', 'oxymade-color-palette'],
OXYMADE_VERSION,
true
);
// Enqueue main script
wp_enqueue_script(
'oxymade-scripts',
OXYMADE_PLUGIN_URL . 'assets/js/oxymade.js',
array_merge($dependencies, ['oxymade-color-utils', 'oxymade-color-palette', 'oxymade-spacing-picker', 'oxymade-input-picker', 'oxymade-color-panel']),
OXYMADE_VERSION,
true // Load in footer
);
}
// Localize script with AJAX URL and nonce only if script was enqueued
if ($css_enabled || $colors_enabled) {
// Get sync setting
$current_settings = get_option('oxymade_settings', []);
// Ensure it's an array (in case it was saved as string previously)
if (!is_array($current_settings)) {
$current_settings = [];
}
$sync_with_oxygen = $current_settings['sync_with_oxygen'] ?? true;
$localize_data = [
'ajaxUrl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('oxymade-color-palette'),
'pluginUrl' => OXYMADE_PLUGIN_URL,
'syncWithOxygen' => $sync_with_oxygen
];
// Localize for main script
wp_localize_script(
'oxymade-scripts',
'oxymadeSettings',
$localize_data
);
// Also localize for color panel script (runs in iframe)
wp_localize_script(
'oxymade-color-panel',
'oxymadeSettings',
$localize_data
);
}
// // Enqueue spacing picker JavaScript
// \wp_enqueue_script(
// 'oxymade-spacing-picker',
// OXYMADE_PLUGIN_URL . 'assets/js/spacing-picker.js',
// ['jquery'],
// BREAKMADE_VERSION,
// true // Load in footer
// );
}
// /**
// * Enqueue scripts for Breakdance builder
// */
// function enqueue_builder_assets() {
// // Check if we're in the Breakdance builder context
// if (isset($_GET['breakdance']) && $_GET['breakdance'] === 'builder') {
// // Enqueue CSS with special handling for the builder
// add_action('admin_head', function() {
// echo '<style id="oxymade-editor-styles">';
// echo file_get_contents(OXYMADE_PLUGIN_DIR . 'assets/css/oxymade.css');
// echo '</style>';
// });
// // Enqueue our script
// \wp_enqueue_script(
// 'oxymade-scripts',
// OXYMADE_PLUGIN_URL . 'assets/js/oxymade.js',
// ['jquery'],
// OXYMADE_VERSION,
// false // Load in head
// );
// // Enqueue our script
// \wp_enqueue_script(
// 'oxymade-scripts',
// BREAKMADE_PLUGIN_URL . 'assets/js/spacing-picker.js',
// ['jquery'],
// OXYMADE_VERSION,
// false // Load in head
// );
// // Enqueue CSS
// \wp_enqueue_style(
// 'oxymade-styles',
// OXYMADE_PLUGIN_URL . 'assets/css/oxymade.css',
// [],
// OXYMADE_VERSION
// );
// }
// }
/**
* Get all installed plugins
*
* @return array Array of installed plugins
*/
function get_all_plugins()
{
require_once \ABSPATH . 'wp-admin/includes/plugin.php';
return \get_plugins();
}
/**
* Check if a plugin is installed by name
*
* @param string $plugin_name The name of the plugin to check
* @return bool True if the plugin is installed, false otherwise
*/
function is_plugin_installed($plugin_name)
{
$all_plugins = get_all_plugins();
foreach ($all_plugins as $plugin_data) {
if ($plugin_data['Name'] == $plugin_name) return true;
}
return false;
}
/**
* Check if a plugin is active by name
*
* @param string $plugin_name The name of the plugin to check
* @return bool True if the plugin is active, false otherwise
*/
function is_plugin_active_by_name($plugin_name)
{
$all_plugins = get_all_plugins();
foreach ($all_plugins as $plugin_path => $plugin_data) {
if ($plugin_data['Name'] == $plugin_name && \is_plugin_active($plugin_path)) return true;
}
return false;
}
/**
* Check if the license is active
*
* @return bool
*/
function is_license_active() {
if (class_exists('\\OxyMade\\License\\LicenseCheck')) {
return \OxyMade\License\LicenseCheck::verify();
}
return false;
}
/**
* Get license data
*
* @return array
*/
function get_license_data() {
if (class_exists('\\OxyMade\\License\\LicenseCheck')) {
return \OxyMade\License\LicenseCheck::get_license_data();
}
return [];
}