Browse files

Merge branch 'master' of github.com:Automattic/developer

  • Loading branch information...
2 parents 7c7799d + d9a3ace commit 57aa4668a9169ea874c6a310cb8cccdba22c3a95 @danielbachhuber danielbachhuber committed Aug 26, 2012
Showing with 170 additions and 164 deletions.
  1. +154 −152 developer.js
  2. +16 −12 developer.php
View
306 developer.js
@@ -1,153 +1,155 @@
-function a8c_developer_lightbox() {
- (function($){
- function make_colorbox( href, transition ) {
- $.colorbox({
- inline: true,
- href: href,
- title: a8c_developer_i18n.lightbox_title,
- innerWidth: 500,
- maxHeight: '100%',
- transition: transition
- });
- }
-
- make_colorbox( '#a8c-developer-setup-dialog-step-1', 'none' );
-
- $('#a8c-developer-setup-dialog-step-1-form').submit( function(e) {
- var form = this;
-
- $('#a8c-developer-setup-dialog-step-1-submit').val( a8c_developer_i18n.saving );
-
- if ( 'yes' != a8c_developer_i18n.go_to_step_2 )
- return;
-
- e.preventDefault();
-
- $.post( ajaxurl, $(form).serialize() )
- .success( function( result ) {
- // If there was an error with the AJAX save, then do a normal POST
- if ( '-1' == result ) {
- location.href = 'options-general.php?page=' + a8c_developer_i18n.settings_slug + '&a8cdev_errorsaving=1';
- return;
- }
-
- // AJAX says no step 2 needed, so head to the settings page
- if ( 'redirect' == result ) {
- location.href = 'options-general.php?page=' + a8c_developer_i18n.settings_slug + '&updated=1';
- return;
- }
-
- // Display the AJAX reponse
- $('#a8c-developer-setup-dialog-step-2').html( result );
- make_colorbox( '#a8c-developer-setup-dialog-step-2' );
- })
- ;
- });
- })(jQuery);
-}
-
-function a8c_developer_bind_events() {
- (function($){
- $('.a8c-developer-button-install').click( function() {
- var button = this;
-
- $(button).html( a8c_developer_i18n.installing );
-
- $.post( ajaxurl, {
- 'action': 'a8c_developer_install_plugin',
- '_ajax_nonce': $(button).attr('data-nonce'),
- 'plugin_slug': $(button).attr('data-pluginslug')
- } )
- .success( function( result ) {
- if ( '1' == result ) {
- $(button).html( a8c_developer_i18n.installed );
- $(button).unbind('click').prop('disabled', true);
- } else {
- $(button).html( a8c_developer_i18n.error );
- }
- })
- .error( function() {
- $(button).html( a8c_developer_i18n.error );
- })
- ;
- });
-
- $('.a8c-developer-button-activate').click( function() {
- var button = this;
-
- $(button).html( a8c_developer_i18n.activating );
-
- $.post( ajaxurl, {
- 'action': 'a8c_developer_activate_plugin',
- '_ajax_nonce': $(button).attr('data-nonce'),
- 'path': $(button).attr('data-path')
- } )
- .success( function( result ) {
- if ( '1' == result ) {
- $(button).html( a8c_developer_i18n.activated );
- $(button).unbind('click').prop('disabled', true);
- } else {
- $(button).html( a8c_developer_i18n.error );
- }
- })
- .error( function() {
- $(button).html( a8c_developer_i18n.error );
- })
- ;
- });
- })(jQuery);
-}
-
-function a8c_developer_bind_settings_events() {
- (function($){
- $('.a8c-developer-button-install').click( function() {
- var button = this;
-
- $(button).html( a8c_developer_i18n.installing );
-
- $.post( ajaxurl, {
- 'action': 'a8c_developer_install_plugin',
- '_ajax_nonce': $(button).attr('data-nonce'),
- 'plugin_slug': $(button).attr('data-pluginslug')
- } )
- .success( function( result ) {
- if ( '1' == result ) {
- $(button).html( a8c_developer_i18n.INSTALLED );
- } else {
- $(button).html( a8c_developer_i18n.ERROR );
- }
- })
- .error( function() {
- $(button).html( a8c_developer_i18n.ERROR );
- })
- ;
-
- return false;
- });
-
- $('.a8c-developer-button-activate').click( function() {
- var button = this;
-
- $(button).html( a8c_developer_i18n.activating );
-
- $.post( ajaxurl, {
- 'action': 'a8c_developer_activate_plugin',
- '_ajax_nonce': $(button).attr('data-nonce'),
- 'path': $(button).attr('data-path')
- } )
- .success( function( result ) {
- if ( '1' == result ) {
- $(button).replaceWith("<span class='a8c-developer-active'>" + a8c_developer_i18n.ACTIVE + "</span>");
- } else {
- $(button).html( a8c_developer_i18n.ERROR );
- }
- })
- .error( function() {
- $(button).html( a8c_developer_i18n.ERROR );
- })
- ;
-
- return false;
- });
- })(jQuery);
+function a8c_developer_lightbox() {
+ (function($){
+ function make_colorbox( href, transition ) {
+ $.colorbox({
+ inline: true,
+ href: href,
+ title: a8c_developer_i18n.lightbox_title,
+ innerWidth: 500,
+ maxHeight: '100%',
+ transition: transition
+ });
+ }
+
+ make_colorbox( '#a8c-developer-setup-dialog-step-1', 'none' );
+
+ $('#a8c-developer-setup-dialog-step-1-form').submit( function(e) {
+ var form = this;
+
+ $('#a8c-developer-setup-dialog-step-1-submit').val( a8c_developer_i18n.saving );
+
+ if ( 'yes' != a8c_developer_i18n.go_to_step_2 )
+ return;
+
+ e.preventDefault();
+
+ $.post( ajaxurl, $(form).serialize() )
+ .success( function( result ) {
+ // If there was an error with the AJAX save, then do a normal POST
+ if ( '-1' == result ) {
+ location.href = 'options-general.php?page=' + a8c_developer_i18n.settings_slug + '&a8cdev_errorsaving=1';
+ return;
+ }
+
+ // AJAX says no step 2 needed, so head to the settings page
+ if ( 'redirect' == result ) {
+ location.href = 'options-general.php?page=' + a8c_developer_i18n.settings_slug + '&updated=1';
+ return;
+ }
+
+ // Display the AJAX reponse
+ $('#a8c-developer-setup-dialog-step-2').html( result );
+ make_colorbox( '#a8c-developer-setup-dialog-step-2' );
+ })
+ ;
+ });
+ })(jQuery);
+}
+
+function a8c_developer_bind_events() {
+ (function($){
+ $('.a8c-developer-button-install').click( function() {
+ var button = this;
+
+ $(button).html( a8c_developer_i18n.installing );
+
+ $.post( ajaxurl, {
+ 'action': 'a8c_developer_install_plugin',
+ '_ajax_nonce': $(button).attr('data-nonce'),
+ 'plugin_slug': $(button).attr('data-pluginslug')
+ } )
+ .success( function( result ) {
+ if ( '1' === result ) {
+ $(button).html( a8c_developer_i18n.installed );
+ $(button).unbind('click').prop('disabled', true);
+ } else {
+ alert( result );
+ $(button).html( a8c_developer_i18n.error );
+ }
+ })
+ .error( function() {
+ $(button).html( a8c_developer_i18n.error );
+ })
+ ;
+ });
+
+ $('.a8c-developer-button-activate').click( function() {
+ var button = this;
+
+ $(button).html( a8c_developer_i18n.activating );
+
+ $.post( ajaxurl, {
+ 'action': 'a8c_developer_activate_plugin',
+ '_ajax_nonce': $(button).attr('data-nonce'),
+ 'path': $(button).attr('data-path')
+ } )
+ .success( function( result ) {
+ if ( '1' === result ) {
+ $(button).html( a8c_developer_i18n.activated );
+ $(button).unbind('click').prop('disabled', true);
+ } else {
+ alert( result );
+ $(button).html( a8c_developer_i18n.error );
+ }
+ })
+ .error( function() {
+ $(button).html( a8c_developer_i18n.error );
+ })
+ ;
+ });
+ })(jQuery);
+}
+
+function a8c_developer_bind_settings_events() {
+ (function($){
+ $('.a8c-developer-button-install').click( function() {
+ var button = this;
+
+ $(button).html( a8c_developer_i18n.installing );
+
+ $.post( ajaxurl, {
+ 'action': 'a8c_developer_install_plugin',
+ '_ajax_nonce': $(button).attr('data-nonce'),
+ 'plugin_slug': $(button).attr('data-pluginslug')
+ } )
+ .success( function( result ) {
+ if ( '1' == result ) {
+ $(button).html( a8c_developer_i18n.INSTALLED );
+ } else {
+ $(button).html( a8c_developer_i18n.ERROR );
+ }
+ })
+ .error( function() {
+ $(button).html( a8c_developer_i18n.ERROR );
+ })
+ ;
+
+ return false;
+ });
+
+ $('.a8c-developer-button-activate').click( function() {
+ var button = this;
+
+ $(button).html( a8c_developer_i18n.activating );
+
+ $.post( ajaxurl, {
+ 'action': 'a8c_developer_activate_plugin',
+ '_ajax_nonce': $(button).attr('data-nonce'),
+ 'path': $(button).attr('data-path')
+ } )
+ .success( function( result ) {
+ if ( '1' == result ) {
+ $(button).replaceWith("<span class='a8c-developer-active'>" + a8c_developer_i18n.ACTIVE + "</span>");
+ } else {
+ $(button).html( a8c_developer_i18n.ERROR );
+ }
+ })
+ .error( function() {
+ $(button).html( a8c_developer_i18n.ERROR );
+ })
+ ;
+
+ return false;
+ });
+ })(jQuery);
}
View
28 developer.php
@@ -60,6 +60,10 @@ public function init() {
}
public function admin_init() {
+ if ( ! empty( $_GET['developer_plugin_reset'] ) && current_user_can( 'manage_options' ) ) {
+ delete_option( self::OPTION );
+ }
+
$this->recommended_plugins = array(
'debug-bar' => array(
'project_type' => 'all',
@@ -193,7 +197,7 @@ public function admin_init() {
if ( ! get_option( self::OPTION ) ) {
if ( ! empty( $_GET['a8cdev_errorsaving'] ) ) {
add_settings_error( self::PAGE_SLUG, self::PAGE_SLUG . '_error_saving', __( 'Error saving settings. Please try again.', 'a8c-developer' ) );
- } elseif ( current_user_can( 'manage_options' ) ) {
+ } elseif ( ! is_network_admin() && current_user_can( 'manage_options' ) ) {
add_action( 'admin_enqueue_scripts', array( $this, 'load_lightbox_scripts_and_styles' ) );
add_action( 'admin_footer', array( $this, 'output_setup_box_html' ) );
}
@@ -255,7 +259,7 @@ public function output_setup_box_html() {
<p>
<label>
<input type="radio" name="a8c_developer_project_type" value="<?php echo esc_attr( $project_slug ); ?>" <?php checked( $i, 1 ); ?> />
- <?php echo esc_html( $project_description ); ?>
+ <?php echo $project_description; ?>
</label>
</p>
<?php endforeach; ?>
@@ -328,19 +332,19 @@ public function ajax_handler( $action ) {
case 'a8c_developer_install_plugin':
if ( empty( $_POST['plugin_slug'] ) )
- die( '-1' );
+ die( __( 'ERROR: No slug was passed to the AJAX callback.', 'a8c-developer' ) );
check_ajax_referer( 'a8c_developer_install_plugin_' . $_POST['plugin_slug'] );
if ( ! current_user_can( 'install_plugins' ) || ! current_user_can( 'activate_plugins' ) )
- die( '-1' );
+ die( __( 'ERROR: You lack permissions to install and/or activate plugins.', 'a8c-developer' ) );
include_once ( ABSPATH . 'wp-admin/includes/plugin-install.php' );
$api = plugins_api( 'plugin_information', array( 'slug' => $_POST['plugin_slug'], 'fields' => array( 'sections' => false ) ) );
if ( is_wp_error( $api ) )
- die( '-1' );
+ die( sprintf( __( 'ERROR: Error fetching plugin information: %s', 'a8c-developer' ), get_error_message( $api ) ) );
$upgrader = new Plugin_Upgrader( new Automattic_Developer_Empty_Upgrader_Skin( array(
'nonce' => 'install-plugin_' . $_POST['plugin_slug'],
@@ -351,28 +355,28 @@ public function ajax_handler( $action ) {
$install_result = $upgrader->install( $api->download_link );
if ( ! $install_result || is_wp_error( $install_result ) )
- die( '-1' );
+ die( sprintf( __( 'ERROR: Failed to install plugin: %s', 'a8c-developer' ), get_error_message( $api ) ) );
$activate_result = activate_plugin( $this->get_path_for_recommended_plugin( $_POST['plugin_slug'] ) );
if ( is_wp_error( $activate_result ) )
- die( '-1' );
+ die( sprintf( __( 'ERROR: Failed to activate plugin: %s', 'a8c-developer' ), get_error_message( $api ) ) );
exit( '1' );
case 'a8c_developer_activate_plugin':
if ( empty( $_POST['path'] ) )
- die( '-1' );
+ die( __( 'ERROR: No slug was passed to the AJAX callback.', 'a8c-developer' ) );
check_ajax_referer( 'a8c_developer_activate_plugin_' . $_POST['path'] );
if ( ! current_user_can( 'activate_plugins' ) )
- die( '-1' );
+ die( __( 'ERROR: You lack permissions to activate plugins.', 'a8c-developer' ) );
$activate_result = activate_plugin( $_POST['path'] );
if ( is_wp_error( $activate_result ) )
- die( '-1' );
+ die( sprintf( __( 'ERROR: Failed to activate plugin: %s', 'a8c-developer' ), get_error_message( $api ) ) );
exit( '1' );
}
@@ -618,9 +622,9 @@ public function is_recommended_plugin_installed( $slug ) {
private function get_project_types() {
return array(
- 'wporg' => __( 'Plugin for a self-hosted WordPress installation', 'a8c-developer' ),
+ 'wporg' => __( 'Plugin for a self-hosted WordPress installation', 'a8c-developer' ),
'wporg-theme' => __( 'Theme for a self-hosted WordPress installation', 'a8c-developer' ),
- 'wpcom-vip' => __( 'Theme for a <a href="http://vip.wordpress.com" target="_blank">WordPress.com VIP</a> site', 'a8c-developer' ),
+ 'wpcom-vip' => __( 'Theme for a <a href="http://vip.wordpress.com" target="_blank">WordPress.com VIP</a> site', 'a8c-developer' ),
);
}
}

0 comments on commit 57aa466

Please sign in to comment.