128 lines
2.8 KiB
Plaintext
128 lines
2.8 KiB
Plaintext
<?php
|
|
/**
|
|
* Plugin Name: {{title}}
|
|
{{#description}}
|
|
* Description: {{description}}
|
|
{{/description}}
|
|
* Version: {{version}}
|
|
{{#author}}
|
|
* Author: {{author}}
|
|
{{/author}}
|
|
* Author URI: https://woo.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;
|
|
|
|
// phpcs:disable WordPress.Files.FileName
|
|
|
|
/**
|
|
* WooCommerce fallback notice.
|
|
*
|
|
* @since {{version}}
|
|
*/
|
|
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://woo.com/" target="_blank">WooCommerce</a>' ) . '</strong></p></div>';
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
if ( ! class_exists( '{{slugSnakeCase}}' ) ) :
|
|
/**
|
|
* The {{slugSnakeCase}} class.
|
|
*/
|
|
class {{slugSnakeCase}} {
|
|
/**
|
|
* This class instance.
|
|
*
|
|
* @var \{{slugSnakeCase}} single instance of this class.
|
|
*/
|
|
private static $instance;
|
|
|
|
/**
|
|
* Constructor.
|
|
*/
|
|
public function __construct() {
|
|
if ( is_admin() ) {
|
|
new Setup();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Cloning is forbidden.
|
|
*/
|
|
public function __clone() {
|
|
wc_doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', '{{slugSnakeCase}}' ), $this->version );
|
|
}
|
|
|
|
/**
|
|
* 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 );
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
}
|
|
|
|
return self::$instance;
|
|
}
|
|
}
|
|
endif;
|
|
|
|
add_action( 'plugins_loaded', '{{slugSnakeCase}}_init', 10 );
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
{{slugSnakeCase}}::instance();
|
|
|
|
}
|