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