PluginProbe
Essential Widgets / 2.0
Essential Widgets v2.0
3.2.1 3.3 3.2 trunk 1.0.0 1.0.1 1.1 1.2 1.2.1 1.2.2 1.3 1.4 1.4.1 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 1.9 2.0 2.1 2.2 All 31 releases
essential-widgets / admin / class-essential-widgets-admin.php

class-essential-widgets-admin.php in Essential Widgets 2.0, at admin/class-essential-widgets-admin.php

224 lines 8.2 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
7 * @since 1.0.0
8 *
9 * @package Essential_Widgets
10 * @subpackage Essential_Widgets/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 Essential_Widgets
20 * @subpackage Essential_Widgets/admin
21 * @author Catch Plugins <info@catchplugins.com>
22 */
23 class Essential_Widgets_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 Essential_Widgets_Loader as all of the hooks are defined
69 * in that particular class.
70 *
71 * The Essential_Widgets_Loader will then create the relationship
72 * between the defined hooks and the functions defined in this
73 * class.
74 */
75
76 if ( isset( $_GET['page'] ) && 'essential-widgets' == $_GET['page'] ) {
77 wp_enqueue_style( $this->plugin_name . '-display-dashboard-admin', plugin_dir_url( __FILE__ ) . 'css/essential-widgets-dasbhoard-admin.css', array(), $this->version, 'all' );
78 wp_enqueue_style( $this->plugin_name . '-display-dashboard', plugin_dir_url( __FILE__ ) . 'css/admin-dashboard.css', array(), $this->version, 'all' );
79 }
80 global $pagenow;
81 if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) {
82 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/essential-widgets-admin.css', array(), $this->version, 'all' );
83 }
84
85 }
86
87 /**
88 * Register the JavaScript for the admin area.
89 *
90 * @since 1.0.0
91 */
92 public function enqueue_scripts() {
93
94 /**
95 * This function is provided for demonstration purposes only.
96 *
97 * An instance of this class should be passed to the run() function
98 * defined in Essential_Widgets_Loader as all of the hooks are defined
99 * in that particular class.
100 *
101 * The Essential_Widgets_Loader will then create the relationship
102 * between the defined hooks and the functions defined in this
103 * class.
104 */
105
106 if ( isset( $_GET['page'] ) && 'essential-widgets' == $_GET['page'] ) {
107 wp_enqueue_script( 'minHeight', plugin_dir_url( __FILE__ ) . 'js/jquery.matchHeight.min.js', array( 'jquery' ), $this->version, false );
108 wp_enqueue_script( $this->plugin_name . '-admin-script', plugin_dir_url( __FILE__ ) . 'js/admin-scripts.js', array( 'minHeight', 'jquery' ), $this->version, false );
109 }
110 global $pagenow;
111 if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) {
112 wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/essential-widgets-admin.js', array( 'jquery' ), $this->version, false );
113 }
114
115 }
116
117 /**
118 * Essential Widgets: action_links
119 * Essential Widgets Settings Link function callback
120 *
121 * @param arrray $links Link url.
122 *
123 * @param arrray $file File name.
124 */
125 public function action_links( $links, $file ) {
126 if ( $file === $this->plugin_name . '/' . $this->plugin_name . '.php' ) {
127 $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=essential-widgets' ) ) . '">' . esc_html__( 'Settings', 'essential-widgets' ) . '</a>';
128
129 array_unshift( $links, $settings_link );
130 }
131 return $links;
132 }
133
134 /**
135 * Essential Widgets: add_plugin_settings_menu
136 * add Essential Widgets to menu
137 */
138 public function add_plugin_settings_menu() {
139 add_menu_page(
140 esc_html__( 'Essential Widgets', 'essential-widgets' ),
141 esc_html__( 'Essential Widgets', 'essential-widgets' ),
142 'manage_options',
143 'essential-widgets',
144 array( $this, 'settings_page' ),
145 '',
146 '99.01564'
147 );
148 }
149
150 /**
151 * Essential Widgets: catch_web_tools_settings_page
152 * Essential Widgets Setting function
153 */
154 public function settings_page() {
155 if ( ! current_user_can( 'manage_options' ) ) {
156 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
157 }
158
159 require plugin_dir_path( __FILE__ ) . 'partials/essential-widgets-admin-display.php';
160 }
161
162 /**
163 * Essential Widgets: register_settings
164 * Essential Widgets Register Settings
165 */
166 public function register_settings() {
167 register_setting(
168 'essential-widgets-group',
169 'essential_widgets_options',
170 array( $this, 'sanitize_callback' )
171 );
172 }
173
174 public function ew_switch() {
175 if ( ! wp_verify_nonce( $_POST['security'], 'ew_nonce' ) ) {
176 wp_die( esc_html__( 'Unauthorized access!', 'essential-widgets' ) );
177 } else {
178 if ( ! current_user_can( 'manage_options' ) ) {
179 wp_die( esc_html__( 'Permission denied!', 'essential-widgets' ) );
180 }
181 $value = ( 'true' == $_POST['value'] ) ? 1 : 0;
182
183 $option_name = $_POST['option_name'];
184
185 $option_value = essential_widgets_get_options();
186
187 $option_value[ $option_name ] = $value;
188
189 if ( update_option( 'essential_widgets_options', $option_value ) ) {
190 echo $value;
191 } else {
192 esc_html_e( 'Connection Error. Please try again.', 'essential-widgets' );
193 }
194 }
195
196 wp_die(); // this is required to terminate immediately and return a proper response
197 }
198 function add_plugin_meta_links( $meta_fields, $file ) {
199 if ( ESSENTIAL_WIDGETS_BASENAME == $file ) {
200 $meta_fields[] = "<a href='https://catchplugins.com/support-forum/forum/essential-widgets-free-wordpress-plugin/' target='_blank'>Support Forum</a>";
201 $meta_fields[] = "<a href='https://wordpress.org/support/plugin/essential-widgets/reviews/#new-post' target='_blank' title='Rate'>
202 <i class='ct-rate-stars'>"
203 . "<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>"
204 . "<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>"
205 . "<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>"
206 . "<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>"
207 . "<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>"
208 . '</i></a>';
209
210 $stars_color = '#ffb900';
211
212 echo '<style>'
213 . '.ct-rate-stars{display:inline-block;color:' . $stars_color . ';position:relative;top:3px;}'
214 . '.ct-rate-stars svg{fill:' . $stars_color . ';}'
215 . '.ct-rate-stars svg:hover{fill:' . $stars_color . '}'
216 . '.ct-rate-stars svg:hover ~ svg{fill:none;}'
217 . '</style>';
218 }
219
220 return $meta_fields;
221 }
222
223 }
224