Permalink
Browse files

login req

  • Loading branch information...
1 parent f0dc78c commit 13dd4f955eaadb9eff9704121c1e393bc19177d7 @benbalter benbalter committed Sep 17, 2012
Showing with 36 additions and 4 deletions.
  1. +9 −1 js/js.dev.js
  2. +27 −3 kickstart.php
View
@@ -11,7 +11,15 @@ jQuery(document).ready(function($){
action: 'kickstart_vote',
post_ID: $(this).parent().attr( 'data-post-id' )
},
- success: function( data ) { score.text( data ); }
+ success: function( data ) { score.text( data ); },
+ error: function( a, b, error ) {
+
+ if ( error != 'Forbidden' )
+ return;
+
+ document.location.href = kickstart.loginURL;
+
+ }
})
});
View
@@ -38,7 +38,7 @@
*/
//load templating functions
-include dirname( __FILE__ ) . 'templating.php';
+include dirname( __FILE__ ) . '/templating.php';
class Kickstart {
@@ -58,6 +58,7 @@ function __construct() {
add_action( 'init', array( $this, 'register_cpt' ) );
add_action( 'init', array( $this, 'register_cts' ) );
add_action( 'wp_ajax_kickstart_vote', array( $this, 'ajax_vote_handler' ) );
+ add_action( 'wp_ajax_nopriv_kickstart_vote', array( $this, 'ajax_must_login_handler' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_js' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_css' ) );
add_filter( 'the_content', array( $this, 'content_filter' ) );
@@ -66,6 +67,7 @@ function __construct() {
add_filter( 'feed_link', array( $this, 'feed_link_filter' ) );
add_filter( 'parse_request', array( $this, 'request_filter' ) );
add_action( 'save_post', array( $this, 'calculate_score_on_save' ) );
+ add_action( 'login_message', array( $this, 'login_message' ) );
register_activation_hook( __FILE__, 'flush_rewrite_rules' );
@@ -340,12 +342,13 @@ function enqueue_js() {
$js = ( WP_DEBUG ) ? 'js/js.dev.js' : 'js/js.js';
wp_enqueue_script( 'kickstart', plugins_url( $js, __FILE__ ), array( 'jquery' ), $this->version, true );
-
+
$l10n = array(
'ajaxEndpoint' => admin_url( 'admin-ajax.php' ),
+ 'loginURL' => add_query_arg( 'message', 'kickstart_login_required', wp_login_url( esc_url( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) ) ),
);
- if ( isset( $post->ID ) )
+ if ( isset( $post->ID ) )
$l10n['post_ID'] = $post->ID;
wp_localize_script( 'kickstart', 'kickstart', $l10n );
@@ -469,6 +472,27 @@ function calculate_score_on_save( $post ) {
}
+ function ajax_must_login_handler() {
+
+ status_header( 403 );
+ die( -1 );
+
+ }
+
+ function login_message( $message ) {
+
+ if ( !$_GET['message'] )
+ return $message;
+
+ if ( $_GET['message'] != 'kickstart_login_required' )
+ return $message;
+
+ $msg .= '<div class="error" style="margin-bottom: 20px; font-weight: bold; padding: 5px; ">' . __( 'You must login or register below before you can vote or comment', 'kickstart' ) . '</div>';
+
+ return $msg;
+
+ }
+
}
$kickstart = new Kickstart();

0 comments on commit 13dd4f9

Please sign in to comment.