1 | <?php |
---|
2 | /** |
---|
3 | * Plugin Name: Wider Admin Menu |
---|
4 | * Description: Let your admin menu breathe. |
---|
5 | * Author: WPChill |
---|
6 | * Version: 1.4 |
---|
7 | * Author URI: https:/wpchill.com/ |
---|
8 | * Text Domain: wider-admin-menu |
---|
9 | * Requires: 4.6 or higher |
---|
10 | * License: GPLv3 or later |
---|
11 | * License URI: http://www.gnu.org/licenses/gpl-3.0.html |
---|
12 | * Requires PHP: 5.6 |
---|
13 | * Tested up to: 6.6 |
---|
14 | * |
---|
15 | * Copyright 2014-2019 Chris Dillon chris@strongwp.com |
---|
16 | * Copyright 2019 MachoThemes office@machothemes.com |
---|
17 | * |
---|
18 | * Original Plugin URI: https://strongplugins.com/plugins/wider-admin-menu |
---|
19 | * Original Author URI: https://strongplugins.com |
---|
20 | * Original Author: https://profiles.wordpress.org/cdillon27/ |
---|
21 | * |
---|
22 | * NOTE: |
---|
23 | * Chris Dillon transferred ownership rights on: 01/20/2019 06:56:07 PM when ownership was handed over to MachoThemes |
---|
24 | * The MachoThemes ownership period started on: 01/20/2019 06:56:08 PM |
---|
25 | * SVN commit proof of ownership transferral: https://plugins.trac.wordpress.org/changeset/2015927/wider-admin-menu |
---|
26 | * |
---|
27 | * MachoThemes transferred ownership to WPChill on: 5th of November, 2020. WPChill is a restructure and rebrand of MachoThemes. |
---|
28 | * |
---|
29 | * This program is free software; you can redistribute it and/or modify |
---|
30 | * it under the terms of the GNU General Public License, version 3, as |
---|
31 | * published by the Free Software Foundation. |
---|
32 | * |
---|
33 | * This program is distributed in the hope that it will be useful, |
---|
34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
36 | * GNU General Public License for more details. |
---|
37 | * |
---|
38 | * You should have received a copy of the GNU General Public License |
---|
39 | * along with this program; if not, write to the Free Software |
---|
40 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
41 | */ |
---|
42 | |
---|
43 | // Exit if accessed directly |
---|
44 | if ( ! defined( 'ABSPATH' ) ) { |
---|
45 | exit; |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * Class WiderAdminMenu |
---|
50 | */ |
---|
51 | class WiderAdminMenu { |
---|
52 | |
---|
53 | public function __construct() { |
---|
54 | add_action( 'load-settings_page_wider-admin-menu', array( $this, 'load_admin_scripts' ) ); |
---|
55 | add_action( 'load-settings_page_wider-admin-menu', array( $this, 'load_lnt_style' ) ); |
---|
56 | |
---|
57 | add_action( 'admin_head', array( $this, 'custom_admin_style' ) ); |
---|
58 | add_action( 'admin_menu', array( $this, 'add_options_page' ) ); |
---|
59 | add_action( 'admin_init', array( $this, 'register_settings' ) ); |
---|
60 | |
---|
61 | add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 ); |
---|
62 | |
---|
63 | // LNT icon |
---|
64 | add_action( 'load-plugins.php', array( $this, 'load_lnt_style' ) ); |
---|
65 | add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 ); |
---|
66 | |
---|
67 | add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); |
---|
68 | } |
---|
69 | |
---|
70 | public function load_textdomain() { |
---|
71 | load_plugin_textdomain( 'wider-admin-menu', false, basename( dirname( __FILE__ ) ) . '/languages' ); |
---|
72 | } |
---|
73 | |
---|
74 | public function load_admin_scripts() { |
---|
75 | wp_enqueue_style( 'wpmwam-options', plugins_url( '/css/options.css', __FILE__ ) ); |
---|
76 | |
---|
77 | $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'settings'; |
---|
78 | if ( 'settings' == $active_tab ) { |
---|
79 | |
---|
80 | wp_enqueue_script( 'jquery-ui-slider' ); |
---|
81 | wp_enqueue_script( 'wpmwam-script', plugins_url( '/js/wider-admin-menu.js', __FILE__ ), array( 'jquery-ui-slider' ) ); |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | public function load_lnt_style() { |
---|
86 | wp_enqueue_style( 'wpmwam-lnt', plugins_url( '/css/lnt.css', __FILE__ ) ); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * Install with default setting. |
---|
91 | */ |
---|
92 | public static function plugin_activation() { |
---|
93 | $options = array( |
---|
94 | 'wpmwam_width' => 200, |
---|
95 | 'wpmwam_lnt' => 1, |
---|
96 | ); |
---|
97 | update_option( 'wpmwam_options', $options ); |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * Plugin list action links |
---|
102 | * |
---|
103 | * @param $links |
---|
104 | * @param $file |
---|
105 | * |
---|
106 | * @return mixed |
---|
107 | */ |
---|
108 | public function plugin_action_links( $links, $file ) { |
---|
109 | if ( $file == plugin_basename( __FILE__ ) ) { |
---|
110 | $settings_link = '<a href="' . esc_url( admin_url( 'options-general.php?page=wider-admin-menu.php' ) ) . '">' . esc_html__( 'Settings', 'wider-admin-menu' ) . '</a>'; |
---|
111 | array_unshift( $links, $settings_link ); |
---|
112 | } |
---|
113 | |
---|
114 | return $links; |
---|
115 | } |
---|
116 | |
---|
117 | /** |
---|
118 | * Plugin meta row |
---|
119 | * |
---|
120 | * @param $plugin_meta |
---|
121 | * @param $plugin_file |
---|
122 | * @param $plugin_data |
---|
123 | * @param $status |
---|
124 | * |
---|
125 | * @return array |
---|
126 | */ |
---|
127 | public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) { |
---|
128 | if ( $plugin_file == plugin_basename( __FILE__ ) ) { |
---|
129 | $plugin_meta[] = '<span class="lnt">' . esc_html__( 'Leave No Trace', 'wider-admin-menu' ) . '</span>'; |
---|
130 | } |
---|
131 | |
---|
132 | return $plugin_meta; |
---|
133 | } |
---|
134 | |
---|
135 | /** |
---|
136 | * Insert custom admin style. |
---|
137 | */ |
---|
138 | public function custom_admin_style() { |
---|
139 | $wp_version = get_bloginfo( 'version' ); |
---|
140 | // Get width option. Prevent zero in case of installation error. |
---|
141 | $wpmwam = get_option( 'wpmwam_options' ); |
---|
142 | $w = (int) $wpmwam['wpmwam_width']; |
---|
143 | if ( ! $w ) { |
---|
144 | $w = 160; |
---|
145 | } |
---|
146 | $wpx = $w . 'px'; |
---|
147 | $w1px = ( $w + 1 ) . 'px'; |
---|
148 | $w2px = ( $w + 20 ) . 'px'; |
---|
149 | |
---|
150 | $file = ''; |
---|
151 | |
---|
152 | if ( version_compare( $wp_version, '5', '>' ) ) { |
---|
153 | $file = 'style50'; |
---|
154 | } elseif ( version_compare( $wp_version, '4', '>=' ) ) { |
---|
155 | $file = 'style40'; |
---|
156 | } elseif ( version_compare( $wp_version, '3.8', '>=' ) ) { |
---|
157 | $file = 'style38'; |
---|
158 | } elseif ( version_compare( $wp_version, '3.5', '>=' ) ) { |
---|
159 | $file = 'style35'; |
---|
160 | } elseif ( version_compare( $wp_version, '3.3', '>=' ) ) { |
---|
161 | $file = 'style33'; |
---|
162 | } |
---|
163 | |
---|
164 | if ( $file ) { |
---|
165 | include plugin_dir_path( __FILE__ ) . "includes/$file.php"; |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | /** |
---|
170 | * Add options page to Settings menu. |
---|
171 | */ |
---|
172 | public function add_options_page() { |
---|
173 | add_options_page( |
---|
174 | 'Wider Admin Menu', |
---|
175 | 'Wider Admin Menu', |
---|
176 | 'manage_options', |
---|
177 | basename( __FILE__ ), |
---|
178 | array( |
---|
179 | $this, |
---|
180 | 'settings_page', |
---|
181 | ) |
---|
182 | ); |
---|
183 | } |
---|
184 | |
---|
185 | /** |
---|
186 | * Register the setting. |
---|
187 | */ |
---|
188 | public function register_settings() { |
---|
189 | register_setting( 'wpmwam_settings_group', 'wpmwam_options', array( $this, 'sanitize_options' ) ); |
---|
190 | } |
---|
191 | |
---|
192 | /** |
---|
193 | * Sanitize user input. |
---|
194 | * |
---|
195 | * @param $input |
---|
196 | * |
---|
197 | * @return mixed |
---|
198 | */ |
---|
199 | public function sanitize_options( $input ) { |
---|
200 | $input['wpmwam_width'] = sanitize_text_field( $input['wpmwam_width'] ); |
---|
201 | $input['wpmwam_lnt'] = isset( $input['wpmwam_lnt'] ) ? $input['wpmwam_lnt'] : 0; |
---|
202 | |
---|
203 | return $input; |
---|
204 | } |
---|
205 | |
---|
206 | /** |
---|
207 | * Our settings page. |
---|
208 | */ |
---|
209 | function settings_page() { |
---|
210 | if ( ! current_user_can( 'manage_options' ) ) { |
---|
211 | wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) ); |
---|
212 | } |
---|
213 | |
---|
214 | $wp_version = get_bloginfo( 'version' ); |
---|
215 | ?> |
---|
216 | <div class="wrap"> |
---|
217 | <h2><?php esc_html_e( 'Wider Admin Menu', 'wider-admin-menu' ); ?></h2> |
---|
218 | <p><?php esc_html_e( 'Adjust the width of the admin menu to accomodate longer menu items.', 'wider-admin-menu' ); ?></p> |
---|
219 | |
---|
220 | <?php $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( wp_unslash( $_GET['tab'] ) ) : 'settings'; ?> |
---|
221 | <h2 class="nav-tab-wrapper"> |
---|
222 | <a href="?page=wider-admin-menu.php" |
---|
223 | class="nav-tab <?php echo $active_tab == 'settings' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Settings', 'wider-admin-menu' ); ?></a> |
---|
224 | <a href="?page=wider-admin-menu.php&tab=alternate" |
---|
225 | class="nav-tab <?php echo $active_tab == 'alternate' ? 'nav-tab-active' : ''; ?>"><?php esc_html_e( 'Alternate Method', 'wider-admin-menu' ); ?></a> |
---|
226 | </h2> |
---|
227 | |
---|
228 | <?php |
---|
229 | if ( $active_tab == 'alternate' ) { |
---|
230 | include plugin_dir_path( __FILE__ ) . 'includes/settings-alternate.php'; |
---|
231 | } else { |
---|
232 | include plugin_dir_path( __FILE__ ) . 'includes/settings-form.php'; |
---|
233 | } |
---|
234 | ?> |
---|
235 | </div> |
---|
236 | <?php |
---|
237 | } |
---|
238 | |
---|
239 | } |
---|
240 | |
---|
241 | register_activation_hook( __FILE__, array( 'WiderAdminMenu', 'plugin_activation' ) ); |
---|
242 | |
---|
243 | new WiderAdminMenu(); |
---|