PluginProbe
Authorsy – Author Box, Multiple Authors, Guest Authors & Post Rating / 1.0.8
Authorsy – Author Box, Multiple Authors, Guest Authors & Post Rating v1.0.8
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8
authorsy / authorsy.php

authorsy.php in Authorsy – Author Box, Multiple Authors, Guest Authors & Post Rating 1.0.8, at authorsy.php

273 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Authorsy
5 * Plugin URI: https://apselo.com/authorsy
6 * Description: Author box and bio link for WordPress.
7 * Version: 1.0.8
8 * Requires at least: 5.2
9 * Requires PHP: 7.4
10 * Author: apselo
11 * Author URI: https://apselo.com/
12 * License: GPL v2 or later
13 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
14 * Text Domain: authorsy
15 * Domain Path: /languages
16
17 * Authorsy is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 2 of the License, or
20 * any later version.
21
22 * You should have received a copy of the GNU General Public License
23 * along with Authorsy. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * @package Authorsy
26 * @category Core
27 * @author themeplugs
28 * @version 1.0.0
29 */
30
31 use Authorsy as GlobalEasyAuthor;
32
33 // Exit if accessed directly.
34 defined( 'ABSPATH' ) || exit;
35
36 /**
37 * The Main Plugin Requirements Checker
38 *
39 * @since 1.0.0
40 */
41 final class Authorsy {
42
43 /**
44 * Static Property To Hold Singleton Instance
45 *
46 * @var Authorsy The Authorsy Requirement Checker Instance
47 */
48 private static $instance;
49
50 /**
51 * Plugin Current Production Version
52 *
53 * @return string
54 */
55 public static function get_version() {
56 return '1.0.8';
57 }
58
59 /**
60 * Requirements Array
61 *
62 * @since 1.0.0
63 * @var array
64 */
65 private $requirements = array(
66 'php' => array(
67 'name' => 'PHP',
68 'minimum' => '7.3',
69 'exists' => true,
70 'met' => false,
71 'checked' => false,
72 'current' => false,
73 ),
74 'wp' => array(
75 'name' => 'WordPress',
76 'minimum' => '5.2',
77 'exists' => true,
78 'checked' => false,
79 'met' => false,
80 'current' => false,
81 ),
82 );
83
84 /**
85 * Singleton Instance
86 *
87 * @return Authorsy
88 */
89 public static function get_instance() {
90 if ( null === self::$instance ) {
91 self::$instance = new self();
92 }
93
94 return self::$instance;
95 }
96
97 /**
98 * Setup Plugin Requirements
99 *
100 * @since 1.0.0
101 */
102 private function __construct() {
103 // Always load translation.
104 add_action( 'plugins_loaded', array( $this, 'load_text_domain' ) );
105
106 // Initialize plugin functionalities or quit.
107 $this->requirements_met() ? $this->initialize_modules() : $this->quit();
108 }
109
110 /**
111 * Load Localization Files
112 *
113 * @since 1.0
114 * @return void
115 */
116 public function load_text_domain() {
117 $locale = apply_filters( 'plugin_locale', get_user_locale(), 'authorsy' );
118
119 unload_textdomain( 'authorsy' );
120 load_textdomain( 'authorsy', WP_LANG_DIR . '/authorsy/authorsy-' . $locale . '.mo' );
121 load_plugin_textdomain( 'authorsy', false, self::get_plugin_dir() . 'languages/' );
122 }
123
124 /**
125 * Initialize Plugin Modules
126 *
127 * @since 1.0.0
128 * @return void
129 */
130 private function initialize_modules() {
131 require_once dirname( __FILE__ ) . '/autoloader.php';
132 require_once dirname( __FILE__ ) . '/core/settings/settings.php';
133
134 require_once dirname( __FILE__ ) . '/utils/global-helper.php';
135
136 // Include the bootstrap file if not loaded.
137 if ( ! class_exists( 'Authorsy\Bootstrap' ) ) {
138 require_once self::get_plugin_dir() . 'bootstrap.php';
139 }
140
141 // Initialize the bootstraper if exists.
142 if ( class_exists( 'Authorsy\Bootstrap' ) ) {
143
144 // Initialize all modules through plugins_loaded.
145 add_action( 'plugins_loaded', array( $this, 'init' ) );
146
147 register_activation_hook( self::get_plugin_file(), array( $this, 'activate' ) );
148 register_deactivation_hook( self::get_plugin_file(), array( $this, 'deactivate' ) );
149 }
150 }
151
152 /**
153 * Check If All Requirements Are Fulfilled
154 *
155 * @return boolean
156 */
157 private function requirements_met() {
158 $this->prepare_requirement_versions();
159
160 $passed = true;
161 $to_meet = wp_list_pluck( $this->requirements, 'met' );
162
163 foreach ( $to_meet as $met ) {
164 if ( empty( $met ) ) {
165 $passed = false;
166 continue;
167 }
168 }
169
170 return $passed;
171 }
172
173 /**
174 * Requirement Version Prepare
175 *
176 * @since 1.0.0
177 *
178 * @return void
179 */
180 private function prepare_requirement_versions() {
181 foreach ( $this->requirements as $dependency => $config ) {
182 switch ( $dependency ) {
183 case 'php':
184 $version = phpversion();
185 break;
186 case 'wp':
187 $version = get_bloginfo( 'version' );
188 break;
189 default:
190 $version = false;
191 }
192
193 if ( ! empty( $version ) ) {
194 $this->requirements[$dependency]['current'] = $version;
195 $this->requirements[$dependency]['checked'] = true;
196 $this->requirements[$dependency]['met'] = version_compare( $version, $config['minimum'], '>=' );
197 }
198 }
199 }
200
201 /**
202 * Initialize everything
203 *
204 * @since 1.0.0
205 *
206 * @return void
207 */
208 public function init() {
209 Authorsy\Bootstrap::instantiate( self::get_plugin_file() );
210 }
211
212 /**
213 * Called Only Once While Activation
214 *
215 * @return void
216 */
217 public function activate() {
218 // Insert new role.
219 Authorsy\Base\Role::instance()->init();
220 // Update default settings.
221 authorsy_update_default_settings();
222
223 }
224 /**
225 * Called Only Once While Activation
226 *
227 * @return void
228 */
229 public function deactivate() {
230
231 }
232
233 /**
234 * Quit Plugin Execution
235 *
236 * @return void
237 */
238 private function quit() {
239 add_action( 'admin_head', array( $this, 'show_plugin_requirements_not_met_notice' ) );
240 }
241
242 /**
243 * Show Error Notice For Missing Requirements
244 *
245 * @return void
246 */
247 public function show_plugin_requirements_not_met_notice() {
248 printf( '<div>Minimum requirements for Authorsy are not met. Please update requirements to continue.</div>' );
249 }
250
251 /**
252 * Plugin Main File
253 *
254 * @return string
255 */
256 public static function get_plugin_file() {
257 return __FILE__;
258 }
259
260 /**
261 * Plugin Base Directory Path
262 *
263 * @return string
264 */
265 public static function get_plugin_dir() {
266 return trailingslashit( plugin_dir_path( self::get_plugin_file() ) );
267 }
268 }
269
270 Authorsy::get_instance();
271
272
273