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