-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
156 lines (135 loc) · 4.49 KB
/
plugin.php
File metadata and controls
156 lines (135 loc) · 4.49 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* Plugin Name: Games Collector
* Plugin URI: https://github.com/jazzsequence/games-collector
* Description: Catalog all your tabletop (or other) games in your WordPress site and display a list of games in your collection.
* Version: 2.0.0
* Author: Chris Reynolds
* Author URI: https://jazzsequence.com
* Donate link: https://paypal.me/jazzsequence
* License: GPLv3
* Text Domain: games-collector
* Domain Path: /languages
* Requires at least: 4.4
* Tested up to: 6.9
* Requires PHP: 7.4
*
* @link https://github.com/jazzsequence/games-collector
*
* @package GamesCollector
* @version 2.0.0
*/
/**
* Copyright (c) 2017 Chris Reynolds (email : me@chrisreynolds.io)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
* your discretion, any later version, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace GC\GamesCollector;
define( 'GC_VERSION', '2.0.0' );
/**
* Handles autoloading the namespaces and other required files.
*
* @since 1.1.0
*/
function autoload_init() {
$cmb2_path = maybe_get_cmb2_path();
// Add in some specific includes and vendor libraries.
$files = [
__DIR__ . '/inc/namespace.php',
__DIR__ . '/inc/functions.php',
];
// Only add CMB2 if we found it.
if ( $cmb2_path ) {
$files[] = $cmb2_path;
}
// Check for extended cpts, load it if it hasn't already been loaded.
if ( ! function_exists( 'register_extended_post_type' ) ) {
$plugin_vendor = __DIR__ . '/vendor/johnbillion/extended-cpts/extended-cpts.php';
$root_vendor = ABSPATH . '/vendor/johnbillion/extended-cpts/extended-cpts.php';
// Check if extended cpts exists. If not, deactivate the plugin.
$exists = file_exists( $plugin_vendor ) || file_exists( $root_vendor );
if ( $exists ) {
$files[] = $exists ? $plugin_vendor : $root_vendor;
} elseif ( function_exists( '\deactivate_plugins' ) ) {
/* Extended CPTs not found — deactivate if the admin function is available. */
\deactivate_plugins( plugin_basename( __FILE__ ) );
}
}
// Autoload the namespaces.
$namespaces = array_filter( glob( __DIR__ . '/inc/*' ), 'is_dir' );
foreach ( $namespaces as $namespace ) {
$files[] = $namespace . '/namespace.php';
}
// Loop through and load all the things!
foreach ( $files as $file ) {
require_once $file;
}
}
/**
* Try to get the path to the CMB2 library.
*
* @since 1.3.6
*/
function maybe_get_cmb2_path() {
// If the CMB2 library is already loaded (CMB2_LOADED is defined in its constructor), bail.
if ( defined( 'CMB2_LOADED' ) ) {
return '';
}
// Maybe load from the vendor directory (composer package: cmb2/cmb2).
if ( file_exists( __DIR__ . '/vendor/cmb2/cmb2/init.php' ) ) {
return __DIR__ . '/vendor/cmb2/cmb2/init.php';
}
// Maybe load from the root /vendor directory.
if ( file_exists( ABSPATH . '/vendor/cmb2/cmb2/init.php' ) ) {
return ABSPATH . '/vendor/cmb2/cmb2/init.php';
}
// Was it installed as a plugin?
if ( file_exists( WP_PLUGIN_DIR . '/cmb2/init.php' ) ) {
// Activate the plugin.
activate_plugin( 'cmb2' );
}
// Last chance, maybe it's in the mu-plugins directory. If it's here, it should already be activated.
if ( file_exists( WPMU_PLUGIN_DIR . '/cmb2/init.php' ) ) {
return WPMU_PLUGIN_DIR . '/cmb2/init.php';
}
// If we got here, we couldn't find CMB2.
return '';
}
/**
* Main initialization function.
*
* @since 1.1.0
*/
function init() {
// Load all the required files.
autoload_init();
// If CMB2 was not loaded, deactivate ourself.
if ( ! defined( 'CMB2_LOADED' ) ) {
/*
* deactivate_plugins is in wp-admin/includes/plugin.php and may not be
* loaded during test bootstraps or early in the WP loading sequence.
*/
if ( function_exists( '\deactivate_plugins' ) ) {
\deactivate_plugins( plugin_basename( __FILE__ ) );
}
return;
}
// Register activation hook.
register_activation_hook( __FILE__, __NAMESPACE__ . '\\activate' );
// Kick it off.
add_action( 'plugins_loaded', __NAMESPACE__ . '\\bootstrap' );
}
// Kick it off!
init();