@@ -28,323 +28,323 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class WPB { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * The loader that's responsible for maintaining and registering all hooks that power |
|
| 33 | - * the plugin. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.0 |
|
| 36 | - * @access protected |
|
| 37 | - * @var WPB_Loader $loader Maintains and registers all hooks for the plugin. |
|
| 38 | - */ |
|
| 39 | - protected $loader; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * The unique identifier of this plugin. |
|
| 43 | - * |
|
| 44 | - * @since 1.0.0 |
|
| 45 | - * @access protected |
|
| 46 | - * @var string $plugin_name The string used to uniquely identify this plugin. |
|
| 47 | - */ |
|
| 48 | - protected $plugin_name; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * The current version of the plugin. |
|
| 52 | - * |
|
| 53 | - * @since 1.0.0 |
|
| 54 | - * @access protected |
|
| 55 | - * @var string $version The current version of the plugin. |
|
| 56 | - */ |
|
| 57 | - protected $version; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Define the core functionality of the plugin. |
|
| 61 | - * |
|
| 62 | - * Set the plugin name and the plugin version that can be used throughout the plugin. |
|
| 63 | - * Load the dependencies, define the locale, and set the hooks for the admin area and |
|
| 64 | - * the public-facing side of the site. |
|
| 65 | - * |
|
| 66 | - * @since 1.0.0 |
|
| 67 | - */ |
|
| 68 | - public function __construct() { |
|
| 69 | - |
|
| 70 | - $this->define_constants(); |
|
| 71 | - |
|
| 72 | - if ( defined( 'WPB_VERSION' ) ) { |
|
| 73 | - $this->version = WPB_VERSION; |
|
| 74 | - } else { |
|
| 75 | - $this->version = '1.0.0'; |
|
| 76 | - } |
|
| 77 | - $this->plugin_name = 'wpb'; |
|
| 78 | - $this->load_dependencies(); |
|
| 79 | - $this->set_locale(); |
|
| 80 | - $this->define_admin_hooks(); |
|
| 81 | - $this->define_public_hooks(); |
|
| 82 | - $this->register_assets(); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Load the required dependencies for this plugin. |
|
| 87 | - * |
|
| 88 | - * Include the following files that make up the plugin: |
|
| 89 | - * |
|
| 90 | - * - WPB_Loader. Orchestrates the hooks of the plugin. |
|
| 91 | - * - WPB_i18n. Defines internationalization functionality. |
|
| 92 | - * - WPB_Admin. Defines all hooks for the admin area. |
|
| 93 | - * - WPB_Public. Defines all hooks for the public side of the site. |
|
| 94 | - * |
|
| 95 | - * Create an instance of the loader which will be used to register the hooks |
|
| 96 | - * with WordPress. |
|
| 97 | - * |
|
| 98 | - * @since 1.0.0 |
|
| 99 | - * @access private |
|
| 100 | - */ |
|
| 101 | - private function load_dependencies() { |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * The class responsible for orchestrating the actions and filters of the |
|
| 105 | - * core plugin. |
|
| 106 | - */ |
|
| 107 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-loader.php'; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * The class responsible for defining internationalization functionality |
|
| 111 | - * of the plugin. |
|
| 112 | - */ |
|
| 113 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-i18n.php'; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * The class responsible for defining all actions that occur in the admin area. |
|
| 117 | - */ |
|
| 118 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin.php'; |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * The class responsible for defining all menu actions that occur in the admin area. |
|
| 122 | - */ |
|
| 123 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-menu.php'; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * The class responsible for defining all submenu actions that occur in the admin area. |
|
| 127 | - */ |
|
| 128 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-submenu.php'; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * The class responsible for defining all actions that occur in the public-facing |
|
| 132 | - * side of the site. |
|
| 133 | - */ |
|
| 134 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpb-public.php'; |
|
| 135 | - |
|
| 136 | - $this->loader = new WPB_Loader(); |
|
| 137 | - |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Define the locale for this plugin for internationalization. |
|
| 142 | - * |
|
| 143 | - * Uses the WPB_i18n class in order to set the domain and to register the hook |
|
| 144 | - * with WordPress. |
|
| 145 | - * |
|
| 146 | - * @since 1.0.0 |
|
| 147 | - * @access private |
|
| 148 | - */ |
|
| 149 | - private function set_locale() { |
|
| 150 | - |
|
| 151 | - $plugin_i18n = new WPB_I18n(); |
|
| 152 | - |
|
| 153 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 154 | - |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Register all of the hooks related to the admin area functionality |
|
| 159 | - * of the plugin. |
|
| 160 | - * |
|
| 161 | - * @since 1.0.0 |
|
| 162 | - * @access private |
|
| 163 | - */ |
|
| 164 | - private function define_admin_hooks() { |
|
| 165 | - |
|
| 166 | - $plugin_admin = new WPB_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 167 | - |
|
| 168 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 169 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 170 | - |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Register all of the hooks related to the public-facing functionality |
|
| 175 | - * of the plugin. |
|
| 176 | - * |
|
| 177 | - * @since 1.0.0 |
|
| 178 | - * @access private |
|
| 179 | - */ |
|
| 180 | - private function define_public_hooks() { |
|
| 181 | - |
|
| 182 | - $plugin_public = new WPB_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 183 | - |
|
| 184 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 185 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 186 | - |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Run the loader to execute all of the hooks with WordPress. |
|
| 191 | - * |
|
| 192 | - * @since 1.0.0 |
|
| 193 | - */ |
|
| 194 | - public function run() { |
|
| 195 | - $this->loader->run(); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * The name of the plugin used to uniquely identify it within the context of |
|
| 200 | - * WordPress and to define internationalization functionality. |
|
| 201 | - * |
|
| 202 | - * @since 1.0.0 |
|
| 203 | - * @return string The name of the plugin. |
|
| 204 | - */ |
|
| 205 | - public function get_plugin_name() { |
|
| 206 | - return $this->plugin_name; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * The reference to the class that orchestrates the hooks with the plugin. |
|
| 211 | - * |
|
| 212 | - * @since 1.0.0 |
|
| 213 | - * @return WPB_Loader Orchestrates the hooks of the plugin. |
|
| 214 | - */ |
|
| 215 | - public function get_loader() { |
|
| 216 | - return $this->loader; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Retrieve the version number of the plugin. |
|
| 221 | - * |
|
| 222 | - * @since 1.0.0 |
|
| 223 | - * @return string The version number of the plugin. |
|
| 224 | - */ |
|
| 225 | - public function get_version() { |
|
| 226 | - return $this->version; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Define the constants. |
|
| 231 | - * |
|
| 232 | - * @return void |
|
| 233 | - */ |
|
| 234 | - public function define_constants() { |
|
| 235 | - define( 'WPB_VERSION', $this->version ); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Register our app scripts and styles. |
|
| 240 | - * |
|
| 241 | - * @return void |
|
| 242 | - */ |
|
| 243 | - public function register_assets() { |
|
| 244 | - $this->register_scripts( $this->get_scripts() ); |
|
| 245 | - $this->register_styles( $this->get_styles() ); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Register scripts. |
|
| 250 | - * |
|
| 251 | - * @param array $scripts All Scripts as an array. |
|
| 252 | - * |
|
| 253 | - * @return void |
|
| 254 | - */ |
|
| 255 | - private function register_scripts( $scripts ) { |
|
| 256 | - foreach ( $scripts as $handle => $script ) { |
|
| 257 | - $deps = isset( $script['deps'] ) ? $script['deps'] : false; |
|
| 258 | - $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false; |
|
| 259 | - $version = isset( $script['version'] ) ? $script['version'] : WPB_VERSION; |
|
| 260 | - |
|
| 261 | - wp_register_script( $handle, $script['src'], $deps, $version, $in_footer ); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Register styles. |
|
| 267 | - * |
|
| 268 | - * @param array $styles All styles as an array. |
|
| 269 | - * |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - public function register_styles( $styles ) { |
|
| 273 | - foreach ( $styles as $handle => $style ) { |
|
| 274 | - $deps = isset( $style['deps'] ) ? $style['deps'] : false; |
|
| 275 | - |
|
| 276 | - wp_register_style( $handle, $style['src'], $deps, WPB_VERSION ); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Get all registered scripts. |
|
| 282 | - * |
|
| 283 | - * @return array |
|
| 284 | - */ |
|
| 285 | - public function get_scripts() { |
|
| 286 | - |
|
| 287 | - $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.min' : ''; |
|
| 288 | - |
|
| 289 | - $scripts = array( |
|
| 290 | - 'wpb-runtime' => array( |
|
| 291 | - 'src' => WPB_ASSETS . '/js/runtime.js', |
|
| 292 | - 'version' => filemtime( WPB_PATH . '/public/js/runtime.js' ), |
|
| 293 | - 'in_footer' => true, |
|
| 294 | - ), |
|
| 295 | - 'wpb-vendor' => array( |
|
| 296 | - 'src' => WPB_ASSETS . '/js/vendors.js', |
|
| 297 | - 'version' => filemtime( WPB_PATH . '/public/js/vendors.js' ), |
|
| 298 | - 'in_footer' => true, |
|
| 299 | - ), |
|
| 300 | - 'wpb-frontend' => array( |
|
| 301 | - 'src' => WPB_ASSETS . '/js/frontend.js', |
|
| 302 | - 'deps' => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ), |
|
| 303 | - 'version' => filemtime( WPB_PATH . '/public/js/frontend.js' ), |
|
| 304 | - 'in_footer' => true, |
|
| 305 | - ), |
|
| 306 | - 'wpb-admin' => array( |
|
| 307 | - 'src' => WPB_ASSETS . '/js/admin.js', |
|
| 308 | - 'deps' => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ), |
|
| 309 | - 'version' => filemtime( WPB_PATH . '/public/js/admin.js' ), |
|
| 310 | - 'in_footer' => true, |
|
| 311 | - ), |
|
| 312 | - 'wpb-spa' => array( |
|
| 313 | - 'src' => WPB_ASSETS . '/js/spa.js', |
|
| 314 | - 'deps' => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ), |
|
| 315 | - 'version' => filemtime( WPB_PATH . '/public/js/spa.js' ), |
|
| 316 | - 'in_footer' => true, |
|
| 317 | - ), |
|
| 318 | - ); |
|
| 319 | - |
|
| 320 | - return $scripts; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Get registered styles. |
|
| 325 | - * |
|
| 326 | - * @return array |
|
| 327 | - */ |
|
| 328 | - public function get_styles() { |
|
| 329 | - |
|
| 330 | - $styles = array( |
|
| 331 | - 'wpb-style' => array( |
|
| 332 | - 'src' => WPB_ASSETS . '/css/style.css', |
|
| 333 | - ), |
|
| 334 | - 'wpb-frontend' => array( |
|
| 335 | - 'src' => WPB_ASSETS . '/css/frontend.css', |
|
| 336 | - ), |
|
| 337 | - 'wpb-admin' => array( |
|
| 338 | - 'src' => WPB_ASSETS . '/css/admin.css', |
|
| 339 | - ), |
|
| 340 | - 'wpb-spa' => array( |
|
| 341 | - 'src' => WPB_ASSETS . '/css/spa.css', |
|
| 342 | - ), |
|
| 343 | - 'wpb-vendors' => array( |
|
| 344 | - 'src' => WPB_ASSETS . '/css/vendors.css', |
|
| 345 | - ), |
|
| 346 | - ); |
|
| 347 | - |
|
| 348 | - return $styles; |
|
| 349 | - } |
|
| 31 | + /** |
|
| 32 | + * The loader that's responsible for maintaining and registering all hooks that power |
|
| 33 | + * the plugin. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.0 |
|
| 36 | + * @access protected |
|
| 37 | + * @var WPB_Loader $loader Maintains and registers all hooks for the plugin. |
|
| 38 | + */ |
|
| 39 | + protected $loader; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * The unique identifier of this plugin. |
|
| 43 | + * |
|
| 44 | + * @since 1.0.0 |
|
| 45 | + * @access protected |
|
| 46 | + * @var string $plugin_name The string used to uniquely identify this plugin. |
|
| 47 | + */ |
|
| 48 | + protected $plugin_name; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * The current version of the plugin. |
|
| 52 | + * |
|
| 53 | + * @since 1.0.0 |
|
| 54 | + * @access protected |
|
| 55 | + * @var string $version The current version of the plugin. |
|
| 56 | + */ |
|
| 57 | + protected $version; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Define the core functionality of the plugin. |
|
| 61 | + * |
|
| 62 | + * Set the plugin name and the plugin version that can be used throughout the plugin. |
|
| 63 | + * Load the dependencies, define the locale, and set the hooks for the admin area and |
|
| 64 | + * the public-facing side of the site. |
|
| 65 | + * |
|
| 66 | + * @since 1.0.0 |
|
| 67 | + */ |
|
| 68 | + public function __construct() { |
|
| 69 | + |
|
| 70 | + $this->define_constants(); |
|
| 71 | + |
|
| 72 | + if ( defined( 'WPB_VERSION' ) ) { |
|
| 73 | + $this->version = WPB_VERSION; |
|
| 74 | + } else { |
|
| 75 | + $this->version = '1.0.0'; |
|
| 76 | + } |
|
| 77 | + $this->plugin_name = 'wpb'; |
|
| 78 | + $this->load_dependencies(); |
|
| 79 | + $this->set_locale(); |
|
| 80 | + $this->define_admin_hooks(); |
|
| 81 | + $this->define_public_hooks(); |
|
| 82 | + $this->register_assets(); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Load the required dependencies for this plugin. |
|
| 87 | + * |
|
| 88 | + * Include the following files that make up the plugin: |
|
| 89 | + * |
|
| 90 | + * - WPB_Loader. Orchestrates the hooks of the plugin. |
|
| 91 | + * - WPB_i18n. Defines internationalization functionality. |
|
| 92 | + * - WPB_Admin. Defines all hooks for the admin area. |
|
| 93 | + * - WPB_Public. Defines all hooks for the public side of the site. |
|
| 94 | + * |
|
| 95 | + * Create an instance of the loader which will be used to register the hooks |
|
| 96 | + * with WordPress. |
|
| 97 | + * |
|
| 98 | + * @since 1.0.0 |
|
| 99 | + * @access private |
|
| 100 | + */ |
|
| 101 | + private function load_dependencies() { |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * The class responsible for orchestrating the actions and filters of the |
|
| 105 | + * core plugin. |
|
| 106 | + */ |
|
| 107 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-loader.php'; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * The class responsible for defining internationalization functionality |
|
| 111 | + * of the plugin. |
|
| 112 | + */ |
|
| 113 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpb-i18n.php'; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * The class responsible for defining all actions that occur in the admin area. |
|
| 117 | + */ |
|
| 118 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin.php'; |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * The class responsible for defining all menu actions that occur in the admin area. |
|
| 122 | + */ |
|
| 123 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-menu.php'; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * The class responsible for defining all submenu actions that occur in the admin area. |
|
| 127 | + */ |
|
| 128 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpb-admin-submenu.php'; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * The class responsible for defining all actions that occur in the public-facing |
|
| 132 | + * side of the site. |
|
| 133 | + */ |
|
| 134 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpb-public.php'; |
|
| 135 | + |
|
| 136 | + $this->loader = new WPB_Loader(); |
|
| 137 | + |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Define the locale for this plugin for internationalization. |
|
| 142 | + * |
|
| 143 | + * Uses the WPB_i18n class in order to set the domain and to register the hook |
|
| 144 | + * with WordPress. |
|
| 145 | + * |
|
| 146 | + * @since 1.0.0 |
|
| 147 | + * @access private |
|
| 148 | + */ |
|
| 149 | + private function set_locale() { |
|
| 150 | + |
|
| 151 | + $plugin_i18n = new WPB_I18n(); |
|
| 152 | + |
|
| 153 | + $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 154 | + |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Register all of the hooks related to the admin area functionality |
|
| 159 | + * of the plugin. |
|
| 160 | + * |
|
| 161 | + * @since 1.0.0 |
|
| 162 | + * @access private |
|
| 163 | + */ |
|
| 164 | + private function define_admin_hooks() { |
|
| 165 | + |
|
| 166 | + $plugin_admin = new WPB_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 167 | + |
|
| 168 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 169 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 170 | + |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Register all of the hooks related to the public-facing functionality |
|
| 175 | + * of the plugin. |
|
| 176 | + * |
|
| 177 | + * @since 1.0.0 |
|
| 178 | + * @access private |
|
| 179 | + */ |
|
| 180 | + private function define_public_hooks() { |
|
| 181 | + |
|
| 182 | + $plugin_public = new WPB_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 183 | + |
|
| 184 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 185 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 186 | + |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Run the loader to execute all of the hooks with WordPress. |
|
| 191 | + * |
|
| 192 | + * @since 1.0.0 |
|
| 193 | + */ |
|
| 194 | + public function run() { |
|
| 195 | + $this->loader->run(); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * The name of the plugin used to uniquely identify it within the context of |
|
| 200 | + * WordPress and to define internationalization functionality. |
|
| 201 | + * |
|
| 202 | + * @since 1.0.0 |
|
| 203 | + * @return string The name of the plugin. |
|
| 204 | + */ |
|
| 205 | + public function get_plugin_name() { |
|
| 206 | + return $this->plugin_name; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * The reference to the class that orchestrates the hooks with the plugin. |
|
| 211 | + * |
|
| 212 | + * @since 1.0.0 |
|
| 213 | + * @return WPB_Loader Orchestrates the hooks of the plugin. |
|
| 214 | + */ |
|
| 215 | + public function get_loader() { |
|
| 216 | + return $this->loader; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Retrieve the version number of the plugin. |
|
| 221 | + * |
|
| 222 | + * @since 1.0.0 |
|
| 223 | + * @return string The version number of the plugin. |
|
| 224 | + */ |
|
| 225 | + public function get_version() { |
|
| 226 | + return $this->version; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Define the constants. |
|
| 231 | + * |
|
| 232 | + * @return void |
|
| 233 | + */ |
|
| 234 | + public function define_constants() { |
|
| 235 | + define( 'WPB_VERSION', $this->version ); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Register our app scripts and styles. |
|
| 240 | + * |
|
| 241 | + * @return void |
|
| 242 | + */ |
|
| 243 | + public function register_assets() { |
|
| 244 | + $this->register_scripts( $this->get_scripts() ); |
|
| 245 | + $this->register_styles( $this->get_styles() ); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Register scripts. |
|
| 250 | + * |
|
| 251 | + * @param array $scripts All Scripts as an array. |
|
| 252 | + * |
|
| 253 | + * @return void |
|
| 254 | + */ |
|
| 255 | + private function register_scripts( $scripts ) { |
|
| 256 | + foreach ( $scripts as $handle => $script ) { |
|
| 257 | + $deps = isset( $script['deps'] ) ? $script['deps'] : false; |
|
| 258 | + $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false; |
|
| 259 | + $version = isset( $script['version'] ) ? $script['version'] : WPB_VERSION; |
|
| 260 | + |
|
| 261 | + wp_register_script( $handle, $script['src'], $deps, $version, $in_footer ); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Register styles. |
|
| 267 | + * |
|
| 268 | + * @param array $styles All styles as an array. |
|
| 269 | + * |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + public function register_styles( $styles ) { |
|
| 273 | + foreach ( $styles as $handle => $style ) { |
|
| 274 | + $deps = isset( $style['deps'] ) ? $style['deps'] : false; |
|
| 275 | + |
|
| 276 | + wp_register_style( $handle, $style['src'], $deps, WPB_VERSION ); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Get all registered scripts. |
|
| 282 | + * |
|
| 283 | + * @return array |
|
| 284 | + */ |
|
| 285 | + public function get_scripts() { |
|
| 286 | + |
|
| 287 | + $prefix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.min' : ''; |
|
| 288 | + |
|
| 289 | + $scripts = array( |
|
| 290 | + 'wpb-runtime' => array( |
|
| 291 | + 'src' => WPB_ASSETS . '/js/runtime.js', |
|
| 292 | + 'version' => filemtime( WPB_PATH . '/public/js/runtime.js' ), |
|
| 293 | + 'in_footer' => true, |
|
| 294 | + ), |
|
| 295 | + 'wpb-vendor' => array( |
|
| 296 | + 'src' => WPB_ASSETS . '/js/vendors.js', |
|
| 297 | + 'version' => filemtime( WPB_PATH . '/public/js/vendors.js' ), |
|
| 298 | + 'in_footer' => true, |
|
| 299 | + ), |
|
| 300 | + 'wpb-frontend' => array( |
|
| 301 | + 'src' => WPB_ASSETS . '/js/frontend.js', |
|
| 302 | + 'deps' => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ), |
|
| 303 | + 'version' => filemtime( WPB_PATH . '/public/js/frontend.js' ), |
|
| 304 | + 'in_footer' => true, |
|
| 305 | + ), |
|
| 306 | + 'wpb-admin' => array( |
|
| 307 | + 'src' => WPB_ASSETS . '/js/admin.js', |
|
| 308 | + 'deps' => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ), |
|
| 309 | + 'version' => filemtime( WPB_PATH . '/public/js/admin.js' ), |
|
| 310 | + 'in_footer' => true, |
|
| 311 | + ), |
|
| 312 | + 'wpb-spa' => array( |
|
| 313 | + 'src' => WPB_ASSETS . '/js/spa.js', |
|
| 314 | + 'deps' => array( 'jquery', 'wpb-vendor', 'wpb-runtime' ), |
|
| 315 | + 'version' => filemtime( WPB_PATH . '/public/js/spa.js' ), |
|
| 316 | + 'in_footer' => true, |
|
| 317 | + ), |
|
| 318 | + ); |
|
| 319 | + |
|
| 320 | + return $scripts; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Get registered styles. |
|
| 325 | + * |
|
| 326 | + * @return array |
|
| 327 | + */ |
|
| 328 | + public function get_styles() { |
|
| 329 | + |
|
| 330 | + $styles = array( |
|
| 331 | + 'wpb-style' => array( |
|
| 332 | + 'src' => WPB_ASSETS . '/css/style.css', |
|
| 333 | + ), |
|
| 334 | + 'wpb-frontend' => array( |
|
| 335 | + 'src' => WPB_ASSETS . '/css/frontend.css', |
|
| 336 | + ), |
|
| 337 | + 'wpb-admin' => array( |
|
| 338 | + 'src' => WPB_ASSETS . '/css/admin.css', |
|
| 339 | + ), |
|
| 340 | + 'wpb-spa' => array( |
|
| 341 | + 'src' => WPB_ASSETS . '/css/spa.css', |
|
| 342 | + ), |
|
| 343 | + 'wpb-vendors' => array( |
|
| 344 | + 'src' => WPB_ASSETS . '/css/vendors.css', |
|
| 345 | + ), |
|
| 346 | + ); |
|
| 347 | + |
|
| 348 | + return $styles; |
|
| 349 | + } |
|
| 350 | 350 | } |
@@ -21,106 +21,106 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class WPB_Admin { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The ID of this plugin. |
|
| 26 | - * |
|
| 27 | - * @since 1.0.0 |
|
| 28 | - * @access private |
|
| 29 | - * @var string $plugin_name The ID of this plugin. |
|
| 30 | - */ |
|
| 31 | - private $plugin_name; |
|
| 24 | + /** |
|
| 25 | + * The ID of this plugin. |
|
| 26 | + * |
|
| 27 | + * @since 1.0.0 |
|
| 28 | + * @access private |
|
| 29 | + * @var string $plugin_name The ID of this plugin. |
|
| 30 | + */ |
|
| 31 | + private $plugin_name; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The version of this plugin. |
|
| 35 | - * |
|
| 36 | - * @since 1.0.0 |
|
| 37 | - * @access private |
|
| 38 | - * @var string $version The current version of this plugin. |
|
| 39 | - */ |
|
| 40 | - private $version; |
|
| 33 | + /** |
|
| 34 | + * The version of this plugin. |
|
| 35 | + * |
|
| 36 | + * @since 1.0.0 |
|
| 37 | + * @access private |
|
| 38 | + * @var string $version The current version of this plugin. |
|
| 39 | + */ |
|
| 40 | + private $version; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Initialize the class and set its properties. |
|
| 44 | - * |
|
| 45 | - * @since 1.0.0 |
|
| 46 | - * @param string $plugin_name The name of this plugin. |
|
| 47 | - * @param string $version The version of this plugin. |
|
| 48 | - */ |
|
| 49 | - public function __construct( $plugin_name, $version ) { |
|
| 42 | + /** |
|
| 43 | + * Initialize the class and set its properties. |
|
| 44 | + * |
|
| 45 | + * @since 1.0.0 |
|
| 46 | + * @param string $plugin_name The name of this plugin. |
|
| 47 | + * @param string $version The version of this plugin. |
|
| 48 | + */ |
|
| 49 | + public function __construct( $plugin_name, $version ) { |
|
| 50 | 50 | |
| 51 | - $this->plugin_name = $plugin_name; |
|
| 52 | - $this->version = $version; |
|
| 53 | - $this->register_menus(); |
|
| 54 | - } |
|
| 51 | + $this->plugin_name = $plugin_name; |
|
| 52 | + $this->version = $version; |
|
| 53 | + $this->register_menus(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Register the stylesheets for the admin area. |
|
| 58 | - * |
|
| 59 | - * @since 1.0.0 |
|
| 60 | - */ |
|
| 61 | - public function enqueue_styles() { |
|
| 56 | + /** |
|
| 57 | + * Register the stylesheets for the admin area. |
|
| 58 | + * |
|
| 59 | + * @since 1.0.0 |
|
| 60 | + */ |
|
| 61 | + public function enqueue_styles() { |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * This function is provided for demonstration purposes only. |
|
| 65 | - * |
|
| 66 | - * An instance of this class should be passed to the run() function |
|
| 67 | - * defined in WPB_Loader as all of the hooks are defined |
|
| 68 | - * in that particular class. |
|
| 69 | - * |
|
| 70 | - * The WPB_Loader will then create the relationship |
|
| 71 | - * between the defined hooks and the functions defined in this |
|
| 72 | - * class. |
|
| 73 | - */ |
|
| 63 | + /** |
|
| 64 | + * This function is provided for demonstration purposes only. |
|
| 65 | + * |
|
| 66 | + * An instance of this class should be passed to the run() function |
|
| 67 | + * defined in WPB_Loader as all of the hooks are defined |
|
| 68 | + * in that particular class. |
|
| 69 | + * |
|
| 70 | + * The WPB_Loader will then create the relationship |
|
| 71 | + * between the defined hooks and the functions defined in this |
|
| 72 | + * class. |
|
| 73 | + */ |
|
| 74 | 74 | |
| 75 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wpb-admin.css', array(), $this->version, 'all' ); |
|
| 75 | + wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wpb-admin.css', array(), $this->version, 'all' ); |
|
| 76 | 76 | |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Register the JavaScript for the admin area. |
|
| 81 | - * |
|
| 82 | - * @since 1.0.0 |
|
| 83 | - */ |
|
| 84 | - public function enqueue_scripts() { |
|
| 79 | + /** |
|
| 80 | + * Register the JavaScript for the admin area. |
|
| 81 | + * |
|
| 82 | + * @since 1.0.0 |
|
| 83 | + */ |
|
| 84 | + public function enqueue_scripts() { |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * This function is provided for demonstration purposes only. |
|
| 88 | - * |
|
| 89 | - * An instance of this class should be passed to the run() function |
|
| 90 | - * defined in WPB_Loader as all of the hooks are defined |
|
| 91 | - * in that particular class. |
|
| 92 | - * |
|
| 93 | - * The WPB_Loader will then create the relationship |
|
| 94 | - * between the defined hooks and the functions defined in this |
|
| 95 | - * class. |
|
| 96 | - */ |
|
| 86 | + /** |
|
| 87 | + * This function is provided for demonstration purposes only. |
|
| 88 | + * |
|
| 89 | + * An instance of this class should be passed to the run() function |
|
| 90 | + * defined in WPB_Loader as all of the hooks are defined |
|
| 91 | + * in that particular class. |
|
| 92 | + * |
|
| 93 | + * The WPB_Loader will then create the relationship |
|
| 94 | + * between the defined hooks and the functions defined in this |
|
| 95 | + * class. |
|
| 96 | + */ |
|
| 97 | 97 | |
| 98 | - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wpb-admin.js', array( 'jquery' ), $this->version, false ); |
|
| 98 | + wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wpb-admin.js', array( 'jquery' ), $this->version, false ); |
|
| 99 | 99 | |
| 100 | - } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Register all menus here. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.0 |
|
| 106 | - */ |
|
| 107 | - public function register_menus() { |
|
| 108 | - // Registerv root menu. |
|
| 109 | - $menu = new WPB_Admin_Menu( $this->plugin_name ); |
|
| 110 | - $menu->page_title = 'WPB'; |
|
| 111 | - $menu->menu_title = 'WPB'; |
|
| 112 | - $menu->capability = 'manage_options'; |
|
| 113 | - $menu->slug = 'wpb'; |
|
| 114 | - $menu->icon = 'dashicons-text'; |
|
| 115 | - $menu->save(); |
|
| 116 | - // Register submenu for root menu. |
|
| 117 | - $submenu = new WPB_Admin_SubMenu( $this->plugin_name ); |
|
| 118 | - $submenu->parent_slug = $menu->slug; |
|
| 119 | - $submenu->page_title = 'Settings'; |
|
| 120 | - $submenu->menu_title = 'Settings'; |
|
| 121 | - $submenu->capability = 'manage_options'; |
|
| 122 | - $submenu->slug = 'admin.php?page=' . $menu->slug . '#/settings'; |
|
| 123 | - $submenu->save(); |
|
| 124 | - } |
|
| 102 | + /** |
|
| 103 | + * Register all menus here. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.0 |
|
| 106 | + */ |
|
| 107 | + public function register_menus() { |
|
| 108 | + // Registerv root menu. |
|
| 109 | + $menu = new WPB_Admin_Menu( $this->plugin_name ); |
|
| 110 | + $menu->page_title = 'WPB'; |
|
| 111 | + $menu->menu_title = 'WPB'; |
|
| 112 | + $menu->capability = 'manage_options'; |
|
| 113 | + $menu->slug = 'wpb'; |
|
| 114 | + $menu->icon = 'dashicons-text'; |
|
| 115 | + $menu->save(); |
|
| 116 | + // Register submenu for root menu. |
|
| 117 | + $submenu = new WPB_Admin_SubMenu( $this->plugin_name ); |
|
| 118 | + $submenu->parent_slug = $menu->slug; |
|
| 119 | + $submenu->page_title = 'Settings'; |
|
| 120 | + $submenu->menu_title = 'Settings'; |
|
| 121 | + $submenu->capability = 'manage_options'; |
|
| 122 | + $submenu->slug = 'admin.php?page=' . $menu->slug . '#/settings'; |
|
| 123 | + $submenu->save(); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | 126 | } |
@@ -21,160 +21,160 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class WPB_Admin_Menu { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * The menu page title. |
|
| 26 | - * |
|
| 27 | - * @since 1.0.0 |
|
| 28 | - * @access public |
|
| 29 | - * @var string $page_title The string used to set menu page title. |
|
| 30 | - */ |
|
| 31 | - public $page_title; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * The menu title. |
|
| 35 | - * |
|
| 36 | - * @since 1.0.0 |
|
| 37 | - * @access public |
|
| 38 | - * @var string $menu_title The string used to set menu title. |
|
| 39 | - */ |
|
| 40 | - public $menu_title; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * The menu capability. |
|
| 44 | - * |
|
| 45 | - * @since 1.0.0 |
|
| 46 | - * @access public |
|
| 47 | - * @var string $capability The string used to set menu capability. |
|
| 48 | - */ |
|
| 49 | - public $capability; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The menu slug. |
|
| 53 | - * |
|
| 54 | - * @since 1.0.0 |
|
| 55 | - * @access public |
|
| 56 | - * @var string $slug The string used to set menu slug. |
|
| 57 | - */ |
|
| 58 | - public $slug; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The callback to render content. |
|
| 62 | - * |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - * @access public |
|
| 65 | - * @var callback $callback The callback used to render content. |
|
| 66 | - */ |
|
| 67 | - public $callback = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The menu icon. |
|
| 71 | - * |
|
| 72 | - * @since 1.0.0 |
|
| 73 | - * @access public |
|
| 74 | - * @var string $icon The string used to set menu icon. |
|
| 75 | - */ |
|
| 76 | - public $icon; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * The menu position. |
|
| 80 | - * |
|
| 81 | - * @since 1.0.0 |
|
| 82 | - * @access public |
|
| 83 | - * @var int $position The string used to set menu position. |
|
| 84 | - */ |
|
| 85 | - public $position; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * The menu plugin name. |
|
| 89 | - * |
|
| 90 | - * @since 1.0.0 |
|
| 91 | - * @access private |
|
| 92 | - * @var string $plugin_name The string used to uniquely identify this plugin. |
|
| 93 | - */ |
|
| 94 | - private $plugin_name; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Boot Menu. |
|
| 98 | - * |
|
| 99 | - * @param string $plugin_name The string used to uniquely identify this plugin. |
|
| 100 | - * @since 1.0.0 |
|
| 101 | - * @access public |
|
| 102 | - */ |
|
| 103 | - public function __construct( $plugin_name ) { |
|
| 104 | - $this->plugin_name = $plugin_name; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Create a new menu page. |
|
| 109 | - * |
|
| 110 | - * @since 1.0.0 |
|
| 111 | - * @access public |
|
| 112 | - */ |
|
| 113 | - public function save() { |
|
| 114 | - add_action( 'admin_menu', array( $this, 'create_menu' ) ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Create a new menu page. |
|
| 119 | - * |
|
| 120 | - * @since 1.0.0 |
|
| 121 | - * @param array $options Pass proprties as an array. |
|
| 122 | - * @access public |
|
| 123 | - */ |
|
| 124 | - public function make( $options = array() ) { |
|
| 125 | - foreach ( $options as $property => $value ) { |
|
| 126 | - if ( property_exists( get_called_class(), $property ) ) { |
|
| 127 | - $this->{$property} = $value; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - add_action( 'admin_menu', array( $this, 'create_menu' ) ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Register new menu page. |
|
| 135 | - * |
|
| 136 | - * @return void |
|
| 137 | - */ |
|
| 138 | - public function create_menu() { |
|
| 139 | - $callback = $this->callback ?? array( $this, 'render_content' ); |
|
| 140 | - $hook = add_menu_page( |
|
| 141 | - $this->page_title, |
|
| 142 | - $this->menu_title, |
|
| 143 | - $this->capability, |
|
| 144 | - $this->slug, |
|
| 145 | - $callback, |
|
| 146 | - $this->icon |
|
| 147 | - ); |
|
| 148 | - |
|
| 149 | - add_action( 'load-' . $hook, array( $this, 'init_hooks' ) ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Initialize hooks for the admin page. |
|
| 154 | - * |
|
| 155 | - * @return void |
|
| 156 | - */ |
|
| 157 | - public function init_hooks() { |
|
| 158 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Load scripts and styles for the current menu page. |
|
| 163 | - * |
|
| 164 | - * @return void |
|
| 165 | - */ |
|
| 166 | - public function enqueue_scripts() { |
|
| 167 | - wp_enqueue_style( $this->plugin_name . '-vendors' ); |
|
| 168 | - wp_enqueue_style( $this->plugin_name . '-admin' ); |
|
| 169 | - wp_enqueue_script( $this->plugin_name . '-admin' ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Render app content. |
|
| 174 | - * |
|
| 175 | - * @return void |
|
| 176 | - */ |
|
| 177 | - public function render_content() { |
|
| 178 | - echo '<div class="wrap"><div id="wpb-admin" base-url="' . esc_attr( get_site_url() ) . '" csrf-token="' . esc_attr( wpb_csrf_token() ) . '"></div></div>'; |
|
| 179 | - } |
|
| 24 | + /** |
|
| 25 | + * The menu page title. |
|
| 26 | + * |
|
| 27 | + * @since 1.0.0 |
|
| 28 | + * @access public |
|
| 29 | + * @var string $page_title The string used to set menu page title. |
|
| 30 | + */ |
|
| 31 | + public $page_title; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * The menu title. |
|
| 35 | + * |
|
| 36 | + * @since 1.0.0 |
|
| 37 | + * @access public |
|
| 38 | + * @var string $menu_title The string used to set menu title. |
|
| 39 | + */ |
|
| 40 | + public $menu_title; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * The menu capability. |
|
| 44 | + * |
|
| 45 | + * @since 1.0.0 |
|
| 46 | + * @access public |
|
| 47 | + * @var string $capability The string used to set menu capability. |
|
| 48 | + */ |
|
| 49 | + public $capability; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The menu slug. |
|
| 53 | + * |
|
| 54 | + * @since 1.0.0 |
|
| 55 | + * @access public |
|
| 56 | + * @var string $slug The string used to set menu slug. |
|
| 57 | + */ |
|
| 58 | + public $slug; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The callback to render content. |
|
| 62 | + * |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + * @access public |
|
| 65 | + * @var callback $callback The callback used to render content. |
|
| 66 | + */ |
|
| 67 | + public $callback = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The menu icon. |
|
| 71 | + * |
|
| 72 | + * @since 1.0.0 |
|
| 73 | + * @access public |
|
| 74 | + * @var string $icon The string used to set menu icon. |
|
| 75 | + */ |
|
| 76 | + public $icon; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * The menu position. |
|
| 80 | + * |
|
| 81 | + * @since 1.0.0 |
|
| 82 | + * @access public |
|
| 83 | + * @var int $position The string used to set menu position. |
|
| 84 | + */ |
|
| 85 | + public $position; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * The menu plugin name. |
|
| 89 | + * |
|
| 90 | + * @since 1.0.0 |
|
| 91 | + * @access private |
|
| 92 | + * @var string $plugin_name The string used to uniquely identify this plugin. |
|
| 93 | + */ |
|
| 94 | + private $plugin_name; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Boot Menu. |
|
| 98 | + * |
|
| 99 | + * @param string $plugin_name The string used to uniquely identify this plugin. |
|
| 100 | + * @since 1.0.0 |
|
| 101 | + * @access public |
|
| 102 | + */ |
|
| 103 | + public function __construct( $plugin_name ) { |
|
| 104 | + $this->plugin_name = $plugin_name; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Create a new menu page. |
|
| 109 | + * |
|
| 110 | + * @since 1.0.0 |
|
| 111 | + * @access public |
|
| 112 | + */ |
|
| 113 | + public function save() { |
|
| 114 | + add_action( 'admin_menu', array( $this, 'create_menu' ) ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Create a new menu page. |
|
| 119 | + * |
|
| 120 | + * @since 1.0.0 |
|
| 121 | + * @param array $options Pass proprties as an array. |
|
| 122 | + * @access public |
|
| 123 | + */ |
|
| 124 | + public function make( $options = array() ) { |
|
| 125 | + foreach ( $options as $property => $value ) { |
|
| 126 | + if ( property_exists( get_called_class(), $property ) ) { |
|
| 127 | + $this->{$property} = $value; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + add_action( 'admin_menu', array( $this, 'create_menu' ) ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Register new menu page. |
|
| 135 | + * |
|
| 136 | + * @return void |
|
| 137 | + */ |
|
| 138 | + public function create_menu() { |
|
| 139 | + $callback = $this->callback ?? array( $this, 'render_content' ); |
|
| 140 | + $hook = add_menu_page( |
|
| 141 | + $this->page_title, |
|
| 142 | + $this->menu_title, |
|
| 143 | + $this->capability, |
|
| 144 | + $this->slug, |
|
| 145 | + $callback, |
|
| 146 | + $this->icon |
|
| 147 | + ); |
|
| 148 | + |
|
| 149 | + add_action( 'load-' . $hook, array( $this, 'init_hooks' ) ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Initialize hooks for the admin page. |
|
| 154 | + * |
|
| 155 | + * @return void |
|
| 156 | + */ |
|
| 157 | + public function init_hooks() { |
|
| 158 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Load scripts and styles for the current menu page. |
|
| 163 | + * |
|
| 164 | + * @return void |
|
| 165 | + */ |
|
| 166 | + public function enqueue_scripts() { |
|
| 167 | + wp_enqueue_style( $this->plugin_name . '-vendors' ); |
|
| 168 | + wp_enqueue_style( $this->plugin_name . '-admin' ); |
|
| 169 | + wp_enqueue_script( $this->plugin_name . '-admin' ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Render app content. |
|
| 174 | + * |
|
| 175 | + * @return void |
|
| 176 | + */ |
|
| 177 | + public function render_content() { |
|
| 178 | + echo '<div class="wrap"><div id="wpb-admin" base-url="' . esc_attr( get_site_url() ) . '" csrf-token="' . esc_attr( wpb_csrf_token() ) . '"></div></div>'; |
|
| 179 | + } |
|
| 180 | 180 | } |
@@ -27,177 +27,177 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class ComposerScripts { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Handle the post-install Composer event. |
|
| 32 | - * |
|
| 33 | - * @param \Composer\Script\Event $event The composer event. |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public static function post_install( Event $event ) { |
|
| 37 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Handle the post-update Composer event. |
|
| 42 | - * |
|
| 43 | - * @param \Composer\Script\Event $event The composer event. |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public static function post_update( Event $event ) { |
|
| 47 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Handle the post-autoload-dump Composer event. |
|
| 52 | - * |
|
| 53 | - * @param \Composer\Script\Event $event The composer event. |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public static function post_autoload_dump( Event $event ) { |
|
| 57 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 58 | - |
|
| 59 | - $dir = $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/../'; |
|
| 60 | - $root = dirname( $event->getComposer()->getConfig()->get( 'vendor-dir' ) ); |
|
| 61 | - |
|
| 62 | - $vendor_name = strtolower( basename( $root ) ); |
|
| 63 | - $partials = explode( '-', $vendor_name ); |
|
| 64 | - $camel_case_partials = array(); |
|
| 65 | - foreach ( $partials as $partial ) { |
|
| 66 | - $camel_case_partials[] = ucfirst( strtolower( $partial ) ); |
|
| 67 | - } |
|
| 68 | - $camel_case = implode( '_', $camel_case_partials ); |
|
| 69 | - $snake_case = implode( '_', $partials ); |
|
| 70 | - |
|
| 71 | - $files = array( |
|
| 72 | - '/admin/class-wpb-admin.php', |
|
| 73 | - '/admin/class-wpb-admin-menu.php', |
|
| 74 | - '/admin/class-wpb-admin-submenu.php', |
|
| 75 | - '/admin/partials/wpb-admin-display.php', |
|
| 76 | - '/admin/css/wpb-admin.css', |
|
| 77 | - '/admin/js/wpb-admin.js', |
|
| 78 | - '/app/Exceptions/Handler.php', |
|
| 79 | - '/app/Http/Controllers/ProductController.php', |
|
| 80 | - '/app/Http/Middleware/AuthMiddleware.php', |
|
| 81 | - '/app/Http/Middleware/VerifyCsrfToken.php', |
|
| 82 | - '/app/Http/Kernel.php', |
|
| 83 | - '/app/User.php', |
|
| 84 | - '/app/Post.php', |
|
| 85 | - '/bootstrap/app.php', |
|
| 86 | - '/config/app.php', |
|
| 87 | - '/config/database.php', |
|
| 88 | - '/config/view.php', |
|
| 89 | - '/database/migrations/class-create-customers-table.php', |
|
| 90 | - '/database/seeds/class-customers-table.php', |
|
| 91 | - '/includes/class-wpb-activator.php', |
|
| 92 | - '/includes/class-wpb-deactivator.php', |
|
| 93 | - '/includes/class-wpb-i18n.php', |
|
| 94 | - '/includes/class-wpb-loader.php', |
|
| 95 | - '/includes/class-wpb.php', |
|
| 96 | - '/public/class-wpb-public.php', |
|
| 97 | - '/public/partials/wpb-public-display.php', |
|
| 98 | - '/public/css/wpb-public.css', |
|
| 99 | - '/public/js/wpb-public.js', |
|
| 100 | - '/resources/js/admin/main.js', |
|
| 101 | - '/resources/js/admin/router/index.js', |
|
| 102 | - '/resources/js/frontend/main.js', |
|
| 103 | - '/resources/js/spa/main.js', |
|
| 104 | - '/routes/web.php', |
|
| 105 | - '/routes/api.php', |
|
| 106 | - '/src/Contracts/Http/Kernel.php', |
|
| 107 | - '/src/Contracts/ExceptionHandler.php', |
|
| 108 | - '/src/Database/Eloquent/Scopes/PostAuthorScope.php', |
|
| 109 | - '/src/Database/Eloquent/Scopes/PostStatusScope.php', |
|
| 110 | - '/src/Database/Eloquent/Scopes/PostTypeScope.php', |
|
| 111 | - '/src/Database/DB.php', |
|
| 112 | - '/src/Exceptions/Handler.php', |
|
| 113 | - '/src/Http/Events/RequestHandler.php', |
|
| 114 | - '/src/Http/Kernel.php', |
|
| 115 | - '/src/helpers.php', |
|
| 116 | - '/src/Support/Facades/Config.php', |
|
| 117 | - '/src/Support/Facades/Route.php', |
|
| 118 | - '/src/Application.php', |
|
| 119 | - '/tests/Application.php', |
|
| 120 | - '/wpb.php', |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - foreach ( $files as $file ) { |
|
| 124 | - $file = $root . $file; |
|
| 125 | - if ( file_exists( $file ) ) { |
|
| 126 | - |
|
| 127 | - $filesystem = new Filesystem(); |
|
| 128 | - |
|
| 129 | - $contents = $filesystem->get( $file ); |
|
| 130 | - $contents = str_replace( 'wpb_', $snake_case . '_', $contents ); |
|
| 131 | - $contents = str_replace( 'wpb', $vendor_name, $contents ); |
|
| 132 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
| 133 | - $contents = str_replace( 'WPB_FILE', strtoupper( $camel_case ) . '_FILE', $contents ); |
|
| 134 | - $contents = str_replace( 'WPB_PATH', strtoupper( $camel_case ) . '_PATH', $contents ); |
|
| 135 | - $contents = str_replace( 'WPB_INCLUDES', strtoupper( $camel_case ) . '_INCLUDES', $contents ); |
|
| 136 | - $contents = str_replace( 'WPB_URL', strtoupper( $camel_case ) . '_URL', $contents ); |
|
| 137 | - $contents = str_replace( 'WPB_ASSETS', strtoupper( $camel_case ) . '_ASSETS', $contents ); |
|
| 138 | - $contents = str_replace( 'WPB_VERSION', strtoupper( $camel_case ) . '_VERSION', $contents ); |
|
| 139 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
| 140 | - $filesystem->put( |
|
| 141 | - $file, |
|
| 142 | - $contents |
|
| 143 | - ); |
|
| 144 | - |
|
| 145 | - $dir = dirname( $file ); |
|
| 146 | - $file_name = basename( $file ); |
|
| 147 | - $new_file_name = str_replace( 'wpb', $vendor_name, $file_name ); |
|
| 148 | - |
|
| 149 | - if ( $file_name !== $new_file_name ) { |
|
| 150 | - rename( $file, $dir . '/' . $new_file_name ); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - static::update_composer( $filesystem, $root, $camel_case ); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Replace bootstrap file. |
|
| 160 | - * |
|
| 161 | - * @since 1.0.0 |
|
| 162 | - * @access public |
|
| 163 | - * |
|
| 164 | - * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
| 165 | - * @param string $root The string is unique root path for each plugin. |
|
| 166 | - * @param string $camel_case This string is camel case of project name. |
|
| 167 | - * |
|
| 168 | - * @return void |
|
| 169 | - */ |
|
| 170 | - protected static function update_bootstrap( $filesystem, $root, $camel_case ) { |
|
| 171 | - $file = $root . '/bootstrap/app.php'; |
|
| 172 | - if ( file_exists( $file ) ) { |
|
| 173 | - $contents = $filesystem->get( $file ); |
|
| 174 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
| 175 | - $filesystem->put( |
|
| 176 | - $file, |
|
| 177 | - $contents |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Update composer. |
|
| 185 | - * |
|
| 186 | - * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
| 187 | - * @param string $root The app root. |
|
| 188 | - * @param string $camel_case The composer event. |
|
| 189 | - * |
|
| 190 | - * @return void |
|
| 191 | - */ |
|
| 192 | - protected static function update_composer( $filesystem, $root, $camel_case ) { |
|
| 193 | - $file = $root . '/composer.json'; |
|
| 194 | - if ( file_exists( $file ) ) { |
|
| 195 | - $contents = $filesystem->get( $file ); |
|
| 196 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
| 197 | - $filesystem->put( |
|
| 198 | - $file, |
|
| 199 | - $contents |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - } |
|
| 30 | + /** |
|
| 31 | + * Handle the post-install Composer event. |
|
| 32 | + * |
|
| 33 | + * @param \Composer\Script\Event $event The composer event. |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public static function post_install( Event $event ) { |
|
| 37 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Handle the post-update Composer event. |
|
| 42 | + * |
|
| 43 | + * @param \Composer\Script\Event $event The composer event. |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public static function post_update( Event $event ) { |
|
| 47 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Handle the post-autoload-dump Composer event. |
|
| 52 | + * |
|
| 53 | + * @param \Composer\Script\Event $event The composer event. |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public static function post_autoload_dump( Event $event ) { |
|
| 57 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
| 58 | + |
|
| 59 | + $dir = $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/../'; |
|
| 60 | + $root = dirname( $event->getComposer()->getConfig()->get( 'vendor-dir' ) ); |
|
| 61 | + |
|
| 62 | + $vendor_name = strtolower( basename( $root ) ); |
|
| 63 | + $partials = explode( '-', $vendor_name ); |
|
| 64 | + $camel_case_partials = array(); |
|
| 65 | + foreach ( $partials as $partial ) { |
|
| 66 | + $camel_case_partials[] = ucfirst( strtolower( $partial ) ); |
|
| 67 | + } |
|
| 68 | + $camel_case = implode( '_', $camel_case_partials ); |
|
| 69 | + $snake_case = implode( '_', $partials ); |
|
| 70 | + |
|
| 71 | + $files = array( |
|
| 72 | + '/admin/class-wpb-admin.php', |
|
| 73 | + '/admin/class-wpb-admin-menu.php', |
|
| 74 | + '/admin/class-wpb-admin-submenu.php', |
|
| 75 | + '/admin/partials/wpb-admin-display.php', |
|
| 76 | + '/admin/css/wpb-admin.css', |
|
| 77 | + '/admin/js/wpb-admin.js', |
|
| 78 | + '/app/Exceptions/Handler.php', |
|
| 79 | + '/app/Http/Controllers/ProductController.php', |
|
| 80 | + '/app/Http/Middleware/AuthMiddleware.php', |
|
| 81 | + '/app/Http/Middleware/VerifyCsrfToken.php', |
|
| 82 | + '/app/Http/Kernel.php', |
|
| 83 | + '/app/User.php', |
|
| 84 | + '/app/Post.php', |
|
| 85 | + '/bootstrap/app.php', |
|
| 86 | + '/config/app.php', |
|
| 87 | + '/config/database.php', |
|
| 88 | + '/config/view.php', |
|
| 89 | + '/database/migrations/class-create-customers-table.php', |
|
| 90 | + '/database/seeds/class-customers-table.php', |
|
| 91 | + '/includes/class-wpb-activator.php', |
|
| 92 | + '/includes/class-wpb-deactivator.php', |
|
| 93 | + '/includes/class-wpb-i18n.php', |
|
| 94 | + '/includes/class-wpb-loader.php', |
|
| 95 | + '/includes/class-wpb.php', |
|
| 96 | + '/public/class-wpb-public.php', |
|
| 97 | + '/public/partials/wpb-public-display.php', |
|
| 98 | + '/public/css/wpb-public.css', |
|
| 99 | + '/public/js/wpb-public.js', |
|
| 100 | + '/resources/js/admin/main.js', |
|
| 101 | + '/resources/js/admin/router/index.js', |
|
| 102 | + '/resources/js/frontend/main.js', |
|
| 103 | + '/resources/js/spa/main.js', |
|
| 104 | + '/routes/web.php', |
|
| 105 | + '/routes/api.php', |
|
| 106 | + '/src/Contracts/Http/Kernel.php', |
|
| 107 | + '/src/Contracts/ExceptionHandler.php', |
|
| 108 | + '/src/Database/Eloquent/Scopes/PostAuthorScope.php', |
|
| 109 | + '/src/Database/Eloquent/Scopes/PostStatusScope.php', |
|
| 110 | + '/src/Database/Eloquent/Scopes/PostTypeScope.php', |
|
| 111 | + '/src/Database/DB.php', |
|
| 112 | + '/src/Exceptions/Handler.php', |
|
| 113 | + '/src/Http/Events/RequestHandler.php', |
|
| 114 | + '/src/Http/Kernel.php', |
|
| 115 | + '/src/helpers.php', |
|
| 116 | + '/src/Support/Facades/Config.php', |
|
| 117 | + '/src/Support/Facades/Route.php', |
|
| 118 | + '/src/Application.php', |
|
| 119 | + '/tests/Application.php', |
|
| 120 | + '/wpb.php', |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + foreach ( $files as $file ) { |
|
| 124 | + $file = $root . $file; |
|
| 125 | + if ( file_exists( $file ) ) { |
|
| 126 | + |
|
| 127 | + $filesystem = new Filesystem(); |
|
| 128 | + |
|
| 129 | + $contents = $filesystem->get( $file ); |
|
| 130 | + $contents = str_replace( 'wpb_', $snake_case . '_', $contents ); |
|
| 131 | + $contents = str_replace( 'wpb', $vendor_name, $contents ); |
|
| 132 | + $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
| 133 | + $contents = str_replace( 'WPB_FILE', strtoupper( $camel_case ) . '_FILE', $contents ); |
|
| 134 | + $contents = str_replace( 'WPB_PATH', strtoupper( $camel_case ) . '_PATH', $contents ); |
|
| 135 | + $contents = str_replace( 'WPB_INCLUDES', strtoupper( $camel_case ) . '_INCLUDES', $contents ); |
|
| 136 | + $contents = str_replace( 'WPB_URL', strtoupper( $camel_case ) . '_URL', $contents ); |
|
| 137 | + $contents = str_replace( 'WPB_ASSETS', strtoupper( $camel_case ) . '_ASSETS', $contents ); |
|
| 138 | + $contents = str_replace( 'WPB_VERSION', strtoupper( $camel_case ) . '_VERSION', $contents ); |
|
| 139 | + $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
| 140 | + $filesystem->put( |
|
| 141 | + $file, |
|
| 142 | + $contents |
|
| 143 | + ); |
|
| 144 | + |
|
| 145 | + $dir = dirname( $file ); |
|
| 146 | + $file_name = basename( $file ); |
|
| 147 | + $new_file_name = str_replace( 'wpb', $vendor_name, $file_name ); |
|
| 148 | + |
|
| 149 | + if ( $file_name !== $new_file_name ) { |
|
| 150 | + rename( $file, $dir . '/' . $new_file_name ); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + static::update_composer( $filesystem, $root, $camel_case ); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Replace bootstrap file. |
|
| 160 | + * |
|
| 161 | + * @since 1.0.0 |
|
| 162 | + * @access public |
|
| 163 | + * |
|
| 164 | + * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
| 165 | + * @param string $root The string is unique root path for each plugin. |
|
| 166 | + * @param string $camel_case This string is camel case of project name. |
|
| 167 | + * |
|
| 168 | + * @return void |
|
| 169 | + */ |
|
| 170 | + protected static function update_bootstrap( $filesystem, $root, $camel_case ) { |
|
| 171 | + $file = $root . '/bootstrap/app.php'; |
|
| 172 | + if ( file_exists( $file ) ) { |
|
| 173 | + $contents = $filesystem->get( $file ); |
|
| 174 | + $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
| 175 | + $filesystem->put( |
|
| 176 | + $file, |
|
| 177 | + $contents |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Update composer. |
|
| 185 | + * |
|
| 186 | + * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
| 187 | + * @param string $root The app root. |
|
| 188 | + * @param string $camel_case The composer event. |
|
| 189 | + * |
|
| 190 | + * @return void |
|
| 191 | + */ |
|
| 192 | + protected static function update_composer( $filesystem, $root, $camel_case ) { |
|
| 193 | + $file = $root . '/composer.json'; |
|
| 194 | + if ( file_exists( $file ) ) { |
|
| 195 | + $contents = $filesystem->get( $file ); |
|
| 196 | + $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
| 197 | + $filesystem->put( |
|
| 198 | + $file, |
|
| 199 | + $contents |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | } |