PluginProbe
Catch Gallery / trunk
Catch Gallery vtrunk
trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.5 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 All 27 releases
catch-gallery / admin / admin.php

admin.php in Catch Gallery trunk, at admin/admin.php

165 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if (! defined('ABSPATH')) exit;
5
6 /**
7 * Provide a admin area view for the plugin
8 *
9 * This file is used to add the admin-facing aspects of the plugin.
10 *
11 * @link catchplugins.com
12 * @since 1.0.0
13 *
14 * @package Catch_Gallery
15 * @subpackage Catch_Gallery/admin
16 */
17
18 if (! function_exists('catch_gallery_add_plugin_settings_menu')) :
19 function catch_gallery_add_plugin_settings_menu()
20 {
21 add_menu_page(
22 esc_html__('Catch Gallery', 'catch-gallery'), //page title
23 esc_html__('Catch Gallery', 'catch-gallery'), //menu title
24 'manage_options', //capability needed
25 'catch-gallery', //menu slug (and page query url)
26 'catch_gallery_settings',
27 'dashicons-format-gallery',
28 '99.01564'
29 );
30 }
31 endif; // catch_gallery_add_plugin_settings_menu
32 add_action('admin_menu', 'catch_gallery_add_plugin_settings_menu');
33
34
35 if (! function_exists('catch_gallery_settings')) :
36 function catch_gallery_settings()
37 {
38 $child_theme = false;
39 if (! current_user_can('manage_options')) {
40 wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'catch-gallery'));
41 }
42
43 require_once plugin_dir_path(__FILE__) . 'catch-gallery-display.php';
44 }
45 endif; // catch_gallery_settings
46
47 if (! function_exists('catch_gallery_enqueue_styles')) :
48 /**
49 * Enqueue Admin CSS
50 */
51 function catch_gallery_enqueue_styles($hook_suffix)
52 {
53
54 if ('toplevel_page_catch-gallery' === $hook_suffix) {
55
56 wp_enqueue_style('catch-gallery-dashboard', plugin_dir_url(__FILE__) . 'css/admin-dashboard.css', array(), CATCH_GALLERY_VERSION, 'all');
57
58 wp_enqueue_script('minHeight', plugin_dir_url(__FILE__) . 'js/jquery.matchHeight.min.js', array('jquery'), CATCH_GALLERY_VERSION, false);
59
60 wp_enqueue_script('catch-gallery-dashboard', plugin_dir_url(__FILE__) . 'js/admin.js', array('jquery', 'jquery-ui-tooltip'), CATCH_GALLERY_VERSION, false);
61 }
62 }
63 endif; // catch_gallery_enqueue_styles
64 add_action('admin_enqueue_scripts', 'catch_gallery_enqueue_styles');
65
66 if (! function_exists('catch_gallery_register_settings')):
67 /**
68 * Catch gallery: register_settings
69 * Catch gallery Register Settings
70 */
71 function catch_gallery_register_settings()
72 {
73 register_setting(
74 'catch-gallery-group',
75 'catch_gallery_options',
76 'catch_gallery_sanitize_callback'
77 );
78 }
79 endif;
80 add_action('admin_init', 'catch_gallery_register_settings');
81
82 if (! function_exists('catch_gallery_sanitize_checkbox')):
83 function catch_gallery_sanitize_checkbox($checked)
84 {
85 // Boolean check.
86 return ((isset($checked) && true == $checked) ? true : false);
87 }
88 endif;
89
90 if (! function_exists('catch_gallery_sanitize_callback')):
91 /**
92 * Catch gallery: sanitize_callback
93 * Catch gallery Sanitization function callback
94 *
95 * @param array $input Input data for sanitization.
96 * @return array Sanitized options array.
97 */
98 function catch_gallery_sanitize_callback($input)
99 {
100 $defaults = catch_gallery_default_options();
101
102 if (isset($input['reset']) && $input['reset']) {
103 // If reset, restore defaults.
104 return $defaults;
105 }
106
107 // Bail on autosave or failed nonce — return defaults to avoid corrupting saved data.
108 if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
109 || ! isset($_POST['catch_gallery_nounce'])
110 || ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['catch_gallery_nounce'])), basename(__FILE__))
111 || ! check_admin_referer(basename(__FILE__), 'catch_gallery_nounce')
112 ) {
113 return $defaults;
114 }
115
116 // Sanitize each field explicitly.
117 $output = array();
118
119 $output['carousel_enable'] = isset($input['carousel_enable'])
120 ? catch_gallery_sanitize_checkbox($input['carousel_enable'])
121 : false;
122
123 $output['carousel_background_color'] = isset($input['carousel_background_color'])
124 ? sanitize_key($input['carousel_background_color'])
125 : 'black';
126
127 $output['carousel_display_exif'] = isset($input['carousel_display_exif'])
128 ? catch_gallery_sanitize_checkbox($input['carousel_display_exif'])
129 : false;
130
131 $output['comments_display'] = isset($input['comments_display'])
132 ? catch_gallery_sanitize_checkbox($input['comments_display'])
133 : false;
134
135 $output['fullsize_display'] = isset($input['fullsize_display'])
136 ? catch_gallery_sanitize_checkbox($input['fullsize_display'])
137 : false;
138
139 $output['reset'] = false;
140
141 return $output;
142 }
143 endif;
144
145 if (! function_exists('catch_gallery_action_links')) :
146 /**
147 * Catch_IDs: catch_gallery_action_links
148 * Catch_IDs Settings Link function callback
149 *
150 * @param arrray $links Link url.
151 *
152 * @param arrray $file File name.
153 */
154 function catch_gallery_action_links($links, $file)
155 {
156 if ($file === 'catch-gallery/catch-gallery.php') {
157 $settings_link = '<a href="' . esc_url(admin_url('admin.php?page=catch-gallery')) . '">' . esc_html__('Settings', 'catch-gallery') . '</a>';
158
159 array_unshift($links, $settings_link);
160 }
161 return $links;
162 }
163 endif; // catch_gallery_action_links
164 add_filter('plugin_action_links', 'catch_gallery_action_links', 10, 2);
165