Files
autocart_plugin/timber-check.php
2023-12-20 21:51:08 +00:00

46 lines
1.4 KiB
PHP

<?php
$vendor_path = ABSPATH . '/vendor/autoload.php';
if (file_exists($vendor_path)) {
require_once $vendor_path;
if (!class_exists('Timber\Timber')) {
// Timber is not active.. so display a notice
update_option('autocart_dependencies', false);
} else {
Timber\Timber::init();
update_option('autocart_dependencies', true);
}
} else {
update_option('autocart_dependencies', false);
}
// Display notice for missing Timber plugin
function custom_inventory_search_timber_notice() {
?>
<div class="notice notice-error is-dismissible">
<p><?php _e('The <strong>Custom Inventory Search</strong> plugin requires the <strong>Timber</strong> plugin to be installed. To install Timber, you can use the following command:', 'custom-inventory-search'); ?></p>
<pre><code>composer require timber/timber</code> <span class="dashicons dashicons-clipboard" onclick="copyToClipboard()"></span></pre>
</div>
<script>
function copyToClipboard() {
const commandToCopy = 'composer require timber/timber';
const textArea = document.createElement('textarea');
textArea.value = commandToCopy;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
// Optionally, you can provide feedback to the user
alert('Command copied to clipboard!');
}
</script>
<?php
}
?>