PluginProbe
Button Block – Stylish buttons that get more clicks / 1.2.5
Button Block – Stylish buttons that get more clicks v1.2.5
1.2.6 1.2.5 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 All 28 releases
button-block / includes / admin / AdminMenu.php

AdminMenu.php in Button Block – Stylish buttons that get more clicks 1.2.5, at includes/admin/AdminMenu.php

84 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace BTNB\Admin;
3
4 if ( !defined( 'ABSPATH' ) ) { exit; }
5
6 /**
7 * AdminMenu class
8 * Registers the settings field to hide the CPT menu and adds the dashboard submenu page.
9 *
10 * @package BTN\Admin
11 */
12 class AdminMenu {
13 public $post_type = 'button-block';
14
15 /**
16 * Constructor.
17 * Registers hooks for admin settings, scripts, and menu.
18 */
19 public function __construct() {
20 add_action( 'admin_init', array($this, 'adminInit') );
21 add_action( 'admin_enqueue_scripts', [$this, 'adminEnqueueScripts'] );
22 add_action( 'admin_menu', [ $this, 'adminMenu' ] );
23 }
24
25 /**
26 * Registers the 'button_block_option' setting and adds a toggle field to Settings > General.
27 *
28 * @return void
29 */
30 function adminInit(){
31 register_setting( 'general', 'button_block_option', 'sanitize_text_field' );
32
33 add_settings_field(
34 'button_block_option_field',
35 'Hide Button Block from admin Menu',
36 [ $this , 'optionCallback' ],
37 'general'
38 );
39 }
40
41 /**
42 * Renders the checkbox toggle for the 'Hide Button Block from admin menu' setting.
43 *
44 * @return void
45 */
46 function optionCallback() {
47 $value = get_option( 'button_block_option', '' ); ?>
48
49 <label class='btnAdminHideSwitch'>
50 <input type='checkbox' id='button_block_option' name='button_block_option' value='true' <?php checked( $value, 'true' ); ?>>
51 <span class='slider round'></span>
52 </label>
53 <p class='description'>Turn this setting on or off.</p>
54 <?php }
55
56 /**
57 * Enqueues admin styles for the General Settings page.
58 *
59 * @param string $hook The current admin page hook suffix.
60 * @return void
61 */
62 function adminEnqueueScripts( $hook ){
63 if( 'options-general.php' === $hook ){
64 wp_enqueue_style( 'btn-admin-general', BTNB_DIR_URL . 'build/admin/general.css', [], BTNB_VERSION );
65 }
66 }
67
68 /**
69 * Adds the 'Help & Demos' submenu page under the button-block CPT menu.
70 *
71 * @return void
72 */
73 function adminMenu() {
74 add_submenu_page(
75 'edit.php?post_type=' . $this->post_type,
76 __( 'Help & Demos - Button Block', 'button-block' ),
77 __( 'Help & Demos', 'button-block' ),
78 'manage_options',
79 'button-block',
80 [ \BTNBPlugin::class, 'renderDashboard' ]
81 );
82 }
83 }
84 new AdminMenu();