Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
27.27% |
3 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| WooCommerceBacklink | |
27.27% |
3 / 11 |
|
50.00% |
1 / 2 |
6.46 | |
0.00% |
0 / 1 |
| init | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| add_back_link | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace NewfoldLabs\WP\Module\ECommerce\Partials; |
| 3 | |
| 4 | use NewfoldLabs\WP\ModuleLoader\Container; |
| 5 | /** |
| 6 | * Class WooCommerceBacklink |
| 7 | * |
| 8 | * @package NewfoldLabs\WP\Module\ECommerce\Partials |
| 9 | */ |
| 10 | class WooCommerceBacklink { |
| 11 | |
| 12 | /** |
| 13 | * Container for managing application dependencies. |
| 14 | * |
| 15 | * @var mixed $container This variable holds the container instance. |
| 16 | */ |
| 17 | public static $container; |
| 18 | /** |
| 19 | * Hook suffixes to attach Back button |
| 20 | * |
| 21 | * @var array |
| 22 | */ |
| 23 | public static $hook_suffixes = array( |
| 24 | 'post.php', |
| 25 | 'post-new.php', |
| 26 | 'edit-tags.php', |
| 27 | 'woocommerce_page_wc-admin', |
| 28 | 'woocommerce_page_wc-settings', |
| 29 | 'product_page_product_importer', |
| 30 | ); |
| 31 | |
| 32 | /** |
| 33 | * Initialize the CaptiveFlow functionality. |
| 34 | * |
| 35 | * Sets up the container and hooks for adding back links. |
| 36 | * |
| 37 | * @param Container $container The container instance to be used. |
| 38 | * @return void |
| 39 | */ |
| 40 | public static function init( Container $container ) { |
| 41 | self::$container = $container; |
| 42 | foreach ( self::$hook_suffixes as $hook_suffix ) { |
| 43 | add_action( 'load-' . $hook_suffix, array( __CLASS__, 'add_back_link' ), 100 ); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Adds back link functionality to WooCommerce admin pages. |
| 49 | * |
| 50 | * This function enqueues necessary JavaScript and CSS files for adding a back link, |
| 51 | * |
| 52 | * @return void |
| 53 | */ |
| 54 | public static function add_back_link() { |
| 55 | $runtime = array( 'pluginId' => self::$container->plugin()->id ); |
| 56 | \wp_enqueue_script( 'nfd-ecommerce-woocommerce-captive', NFD_ECOMMERCE_PLUGIN_URL . 'vendor/newfold-labs/wp-module-ecommerce/includes/Partials/woocommerce.js', array(), '1', true ); |
| 57 | \wp_enqueue_style( 'nfd-ecommerce-woocommerce-captive', NFD_ECOMMERCE_PLUGIN_URL . 'vendor/newfold-labs/wp-module-ecommerce/includes/Partials/woocommerce.css', null, '1', 'screen' ); |
| 58 | \wp_add_inline_script( |
| 59 | 'nfd-ecommerce-woocommerce-captive', |
| 60 | 'nfdEcommerce =' . wp_json_encode( $runtime ) . ';', |
| 61 | 'before' |
| 62 | ); |
| 63 | } |
| 64 | } |