WordPress.org

Make WordPress Core

Ticket #4066: wp-plugins-sort-patch.dff

File wp-plugins-sort-patch.dff, 12.2 KB (added by ttech5593, 7 years ago)

Patch containing all modified files (Updated with if statment correction. Sorry)

Line 
1Index: wp-admin/admin-functions.php
2===================================================================
3--- wp-admin/admin-functions.php        (revision 5168)
4+++ wp-admin/admin-functions.php        (working copy)
5@@ -1812,6 +1812,31 @@
6        return $wp_plugins;
7 }
8 
9+function wp_sort_plugins(&$plugins, $manual=FALSE){
10+       if(get_option('use_sort_plugins') == TRUE) {
11+               if(strval($_REQUEST['sort_by']) == 'widgets' OR ($manual==TRUE)) {
12+                       $remove_widgets=FALSE; // Sort Widgets
13+               } else {
14+                       $remove_widgets=TRUE; // Sort Plugins
15+               }
16+               if(is_array($plugins)) {
17+                       foreach($plugins as $plugin_file => $plugin_data) {
18+                               if($remove_widgets === FALSE) {
19+                                       if((!stristr(strval($plugin_data['Name']), "widget"))
20+                                       OR stristr($plugin_data['Name'], "Sidebar Widgets")) {
21+                                               unset($plugins[$plugin_file]);
22+                                       }
23+                               } else {
24+                                       if(stristr(strval($plugin_data['Name']), "widget")
25+                                       AND (!stristr($plugin_data['Name'], "Sidebar Widgets"))) {
26+                                               unset($plugins[$plugin_file]);
27+                                       }
28+                               }
29+                       } // End foreach
30+               }
31+       } // If sort_plugins is off just display the full array
32+}
33+
34 function get_plugin_page_hookname( $plugin_page, $parent_page ) {
35        global $admin_page_hooks;
36 
37Index: wp-admin/menu.php
38===================================================================
39--- wp-admin/menu.php   (revision 5168)
40+++ wp-admin/menu.php   (working copy)
41@@ -19,6 +19,7 @@
42 $menu[20] = array(__('Blogroll'), 'manage_links', 'link-manager.php');
43 $menu[25] = array(__('Presentation'), 'switch_themes', 'themes.php');
44 $menu[30] = array(__('Plugins'), 'activate_plugins', 'plugins.php');
45+//$menu[30] = array(__('Widgets'), 'activate_widgets', 'plugins.php?sort_by=widgets');
46 if ( current_user_can('edit_users') )
47        $menu[35] = array(__('Users'), 'edit_users', 'users.php');
48 else
49@@ -64,8 +65,12 @@
50 $submenu['options-general.php'][40] = array(__('Miscellaneous'), 'manage_options', 'options-misc.php');
51 
52 $submenu['plugins.php'][5] = array(__('Plugins'), 'activate_plugins', 'plugins.php');
53-$submenu['plugins.php'][10] = array(__('Plugin Editor'), 'edit_plugins', 'plugin-editor.php');
54+if(get_option('use_sort_plugins') == TRUE)
55+$submenu['plugins.php'][10] = array(__('Widgets'), 'activate_plugins', 'widgets.php');
56 
57+$submenu['plugins.php'][15] = array(__('Plugin Editor'), 'edit_plugins', 'plugin-editor.php');
58+
59+
60 $submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php');
61 $submenu['themes.php'][10] = array(__('Theme Editor'), 'edit_themes', 'theme-editor.php');
62 
63Index: wp-admin/options-misc.php
64===================================================================
65--- wp-admin/options-misc.php   (revision 5168)
66+++ wp-admin/options-misc.php   (working copy)
67@@ -35,15 +35,18 @@
68 </table>
69 </fieldset>
70 
71+
72 <p><input name="use_linksupdate" type="checkbox" id="use_linksupdate" value="1" <?php checked('1', get_option('use_linksupdate')); ?> />
73 <label for="use_linksupdate"><?php _e('Track Links&#8217; Update Times') ?></label></p>
74+<p><input name="use_sort_plugins" type="checkbox" id="use_sort_plugins" value="1" <?php checked('1', get_option('use_sort_plugins')); ?> />
75+<label for="use_sort_plugins"><?php _e('Enable Widget and Plugin Grouping (Sorting)') ?></label></p>
76 <p>
77 <label><input type="checkbox" name="hack_file" value="1" <?php checked('1', get_option('hack_file')); ?> /> <?php _e('Use legacy <code>my-hacks.php</code> file support') ?></label>
78 </p>
79 
80 <p class="submit">
81 <input type="hidden" name="action" value="update" />
82-<input type="hidden" name="page_options" value="hack_file,use_linksupdate,uploads_use_yearmonth_folders,upload_path" />
83+<input type="hidden" name="page_options" value="hack_file,use_sort_plugins,use_linksupdate,uploads_use_yearmonth_folders,upload_path" />
84 <input type="submit" name="Submit" value="<?php _e('Update Options &raquo;') ?>" />
85 </p>
86 </form>
87Index: wp-admin/plugins.php
88===================================================================
89--- wp-admin/plugins.php        (revision 5168)
90+++ wp-admin/plugins.php        (working copy)
91@@ -69,7 +69,6 @@
92        }
93 }
94 ?>
95-
96 <?php if ( isset($_GET['error']) ) : ?>
97        <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p></div>
98 <?php elseif ( isset($_GET['activate']) ) : ?>
99@@ -89,6 +88,8 @@
100        $current_plugins = get_option('active_plugins');
101 
102 $plugins = get_plugins();
103+/* Right after the plugins array is set so we can sort if its enabled */
104+wp_sort_plugins($plugins);
105 
106 if (empty($plugins)) {
107        echo '<p>';
108Index: wp-admin/widgets.php
109===================================================================
110--- wp-admin/widgets.php        (revision 0)
111+++ wp-admin/widgets.php        (revision 0)
112@@ -0,0 +1,172 @@
113+<?php
114+/* This file is here becaues I could not get WP to think plugins.php?sort_by=widgets was a different page from plugins.php. It is the exact same code as in plugins.php only on line 92, I call the added function wp_sort_plugins() and set it to ignore the $_GET requests since it is not needed. plugin.php the function is there so if sorting is enabled only plugins will show up. If that problem can be solved there is no need for this file. */
115+require_once('admin.php');
116+
117+if ( isset($_GET['action']) ) {
118+       if ('activate' == $_GET['action']) {
119+               check_admin_referer('activate-plugin_' . $_GET['plugin']);
120+               $current = get_option('active_plugins');
121+               $plugin = trim($_GET['plugin']);
122+               if ( validate_file($plugin) )
123+                       wp_die(__('Invalid plugin.'));
124+               if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
125+                       wp_die(__('Plugin file does not exist.'));
126+               if (!in_array($plugin, $current)) {
127+                       wp_redirect('plugins.php?error=true'); // we'll override this later if the plugin can be included without fatal error
128+                       @include(ABSPATH . PLUGINDIR . '/' . $plugin);
129+                       $current[] = $plugin;
130+                       sort($current);
131+                       update_option('active_plugins', $current);
132+                       do_action('activate_' . $plugin);
133+               }
134+               wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above
135+       } else if ('deactivate' == $_GET['action']) {
136+               check_admin_referer('deactivate-plugin_' . $_GET['plugin']);
137+               $current = get_option('active_plugins');
138+               array_splice($current, array_search( $_GET['plugin'], $current), 1 ); // Array-fu!
139+               update_option('active_plugins', $current);
140+               do_action('deactivate_' . trim( $_GET['plugin'] ));
141+               wp_redirect('plugins.php?deactivate=true');
142+       } elseif ($_GET['action'] == 'deactivate-all') {
143+               check_admin_referer('deactivate-all');
144+               $current = get_option('active_plugins');
145+               
146+               foreach ($current as $plugin) {
147+                       array_splice($current, array_search($plugin, $current), 1);
148+                       do_action('deactivate_' . $plugin);
149+               }
150+               
151+               update_option('active_plugins', array());
152+               wp_redirect('plugins.php?deactivate-all=true');
153+       }
154+       exit;
155+}
156+
157+$title = __('Manage Plugins');
158+require_once('admin-header.php');
159+
160+// Clean up options
161+// If any plugins don't exist, axe 'em
162+
163+$check_plugins = get_option('active_plugins');
164+
165+// Sanity check.  If the active plugin list is not an array, make it an
166+// empty array.
167+if ( !is_array($check_plugins) ) {
168+       $check_plugins = array();
169+       update_option('active_plugins', $check_plugins);
170+}
171+
172+// If a plugin file does not exist, remove it from the list of active
173+// plugins.
174+foreach ($check_plugins as $check_plugin) {
175+       if (!file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin)) {
176+                       $current = get_option('active_plugins');
177+                       $key = array_search($check_plugin, $current);
178+                       if ( false !== $key && NULL !== $key ) {
179+                               unset($current[$key]);
180+                               update_option('active_plugins', $current);
181+                       }
182+       }
183+}
184+?>
185+<?php if ( isset($_GET['error']) ) : ?>
186+       <div id="message" class="updated fade"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p></div>
187+<?php elseif ( isset($_GET['activate']) ) : ?>
188+       <div id="message" class="updated fade"><p><?php _e('Plugin <strong>activated</strong>.') ?></p></div>
189+<?php elseif ( isset($_GET['deactivate']) ) : ?>
190+       <div id="message" class="updated fade"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
191+<?php elseif (isset($_GET['deactivate-all'])) : ?>
192+       <div id="message" class="updated fade"><p><?php _e('All plugins <strong>deactivated</strong>.'); ?></p></div>
193+<?php endif; ?>
194+
195+<div class="wrap">
196+<h2><?php _e('Plugin Management'); ?></h2>
197+<p><?php _e('Plugins extend and expand the functionality of WordPress. Once a plugin is installed, you may activate it or deactivate it here.'); ?></p>
198+<?php
199+
200+if ( get_option('active_plugins') )
201+       $current_plugins = get_option('active_plugins');
202+
203+$plugins = get_plugins();
204+/* Right after the plugins array is set so we can sort if its enabled */
205+wp_sort_plugins($plugins, TRUE);
206+
207+if (empty($plugins)) {
208+       echo '<p>';
209+       _e("Couldn&#8217;t open plugins directory or there are no plugins available."); // TODO: make more helpful
210+       echo '</p>';
211+} else {
212+?>
213+<table class="widefat plugins">
214+       <thead>
215+       <tr>
216+               <th><?php _e('Plugin'); ?></th>
217+               <th style="text-align: center"><?php _e('Version'); ?></th>
218+               <th><?php _e('Description'); ?></th>
219+               <th style="text-align: center"<?php if ( current_user_can('edit_plugins') ) echo ' colspan="2"'; ?>><?php _e('Action'); ?></th>
220+       </tr>
221+       </thead>
222+<?php
223+       $style = '';
224+
225+       foreach($plugins as $plugin_file => $plugin_data) {
226+               $style = ('class="alternate"' == $style|| 'class="alternate active"' == $style) ? '' : 'alternate';
227+
228+               if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) {
229+                       $toggle = "<a href='" . wp_nonce_url("plugins.php?action=deactivate&amp;plugin=$plugin_file", 'deactivate-plugin_' . $plugin_file) . "' title='".__('Deactivate this plugin')."' class='delete'>".__('Deactivate')."</a>";
230+                       $plugin_data['Title'] = "<strong>{$plugin_data['Title']}</strong>";
231+                       $style .= $style == 'alternate' ? ' active' : 'active';
232+               } else {
233+                       $toggle = "<a href='" . wp_nonce_url("plugins.php?action=activate&amp;plugin=$plugin_file", 'activate-plugin_' . $plugin_file) . "' title='".__('Activate this plugin')."' class='edit'>".__('Activate')."</a>";
234+               }
235+
236+               $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
237+
238+               // Sanitize all displayed data
239+               $plugin_data['Title']       = wp_kses($plugin_data['Title'], $plugins_allowedtags);
240+               $plugin_data['Version']     = wp_kses($plugin_data['Version'], $plugins_allowedtags);
241+               $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags);
242+               $plugin_data['Author']      = wp_kses($plugin_data['Author'], $plugins_allowedtags);
243+
244+               if ( $style != '' )
245+                       $style = 'class="' . $style . '"';
246+               if ( is_writable(ABSPATH . PLUGINDIR . '/' . $plugin_file) )
247+                       $edit = "<a href='plugin-editor.php?file=$plugin_file' title='".__('Open this file in the Plugin Editor')."' class='edit'>".__('Edit')."</a>";
248+               else
249+                       $edit = '';
250+
251+               echo "
252+       <tr $style>
253+               <td class='name'>{$plugin_data['Title']}</td>
254+               <td class='vers'>{$plugin_data['Version']}</td>
255+               <td class='desc'><p>{$plugin_data['Description']} <cite>".sprintf(__('By %s'), $plugin_data['Author']).".</cite></p></td>
256+               <td class='togl'>$toggle</td>";
257+               if ( current_user_can('edit_plugins') )
258+               echo "
259+               <td>$edit</td>";
260+               echo"
261+       </tr>";
262+       }
263+?>
264+
265+<tr>
266+       <td colspan="5" align="right"><a href="<?php echo wp_nonce_url('plugins.php?action=deactivate-all', 'deactivate-all'); ?>"><?php _e('Deactivate All Plugins'); ?></a></td>
267+</tr>
268+
269+</table>
270+<?php
271+}
272+?>
273+
274+<p><?php printf(__('If something goes wrong with a plugin and you can&#8217;t use WordPress, delete or rename that file in the <code>%s</code> directory and it will be automatically deactivated.'), PLUGINDIR); ?></p>
275+
276+<h2><?php _e('Get More Plugins'); ?></h2>
277+<p><?php _e('You can find additional plugins for your site in the <a href="http://wordpress.org/extend/plugins/">WordPress plugin directory</a>.'); ?></p>
278+<p><?php printf(__('To install a plugin you generally just need to upload the plugin file into your <code>%s</code> directory. Once a plugin is uploaded, you may activate it here.'), PLUGINDIR); ?></p>
279+
280+</div>
281+
282+<?php
283+include('admin-footer.php');
284+?>
285\ No newline at end of file