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