Permalink
Browse files

Introduce some new hooks.

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...
1 parent c3dc8bd commit 7e39692ca7b7098b8446da3a9f3397391b19a5f7 @mjangda mjangda committed Sep 25, 2012
Showing with 17 additions and 6 deletions.
  1. +17 −6 liveblog.php
View
@@ -233,6 +233,8 @@ public static function ajax_entries_between() {
// Get liveblog entries within the start and end boundaries
$entries = self::$entry_query->get_between_timestamps( $start_timestamp, $end_timestamp );
if ( empty( $entries ) ) {
+ do_action( 'liveblog_entry_request_empty' );
+
self::json_return( array(
'entries' => array(),
'latest_timestamp' => null
@@ -254,6 +256,8 @@ public static function ajax_entries_between() {
'latest_timestamp' => $latest_timestamp,
);
+ do_action( 'liveblog_entry_request', $result_for_json );
+
self::json_return( $result_for_json );
}
@@ -382,20 +386,23 @@ public static function ajax_insert_entry() {
// Are we replacing an existing comment?
if ( !empty( $replaces_comment_id ) ) {
- //
add_comment_meta( $new_comment_id, WPCOM_Liveblog_Entry::replaces_meta_key, $replaces_comment_id );
// Update an existing comment
if ( !empty( $entry_content ) ) {
+ do_action( 'liveblog_update_entry', $replaces_comment_id, $new_comment_id, $post_id );
wp_update_comment( array(
'comment_ID' => $replaces_comment_id,
'comment_content' => wp_filter_post_kses( $entry_content ),
) );
// Delete this comment
} else {
+ do_action( 'liveblog_delete_entry', $replaces_comment_id, $post_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 ) );
@@ -412,9 +419,13 @@ public static function ajax_insert_entry() {
function ajax_preview_entry() {
self::ajax_current_user_can_edit_liveblog();
self::ajax_check_nonce();
+
$entry_content = isset( $_REQUEST['entry_content'] ) ? $_REQUEST['entry_content'] : '';
$entry_content = wp_filter_post_kses( $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 ) );
}
@@ -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 ) )
return;
- // Update liveblog beta
- if ( ! empty( $_POST['is-liveblog'] ) )
+ if ( ! empty( $_POST['is-liveblog'] ) ) {
update_post_meta( $post_id, self::key, 1 );
-
- // Delete liveblog meta
- else
+ do_action( 'liveblog_enable_post', $post_id );
+ } else {
delete_post_meta( $post_id, self::key );
+ do_action( 'liveblog_disable_post', $post_id );
+ }
}
/** Error Methods *********************************************************/

0 comments on commit 7e39692

Please sign in to comment.