Skip to content

Commit

Permalink
Merge pull request #10 from Automattic/one-click-jetpack
Browse files Browse the repository at this point in the history
One click Jetpack connection step.
  • Loading branch information
lezama committed Aug 22, 2014
2 parents 7e63872 + 2cd5ef1 commit 41f4a07
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
3 changes: 3 additions & 0 deletions jetpack-start.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

define( 'JETPACK_START_BASE_DIR', dirname( __FILE__ ) );
define( 'JETPACK_START_BASE_URL', plugins_url( 'jetpack-start', dirname( __FILE__ ) ) );
define( 'JETPACK_STEP_AUTO_REDIRECT', true );
define( 'JETPACK_STEP_AUTO_REDIRECT_SRC', 'custom_src' );


function jps_start() {
if (current_user_can_for_blog( get_current_blog_id(), 'switch_themes' ) ) {
Expand Down
5 changes: 4 additions & 1 deletion js/jetpack-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ var jetpackStartWizard = new ( Backbone.View.extend({
},

render: function() {
this.clear();
var currentStepView = this.currentStep().getView();
currentStepView.beforeRender();
this.clear();
jQuery( 'body' ).append( currentStepView.render().delegateEvents().el );
currentStepView.afterRender();
this.renderProgress();
Expand Down Expand Up @@ -112,6 +113,8 @@ var JetpackStartStepView = Backbone.View.extend({
return this;
},

beforeRender: function() {},

afterRender: function() {},

goToNextStep: function( event ) {
Expand Down
4 changes: 1 addition & 3 deletions steps/connect-jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Get out of the middle of the Jetpack - Wordpress.com handshake.
if ( isset( $_GET['page'] ) && $_GET['page'] == 'jetpack' && isset( $_GET['action'] ) && ( $_GET['action'] == 'register' || $_GET['action'] == 'authorize' ) ) {
add_filter( 'jetpack_start_render_wizard', '__return_false' );
set_transient( 'jetpack_tried_to_connect', true, HOUR_IN_SECONDS );
}

class Jetpack_Start_Step_connect_jetpack extends Jetpack_Start_Step {
Expand All @@ -18,7 +19,4 @@ function __construct() {
}
}

function get_jetpack() {
return Jetpack::init();
}
}
21 changes: 14 additions & 7 deletions views/steps/connect-jetpack.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script type="text/template" id="connect_jetpack_template">
<?php if ( ! defined( 'JETPACK_STEP_AUTO_REDIRECT' ) || get_transient( 'jetpack_tried_to_connect' ) ) : ?>
<div class="jetpack-hero">
<?php if ( ! empty( $step->label ) ) : ?>
<h1 class="jetpack-hero__title"><?php echo esc_html( $step->label ); ?></h1>
Expand All @@ -20,14 +21,14 @@
<div class="jetpack-hero__info">
<p class="step-description"><?php _e( 'Jetpack supercharges your self‑hosted WordPress site with the awesome cloud power of WordPress.com at no additional cost.', 'jetpack-start' ) ?></p>
<div class="jetpack-box">
<?php $connected = false; ?>
<a class="button--primary" href="<?php echo $step->get_jetpack()->build_connect_url() ?>" class="jetpack-link" target="_top"><?php echo __( 'Connect to WordPress.com', 'jetpack-start' ); ?></a>
<div class="skip">
<?php printf( __( ' or, <a href="%s" class="next">skip this step</a>', 'jetpack-start' ), home_url() ); ?>
</div>
<a class="button--primary" href="<?php echo Jetpack::init()->build_connect_url() ?>" class="jetpack-link" target="_top"><?php echo __( 'Connect to WordPress.com', 'jetpack-start' ); ?></a>
<div class="skip">
<?php printf( __( ' or, <a href="%s" class="next">skip this step</a>', 'jetpack-start' ), home_url() ); ?>
</div>
</div>
</div>
</div>
<?php endif ?>
</script>

<script>
Expand All @@ -37,7 +38,14 @@

events: {
"click a.next": "goToNextStep"
},

<?php if ( defined( 'JETPACK_STEP_AUTO_REDIRECT' ) && false === get_transient( 'jetpack_tried_to_connect' ) ) : ?>
beforeRender: function() {
window.location = '<?php echo add_query_arg( 'src', JETPACK_STEP_AUTO_REDIRECT_SRC, Jetpack::init()->build_connect_url( true ) ); ?>';
StepView.template_id = '#waiting-redirect';
}
<?php endif ?>

});

Expand All @@ -46,9 +54,8 @@
view: StepView,
slug: '<?php echo $step->slug; ?>',
sort: '<?php echo $step->sort; ?>',
connected: <?php echo $step->get_jetpack()->is_active() ? 'true' : 'false'; ?>,
conditional_display: function( step ) {
return ! step.get( 'connected' );
return <?php echo ( ! Jetpack::init()->is_active() && false === get_transient( 'jetpack_tried_to_connect' ) ) ? 'true' : 'false'; ?>;
}
} )
);
Expand Down

0 comments on commit 41f4a07

Please sign in to comment.