| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Admin Page |
| 4 |
* |
| 5 |
*/ |
| 6 |
|
| 7 |
if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 8 |
|
| 9 |
if( ! class_exists( 'GutSlider_Admin' ) ) { |
| 10 |
|
| 11 |
class GutSlider_Admin { |
| 12 |
|
| 13 |
/** |
| 14 |
* Constructor |
| 15 |
* return void |
| 16 |
*/ |
| 17 |
public function __construct() { |
| 18 |
add_action( 'admin_menu', [ $this, 'admin_menu' ] ); |
| 19 |
add_action( 'admin_enqueue_scripts', [ $this, 'admin_assests' ] ); |
| 20 |
|
| 21 |
// register settings |
| 22 |
add_action('admin_init', [ $this, 'custom_register_settings' ]); |
| 23 |
add_action( 'rest_api_init', [ $this, 'custom_register_settings' ] ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Enqueue admin scripts |
| 28 |
*/ |
| 29 |
public function admin_assests( $screen ) { |
| 30 |
|
| 31 |
if( $screen === 'toplevel_page_gutslider-blocks' ){ |
| 32 |
|
| 33 |
$dependencyFile = GUTSLIDER_DIR . '/build/admin/admin.asset.php'; |
| 34 |
$dependencies = file_exists( $dependencyFile ) ? require_once $dependencyFile : []; |
| 35 |
|
| 36 |
wp_enqueue_style( 'gutslider-admin-style', GUTSLIDER_URL . 'build/admin/style-admin.css', [], GUTSLIDER_VERSION ); |
| 37 |
wp_enqueue_script( 'gutslider-admin-script', GUTSLIDER_URL . 'build/admin/admin.js', $dependencies[ 'dependencies' ] , GUTSLIDER_VERSION, true ); |
| 38 |
|
| 39 |
// enqueue wp-style |
| 40 |
wp_enqueue_style( 'wp-components' ); |
| 41 |
|
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Add admin menu |
| 47 |
*/ |
| 48 |
public function admin_menu() { |
| 49 |
add_menu_page( __( 'GutSlider', 'slider-blocks' ), __( 'GutSlider', 'slider-blocks' ), 'manage_options', 'gutslider-blocks', [ $this, 'gutslider_admin_page' ], 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiByeD0iMTIiIGZpbGw9IiNEOUQ5RDkiLz4KPHBhdGggZD0iTTE1IDdIMTEuODIzNUg5VjE3SDE1VjEyLjQxNjdIMTIuODgyNEgxMS44MjM1IiBzdHJva2U9IiMxRDIzMjciIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIi8+Cjwvc3ZnPgo=', 100 ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Admin page |
| 54 |
*/ |
| 55 |
public function gutslider_admin_page() { |
| 56 |
?> |
| 57 |
<div id="gutslider"></div> |
| 58 |
<?php |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Register settings |
| 63 |
* return void |
| 64 |
*/ |
| 65 |
public function custom_register_settings() { |
| 66 |
|
| 67 |
// assets registration |
| 68 |
register_setting('rest-api-settings', 'swiper_scripts', array( |
| 69 |
'type' => 'boolean', |
| 70 |
'default' => true, |
| 71 |
'show_in_rest' => true, |
| 72 |
'sanitize_callback' => 'rest_sanitize_boolean', |
| 73 |
)); |
| 74 |
|
| 75 |
// fixed content slider |
| 76 |
register_setting('rest-api-settings', 'gut_fixed_content_slider', array( |
| 77 |
'type' => 'boolean', |
| 78 |
'default' => true, |
| 79 |
'show_in_rest' => true, |
| 80 |
'sanitize_callback' => 'rest_sanitize_boolean', |
| 81 |
)); |
| 82 |
|
| 83 |
// any content |
| 84 |
register_setting('rest-api-settings', 'gut_any_content_slider', array( |
| 85 |
'type' => 'boolean', |
| 86 |
'default' => true, |
| 87 |
'show_in_rest' => true, |
| 88 |
'sanitize_callback' => 'rest_sanitize_boolean', |
| 89 |
)); |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
new GutSlider_Admin(); // initialize the class |