Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
92 lines (82 loc) · 2.36 KB
/
Copy pathfunctions.php
File metadata and controls
92 lines (82 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php declare( strict_types=1 );
/**
* Defines the plugin's accessor, boots it on plugins_loaded, unschedules its jobs on deactivation, declares its WooCommerce feature compatibility and loads the files in includes/.
*
* @since 2.0.0
* @version 2.0.0
*
* @package DeepWebSolutions\PluginTemplate
*/
use Automattic\WooCommerce\Utilities\FeaturesUtil;
use DeepWebSolutions\PluginTemplate\Plugin;
defined( 'ABSPATH' ) || exit;
$dws_tpl_includes = glob( __DIR__ . '/includes/*.php' );
if ( false === $dws_tpl_includes ) {
throw new RuntimeException( 'The includes directory could not be read.' );
}
sort( $dws_tpl_includes );
foreach ( $dws_tpl_includes as $dws_tpl_include ) {
if ( ! str_starts_with( basename( $dws_tpl_include ), '_' ) ) { // An underscore prefix keeps a file from loading.
require_once $dws_tpl_include;
}
}
// The hooks come last, so an include that throws leaves nothing of the plugin hooked.
add_action( 'plugins_loaded', 'dws_tpl_boot', 15 );
add_action( 'before_woocommerce_init', 'dws_tpl_declare_compatibility' );
register_deactivation_hook( DWS_TPL_FILE, 'dws_tpl_deactivate' );
/**
* Returns the plugin's composition root, built on first use.
*
* @since 2.0.0
* @version 2.0.0
*
* @return Plugin
*/
function dws_tpl_plugin(): Plugin {
static $plugin = null;
if ( ! $plugin instanceof Plugin ) {
$plugin = new Plugin();
}
return $plugin;
}
/**
* Boots the plugin, reporting a composition root that cannot be built as an incomplete build.
*
* @since 2.0.0
* @version 2.0.0
*
* @return void
*/
function dws_tpl_boot(): void {
try {
dws_tpl_plugin()->boot();
} catch ( Throwable $error ) {
dws_tpl_handle_build_error( $error );
}
}
/**
* Unschedules the plugin's jobs on the site it is deactivated on, reporting a composition root that cannot be built as an incomplete build.
*
* @since 2.0.0
* @version 2.0.0
*
* @return void
*/
function dws_tpl_deactivate(): void {
try {
dws_tpl_plugin()->deactivate();
} catch ( Throwable $error ) {
dws_tpl_handle_build_error( $error );
}
}
/**
* Declares whether the plugin works with WooCommerce's order tables, which each plugin built from the template sets from its own evidence.
*
* @since 2.0.0
* @version 2.0.0
*
* @return void
*/
function dws_tpl_declare_compatibility(): void {
FeaturesUtil::declare_compatibility( 'custom_order_tables', DWS_TPL_FILE, false );
}