forked from Japh/wp-butler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-butler.php
127 lines (107 loc) · 5.12 KB
/
wp-butler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/*
Plugin Name: WP Butler
Plugin URI: http://wpbutler.com
Description: WP Butler brings you what you need in the Wordpress Admin. An autocomplete menu to let you jump to all the common tasks you may need to perform, just hit <code>shift+alt+b</code>!
Version: 1.3
Author: Japh
Author URI: http://japh.com.au
License: GPL2
*/
/* Copyright 2013 Japh (email : wordpress@japh.com.au)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @package WP-Butler
* @version 1.3
*/
class Japh_Butler {
public $version = '1.3';
function __construct() {
if ( is_admin() ) {
add_action( 'admin_enqueue_scripts', array( $this, 'wpbutler_enqueue' ) );
add_action( 'admin_footer', array( $this, 'wpbutler_footer' ) );
add_action( 'wp_ajax_wp_butler_actions', array( $this, 'wpbutler_actions' ) );
}
}
function wpbutler_footer() {
echo '<div id="wp-butler-dialog" title="What would you like to do?">';
echo ' <p>';
echo ' <form id="wp-butler-form"><input type="text" placeholder="Just start typing..." id="wp-butler-field"><input type="hidden" id="wp-butler-nonce" name="wp-butler-nonce" value="' . wp_create_nonce( 'wp_butler_nonce' ) . '" /></form>';
echo ' </p>';
echo '</div>';
}
function wpbutler_enqueue() {
// Enqueue styles
if ( 'classic' == get_user_option( 'admin_color') ) {
wp_enqueue_style ( 'butler-jquery-ui-css', plugin_dir_url( __FILE__ ) . 'jquery-ui-css/jquery-ui-classic.css' );
}
else {
wp_enqueue_style ( 'butler-jquery-ui-css', plugin_dir_url( __FILE__ ) . 'jquery-ui-css/jquery-ui-fresh.css' );
}
wp_enqueue_style( 'wpbutler', plugins_url( 'wpbutler.css', __FILE__ ) );
// Enqueue scripts
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
wp_enqueue_script( 'jquery-ui-dialog' );
wp_enqueue_script( 'keystroke', plugins_url( 'keystroke/jquery.keystroke.min.js', __FILE__ ), array( 'jquery' ), '0d77ac267da80cbe0e0ca8e6fe8b5b2bb8ee1bac', true );
wp_enqueue_script( 'wpbutler', plugins_url( 'wpbutler.js', __FILE__ ), array( 'jquery-ui-core', 'jquery-ui-autocomplete', 'jquery-ui-dialog', 'keystroke' ), $this->version, true );
}
function wpbutler_actions() {
$return = array();
$term = $_REQUEST['term'];
$nonce = $_REQUEST['_nonce'];
if ( is_admin() && wp_verify_nonce( $nonce, 'wp_butler_nonce' ) ) {
$butler_actions = array(
array( "label" => "Go to Dashboard", "url" => "index.php" ),
array( "label" => "Add Page", "url" => "post-new.php?post_type=page" ),
array( "label" => "Add Post", "url" => "post-new.php?post_type=post" ),
array( "label" => "New Page", "url" => "post-new.php?post_type=page" ),
array( "label" => "New Post", "url" => "post-new.php?post_type=post" ),
array( "label" => "Edit Posts", "url" => "edit.php" ),
array( "label" => "Edit Pages", "url" => "edit.php?post_type=page" ),
array( "label" => "View All Posts", "url" => "edit.php" ),
array( "label" => "View All Pages", "url" => "edit.php?post_type=page" ),
array( "label" => "Media Library", "url" => "upload.php" ),
array( "label" => "Add Media", "url" => "media-new.php" ),
array( "label" => "Upload Media", "url" => "media-new.php" ),
array( "label" => "New Media Item", "url" => "media-new.php" ),
array( "label" => "Approve Comments", "url" => "edit-comments.php" ),
array( "label" => "View Comments", "url" => "edit-comments.php" ),
array( "label" => "Change Theme", "url" => "themes.php" ),
array( "label" => "Install Theme", "url" => "theme-install.php" ),
array( "label" => "Add Widgets", "url" => "widgets.php" ),
array( "label" => "Edit Widgets", "url" => "widgets.php" ),
array( "label" => "Add Menu", "url" => "nav-menus.php" ),
array( "label" => "Edit Menus", "url" => "nav-menus.php" ),
array( "label" => "Edit Settings", "url" => "options-general.php" ),
array( "label" => "Edit Permalinks", "url" => "options-permalink.php" ),
array( "label" => "Install Plugin", "url" => "plugin-install.php" ),
array( "label" => "View Plugins", "url" => "plugins.php" ),
array( "label" => "View Users", "url" => "users.php" ),
array( "label" => "Add New User", "url" => "user-new.php" ),
);
$butler_actions = apply_filters( 'wp_butler_ajax_actions', $butler_actions );
foreach ( $butler_actions as $value ) {
if ( preg_match( '/' . $term . '/i', $value['label'] ) ) {
$return[] = array(
'label' => $value['label'],
'url' => $value['url']
);
}
}
}
wp_die( json_encode( $return ) );
}
}
$japh_butler = new Japh_Butler();