PluginProbe
Catch Breadcrumb / 1.1
Catch Breadcrumb v1.1
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.1, at admin/class-catch-breadcrumb-admin.php

180 lines 5.7 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 wp_enqueue_style( $this->plugin_name. '-display-dashboard', plugin_dir_url( __FILE__ ) . 'css/admin-dashboard.css', array(), $this->version, 'all' );
77
78 }
79 }
80 public function enqueue_scripts() {
81
82 /**
83 * This function is provided for demonstration purposes only.
84 *
85 * An instance of this class should be passed to the run() function
86 * defined in Breadcrumb_Loader as all of the hooks are defined
87 * in that particular class.
88 *
89 * The Breadcrumb_Loader will then create the relationship
90 * between the defined hooks and the functions defined in this
91 * class.
92 */
93
94 if ( isset( $_GET['page'] ) && 'catch-breadcrumb' == $_GET['page'] ) {
95 wp_enqueue_script( 'matchHeight', plugin_dir_url( __FILE__ ) . 'js/jquery-matchHeight.min.js', array( 'jquery' ), $this->version, false );
96 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/catch-breadcrumb-admin.js', array( 'jquery', 'matchHeight' ), $this->version, false );
97 }
98 }
99
100 /**
101 * Catch Breadcrumb: action_links
102 * Catch Breadcrumb Settings Link function callback
103 *
104 * @param arrray $links Link url.
105 *
106 * @param arrray $file File name.
107 */
108 public function action_links( $links, $file ) {
109 if ( $file === $this->plugin_name . '/' . $this->plugin_name . '.php' ) {
110 $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=catch-breadcrumb' ) ) . '">' . esc_html__( 'Settings', 'catch-breadcrumb' ) . '</a>';
111
112 array_unshift( $links, $settings_link );
113 }
114 return $links;
115 }
116
117 public function add_plugin_settings_menu() {
118 add_menu_page(
119 esc_html__( 'Catch Breadcrumb', 'catch-breadcrumb' ), // $page_title.
120 esc_html__( 'Catch Breadcrumb', 'catch-breadcrumb' ), // $menu_title.
121 'manage_options', // $capability.
122 'catch-breadcrumb', // $menu_slug.
123 array( $this, 'settings_page' ), // $callback_function.
124 'dashicons-sort', // $icon_url.
125 '99.01564' // $position.
126 );
127 add_submenu_page(
128 'catch-breadcrumb', // $parent_slug.
129 esc_html__( 'Catch Breadcrumb', 'catch-breadcrumb' ), // $page_title.
130 esc_html__( 'Settings', 'catch-breadcrumb' ), // $menu_title.
131 'manage_options', // $capability.
132 'catch-breadcrumb', // $menu_slug.
133 array( $this,'settings_page' ) // $callback_function.
134 );
135 }
136
137
138 public function settings_page() {
139 if ( ! current_user_can( 'manage_options' ) ) {
140 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'catch-breadcrumb' ) );
141 }
142 require plugin_dir_path( __FILE__ ) . 'partials/catch-breadcrumb-admin-display.php';
143 }
144 public function register_settings() {
145 register_setting(
146 'catch-breadcrumb-group',
147 'catch_breadcrumb_options',
148 array( $this, 'sanitize_callback' )
149 );
150 }
151 public function sanitize_callback( $input ) {
152 if ( isset( $input['reset'] ) && $input['reset'] ) {
153 //If reset, restore defaults
154 return catch_breadcrumb_default_options();
155 }
156 $message = null;
157 $type = null;
158
159 // Verify the nonce before proceeding.
160 if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
161 || ( ! isset( $_POST['catch_breadcrumb_nounce'] )
162 || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['catch_breadcrumb_nounce'] ) ), basename( __FILE__ ) ) )
163 || ( ! check_admin_referer( basename( __FILE__ ), 'catch_breadcrumb_nounce' ) ) ) {
164 if ( null !== $input ) {
165
166 $input['status'] = ( isset( $input['status'] ) && '1' == $input['status'] ) ? '1' : '0';
167 if ( isset( $input['breadcrumb_separator'] ) ) {
168 $input['breadcrumb_separator'] = sanitize_text_field( $input['breadcrumb_separator'] );
169 }
170 if ( isset( $input['content_selector'] ) && $input['content_selector'] ) {
171 $input['content_selector'] = wp_kses_post( $input['content_selector'] );
172 }
173 }
174 return $input;
175 }
176 return 'Invalid Nonce';
177 }
178
179 }
180