The WP Remote WordPress Plugin - Version 0.3

Version Description

Download this release

Release Info

Developer willmot
Plugin Icon 128x128 The WP Remote WordPress Plugin
Version 0.3
Comparing to
See all releases

Code changes from version 0.2 to 0.3

Files changed (5) hide show
  1. plugin.php +4 -69
  2. readme.txt +2 -2
  3. wpr.api.php +40 -0
  4. wpr.extend-xmlrpc.php +74 -0
  5. wpr.plugin.php +54 -0
plugin.php CHANGED
@@ -3,77 +3,12 @@
3
  /*
4
  Plugin Name: WP Remote
5
  Description: Extends the functionality of <a href="http://www.wpremote.com">WP Remote</a>.
6
- Version: 0.2
7
  Author: willmot
8
  Author URI: http://humanmade.co.uk/
9
  */
10
 
11
- function wpr_attach_new_xmlrpc($methods) {
12
-
13
- if( !isset( $methods['wp.getPluginList'] ) ) {
14
- $methods['wp.getPluginList'] = 'wpr_get_plugin_list';
15
- }
16
-
17
- return $methods;
18
- }
19
-
20
- add_action('xmlrpc_methods', 'wpr_attach_new_xmlrpc');
21
 
22
- function wpr_get_plugin_list( $args ) {
23
-
24
- $blog_id = (int) $args[0];
25
- $username = $args[1];
26
- $password = $args[2];
27
-
28
- //check if xmlrpc is enabled
29
- if ( !get_option( 'enable_xmlrpc' ) ) {
30
- return new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this blog. An admin user can enable them at %s'), admin_url('options-writing.php') ) );
31
- }
32
-
33
- //authenticate the user
34
- $user = wp_authenticate($username, $password);
35
-
36
- if (is_wp_error($user)) {
37
- return new IXR_Error(403, __('Bad login/pass combination.'));
38
- }
39
-
40
- set_current_user( $user->ID );
41
-
42
- //don't allow anyone to get them via xml rpc
43
- if ( !current_user_can( 'activate_plugins' ) ) {
44
- return new IXR_Error( 401, __( 'Sorry, you cannot manage plugins.' ) );
45
- }
46
-
47
- do_action( 'xmlrpc_call', 'wp.getPluginList' );
48
-
49
- $plugins = get_plugins( );
50
-
51
- if( function_exists( 'get_site_transient' ) )
52
- $current = get_site_transient( 'update_plugins' );
53
- else
54
- $current = get_transient( 'update_plugins' );
55
-
56
- foreach ( (array) $plugins as $plugin_file => $plugin ) {
57
-
58
- $new_version = $current->response[$plugin_file]->new_version;
59
-
60
- if ( is_plugin_active( $plugin_file ) ) {
61
- $plugins[$plugin_file]['active'] = true;
62
- } else {
63
- $plugins[$plugin_file]['active'] = false;
64
- }
65
-
66
- if ( $new_version ) {
67
- $plugins[$plugin_file]['latest_version'] = $new_version;
68
- } else {
69
- $plugins[$plugin_file]['latest_version'] = $plugin['Version'];
70
- }
71
- }
72
-
73
- return $plugins;
74
-
75
-
76
- }
77
-
78
-
79
- ?>
3
  /*
4
  Plugin Name: WP Remote
5
  Description: Extends the functionality of <a href="http://www.wpremote.com">WP Remote</a>.
6
+ Version: 0.3
7
  Author: willmot
8
  Author URI: http://humanmade.co.uk/
9
  */
10
 
11
+ require_once( 'wpr.extend-xmlrpc.php' );
12
+ require_once( 'wpr.plugin.php' );
 
 
 
 
 
 
 
 
13
 
