PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.36
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.36
3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 2.44 All 141 releases
photonic / Admin / Admin_Menu.php

Admin_Menu.php in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 3.36, at Admin/Admin_Menu.php

107 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Photonic_Plugin\Admin;
4
5 use Photonic_Plugin\Core\Photonic;
6 use Photonic_Plugin\Options\Defaults;
7
8 class Admin_Menu {
9 private string $file;
10 private Photonic $core;
11
12 public function __construct($file, $core) {
13 $this->file = $file;
14 $this->core = $core;
15
16 $this->register_settings();
17
18 add_action('admin_enqueue_scripts', [&$this, 'enqueue']);
19 }
20
21 public function settings() {
22 require_once 'Options_Manager.php';
23 $options_manager = new Options_Manager($this->file, $this->core);
24 $options_manager->init();
25 $options_manager->render('Settings');
26 }
27
28 public function getting_started() {
29 require_once 'Getting_Started.php';
30 $getting_started = Getting_Started::get_instance();
31 $getting_started->render('Getting Started');
32 }
33
34 public function authentication() {
35 require_once 'Authentication.php';
36 $auth_page = Authentication::get_instance();
37 $auth_page->render('Authentication');
38 }
39
40 public function shortcode() {
41 require_once 'Shortcode_Replace.php';
42 $gutenberg = Shortcode_Replace::get_instance();
43 $gutenberg->render('Replace the Gallery Shortcode');
44 }
45
46 public function helpers() {
47 require_once 'Helper.php';
48 $helper_page = new Helper();
49 $helper_page->render('Helpers');
50 }
51
52 /**
53 * Registers settings for the Settings API. Though this applies to the Options_Manager, the settings are required here.
54 * The Options_Manager class is big and heavy, so we don't load it on all Photonic admin pages.
55 * But since saving options calls WP's native options.php, when options.php is loaded without registering settings,
56 * it triggers an "Error: options page not found" error.
57 *
58 * So, the definition of the settings is done here, since this file is always loaded in the admin page.
59 */
60 public function register_settings() {
61 $pages = Defaults::get_options_pages();
62 foreach ($pages as $page) {
63 register_setting('photonic_options-' . $page, 'photonic_options', [&$this, 'validate_options']);
64 }
65 }
66
67 /**
68 * A wrapper for the <code>validate_options</code> function in Options_Manager. This is required because of the
69 * <code>register_settings</code> call (which is a run-time call requiring a validation function) running without initiating
70 * the Options_Manager at compile-time.
71 *
72 * @param $options
73 * @return array
74 */
75 public function validate_options($options): array {
76 require_once 'Options_Manager.php';
77 $options_manager = new Options_Manager($this->file, $this->core);
78 return $options_manager->validate_options($options);
79 }
80
81 public function enqueue($hook) {
82 $prefix = ['toplevel_page_', 'photonic_page_'];
83 $mod_hook = str_replace($prefix, '', $hook);
84 if ('photonic-options-manager' === $mod_hook) {
85 wp_enqueue_style('photonic-admin-css', PHOTONIC_URL . 'include/css/admin/admin.css', ['wp-color-picker'], Photonic::get_version(PHOTONIC_PATH . '/include/css/admin/admin.css'));
86 global $photonic_options;
87 $js_array = [
88 'category' => sanitize_text_field(isset($photonic_options) && isset($photonic_options['last-set-section']) ? $photonic_options['last-set-section'] : 'generic-settings'),
89 ];
90 wp_enqueue_script('photonic-options-js', PHOTONIC_URL . 'include/js/admin/options-manager.js', ['jquery', 'wp-color-picker'], Photonic::get_version(PHOTONIC_PATH . '/include/js/admin/options-manager.js'), true);
91 wp_localize_script('photonic-options-js', 'Photonic_Options_JS', $js_array);
92 }
93 elseif (in_array($mod_hook, ['photonic-helpers', 'photonic-auth', 'photonic-shortcode-replace'], true)) {
94 wp_enqueue_script('photonic-admin-js', PHOTONIC_URL . 'include/js/admin/helpers.js', ['jquery'], Photonic::get_version(PHOTONIC_PATH . '/include/js/admin/helpers.js'), true);
95 wp_enqueue_style('photonic-admin-css', PHOTONIC_URL . 'include/css/admin/admin.css', [], Photonic::get_version(PHOTONIC_PATH . '/include/css/admin/admin.css'));
96
97 $js_array = [
98 'obtain_token' => esc_attr__('Step 2: Obtain Token', 'photonic')
99 ];
100 wp_localize_script('photonic-admin-js', 'Photonic_Admin_JS', $js_array);
101 }
102 elseif (in_array($mod_hook, ['photonic-getting-started'], true)) {
103 wp_enqueue_style('photonic-admin-css', PHOTONIC_URL . 'include/css/admin/admin.css', [], Photonic::get_version(PHOTONIC_PATH . '/include/css/admin/admin.css'));
104 }
105 }
106 }
107