css
5 months ago
images
5 months ago
js
5 months ago
partials
5 months ago
class-catch-scroll-progress-bar-admin.php
5 months ago
index.php
5 months ago
class-catch-scroll-progress-bar-admin.php
247 lines
| 1 | <?php |
| 2 | |
| 3 | // Exit if accessed directly |
| 4 | if (! defined('ABSPATH')) exit; |
| 5 | |
| 6 | /** |
| 7 | * The admin-specific functionality of the plugin. |
| 8 | * |
| 9 | * @link www.catchplugins.com |
| 10 | * @since 1.0.0 |
| 11 | * |
| 12 | * @package Catch_Scroll_Progress_Bar |
| 13 | * @subpackage Catch_Scroll_Progress_Bar/admin |
| 14 | */ |
| 15 | |
| 16 | |
| 17 | class Catch_Scroll_Progress_Bar_Admin |
| 18 | { |
| 19 | |
| 20 | /** |
| 21 | * The ID of this plugin. |
| 22 | * |
| 23 | * @since 1.0.0 |
| 24 | * @access private |
| 25 | * @var string $plugin_name The ID of this plugin. |
| 26 | */ |
| 27 | private $plugin_name; |
| 28 | |
| 29 | /** |
| 30 | * The version of this plugin. |
| 31 | * |
| 32 | * @since 1.0.0 |
| 33 | * @access private |
| 34 | * @var string $version The current version of this plugin. |
| 35 | */ |
| 36 | private $version; |
| 37 | |
| 38 | /** |
| 39 | * Initialize the class and set its properties. |
| 40 | * |
| 41 | * @since 1.0.0 |
| 42 | * @param string $plugin_name The name of this plugin. |
| 43 | * @param string $version The version of this plugin. |
| 44 | */ |
| 45 | public function __construct($plugin_name, $version) |
| 46 | { |
| 47 | |
| 48 | $this->plugin_name = $plugin_name; |
| 49 | $this->version = $version; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Register the stylesheets for the admin area. |
| 54 | * |
| 55 | * @since 1.0.0 |
| 56 | */ |
| 57 | public function enqueue_styles() |
| 58 | { |
| 59 | |
| 60 | /** |
| 61 | * This function is provided for demonstration purposes only. |
| 62 | * |
| 63 | * An instance of this class should be passed to the run() function |
| 64 | * defined in Catch_Progress_Bar_Loader as all of the hooks are defined |
| 65 | * in that particular class. |
| 66 | * |
| 67 | * The Catch_Progress_Bar_Loader will then create the relationship |
| 68 | * between the defined hooks and the functions defined in this |
| 69 | * class. |
| 70 | */ |
| 71 | |
| 72 | |
| 73 | |
| 74 | if (isset($_GET['page']) && 'catch-scroll-progress-bar' == $_GET['page']) { |
| 75 | wp_enqueue_style($this->plugin_name . '-display-dashboard', plugin_dir_url(__FILE__) . 'css/catch-scroll-progress-bar-admin.css', array(), $this->version, 'all'); |
| 76 | } |
| 77 | } |
| 78 | /** |
| 79 | * Register the JavaScript for the admin area. |
| 80 | * |
| 81 | * @since 1.0.0 |
| 82 | */ |
| 83 | public function enqueue_scripts() |
| 84 | { |
| 85 | |
| 86 | /** |
| 87 | * This function is provided for demonstration purposes only. |
| 88 | * |
| 89 | * An instance of this class should be passed to the run() function |
| 90 | * defined in Catch_Progress_Bar_Loader as all of the hooks are defined |
| 91 | * in that particular class. |
| 92 | * |
| 93 | * The Catch_Progress_Bar_Loader will then create the relationship |
| 94 | * between the defined hooks and the functions defined in this |
| 95 | * class. |
| 96 | */ |
| 97 | |
| 98 | if (isset($_GET['page']) && 'catch-scroll-progress-bar' == $_GET['page']) { |
| 99 | wp_enqueue_script('matchHeight', plugin_dir_url(__FILE__) . 'js/jquery-matchHeight.min.js', array('jquery'), $this->version, false); |
| 100 | wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/catch-scroll-progress-bar-admin.js', array('jquery', 'matchHeight', 'jquery-ui-tooltip'), $this->version, false); |
| 101 | wp_enqueue_script('catch-scroll-progress-bar-color-picker', plugin_dir_url(__FILE__) . 'js/wp-color-picker.js', array('wp-color-picker', 'jquery'), $this->version, false); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | public function add_plugin_settings_menu() |
| 106 | { |
| 107 | add_menu_page( |
| 108 | esc_html__('Catch Scroll Progress Bar ', 'catch-scroll-progress-bar'), // $page_title. |
| 109 | esc_html__('Catch Scroll Progress Bar ', 'catch-scroll-progress-bar'), // $menu_title. |
| 110 | 'manage_options', // $capability. |
| 111 | 'catch-scroll-progress-bar', // $menu_slug. |
| 112 | array($this, 'settings_page'), // $callback_function. |
| 113 | 'dashicons-editor-alignleft', // $icon_url. |
| 114 | '99.01564' // $position. |
| 115 | ); |
| 116 | add_submenu_page( |
| 117 | 'catch-scroll-progress-bar', // $parent_slug. |
| 118 | esc_html__('Catch Scroll Progress Bar', 'catch-scroll-progress-bar'), // $page_title. |
| 119 | esc_html__('Settings', 'catch-scroll-progress-bar'), // $menu_title. |
| 120 | 'manage_options', // $capability. |
| 121 | 'catch-scroll-progress-bar', // $menu_slug. |
| 122 | array($this, 'settings_page') // $callback_function. |
| 123 | ); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Catch Scroll Progress Bar: action_links |
| 128 | * Catch Scroll Progress Bar Settings Link function callback |
| 129 | * |
| 130 | * @param array $links Link url. |
| 131 | * |
| 132 | * @param array $file File name. |
| 133 | */ |
| 134 | public function action_links($links, $file) |
| 135 | { |
| 136 | if ($file === $this->plugin_name . '/' . $this->plugin_name . '.php') { |
| 137 | $settings_link = '<a href="' . esc_url(admin_url('admin.php?page=catch-scroll-progress-bar')) . '">' . esc_html__('Settings', 'catch-scroll-progress-bar') . '</a>'; |
| 138 | |
| 139 | array_unshift($links, $settings_link); |
| 140 | } |
| 141 | return $links; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | public function settings_page() |
| 146 | { |
| 147 | if (! current_user_can('manage_options')) { |
| 148 | wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'catch-scroll-progress-bar')); |
| 149 | } |
| 150 | require plugin_dir_path(__FILE__) . 'partials/catch-scroll-progress-bar-admin-display.php'; |
| 151 | } |
| 152 | public function register_settings() |
| 153 | { |
| 154 | register_setting( |
| 155 | 'catch-scroll-progress-bar-group', |
| 156 | 'catch_progress_bar_options', |
| 157 | array($this, 'sanitize_callback') |
| 158 | ); |
| 159 | } |
| 160 | |
| 161 | public function sanitize_callback($input) |
| 162 | { |
| 163 | if (isset($input['reset']) && $input['reset']) { |
| 164 | //If reset, restore defaults |
| 165 | return catch_progress_bar_default_options(); |
| 166 | } |
| 167 | |
| 168 | // Verify the nonce before proceeding. |
| 169 | if ( |
| 170 | (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) |
| 171 | || |
| 172 | ( |
| 173 | ! isset($_POST['catch_progress_bar_nonce']) |
| 174 | || |
| 175 | ! wp_verify_nonce($_POST['catch_progress_bar_nonce'], CATCH_SCROLL_PROGRESS_BAR_BASENAME) |
| 176 | ) |
| 177 | || |
| 178 | ! check_admin_referer(CATCH_SCROLL_PROGRESS_BAR_BASENAME, 'catch_progress_bar_nonce') |
| 179 | ) { |
| 180 | |
| 181 | echo esc_html__('Sorry, your nonce did not verify.', 'catch-scroll-progress-bar'); |
| 182 | exit; |
| 183 | } else { |
| 184 | |
| 185 | if (null !== $input) { |
| 186 | |
| 187 | $input['reset'] = (isset($input['reset']) && '1' == $input['reset']) ? '1' : '0'; |
| 188 | $input['home'] = (isset($input['home']) && '1' == $input['home']) ? 1 : 0; |
| 189 | $input['blog'] = (isset($input['blog']) && '1' == $input['blog']) ? 1 : 0; |
| 190 | $input['archive'] = (isset($input['archive']) && '1' == $input['archive']) ? 1 : 0; |
| 191 | $input['single'] = (isset($input['single']) && '1' == $input['single']) ? 1 : 0; |
| 192 | |
| 193 | $post_types = get_post_types(array('public' => true), 'objects'); |
| 194 | foreach ($post_types as $type => $obj) { |
| 195 | $input['field_posttypes'][$type] = (isset($input['field_posttypes'][$type]) && '1' == $input['field_posttypes'][$type]) ? 1 : 0; |
| 196 | } |
| 197 | |
| 198 | if (isset($input['radius'])) { |
| 199 | $input['radius'] = sanitize_text_field($input['radius']); |
| 200 | } |
| 201 | if (isset($input['bar_height'])) { |
| 202 | $input['bar_height'] = sanitize_text_field($input['bar_height']); |
| 203 | } |
| 204 | if (isset($input['background_opacity'])) { |
| 205 | $input['background_opacity'] = floatval($input['background_opacity']); |
| 206 | } |
| 207 | if (isset($input['foreground_opacity'])) { |
| 208 | $input['foreground_opacity'] = floatval($input['foreground_opacity']); |
| 209 | } |
| 210 | if (isset($input['background_color']) && $input['background_color']) { |
| 211 | $input['background_color'] = sanitize_hex_color($input['background_color']); |
| 212 | } |
| 213 | if (isset($input['foreground_color']) && $input['foreground_color']) { |
| 214 | $input['foreground_color'] = sanitize_hex_color($input['foreground_color']); |
| 215 | } |
| 216 | return $input; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | function add_plugin_meta_links($meta_fields, $file) |
| 222 | { |
| 223 | if (CATCH_SCROLL_PROGRESS_BAR_BASENAME == $file) { |
| 224 | $meta_fields[] = "<a href='https://catchplugins.com/support-forum/forum/catch-scroll-progress-bar/' target='_blank'>Support Forum</a>"; |
| 225 | $meta_fields[] = "<a href='https://wordpress.org/support/plugin/catch-scroll-progress-bar/reviews#new-post' target='_blank' title='Rate'> |
| 226 | <i class='ct-rate-stars'>" |
| 227 | . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" |
| 228 | . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" |
| 229 | . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" |
| 230 | . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" |
| 231 | . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>" |
| 232 | . "</i></a>"; |
| 233 | |
| 234 | $stars_color = "#ffb900"; |
| 235 | |
| 236 | echo "<style>" |
| 237 | . ".ct-rate-stars{display:inline-block;color:" . esc_attr($stars_color) . ";position:relative;top:3px;}" |
| 238 | . ".ct-rate-stars svg{fill:" . esc_attr($stars_color) . ";}" |
| 239 | . ".ct-rate-stars svg:hover{fill:" . esc_attr($stars_color) . "}" |
| 240 | . ".ct-rate-stars svg:hover ~ svg{fill:none;}" |
| 241 | . "</style>"; |
| 242 | } |
| 243 | |
| 244 | return $meta_fields; |
| 245 | } |
| 246 | } |
| 247 |