Skip to content

Commit

Permalink
Merge pull request #7 from rhaseven7h/class-separation
Browse files Browse the repository at this point in the history
Separation completed.
  • Loading branch information
rhaseven7h committed Sep 18, 2024
2 parents 886dbaf + 3938a32 commit 4747689
Show file tree
Hide file tree
Showing 15 changed files with 398 additions and 181 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
commit 3c14192fd32536cddae93b4baf6d5df2c954c6d6
Merge: 886dbaf 3938a32
Author: Gabriel Medina <rha7.com@gmail.com>
Date: Wed Sep 18 01:38:21 2024 -0600

Merge pull request #7 from rhaseven7h/class-separation

Separation completed.

commit 3938a3223b7c5fa609ad69d9a6bfd251e11d5b4f
Author: Gabriel Medina <rha7.com@gmail.com>
Date: Wed Sep 18 01:31:30 2024 -0600

Separation completed.

commit 886dbaf9a5f9fb867dc84da24bc81c46ebb0ecef
Merge: 6b1767c 768ac0e
Author: Gabriel Medina <rha7.com@gmail.com>
Date: Tue Sep 17 17:26:53 2024 -0600

Merge pull request #5 from rhaseven7h/small-fixes

Small fixes, versions and changelog.

commit 768ac0e608a26f52a6a402a9f3e5bb40da4bcdd8
Author: Gabriel Medina <rha7.com@gmail.com>
Date: Tue Sep 17 04:20:20 2024 -0600

Small fixes, versions and changelog.

commit 6b1767c12c7bc027d44caac7ccb55bc40f6820a5
Author: Gabriel Medina <rha7.com@gmail.com>
Date: Tue Sep 17 04:03:54 2024 -0600
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: rhaseventh
Tags: admin, menu, width, customize
Requires at least: 4.7
Tested up to: 6.6
Stable tag: 1.0.1
Stable tag: 1.1.0
Requires PHP: 7.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
36 changes: 36 additions & 0 deletions class.wide-admin-menu-custom-width-styles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
die( 'No direct access allowed' );
}

if ( ! defined( 'Wide_Admin_Menu_Custom_Width_Styles' ) ) {
class Wide_Admin_Menu_Custom_Width_Styles {
private Wide_Admin_Menu_Renderer $renderer;
private int $admin_menu_width;

function __construct(
Wide_Admin_Menu_Renderer $renderer,
int $admin_menu_width
) {
$this->renderer = $renderer;
$this->admin_menu_width = $admin_menu_width;
add_action(
'admin_head',
array(
$this,
'render_wide_admin_menu_custom_styles'
)
);
}

public function render_wide_admin_menu_custom_styles(): void {
$this->renderer->render(
'wide-admin-menu-head-styles',
array(
'width' => $this->admin_menu_width
)
);
}
}
}
23 changes: 23 additions & 0 deletions class.wide-admin-menu-renderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
die( 'No direct access allowed' );
}

require_once 'constants.php';

if ( ! class_exists( 'Wide_Admin_Menu_Renderer' ) ) {
class Wide_Admin_Menu_Renderer {
private Mustache_Engine $mustache_engine;

public function __construct( string $views_path ) {
$mustache_loader = new Mustache_Loader_FilesystemLoader( $views_path );
$mustache_options = array( 'loader' => $mustache_loader );
$this->mustache_engine = new Mustache_Engine( $mustache_options );
}

public function render( $template_name, $data = array() ): void {
echo $this->mustache_engine->render( $template_name, $data );
}
}
}
136 changes: 136 additions & 0 deletions class.wide-admin-menu-settings-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

require_once 'constants.php';

