Skip to content

Commit

Permalink
Introduce some new hooks.
Browse files Browse the repository at this point in the history
Add some hooks at some key points in the liveblog flow which can be useful for manipulating the behaviour or things like stats tracking. Some hooks include:

* liveblog_insert_entry
* liveblog_update_entry
* liveblog_delete_entry
* liveblog_preview_entry
* liveblog_enable_post
* liveblog_disable_post
* etc.
  • Loading branch information
mjangda committed Sep 25, 2012
1 parent c3dc8bd commit 7e39692
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions liveblog.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public static function ajax_entries_between() {
// Get liveblog entries within the start and end boundaries // Get liveblog entries within the start and end boundaries
$entries = self::$entry_query->get_between_timestamps( $start_timestamp, $end_timestamp ); $entries = self::$entry_query->get_between_timestamps( $start_timestamp, $end_timestamp );
if ( empty( $entries ) ) { if ( empty( $entries ) ) {
do_action( 'liveblog_entry_request_empty' );

self::json_return( array( self::json_return( array(
'entries' => array(), 'entries' => array(),
'latest_timestamp' => null 'latest_timestamp' => null
Expand All @@ -254,6 +256,8 @@ public static function ajax_entries_between() {
'latest_timestamp' => $latest_timestamp, 'latest_timestamp' => $latest_timestamp,
); );


do_action( 'liveblog_entry_request', $result_for_json );

self::json_return( $result_for_json ); self::json_return( $result_for_json );
} }


Expand Down Expand Up @@ -382,20 +386,23 @@ public static function ajax_insert_entry() {
// Are we replacing an existing comment? // Are we replacing an existing comment?
if ( !empty( $replaces_comment_id ) ) { if ( !empty( $replaces_comment_id ) ) {


//
add_comment_meta( $new_comment_id, WPCOM_Liveblog_Entry::replaces_meta_key, $replaces_comment_id ); add_comment_meta( $new_comment_id, WPCOM_Liveblog_Entry::replaces_meta_key, $replaces_comment_id );


// Update an existing comment // Update an existing comment
if ( !empty( $entry_content ) ) { if ( !empty( $entry_content ) ) {
do_action( 'liveblog_update_entry', $replaces_comment_id, $new_comment_id, $post_id );
wp_update_comment( array( wp_update_comment( array(
'comment_ID' => $replaces_comment_id, 'comment_ID' => $replaces_comment_id,
'comment_content' => wp_filter_post_kses( $entry_content ), 'comment_content' => wp_filter_post_kses( $entry_content ),
) ); ) );


// Delete this comment // Delete this comment
} else { } else {
do_action( 'liveblog_delete_entry', $replaces_comment_id, $post_id );
wp_delete_comment( $replaces_comment_id ); wp_delete_comment( $replaces_comment_id );
} }
} else {
do_action( 'liveblog_insert_entry', $new_comment_id, $post_id );
} }


$entry = WPCOM_Liveblog_Entry::from_comment( get_comment( $new_comment_id ) ); $entry = WPCOM_Liveblog_Entry::from_comment( get_comment( $new_comment_id ) );
Expand All @@ -412,9 +419,13 @@ public static function ajax_insert_entry() {
function ajax_preview_entry() { function ajax_preview_entry() {
self::ajax_current_user_can_edit_liveblog(); self::ajax_current_user_can_edit_liveblog();
self::ajax_check_nonce(); self::ajax_check_nonce();

$entry_content = isset( $_REQUEST['entry_content'] ) ? $_REQUEST['entry_content'] : ''; $entry_content = isset( $_REQUEST['entry_content'] ) ? $_REQUEST['entry_content'] : '';
$entry_content = wp_filter_post_kses( $entry_content ); $entry_content = wp_filter_post_kses( $entry_content );
$entry_content = WPCOM_Liveblog_Entry::render_content( $entry_content ); $entry_content = WPCOM_Liveblog_Entry::render_content( $entry_content );

do_action( 'liveblog_preview_entry', $entry_content );

self::json_return( array( 'html' => $entry_content ) ); self::json_return( array( 'html' => $entry_content ) );
} }


Expand Down Expand Up @@ -648,13 +659,13 @@ public function save_meta_box( $post_id ) {
if ( empty( $_POST[self::nonce_key] ) || ! wp_verify_nonce( $_POST[self::nonce_key], self::nonce_key ) ) if ( empty( $_POST[self::nonce_key] ) || ! wp_verify_nonce( $_POST[self::nonce_key], self::nonce_key ) )
return; return;


// Update liveblog beta if ( ! empty( $_POST['is-liveblog'] ) ) {
if ( ! empty( $_POST['is-liveblog'] ) )
update_post_meta( $post_id, self::key, 1 ); update_post_meta( $post_id, self::key, 1 );

do_action( 'liveblog_enable_post', $post_id );
// Delete liveblog meta } else {
else
delete_post_meta( $post_id, self::key ); delete_post_meta( $post_id, self::key );
do_action( 'liveblog_disable_post', $post_id );
}
} }


/** Error Methods *********************************************************/ /** Error Methods *********************************************************/
Expand Down

0 comments on commit 7e39692

Please sign in to comment.