2019-12-15 22:59:35 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Plugin Name: {{extension_name}}
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin
|
2019-12-15 22:59:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2022-04-25 20:51:35 +00:00
|
|
|
* Register the JS and CSS.
|
2019-12-15 22:59:35 +00:00
|
|
|
*/
|
|
|
|
function add_extension_register_script() {
|
2022-04-25 20:51:35 +00:00
|
|
|
if (
|
|
|
|
! method_exists( 'Automattic\WooCommerce\Admin\Loader', 'is_admin_or_embed_page' ) ||
|
|
|
|
! \Automattic\WooCommerce\Admin\Loader::is_admin_or_embed_page()
|
|
|
|
) {
|
2020-11-19 01:09:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-03-09 14:04:34 +00:00
|
|
|
|
2022-04-25 20:51:35 +00:00
|
|
|
|
2019-12-15 22:59:35 +00:00
|
|
|
$script_path = '/build/index.js';
|
|
|
|
$script_asset_path = dirname( __FILE__ ) . '/build/index.asset.php';
|
|
|
|
$script_asset = file_exists( $script_asset_path )
|
|
|
|
? require( $script_asset_path )
|
|
|
|
: array( 'dependencies' => array(), 'version' => filemtime( $script_path ) );
|
|
|
|
$script_url = plugins_url( $script_path, __FILE__ );
|
|
|
|
|
|
|
|
wp_register_script(
|
|
|
|
'{{extension_slug}}',
|
|
|
|
$script_url,
|
|
|
|
$script_asset['dependencies'],
|
|
|
|
$script_asset['version'],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_register_style(
|
|
|
|
'{{extension_slug}}',
|
2020-10-07 18:40:21 +00:00
|
|
|
plugins_url( '/build/index.css', __FILE__ ),
|
2019-12-15 22:59:35 +00:00
|
|
|
// Add any dependencies styles may have, such as wp-components.
|
|
|
|
array(),
|
2020-10-07 18:40:21 +00:00
|
|
|
filemtime( dirname( __FILE__ ) . '/build/index.css' )
|
2019-12-15 22:59:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
wp_enqueue_script( '{{extension_slug}}' );
|
|
|
|
wp_enqueue_style( '{{extension_slug}}' );
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'admin_enqueue_scripts', 'add_extension_register_script' );
|
2022-04-25 20:51:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a WooCommerce Admin page.
|
|
|
|
*/
|
|
|
|
function add_extension_register_page() {
|
|
|
|
if ( ! function_exists( 'wc_admin_register_page' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wc_admin_register_page( array(
|
|
|
|
'id' => 'my-example-page',
|
|
|
|
'title' => __( 'My Example Page', 'my-textdomain' ),
|
|
|
|
'parent' => 'woocommerce',
|
|
|
|
'path' => '/example',
|
|
|
|
'nav_args' => array(
|
|
|
|
'order' => 10,
|
|
|
|
'parent' => 'woocommerce',
|
|
|
|
),
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'admin_menu', 'add_extension_register_page' );
|