-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdws-plugin-template.php
More file actions
118 lines (105 loc) · 4.71 KB
/
Copy pathdws-plugin-template.php
File metadata and controls
118 lines (105 loc) · 4.71 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php declare( strict_types=1 );
/**
* Plugin Name: DWS Plugin Template
* Plugin URI: https://github.com/ahegyes/wordpress-plugin-template
* Description: Starting point for WordPress plugins built on the DWS framework.
* Version: 2.0.0
* Requires PHP: 8.5
* Requires at least: 7.0
* Author: Contributors
* Author URI: https://github.com/ahegyes
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: dws-plugin-template
* Domain Path: /languages
*
* @since 2.0.0
* @version 2.0.0
*
* @package DeepWebSolutions\PluginTemplate
*/
use DeepWebSolutions\PluginTemplate\Plugin;
use DeepWebSolutions\PluginTemplate\Scoped\DeepWebSolutions\Framework\Core\PluginKernel;
use function DeepWebSolutions\PluginTemplate\Scoped\DeepWebSolutions\Framework\Bootstrap\Notice\output_requirements_error;
use function DeepWebSolutions\PluginTemplate\Scoped\DeepWebSolutions\Framework\Bootstrap\Requirements\check_requirements;
defined( 'ABSPATH' ) || exit;
$dws_plugin_template_autoload = __DIR__ . '/vendor/autoload.php';
$dws_plugin_template_scoped_autoload = __DIR__ . '/dependencies/scoper-autoload.php';
$dws_plugin_template_scoped_bootstrap = __DIR__ . '/dependencies/ahegyes/wp-framework-bootstrap/functions.php';
/*
* The Composer autoloader and the scoped framework output are both build artifacts of `composer
* packages-install`. A partial install carrying one but not the other fatals on a require below, so a missing
* build registers an admin notice — using no framework class, since the scoped framework is exactly what is
* absent — instead of leaving the activated plugin silently inert.
*/
if ( dws_plugin_template_dependencies_missing(
$dws_plugin_template_autoload,
$dws_plugin_template_scoped_autoload,
$dws_plugin_template_scoped_bootstrap
) ) {
add_action( 'admin_notices', 'dws_plugin_template_render_setup_notice' );
return;
}
if ( ! defined( 'DWS_PLUGIN_TEMPLATE_FILE' ) ) {
define( 'DWS_PLUGIN_TEMPLATE_FILE', __FILE__ );
}
if ( ! defined( 'DWS_PLUGIN_TEMPLATE_VERSION' ) ) {
define( 'DWS_PLUGIN_TEMPLATE_VERSION', '2.0.0' );
}
/*
* The scoped framework uses PHP 8.5+ syntax that fails to compile below the framework floor, so the
* requirements gate runs from the PHP 5.6-safe bootstrap package first; the full autoloader loads only once
* PHP and WordPress clear the floor, keeping the requirements notice reachable on an unsupported runtime.
*/
require_once $dws_plugin_template_scoped_bootstrap;
$dws_plugin_template_requirements = check_requirements( plugin_basename( __FILE__ ) );
if ( $dws_plugin_template_requirements instanceof \WP_Error ) {
output_requirements_error( plugin_basename( __FILE__ ), $dws_plugin_template_requirements );
return;
}
unset( $dws_plugin_template_requirements );
require_once $dws_plugin_template_autoload;
require_once __DIR__ . '/functions.php';
// Activation/deactivation must be wired during the include, before the plugins_loaded-deferred boot.
PluginKernel::register_lifecycle_hooks( Plugin::get_instance() );
add_action( 'plugins_loaded', 'dws_plugin_template_boot', 15 );
/**
* Whether any `composer packages-install` build artifact the boot below requires is absent. A missing artifact
* means a partial or skipped install, so the boot stops and the setup notice runs in its place. Takes its paths
* as arguments and uses no framework class, so it stays callable before the autoloader and on any PHP the floor
* notice must still reach.
*
* @since 2.0.0
* @version 2.0.0
*
* @param string $autoload Path to the Composer autoloader.
* @param string $scoped Path to the generated scoped-framework autoloader.
* @param string $bootstrap Path to the scoped bootstrap package's function aggregator.
*
* @return bool
*/
function dws_plugin_template_dependencies_missing( $autoload, $scoped, $bootstrap ) {
return ! is_file( $autoload ) || ! is_file( $scoped ) || ! is_file( $bootstrap );
}
/**
* Renders the admin notice shown when the plugin is active but its Composer/scoped dependencies are unbuilt.
* Self-contained — references no framework class — because the scoped framework is precisely what is missing.
*
* @since 2.0.0
* @version 2.0.0
*
* @return void
*/
function dws_plugin_template_render_setup_notice() {
// The build state is operator information: only users who could act on it (plugin managers) see it.
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
printf(
'<div class="notice notice-error"><p>%s</p></div>',
esc_html__(
'DWS Plugin Template is active but its dependencies are not installed. Run "composer packages-install" from the plugin directory to build them.',
'dws-plugin-template'
)
);
}