Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
cutoff attempts to comment through wp-comments-post.php if Comments B…
Browse files Browse the repository at this point in the history
…ox enabled for the post type of the comment post ID
  • Loading branch information
niallkennedy committed Mar 23, 2013
1 parent 7a94756 commit f28ced5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
20 changes: 19 additions & 1 deletion facebook.php
Expand Up @@ -99,6 +99,7 @@ public function __construct() {
$this->admin_init();
} else {
add_action( 'wp_enqueue_scripts', array( &$this, 'register_js_sdk' ), 1 );
add_action( 'init', array( &$this, 'public_early_init' ), 1, 0 );
add_action( 'wp', array( &$this, 'public_init' ) );
}
}
Expand Down Expand Up @@ -265,6 +266,22 @@ public function get_php_sdk() {
) );
}

/**
* Add overrides early in the WordPress loading process for front-end views
*
* @since 1.3.1
*/
public function public_early_init() {
// add possible comments submission override if Comments Box enabled for one or more post types
if ( get_option( 'facebook_comments_enabled' ) ) {
if ( ! class_exists( 'Facebook_Comments' ) )
require_once( $this->plugin_directory . 'social-plugins/class-facebook-comments.php' );

// cutoff new comment attempts for post types under management by Comments Box
add_action( 'pre_comment_on_post', array( 'Facebook_Comments', 'pre_comment_on_post' ), 1, 1 );
}
}

/**
* Intialize the public, front end views
*
Expand All @@ -289,9 +306,10 @@ public function public_init() {
if ( ! class_exists( 'Facebook_Comments' ) )
require_once( $this->plugin_directory . 'social-plugins/class-facebook-comments.php' );

// treat as if comments are open for post types with comments under management by Comments Box
add_filter( 'comments_open', array( 'Facebook_Comments', 'comments_open_filter' ), 10, 2 );

// display comments number if used in template
// display comments number XFBML for JS SDK interpretation if used in template
add_filter( 'comments_number', array( 'Facebook_Comments', 'comments_number_filter' ), 10, 2 );
}

Expand Down
17 changes: 17 additions & 0 deletions social-plugins/class-facebook-comments.php
Expand Up @@ -63,6 +63,23 @@ public static function comments_open_filter( $open, $post_id = null ) {
return $open;
}

/**
* Kill attempts to comment on a post managed by Facebook Comments Box
*
* @since 1.3.1
* @param int post_id post identifer
*/
public static function pre_comment_on_post( $post_id ) {
if ( ! $post_id )
return;
$_post = get_post( $post_id );
if ( $_post && self::comments_enabled_for_post_type( $_post ) ) {
// match comments closed message and behavior
do_action( 'comment_closed', $post_id );
wp_die( __('Sorry, comments are closed for this item.') );
}
}

/**
* Overrides text displayed with comments number, inserting Facebook XFBML to be replaced by a number with the Facebook JavaScript SDK
*
Expand Down

0 comments on commit f28ced5

Please sign in to comment.