if ( ! class_exists( 'Wide_Admin_Menu_Settings_Page' ) ) {
class Wide_Admin_Menu_Settings_Page {
private Wide_Admin_Menu_Renderer $renderer;
private int $width;

public function __construct( Wide_Admin_Menu_Renderer $renderer, int $width ) {
$this->renderer = $renderer;
$this->width = $width;
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}

public function admin_menu(): void {
add_options_page(
esc_html__( 'Wide Admin Menu', 'wide-admin-menu' ),
esc_html__( 'Wide Admin Menu', 'wide-admin-menu' ),
'manage_options',
'wide-admin-menu',
array(
$this,
'admin_options_page'
),
99
);
}

public function admin_options_page(): void {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}

if ( isset( $_GET['settings-updated'] ) ) {
add_settings_error(
'wide-admin-menu-options',
'wide-admin-menu',
esc_html__( 'Settings Saved', 'wide-admin-menu' ),
'success'
);
}

ob_start();
settings_fields( 'wide-admin-menu-option-group' );
$settings_fields = ob_get_clean();

ob_start();
do_settings_sections( 'wide-admin-menu-settings-page-general' );
$do_settings_sections = ob_get_clean();

ob_start();
submit_button( __( 'Save Settings', 'wide-admin-menu' ) );
$submit_button = ob_get_clean();

$this->renderer->render( 'wide-admin-menu-admin-options-page', array(
'pageTitle' => esc_html( get_admin_page_title() ),
'settings_fields' => $settings_fields,
'do_settings_sections' => $do_settings_sections,
'submit_button' => $submit_button
) );
}

public function register_settings(): void {
register_setting(
'wide-admin-menu-option-group',
'wide-admin-menu-options',
array(
'label' => esc_html__( 'Wide Admin Menu', 'wide-admin-menu' ),
'description' => esc_html__( 'Settings for the Wide Admin Menu plugin.', 'wide-admin-menu' ),
'sanitize_callback' => array( $this, 'sanitize_options' ),
'show_in_rest' => true,
'default' => array(
'wide_admin_menu_width' => $this->width
),
)
);
add_settings_section(
'wide-admin-menu-settings-section-general',
esc_html__( 'General', 'wide-admin-menu' ),
array( $this, 'section_general' ),
'wide-admin-menu-settings-page-general'
);
add_settings_field(
'wide-admin-menu-width',
esc_html__( 'Width', 'wide-admin-menu' ),
array( $this, 'menu_width_field' ),
'wide-admin-menu-settings-page-general',
'wide-admin-menu-settings-section-general',
array( 'label_for' => 'wide-admin-menu-width' )
);
}

public function sanitize_options( $options ): array {
$options['wide-admin-menu-width'] = sanitize_text_field( $options['wide-admin-menu-width'] );
$options['wide-admin-menu-width'] = (int) $options['wide-admin-menu-width'];
if ( $options['wide-admin-menu-width'] < 160 ) {
$options['wide-admin-menu-width'] = 160;
}
if ( $options['wide-admin-menu-width'] > 512 ) {
$options['wide-admin-menu-width'] = 512;
}

return $options;
}

public function section_general(): void {
$this->renderer->render( 'wide-admin-menu-settings-section-general-description', array(
'section_description' => esc_html__(
'General settings for the Wide Admin Menu plugin.',
'wide-admin-menu'
)
) );
}

public function menu_width_field(): void {
$field_value = esc_attr( $this->width );
$field_description = esc_html__(
'The width for the Admin menu.',
'wide-admin-menu'
);
$this->renderer->render(
'wide-admin-menu-width-input-field',
array(
'field_value' => $field_value,
'field_description' => $field_description
)
);
}
}
}
24 changes: 24 additions & 0 deletions class.wide-admin-menu-styles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
die( 'No direct access allowed' );
}

require_once 'constants.php';

if ( ! class_exists( 'Wide_Admin_Menu_Styles' ) ) {
class Wide_Admin_Menu_Styles {
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
}

public function enqueue_scripts(): void {
wp_enqueue_style(
'wide-admin-menu-styles',
WIDE_ADMIN_MENU_URL . '/assets/css/styles.dist.css',
array(),
WIDE_ADMIN_MENU_VERSION
);
}
}
}
Loading

0 comments on commit 4747689

Please sign in to comment.