14
+ tj_add_rewrite_rule( 'wpremote-api', null, dirname( __FILE__ ) . '/wpr.api.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -3,10 +3,10 @@ Contributors: willmot, joehoyle
3
  Tags: wpremote, remote, xmlrpc
4
  Requires at least: 2.7
5
  Tested up to: 3.0
6
- Stable tag: 0.2
7
 
8
  Adds extra functionality for use with WP Remote
9
 
10
  == Description ==
11
 
12
- The WP Remote WordPress Plugin adds some extra features to WordPress for the use with [WP Remote](http://www.wpremote.com/)
3
  Tags: wpremote, remote, xmlrpc
4
  Requires at least: 2.7
5
  Tested up to: 3.0
6
+ Stable tag: 0.3
7
 
8
  Adds extra functionality for use with WP Remote
9
 
10
  == Description ==
11
 
12
+ The WP Remote WordPress Plugin if required for the use with [WP Remote](http://www.wpremote.com/)
wpr.api.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if( !urlencode( $_GET['api_key'] ) || urlencode( $_GET['api_key'] ) !== get_option( 'wpr_api_key' ) || !isset( $_GET['actions'] ) ) {
4
+ echo json_encode( 'bad-api-key' );
5
+ exit;
6
+ }
7
+
8
+ $actions = explode( ',', $_GET['actions'] );
9
+ $actions = array_flip( $actions );
10
+
11
+ wp_set_current_user( 1 );
12
+
13
+ foreach( $actions as $action => $value ) :
14
+
15
+ switch( $action ) :
16
+
17
+ //Plugin version
18
+ case 'get_plugin_version' :
19
+ $actions[$action] = '1.1';
20
+ break;
21
+
22
+ case 'get_wp_version' :
23
+
24
+ global $wp_version;
25
+ $actions[$action] = (string) $wp_version;
26
+
27
+ break;
28
+
29
+ case 'get_plugins' :
30
+ $actions[$action] = _wpr_get_plugins();
31
+ break;
32
+
33
+ default :
34
+ $actions[$action] = 'not-implemented';
35
+
36
+ endswitch;
37
+
38
+ endforeach;
39
+
40
+ echo json_encode( $actions );
wpr.extend-xmlrpc.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function wpr_attach_new_xmlrpc($methods) {
4
+
5
+ if( !isset( $methods['wp.getPluginList'] ) ) {
6
+ $methods['wp.getPluginList'] = 'wpr_get_plugin_list';
7
+ }
8
+
9
+ return $methods;
10
+ }
11
+
12
+ add_action('xmlrpc_methods', 'wpr_attach_new_xmlrpc');
13
+
14
+ function wpr_get_plugin_list( $args ) {
15
+
16
+ $blog_id = (int) $args[0];
17
+ $username = $args[1];
18
+ $password = $args[2];
19
+
20
+ //check if xmlrpc is enabled
21
+ if ( !get_option( 'enable_xmlrpc' ) ) {
22
+ return new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this blog. An admin user can enable them at %s'), admin_url('options-writing.php') ) );
23
+ }
24
+
25
+ //authenticate the user
26
+ $user = wp_authenticate($username, $password);
27
+
28
+ if (is_wp_error($user)) {
29
+ return new IXR_Error(403, __('Bad login/pass combination.'));
30
+ }
31
+
32
+ set_current_user( $user->ID );
33
+
34
+ //don't allow anyone to get them via xml rpc
35
+ if ( !current_user_can( 'activate_plugins' ) ) {
36
+ return new IXR_Error( 401, __( 'Sorry, you cannot manage plugins.' ) );
37
+ }
38
+
39
+ do_action( 'xmlrpc_call', 'wp.getPluginList' );
40
+
41
+ return _wpr_get_plugins();
42
+
43
+ }
44
+
45
+ function _wpr_get_plugins() {
46
+
47
+ require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
48
+
49
+ $plugins = get_plugins( );
50
+
51
+ if( function_exists( 'get_site_transient' ) )
52
+ $current = get_site_transient( 'update_plugins' );
53
+ else
54
+ $current = get_transient( 'update_plugins' );
55
+
56
+ foreach ( (array) $plugins as $plugin_file => $plugin ) {
57
+
58
+ $new_version = $current->response[$plugin_file]->new_version;
59
+
60
+ if ( is_plugin_active( $plugin_file ) ) {
61
+ $plugins[$plugin_file]['active'] = true;
62
+ } else {
63
+ $plugins[$plugin_file]['active'] = false;
64
+ }
65
+
66
+ if ( $new_version ) {
67
+ $plugins[$plugin_file]['latest_version'] = $new_version;
68
+ } else {
69
+ $plugins[$plugin_file]['latest_version'] = $plugin['Version'];
70
+ }
71
+ }
72
+
73
+ return $plugins;
74
+ }
wpr.plugin.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function wpr_setup_admin() {
4
+
5
+ //register the options page
6
+ wpr_register_settings();
7
+ add_options_page('WP Remote Settings', 'WP Remote', 'manage_options', 'wp-remote-options', 'wpr_options_page');
8
+
9
+ }
10
+ add_action('admin_menu', 'wpr_setup_admin');
11
+
12
+ function wpr_register_settings() {
13
+
14
+ register_setting( 'wpr-settings', 'wpr_api_key' );
15
+ }
16
+
17
+ function wpr_options_page() {
18
+
19
+ ?>
20
+
21
+ <div class="wrap">
22
+ <h2>WP Remote Settings</h2>
23
+
24
+ <form method="post" action="options.php">
25
+ <table class="form-table">
26
+
27
+ <tr valign="top">
28
+ <th scope="row"><strong>API Key</strong></th>
29
+ <td>
30
+ <input type="text" name="wpr_api_key" class="regular-text" value="<?php echo get_option('wpr_api_key', ''); ?>" /><br />
31
+ <span class="description">If you don't want to use XML-RPC authentication, you can enter your WP Remote API Key</span>
32
+ </td>
33
+ </tr>
34
+
35
+ </table>
36
+
37
+ <input type="hidden" name="action" value="update" />
38
+
39
+ <p class="submit">
40
+ <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
41
+ </p>
42
+
43
+ <?php
44
+ settings_fields( 'wpr-settings' );
45
+
46
+ // Output any sections defined for page sl-settings
47
+ do_settings_sections('wpr-settings');
48
+ ?>
49
+ </form>
50
+
51
+ </div>
52
+ <?php
53
+
54
+ }