Repository navigation
Expand file tree
/
Copy pathwpify-plugin-skeleton.php
More file actions
116 lines (96 loc) · 3.47 KB
/
Copy pathwpify-plugin-skeleton.php
File metadata and controls
116 lines (96 loc) · 3.47 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
<?php
/*
* Plugin Name: Wpify Plugin Skeleton
* Description: Plugin skeleton with theme by WPify
* Version: 1.0.0
* Requires PHP: 7.3.0
* Requires at least: 5.3.0
* Author: WPify
* Author URI: https://www.wpify.io/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wpify-plugin-skeleton
* Domain Path: /languages
*/
use WpifyPluginSkeleton\Plugin;
use WpifyPluginSkeletonDeps\DI\Container;
use WpifyPluginSkeletonDeps\DI\ContainerBuilder;
if ( ! defined( 'WPIFY_PLUGIN_SKELETON_MIN_PHP_VERSION' ) ) {
define( 'WPIFY_PLUGIN_SKELETON_MIN_PHP_VERSION', '7.3.0' );
}
/**
* @return Plugin
* @throws Exception
*/
function wpify_plugin_skeleton(): Plugin {
return wpify_plugin_skeleton_container()->get( Plugin::class );
}
/**
* @return Container
* @throws Exception
*/
function wpify_plugin_skeleton_container(): Container {
static $container;
if ( empty( $container ) ) {
$is_production = ! WP_DEBUG;
$file_data = get_file_data( __FILE__, array( 'version' => 'Version' ) );
$definition = require_once __DIR__ . '/config.php';
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions( $definition );
if ( $is_production ) {
$containerBuilder->enableCompilation( WP_CONTENT_DIR . '/cache/' . dirname( plugin_basename( __FILE__ ) ) . '/' . $file_data['version'], 'WpifyPluginSkeletonCompiledContainer' );
}
$container = $containerBuilder->build();
}
return $container;
}
function wpify_plugin_skeleton_activate( $network_wide ) {
wpify_plugin_skeleton()->activate( $network_wide );
}
function wpify_plugin_skeleton_deactivate( $network_wide ) {
wpify_plugin_skeleton()->deactivate( $network_wide );
}
function wpify_plugin_skeleton_uninstall() {
wpify_plugin_skeleton()->uninstall();
}
function wpify_plugin_skeleton_php_upgrade_notice() {
$info = get_plugin_data( __FILE__ );
echo sprintf(
__( '<div class="error notice"><p>Opps! %s requires a minimum PHP version of %s. Your current version is: %s. Please contact your host to upgrade.</p></div>', 'wpify-plugin-skeleton' ),
$info['Name'],
WPIFY_PLUGIN_SKELETON_MIN_PHP_VERSION,
PHP_VERSION
);
}
function wpify_plugin_skeleton_php_vendor_missing() {
$info = get_plugin_data( __FILE__ );
echo sprintf(
__( '<div class="error notice"><p>Opps! %s is corrupted it seems, please re-install the plugin.</p></div>', 'wpify-plugin-skeleton' ),
$info['Name']
);
}
if ( version_compare( PHP_VERSION, WPIFY_PLUGIN_SKELETON_MIN_PHP_VERSION ) < 0 ) {
add_action( 'admin_notices', 'wpify_plugin_skeleton_php_upgrade_notice' );
} else {
$deps_loaded = false;
$vendor_loaded = false;
$deps = array_filter( array( __DIR__ . '/deps/scoper-autoload.php', __DIR__ . '/deps/autoload.php' ), function ( $path ) {
return file_exists( $path );
} );
foreach ( $deps as $dep ) {
include_once $dep;
$deps_loaded = true;
}
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
include_once __DIR__ . '/vendor/autoload.php';
$vendor_loaded = true;
}
if ( $deps_loaded && $vendor_loaded ) {
add_action( 'plugins_loaded', 'wpify_plugin_skeleton', 11 );
register_activation_hook( __FILE__, 'wpify_plugin_skeleton_activate' );
register_deactivation_hook( __FILE__, 'wpify_plugin_skeleton_deactivate' );
register_uninstall_hook( __FILE__, 'wpify_plugin_skeleton_uninstall' );
} else {
add_action( 'admin_notices', 'wpify_plugin_skeleton_php_vendor_missing' );
}
}