GIF94;
| Path : /var/www/wordpress/wp-content/plugins/oxymade/ |
| Current File : /var/www/wordpress/wp-content/plugins/oxymade/plugin.php |
<?php
/**
* Plugin Name: OxyMade
* Plugin URI: https://oxymade.com/
* Description: Custom elements and extensions for Oxygen page builder.
* Author: OxyMade
* Author URI: https://oxymade.com/
* License: GPLv2
* Text Domain: oxymade
* Domain Path: /languages/
* Version: 1.4.0
*/
namespace OxygenCustomElements;
use function Breakdance\Util\getDirectoryPathRelativeToPluginFolder;
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
define('OXYMADE_PLUGIN_URL', \plugin_dir_url(__FILE__));
define('OXYMADE_PLUGIN_DIR', \plugin_dir_path(__FILE__));
// Load plugin configuration (includes OXYMADE_VERSION and OXYMADE_PUBLIC_TOKEN)
require_once OXYMADE_PLUGIN_DIR . 'config.php';
// Initialize Logger
if (!class_exists('OxyMade\\Includes\\Logger')) {
require_once OXYMADE_PLUGIN_DIR . 'includes/class-oxymade-logger.php';
}
\OxyMade\Includes\Logger::init();
// License debugging disabled for production
/**
* Check for missing required plugins
*/
function get_missing_plugins() {
// Ensure plugin functions are available
if (!function_exists('is_plugin_active')) {
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
}
$missing = array();
// Check Oxygen 6.0 (Breakdance in Oxygen mode)
if (!(defined('__BREAKDANCE_PLUGIN_FILE__') && defined('BREAKDANCE_MODE') && \BREAKDANCE_MODE === 'oxygen')) {
$missing['oxygen'] = 'Oxygen 6.0';
}
// Check Breakdance Elements for Oxygen
if (!\is_plugin_active('breakdance-elements-for-oxygen/plugin.php')) {
$missing['breakdance-elements-for-oxygen'] = 'Breakdance Elements for Oxygen';
}
// Check Breakdance Forms for Oxygen
if (!\is_plugin_active('breakdance-forms-for-oxygen/plugin.php')) {
$missing['breakdance-forms-for-oxygen'] = 'Breakdance Forms for Oxygen';
}
return $missing;
}
/**
* Display admin notice for missing required plugins
*/
\add_action('admin_notices', function() {
// Only show on admin pages, but NOT on OxyMade settings page (we have our own display there)
if (!is_admin()) {
return;
}
// Don't show on OxyMade admin page - avoid cluttering
$screen = get_current_screen();
if ($screen && strpos($screen->id, 'oxymade') !== false) {
return;
}
$missing = get_missing_plugins();
if (empty($missing)) {
return;
}
$count = count($missing);
$plugins_word = $count === 1 ? 'plugin' : 'plugins';
?>
<div class="notice notice-warning is-dismissible">
<p>
<strong>OxyMade requires the following <?php echo esc_html($plugins_word); ?> to be installed and activated:</strong>
</p>
<ul style="list-style: disc; margin-left: 20px;">
<?php foreach ($missing as $slug => $name): ?>
<li><?php echo esc_html($name); ?></li>
<?php endforeach; ?>
</ul>
<p>
Please install and activate the required <?php echo esc_html($plugins_word); ?> for OxyMade to work properly.
</p>
</div>
<?php
});
/**
* Check if Oxygen 6.0 is active
*/
function is_oxygen_active() {
return defined('__BREAKDANCE_PLUGIN_FILE__') &&
defined('BREAKDANCE_MODE') &&
\BREAKDANCE_MODE === 'oxygen';
}
// Initialize licensing
\add_action('init', function() {
if (!isset($GLOBALS['oxymade_license_client'])) {
if (!class_exists('OxyMade\Licensing\Client')) {
require_once __DIR__ . '/licensing/src/Client.php';
}
// Get public token from config.php (loaded at plugin initialization)
// Token is defined in config.php and loaded automatically
if (!defined('OXYMADE_PUBLIC_TOKEN') || empty(OXYMADE_PUBLIC_TOKEN) || OXYMADE_PUBLIC_TOKEN === 'YOUR_SURECART_PUBLIC_TOKEN_HERE') {
// Plugin continues to work without licensing - updates may not be available
return;
}
$public_token = OXYMADE_PUBLIC_TOKEN;
$GLOBALS['oxymade_license_client'] = new \OxyMade\Licensing\Client(
'OxyMade',
$public_token,
__FILE__
);
// Set plugin text domain
$GLOBALS['oxymade_license_client']->set_textdomain('oxymade');
// No separate license page needed - modal-based activation in settings page
}
// Include license functionality
if (file_exists(OXYMADE_PLUGIN_DIR . 'includes/license.php')) {
require_once OXYMADE_PLUGIN_DIR . 'includes/license.php';
}
}, 5);
// Include helper functions
if (file_exists(OXYMADE_PLUGIN_DIR . 'includes/helpers.php')) {
require_once OXYMADE_PLUGIN_DIR . 'includes/helpers.php';
}
// Include color palette functionality
if (file_exists(OXYMADE_PLUGIN_DIR . 'includes/color-palette.php')) {
require_once OXYMADE_PLUGIN_DIR . 'includes/color-palette.php';
}
// Include admin settings
if (file_exists(OXYMADE_PLUGIN_DIR . 'includes/admin-settings.php')) {
require_once OXYMADE_PLUGIN_DIR . 'includes/admin-settings.php';
}
// Include the variables file
require_once OXYMADE_PLUGIN_DIR . 'includes/variables.php';
// Include the components file
require_once OXYMADE_PLUGIN_DIR . 'includes/components.php';
// Include the JSON manager
require_once OXYMADE_PLUGIN_DIR . 'includes/json-manager.php';
// Include the JSON importer file
require_once OXYMADE_PLUGIN_DIR . 'includes/json-importer.php';
// Include typography manager
require_once OXYMADE_PLUGIN_DIR . 'includes/typography.php';
// Include builder autocomplete (on-demand class loading)
require_once OXYMADE_PLUGIN_DIR . 'includes/class-builder-autocomplete.php';
/**
* Plugin activation hook
*/
\register_activation_hook(__FILE__, function() {
// Set default design set as "Layers" on activation
$current_design_set = get_option('oxymade_default_designset_template', false);
if (!$current_design_set) {
update_option('oxymade_default_designset_template', 'Layers');
error_log('🎨 OxyMade: Set default design set to "Layers" on activation');
}
});
/**
* Check and set default design set if not already set
* This runs on every page load to ensure the default is always set
*/
\add_action('init', function() {
$current_design_set = get_option('oxymade_default_designset_template', false);
if (!$current_design_set) {
update_option('oxymade_default_designset_template', 'Layers');
error_log('🎨 OxyMade: Set default design set to "Layers" (fallback check)');
}
}, 1);
\add_action('breakdance_loaded', function () {
// Only register if Oxygen 6.0 is active
if (!is_oxygen_active()) {
return;
}
try {
$namespace = 'OxygenCustomElements';
\Breakdance\ElementStudio\registerSaveLocation(
getDirectoryPathRelativeToPluginFolder(__DIR__) . '/elements',
$namespace,
'element',
'OxyMade Elements',
false
);
\Breakdance\ElementStudio\registerSaveLocation(
getDirectoryPathRelativeToPluginFolder(__DIR__) . '/macros',
$namespace,
'macro',
'OxyMade Macros',
false
);
\Breakdance\ElementStudio\registerSaveLocation(
getDirectoryPathRelativeToPluginFolder(__DIR__) . '/presets',
$namespace,
'preset',
'OxyMade Presets',
false
);
} catch (\Exception $e) {
// Silent fail
}
},
// register elements before loading them
9
);
// Initialize builder class autocomplete + transient caching
\add_action('breakdance_loaded', function() {
if (!is_oxygen_active()) {
return;
}
\OxyMade\Autocomplete\BuilderAutocomplete::init();
}, 5);
// Enqueue assets on frontend
\add_action('wp_enqueue_scripts', function() {
if (function_exists(__NAMESPACE__ . '\\enqueue_assets')) {
enqueue_assets();
}
});
// Enqueue assets in Oxygen builder using proper hooks
\add_action('breakdance_edit_mode_enqueue_scripts', function() {
if (function_exists(__NAMESPACE__ . '\\enqueue_assets')) {
enqueue_assets();
}
});
// Enqueue assets in Oxygen builder iframe
\add_action('oxygen_enqueue_scripts', function() {
if (function_exists(__NAMESPACE__ . '\\enqueue_assets')) {
enqueue_assets();
}
});
// Enqueue assets in Oxygen builder admin context
\add_action('admin_enqueue_scripts', function() {
if (function_exists(__NAMESPACE__ . '\\enqueue_assets')) {
enqueue_assets();
}
});
// Enqueue paste-import.js in builder only - using multiple hooks for reliability
\add_action('breakdance_edit_mode_enqueue_scripts', function() {
\wp_enqueue_script(
'oxymade-paste-import',
OXYMADE_PLUGIN_URL . 'assets/js/paste-import.js',
array(),
OXYMADE_VERSION,
true
);
// Localize script with nonce for AJAX
\wp_localize_script('oxymade-paste-import', 'oxymadeSettings', array(
'breakdanceNonce' => \wp_create_nonce('breakdance_nonce'),
'ajaxUrl' => \admin_url('admin-ajax.php')
));
});
// Backup: Also inject paste-import.js directly in footer for Breakdance builder
\add_action('wp_footer', function() {
// Check if we're in Breakdance builder
if (!isset($_GET['breakdance']) && !isset($_GET['breakdance_iframe'])) {
return;
}
// Output nonce as JavaScript variable if not already set
echo '<script type="text/javascript">';
echo 'if (!window.oxymadeSettings) { window.oxymadeSettings = {}; }';
echo 'window.oxymadeSettings.breakdanceNonce = "' . \wp_create_nonce('breakdance_nonce') . '";';
echo 'window.oxymadeSettings.ajaxUrl = "' . \admin_url('admin-ajax.php') . '";';
echo '</script>';
// Inline the paste-import script directly
$paste_import_code = @file_get_contents(OXYMADE_PLUGIN_DIR . 'assets/js/paste-import.js');
if ($paste_import_code) {
echo '<script type="text/javascript">' . $paste_import_code . '</script>';
}
}, 999);
// Hook into Breakdance loaded to add toolbar button
\add_action('breakdance_loaded', function() {
// Add toolbar button using Breakdance's system
\add_action('breakdance_edit_mode_enqueue_scripts', function() {
// Enqueue Breakdance toolbar script properly
\wp_enqueue_script(
'oxymade-breakdance-toolbar',
OXYMADE_PLUGIN_URL . 'assets/js/admin/breakdance-toolbar.js',
array(),
OXYMADE_VERSION,
true
);
// Pass dynamic data via wp_localize_script
\wp_localize_script('oxymade-breakdance-toolbar', 'oxyMadeData', array(
'ajaxUrl' => \admin_url('admin-ajax.php'),
'nonce' => \wp_create_nonce('oxymade-toolbar'),
'i18n' => array(
'variables' => \__('Variables', 'oxymade'),
'colorPalette' => \__('Color Palette', 'oxymade')
)
));
});
}, 20); // Run after other plugins
// Test: Always inject a simple script to see if the plugin is working
\add_action('wp_head', function() {
echo '<!-- OxyMade Plugin Test -->';
});
/**
* Plugin activation hook
* Add custom capabilities and initialize plugin
*/
\register_activation_hook(__FILE__, function() {
// Include capability class
if (!class_exists('OxyMade\\Includes\\Capabilities')) {
require_once OXYMADE_PLUGIN_DIR . 'includes/class-oxymade-capabilities.php';
}
// Add capabilities
\OxyMade\Includes\Capabilities::add_capabilities();
// Include FileHandler class
if (!class_exists('OxyMade\\Includes\\FileHandler')) {
require_once OXYMADE_PLUGIN_DIR . 'includes/class-oxymade-file-handler.php';
}
// Create upload directory
\OxyMade\Includes\FileHandler::ensure_upload_dir();
// Flush rewrite rules
\flush_rewrite_rules();
});
/**
* Plugin deactivation hook
* Remove custom capabilities
*/
\register_deactivation_hook(__FILE__, function() {
// Include capability class
if (!class_exists('OxyMade\\Includes\\Capabilities')) {
require_once OXYMADE_PLUGIN_DIR . 'includes/class-oxymade-capabilities.php';
}
// Remove capabilities
\OxyMade\Includes\Capabilities::remove_capabilities();
// Clear scheduled events
\wp_clear_scheduled_hook('oxymade_prefetch_components');
// Flush rewrite rules
\flush_rewrite_rules();
});