| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Admin Page |
| 4 |
* @package GutSliderBlocks |
| 5 |
*/ |
| 6 |
|
| 7 |
if (!defined('ABSPATH')) exit; |
| 8 |
|
| 9 |
if (!class_exists('GutSlider_Admin')) { |
| 10 |
class GutSlider_Admin { |
| 11 |
/** |
| 12 |
* Slider block settings |
| 13 |
*/ |
| 14 |
private const BLOCK_SETTINGS = [ |
| 15 |
'gut_fixed_content_slider', |
| 16 |
'gut_any_content_slider', |
| 17 |
'gut_testimonial_slider', |
| 18 |
'gut_post_slider', |
| 19 |
'gut_photo_carousel', |
| 20 |
'gut_logo_carousel', |
| 21 |
'gut_before_after_slider', |
| 22 |
'gut_videos_carousel' |
| 23 |
]; |
| 24 |
|
| 25 |
/** |
| 26 |
* Constructor |
| 27 |
*/ |
| 28 |
public function __construct() { |
| 29 |
add_action('admin_menu', [$this, 'admin_menu'], 20); |
| 30 |
add_action('admin_enqueue_scripts', [$this, 'admin_assets']); |
| 31 |
add_action('admin_init', [$this, 'initialize_admin']); |
| 32 |
add_action('rest_api_init', [$this, 'register_settings']); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Initialize admin functionality |
| 37 |
*/ |
| 38 |
public function initialize_admin() { |
| 39 |
$this->register_settings(); |
| 40 |
$this->include_data_sdk(); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Enqueue admin scripts and styles |
| 45 |
* @param string $screen Current admin screen |
| 46 |
*/ |
| 47 |
public function admin_assets($screen) { |
| 48 |
if ($screen !== 'toplevel_page_gutslider-blocks') { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
$this->enqueue_admin_assets(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Add admin menu |
| 57 |
*/ |
| 58 |
public function admin_menu() { |
| 59 |
add_menu_page( |
| 60 |
__('GutSlider', 'slider-blocks'), |
| 61 |
__('GutSlider', 'slider-blocks'), |
| 62 |
'manage_options', |
| 63 |
'gutslider-blocks', |
| 64 |
[$this, 'render_admin_page'], |
| 65 |
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiByeD0iMTIiIGZpbGw9IiNEOUQ5RDkiLz4KPHBhdGggZD0iTTE1IDdIMTEuODIzNUg5VjE3SDE1VjEyLjQxNjdIMTIuODgyNEgxMS44MjM1IiBzdHJva2U9IiMxRDIzMjciIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIi8+Cjwvc3ZnPgo=', |
| 66 |
100 |
| 67 |
); |
| 68 |
|
| 69 |
add_submenu_page( |
| 70 |
'gutslider-blocks', |
| 71 |
__( 'Welcome', 'slider-blocks' ), |
| 72 |
__( 'Welcome', 'slider-blocks' ), |
| 73 |
'manage_options', |
| 74 |
'gutslider-blocks', |
| 75 |
array( $this, 'render_admin_page' ) |
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Render admin page |
| 81 |
*/ |
| 82 |
public function render_admin_page() { |
| 83 |
echo '<div id="gutslider"></div>'; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Register block settings |
| 88 |
*/ |
| 89 |
public function register_settings() { |
| 90 |
foreach (self::BLOCK_SETTINGS as $setting) { |
| 91 |
register_setting('rest-api-settings', $setting, [ |
| 92 |
'type' => 'boolean', |
| 93 |
'default' => true, |
| 94 |
'show_in_rest' => true, |
| 95 |
'sanitize_callback' => 'rest_sanitize_boolean', |
| 96 |
]); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Include data SDK |
| 102 |
*/ |
| 103 |
private function include_data_sdk() { |
| 104 |
require_once dirname(__FILE__) . '/dci/start.php'; |
| 105 |
|
| 106 |
dci_dynamic_init([ |
| 107 |
'sdk_version' => '1.2.1', |
| 108 |
'product_id' => 3, |
| 109 |
'plugin_name' => 'GutSlider', |
| 110 |
'plugin_title' => 'GutSlider', |
| 111 |
'api_endpoint' => 'https://dashboard.codedivo.com/wp-json/dci/v1/data-insights', |
| 112 |
'slug' => 'gutslider-blocks', |
| 113 |
'core_file' => false, |
| 114 |
'plugin_deactivate_id' => false, |
| 115 |
'menu' => ['slug' => 'gutslider-blocks'], |
| 116 |
'public_key' => 'pk_KxU4qcYXPyqvBDwsyyBkbCfY9Gulc1z5', |
| 117 |
'is_premium' => false, |
| 118 |
'popup_notice' => false, |
| 119 |
'deactivate_feedback' => true, |
| 120 |
'delay_time' => ['time' => 3 * DAY_IN_SECONDS], |
| 121 |
'text_domain' => 'slider-blocks', |
| 122 |
'plugin_msg' => '<p>Thank you for using GutSlider! 🎉</p><p>We collect some non-sensitive data to improve our product and decide which features to build next.</p>', |
| 123 |
]); |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Get GutSlider changelogs |
| 128 |
* @return array|false Changelog data or false on failure |
| 129 |
*/ |
| 130 |
private function get_change_logs() { |
| 131 |
$changelog_file = GUTSLIDER_DIR . '/changelogs.json'; |
| 132 |
|
| 133 |
if (!file_exists($changelog_file)) { |
| 134 |
return false; |
| 135 |
} |
| 136 |
|
| 137 |
global $wp_filesystem; |
| 138 |
if (empty($wp_filesystem)) { |
| 139 |
require_once(ABSPATH . '/wp-admin/includes/file.php'); |
| 140 |
WP_Filesystem(); |
| 141 |
} |
| 142 |
|
| 143 |
$changelogs = $wp_filesystem->get_contents($changelog_file); |
| 144 |
return json_decode($changelogs, true); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Enqueue admin assets |
| 149 |
*/ |
| 150 |
private function enqueue_admin_assets() { |
| 151 |
$dependency_file = GUTSLIDER_DIR . '/build/admin/admin.asset.php'; |
| 152 |
$dependencies = file_exists($dependency_file) ? require_once($dependency_file) : []; |
| 153 |
|
| 154 |
wp_enqueue_style('gutslider-admin-style', GUTSLIDER_URL . 'build/admin/style-admin.css', [], GUTSLIDER_VERSION); |
| 155 |
wp_enqueue_script('gutslider-admin-script', GUTSLIDER_URL . 'build/admin/admin.js', $dependencies['dependencies'], GUTSLIDER_VERSION, true); |
| 156 |
wp_enqueue_style('wp-components'); |
| 157 |
|
| 158 |
wp_localize_script('gutslider-admin-script', 'gutslider', [ |
| 159 |
'version' => GUTSLIDER_VERSION, |
| 160 |
'changeLogs' => $this->get_change_logs(), |
| 161 |
'nonce' => wp_create_nonce('gutslider_nonce'), |
| 162 |
'isPro' => defined('GUTSLIDER_PRO_VERSION'), |
| 163 |
'proVersion' => defined('GUTSLIDER_PRO_VERSION') ? GUTSLIDER_PRO_VERSION : '', |
| 164 |
]); |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
new GutSlider_Admin(); |