PluginProbe
WP Ultimate Post Grid / 4.0.1
WP Ultimate Post Grid v4.0.1
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / vendor / bv-settings / includes / class-bvs-menu.php

class-bvs-menu.php in WP Ultimate Post Grid 4.0.1, at vendor/bv-settings/includes/class-bvs-menu.php

75 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle the settings menu.
4 *
5 * @link https://bootstrapped.ventures
6 * @since 1.0.0
7 *
8 * @package BV_Settings
9 * @author Brecht Vandersmissen <[email protected]>
10 */
11
12 class BV_Menu {
13 private $bvs;
14
15 /**
16 * Store main instance and initialize.
17 *
18 * @since 1.0.0
19 */
20 public function __construct( $bvs ) {
21 $this->bvs = $bvs;
22 $this->init();
23 }
24
25 /**
26 * Register actions and filters.
27 *
28 * @since 1.0.0
29 */
30 private function init() {
31 add_action( 'admin_menu', array( $this, 'add_submenu_page' ), $this->bvs->atts['menu_priority'] );
32 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin' ) );
33 }
34
35 /**
36 * Add the settings menu page.
37 *
38 * @since 1.0.0
39 */
40 public function add_submenu_page() {
41 add_submenu_page( $this->bvs->atts['menu_parent'], $this->bvs->atts['page_title'], $this->bvs->atts['menu_title'], $this->bvs->atts['required_capability'], $this->bvs->atts['page_slug'], array( $this, 'settings_page_template' ) );
42 }
43
44 /**
45 * Get the template for the settings page.
46 *
47 * @since 1.0.0
48 */
49 public function settings_page_template() {
50 wp_localize_script( 'bv-settings', 'bv_settings', array(
51 'structure' => array_values( $this->bvs->get_structure( true ) ),
52 'settings' => $this->bvs->get_settings_with_defaults(),
53 'defaults' => $this->bvs->get_defaults(),
54 'required_addons' => apply_filters( $this->bvs->atts['uid'] . '_settings_required_addons', $this->bvs->atts['required_addons'] ),
55 'eol' => PHP_EOL,
56 'api' => array(
57 'endpoint' => get_rest_url( null, 'bv-settings/v1/' . $this->bvs->atts['uid'] ),
58 'nonce' => wp_create_nonce( 'wp_rest' ),
59 ),
60 ) );
61
62 echo '<div id="bvs-settings" class="wrap">Loading...</div>';
63 }
64
65 public function enqueue_admin() {
66 $screen = get_current_screen();
67
68 // Only enqueue on settings page.
69 if ( $this->bvs->atts['page_slug'] === substr( $screen->id, -1 * strlen( $this->bvs->atts['page_slug'] ) ) ) {
70 wp_enqueue_style( 'bv-settings', BVS_URL . 'dist/admin.css', array(), BVS_VERSION, 'all' );
71 wp_enqueue_script( 'bv-settings', BVS_URL . 'dist/admin.js', array(), BVS_VERSION, true );
72 }
73 }
74 }
75