woocommerce/packages/js/create-woo-extension/$slug.php.mustache

128 lines
2.8 KiB
Plaintext
Raw Normal View History

<?php
/**
* Plugin Name: {{title}}
{{#description}}
* Description: {{description}}
{{/description}}
2022-12-14 15:35:22 +00:00
* Version: {{version}}
{{#author}}
* Author: {{author}}
{{/author}}
* Author URI: https://woocommerce.com
* Text Domain: {{textdomain}}
* Domain Path: /languages
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package {{namespace}}
*/
defined( 'ABSPATH' ) || exit;
if ( ! defined( 'MAIN_PLUGIN_FILE' ) ) {
define( 'MAIN_PLUGIN_FILE', __FILE__ );
}
require_once plugin_dir_path( __FILE__ ) . '/vendor/autoload_packages.php';
use {{slugPascalCase}}\Admin\Setup;
2022-12-14 15:35:22 +00:00
// phpcs:disable WordPress.Files.FileName
/**
2022-12-14 15:35:22 +00:00
* WooCommerce fallback notice.
*
* @since {{version}}
*/
2022-12-14 15:35:22 +00:00
function {{slugSnakeCase}}_missing_wc_notice() {
/* translators: %s WC download URL link. */
echo '<div class="error"><p><strong>' . sprintf( esc_html__( '{{title}} requires WooCommerce to be installed and active. You can download %s here.', '{{slugSnakeCase}}' ), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>';
2022-12-14 15:35:22 +00:00
}
2022-12-14 15:35:22 +00:00
register_activation_hook( __FILE__, '{{slugSnakeCase}}_activate' );
/**
* Activation hook.
*
* @since {{version}}
*/
function {{slugSnakeCase}}_activate() {
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', '{{slugSnakeCase}}_missing_wc_notice' );
return;
}
2022-12-14 15:35:22 +00:00
}
2022-12-14 15:35:22 +00:00
if ( ! class_exists( '{{slugSnakeCase}}' ) ) :
/**
2022-12-14 15:35:22 +00:00
* The {{slugSnakeCase}} class.
*/
2022-12-14 15:35:22 +00:00
class {{slugSnakeCase}} {
/**
* This class instance.
*
* @var \{{slugSnakeCase}} single instance of this class.
*/
private static $instance;
/**
* Constructor.
*/
public function __construct() {
if ( is_admin() ) {
new Setup();
}
}
2022-12-14 15:35:22 +00:00
/**
* Cloning is forbidden.
*/
public function __clone() {
wc_doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', '{{slugSnakeCase}}' ), $this->version );
}
2022-12-14 15:35:22 +00:00
/**
* Unserializing instances of this class is forbidden.
*/
public function __wakeup() {
wc_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', '{{slugSnakeCase}}' ), $this->version );
}
2022-12-14 15:35:22 +00:00
/**
* Gets the main instance.
*
* Ensures only one instance can be loaded.
*
* @return \{{slugSnakeCase}}
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
2022-12-14 15:35:22 +00:00
return self::$instance;
}
2022-12-14 15:35:22 +00:00
}
endif;
add_action( 'plugins_loaded', '{{slugSnakeCase}}_init', 10 );
2022-12-14 15:35:22 +00:00
/**
* Initialize the plugin.
*
* @since {{version}}
*/
function {{slugSnakeCase}}_init() {
load_plugin_textdomain( '{{slugSnakeCase}}', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', '{{slugSnakeCase}}_missing_wc_notice' );
return;
}
2022-12-14 15:35:22 +00:00
{{slugSnakeCase}}::instance();
}