PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.6.2
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.6.2
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 47 releases
content-control / classes / Plugin / Autoloader.php

Autoloader.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More 2.6.2, at classes/Plugin/Autoloader.php

79 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Includes the composer Autoloader used for packages and classes in the classes/ directory.
4 *
5 * @package ContentControl\Plugin
6 */
7
8 namespace ContentControl\Plugin;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Autoloader class.
14 */
15 class Autoloader {
16
17 /**
18 * Static-only class.
19 */
20 private function __construct() {
21 }
22
23 /**
24 * Require the autoloader and return the result.
25 *
26 * If the autoloader is not present, let's log the failure and display a nice admin notice.
27 *
28 * @param string $name Plugin name for error messaging.
29 * @param string $path Path to the plugin.
30 *
31 * @return boolean
32 */
33 public static function init( $name = '', $path = '' ) {
34 $autoloader = $path . '/vendor/autoload.php';
35
36 if ( ! \is_readable( $autoloader ) ) {
37 self::missing_autoloader( $name );
38
39 return false;
40 }
41
42 require_once $autoloader;
43
44 return true;
45 }
46
47 /**
48 * If the autoloader is missing, add an admin notice.
49 *
50 * @param string $plugin_name Plugin name for error messaging.
51 *
52 * @return void
53 */
54 protected static function missing_autoloader( $plugin_name = '' ) {
55 /* translators: 1. Plugin name */
56 $text = __( 'Your installation of %1$s is incomplete. If you installed %1$s from GitHub, please refer to this document to set up your development environment.', 'content-control' );
57
58 $message = sprintf( $text, $plugin_name );
59
60 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
61 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
62 error_log(
63 esc_html( $message )
64 );
65 }
66
67 add_action(
68 'admin_notices',
69 function () use ( $message ) {
70 ?>
71 <div class="notice notice-error">
72 <p><?php echo esc_html( $message ); ?></p>
73 </div>
74 <?php
75 }
76 );
77 }
78 }
79