Skip to content

Commit

Permalink
⚡ REFACTOR: PHP OOP integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
ManiruzzamanAkash committed Jul 30, 2022
1 parent 3139df6 commit fc192c7
Show file tree
Hide file tree
Showing 4 changed files with 457 additions and 35 deletions.
53 changes: 53 additions & 0 deletions includes/Admin/Menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Akash\JobPlace\Admin;

/**
* Admin Menu class.
*
* Responsible for managing admin menus.
*/
class Menu {

/**
* Constructor.
*
* @since 0.2.0
*/
public function __construct() {
add_action( 'admin_menu', [ $this, 'init_menu' ] );
}

/**
* Init Menu.
*
* @since 0.2.0
*
* @return void
*/
public function init_menu() {
global $submenu;

$slug = JOB_PLACE_SLUG;
$menu_position = 50;
$capability = 'manage_options';

add_menu_page( esc_attr__( 'Job Place', 'jobplace' ), esc_attr__( 'Job Place', 'jobplace' ), $capability, $slug, [ $this, 'plugin_page' ], 'dashicons-filter', $menu_position );

if ( current_user_can( $capability ) ) {
$submenu[ $slug ][] = [ esc_attr__( 'Home', 'jobplace' ), $capability, 'admin.php?page=' . $slug . '#/' ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$submenu[ $slug ][] = [ esc_attr__( 'Jobs', 'jobplace' ), $capability, 'admin.php?page=' . $slug . '#/jobs' ]; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
}
}

/**
* Render the plugin page.
*
* @since 0.2.0
*
* @return void
*/
public function plugin_page() {
require_once JOB_PLACE_TEMPLATE_PATH . '/app.php';
}
}
113 changes: 113 additions & 0 deletions includes/Assets/Manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace Akash\JobPlace\Assets;

/**
* Asset Manager class.
*
* Responsible for managing all of the assets (CSS, JS, Images, Locales).
*/
class Manager {

/**
* Constructor.
*
* @since 0.2.0
*/
public function __construct() {
add_action( 'init', [ $this, 'register_all_scripts' ], 10 );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
}

/**
* Register all scripts and styles.
*
* @since 0.2.0
*
* @return void
*/
public function register_all_scripts() {
$this->register_styles( $this->get_styles() );
$this->register_scripts( $this->get_scripts() );
}

/**
* Get all styles.
*
* @since 0.2.0
*
* @return array
*/
public function get_styles(): array {
return [
'job-place-custom-css' => [
'src' => JOB_PLACE_BUILD . '/style-index.css',
'version' => filemtime( JOB_PLACE_DIR . '/build/style-index.css' ),
'deps' => [],
],
'job-place-css' => [
'src' => JOB_PLACE_BUILD . '/index.css',
'version' => filemtime( JOB_PLACE_DIR . '/build/index.css' ),
'deps' => [ 'job-place-custom-css' ],
],
];
}

/**
* Get all scripts.
*
* @since 0.2.0
*
* @return array
*/
public function get_scripts(): array {
$dependency = require_once JOB_PLACE_DIR . '/build/index.asset.php';

return [
'job-place-app' => [
'src' => JOB_PLACE_BUILD . '/index.js',
'version' => filemtime( JOB_PLACE_DIR . '/build/index.js' ),
'deps' => $dependency['dependencies'],
'in_footer' => true,
],
];
}

/**
* Register styles.
*
* @since 0.2.0
*
* @return void
*/
public function register_styles( array $styles ) {
foreach ( $styles as $handle => $style ) {
wp_register_style( $handle, $style['src'], $style['deps'], $style['version'] );
}
}

/**
* Register scripts.
*
* @since 0.2.0
*
* @return void
*/
public function register_scripts( array $scripts ) {
foreach ( $scripts as $handle =>$script ) {
wp_register_script( $handle, $script['src'], $script['deps'], $script['version'], $script['in_footer'] );
}
}

/**
* Enqueue admin styles and scripts.
*
* @since 0.2.0
*
* @return void
*/
public function enqueue_admin_assets() {
wp_enqueue_style( 'job-place-css' );
wp_enqueue_script( 'job-place-app' );
}
}
Loading

0 comments on commit fc192c7

Please sign in to comment.