PluginProbe
Catch Breadcrumb / 1.7
Catch Breadcrumb v1.7
trunk 1.0.0 1.0.1 1.0.2 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6 1.7 1.8 1.9 2.0 2.1 2.2 All 29 releases
catch-breadcrumb / admin / class-catch-breadcrumb-admin.php

class-catch-breadcrumb-admin.php in Catch Breadcrumb 1.7, at admin/class-catch-breadcrumb-admin.php

254 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @link https://catchplugins.com/plugins
7 * @since 1.0.0
8 *
9 * @package Catch_Breadcrumb
10 * @subpackage Catch_Breadcrumb/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_Breadcrumb
20 * @subpackage Catch_Breadcrumb/admin
21 * @author Catch plugins
22 */
23 class Catch_Breadcrumb_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 Breadcrumb_Loader as all of the hooks are defined
69 * in that particular class.
70 *
71 * The Breadcrumb_Loader will then create the relationship
72 * between the defined hooks and the functions defined in this
73 * class.
74 */
75 if ( isset( $_GET['page'] ) && 'catch-breadcrumb' === $_GET['page'] ) {
76
77 wp_enqueue_style( $this->plugin_name . '-display-dashboard', plugin_dir_url( __FILE__ ) . 'css/admin-dashboard.css', array(), $this->version, 'all' );
78
79 }
80
81 }
82
83 public function enqueue_scripts() {
84
85 /**
86 * This function is provided for demonstration purposes only.
87 *
88 * An instance of this class should be passed to the run() function
89 * defined in Breadcrumb_Loader as all of the hooks are defined
90 * in that particular class.
91 *
92 * The Breadcrumb_Loader will then create the relationship
93 * between the defined hooks and the functions defined in this
94 * class.
95 */
96
97 if ( isset( $_GET['page'] ) && 'catch-breadcrumb' == $_GET['page'] ) {
98
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-breadcrumb-admin.js', array( 'jquery', 'matchHeight', 'jquery-ui-tooltip' ), $this->version, false );
101
102 }
103
104 }
105
106 /**
107 * Catch Breadcrumb: action_links
108 * Catch Breadcrumb Settings Link function callback
109 *
110 * @param arrray $links Link url.
111 *
112 * @param arrray $file File name.
113 */
114 public function action_links( $links, $file ) {
115
116 if ( $file === $this->plugin_name . '/' . $this->plugin_name . '.php' ) {
117
118 $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=catch-breadcrumb' ) ) . '">' . esc_html__( 'Settings', 'catch-breadcrumb' ) . '</a>';
119 array_unshift( $links, $settings_link );
120
121 }
122
123 return $links;
124
125 }
126
127 public function add_plugin_settings_menu() {
128
129 add_menu_page(
130 esc_html__( 'Catch Breadcrumb', 'catch-breadcrumb' ), // $page_title.
131 esc_html__( 'Catch Breadcrumb', 'catch-breadcrumb' ), // $menu_title.
132 'manage_options', // $capability.
133 'catch-breadcrumb', // $menu_slug.
134 array( $this, 'settings_page' ), // $callback_function.
135 'dashicons-sort', // $icon_url.
136 '99.01564' // $position.
137 );
138
139 add_submenu_page(
140 'catch-breadcrumb', // $parent_slug.
141 esc_html__( 'Catch Breadcrumb', 'catch-breadcrumb' ), // $page_title.
142 esc_html__( 'Settings', 'catch-breadcrumb' ), // $menu_title.
143 'manage_options', // $capability.
144 'catch-breadcrumb', // $menu_slug.
145 array( $this, 'settings_page' ) // $callback_function.
146 );
147
148 }
149
150 public function settings_page() {
151
152 if ( ! current_user_can( 'manage_options' ) ) {
153
154 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'catch-breadcrumb' ) );
155
156 }
157
158 require plugin_dir_path( __FILE__ ) . 'partials/catch-breadcrumb-admin-display.php';
159
160 }
161
162 public function register_settings() {
163
164 register_setting(
165 'catch-breadcrumb-group',
166 'catch_breadcrumb_options',
167 array( $this, 'sanitize_callback' )
168 );
169
170 }
171
172 public function sanitize_callback( $input ) {
173
174 if ( isset( $input['reset'] ) && $input['reset'] ) {
175
176 //If reset, restore defaults
177 return catch_breadcrumb_default_options();
178
179 }
180
181 // Verify the nonce before proceeding.
182 if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
183 || ( ! isset( $_POST['catch_breadcrumb_nonce'] )
184 || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['catch_breadcrumb_nonce'] ) ), CATCH_BREADCRUMB_BASENAME ) )
185 || ( ! check_admin_referer( CATCH_BREADCRUMB_BASENAME, 'catch_breadcrumb_nonce' ) ) ) {
186
187 return 'Invalid Nonce';
188
189 } else {
190
191 if ( null !== $input ) {
192
193 $input['status'] = ( isset( $input['status'] ) && '1' === $input['status'] ) ? '1' : '0';
194 $input['breadcrumb_home_icon'] = ( isset( $input['breadcrumb_home_icon'] ) && '1' === $input['breadcrumb_home_icon'] ) ? '1' : '0';
195 $input['breadcrumb_display_home'] = ( isset( $input['breadcrumb_display_home'] ) && '1' === $input['breadcrumb_display_home'] ) ? '1' : '0';
196
197 if ( isset( $input['breadcrumb_separator'] ) ) {
198
199 $input['breadcrumb_separator'] = sanitize_text_field( $input['breadcrumb_separator'] );
200
201 }
202
203 if ( isset( $input['content_selector'] ) && $input['content_selector'] ) {
204
205 $input['content_selector'] = wp_kses_post( $input['content_selector'] );
206
207 }
208
209 if ( isset( $input['breadcrumb_dynamic'] ) && $input['breadcrumb_dynamic'] ) {
210
211 $input['breadcrumb_dynamic'] = sanitize_key( $input['breadcrumb_dynamic'] );
212
213 }
214 }
215
216 return $input;
217
218 }
219
220 }
221
222
223
224 function add_plugin_meta_links( $meta_fields, $file ) {
225
226 if ( CATCH_BREADCRUMB_BASENAME === $file ) {
227
228 $meta_fields[] = "<a href='https://catchplugins.com/support-forum/forum/catch-breadcrumb/' target='_blank'>Support Forum</a>";
229 $meta_fields[] = "<a href='https://wordpress.org/support/plugin/catch-breadcrumb/reviews#new-post' target='_blank' title='Rate'>
230 <i class='ct-rate-stars'>"
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 . "<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>"
233 . "<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>"
234 . "<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>"
235 . "<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>"
236 . '</i></a>';
237
238 $stars_color = '#ffb900';
239
240 echo '<style>'
241 . '.ct-rate-stars{display:inline-block;color:' . esc_html( $stars_color ) . ';position:relative;top:3px;}'
242 . '.ct-rate-stars svg{fill:' . esc_html( $stars_color ) . ';}'
243 . '.ct-rate-stars svg:hover{fill:' . esc_html( $stars_color ) . '}'
244 . '.ct-rate-stars svg:hover ~ svg{fill:none;}'
245 . '</style>';
246
247 }
248
249 return $meta_fields;
250
251 }
252
253 }
254