Embed Snippet on Your Site
Code for importing theme files from plugin
Generated by Meta.AI
/**
* Import an entire folder from a plugin into the WordPress theme.
*
* @param string $plugin_folder Plugin folder path.
* @param string $theme_folder Theme folder path.
*
* @return bool True on success, false on failure.
*/
function import_plugin_folder($plugin_folder, $theme_folder) {
// ... (same implementation as before)
}
/**
* Initialize plugin folder importer.
*/
function init_plugin_folder_importer() {
// Set plugin and theme folder paths
$plugin_folder = WP_PLUGIN_DIR . '/$plugin-name';
$theme_folder = get_template_directory();
// Import plugin folder initially
import_plugin_folder($plugin_folder, $theme_folder);
// Schedule regular imports
if (!wp_next_scheduled('import_plugin_folder_event')) {
wp_schedule_event(time(), 'hourly', 'import_plugin_folder_event');
}
// Hook into filesystem events
add_action('filesystem_updated', 'import_plugin_folder_on_update');
}
/**
* Import plugin folder on filesystem update.
*/
function import_plugin_folder_on_update() {
$plugin_folder = WP_PLUGIN_DIR . '/my-customizations';
$theme_folder = get_template_directory();
import_plugin_folder($plugin_folder, $theme_folder);
}
/**
* Handle scheduled import event.
*/
function import_plugin_folder_event() {
$plugin_folder = WP_PLUGIN_DIR . '/my-customizations';
$theme_folder = get_template_directory();
import_plugin_folder($plugin_folder, $theme_folder);
}
// Initialize plugin folder importer
init_plugin_folder_importer();
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Comments