PluginProbe
WP-Stateless – Google Cloud Storage / 3.0.3
WP-Stateless – Google Cloud Storage v3.0.3
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / vendor / udx / lib-wp-bootstrap / lib / classes / class-bootstrap-theme.php

class-bootstrap-theme.php in WP-Stateless – Google Cloud Storage 3.0.3, at vendor/udx/lib-wp-bootstrap/lib/classes/class-bootstrap-theme.php

156 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bootstrap
4 *
5 * @namespace UsabilityDynamics
6 *
7 * This file can be used to bootstrap any of the UD plugins.
8 */
9 namespace UsabilityDynamics\WP {
10
11 if( !class_exists( 'UsabilityDynamics\WP\Bootstrap_Theme' ) ) {
12
13 /**
14 * Bootstrap the plugin in WordPress.
15 *
16 * @class Bootstrap
17 * @author: peshkov@UD
18 */
19 class Bootstrap_Theme extends Bootstrap {
20
21 public static $version = '1.0.3';
22
23 public $type = 'theme';
24
25 /**
26 * Slug of parent theme if exist
27 *
28 * @public
29 * @property schema_path
30 * @var array
31 */
32 public $template = false;
33
34 /**
35 * If theme is child
36 *
37 * @public
38 * @property is_child
39 * @var array
40 */
41 public $is_child = false;
42
43 /**
44 * Constructor
45 * Attention: MUST NOT BE CALLED DIRECTLY! USE get_instance() INSTEAD!
46 *
47 * @author peshkov@UD
48 */
49 protected function __construct( $args ) {
50 parent::__construct( $args );
51 //** Load text domain */
52 add_action( 'after_setup_theme', array( $this, 'load_textdomain' ), 1 );
53 //** TGM Plugin activation. */
54 $this->check_plugins_requirements();
55 //** May be initialize Licenses Manager. */
56 $this->define_license_manager();
57 //** Maybe define license client */
58 $this->define_license_client();
59 add_action( 'after_setup_theme', array( $this, 'pre_init' ), 100 );
60 $this->boot();
61 }
62
63 /**
64 * Determine if we have errors before plugin initialization!
65 *
66 * @since 1.0.6
67 */
68 public function pre_init() {
69 //** Be sure we do not have errors. Do not initialize plugin if we have them. */
70 if( $this->has_errors() ) {
71 if( !is_admin() ) {
72 //** Show message about error on front end only if user administrator! */
73 if( current_user_can( 'manage_options' ) ) {
74 _e( "Theme is activated with errors. Please, follow instructions on admin panel to solve the issue!", $this->domain );
75 }
76 die();
77 }
78 } else {
79 $this->init();
80 }
81 }
82
83 /**
84 * Called in the end of constructor.
85 * Redeclare the method in child class!
86 *
87 * @author peshkov@UD
88 */
89 public function boot() {}
90
91 /**
92 * Load Text Domain
93 *
94 * @author peshkov@UD
95 */
96 public function load_textdomain() {
97 load_theme_textdomain( $this->domain, get_template_directory() . '/static/languages/' );
98 }
99
100 /**
101 * Determine if instance already exists and Return Instance
102 *
103 * Attention: The method MUST be called from plugin core file at first to set correct path to plugin!
104 *
105 * @author peshkov@UD
106 */
107 public static function get_instance( $args = array() ) {
108 $class = get_called_class();
109 //** We must be sure that final class contains static property $instance to prevent issues. */
110 if( !property_exists( $class, 'instance' ) ) {
111 exit( "{$class} must have property \$instance" );
112 }
113 $prop = new \ReflectionProperty( $class, 'instance' );
114 if( !$prop->isStatic() ) {
115 exit( "Property \$instance must be <b>static</b> for {$class}" );
116 }
117 if( null === $class::$instance ) {
118
119 //** Get custom ( undefined ) Headers from style.css */
120 global $wp_theme_directories;
121 $stylesheet = get_stylesheet();
122 $theme_root = get_raw_theme_root($stylesheet);
123 if (false === $theme_root) {
124 $theme_root = WP_CONTENT_DIR . '/themes';
125 } elseif (!in_array($theme_root, (array)$wp_theme_directories)) {
126 $theme_root = WP_CONTENT_DIR . $theme_root;
127 }
128 $data = get_file_data( $theme_root . '/' . get_stylesheet() . '/style.css', array(
129 'uservoice_url' => 'UserVoice',
130 'support_url' => 'Support',
131 ) );
132
133 $t = wp_get_theme( get_template() );
134 $args = array_merge( (array)$args, $data, array(
135 'name' => $t->get( 'Name' ),
136 'version' => $t->get( 'Version' ),
137 'template' => $t->get( 'Template' ),
138 'domain' => $t->get( 'TextDomain' ),
139 'is_child' => is_child_theme(),
140 'root_path' => trailingslashit( wp_normalize_path( get_template_directory() ) ),
141 'root_url' => trailingslashit( wp_normalize_path( get_template_directory_uri() ) ),
142 'schema_path' => trailingslashit( wp_normalize_path( get_template_directory() ) ) . 'composer.json',
143 'boot_file' => trailingslashit( wp_normalize_path( get_template_directory() ) ) . 'style.css',
144 ) );
145 //echo "<pre>"; print_r( $args ); echo "</pre>"; die();
146 $class::$instance = new $class( $args );
147 }
148 return $class::$instance;
149 }
150
151 }
152
153 }
154
155 }
156