Created
April 8, 2016 10:44
-
-
Save haruair/0c15b9bff6be0adcbbc2dad954225243 to your computer and use it in GitHub Desktop.
FeedWordPress Bulk Zap Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: FeedWordPress Bulk Zap | |
Plugin URI: http://haruair.com | |
Description: Code snipet for bulk zap of FeedWordPress | |
Version: 0.1 | |
Author: Haruair | |
Author URI: http://haruair.com | |
License: GPL v2 | |
*/ | |
add_action( 'admin_footer-edit.php', 'haruair_feedwordpress_bulk_actions' ); | |
add_action( 'admin_action_zap', 'haruair_feedwordpress_bulk_action_zap' ); | |
function haruair_feedwordpress_bulk_actions() | |
{ | |
global $typenow; if( $typenow != 'post' ) return; // if used on edit.php screen | |
?> | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
$('<option>').val('zap').text("Zap/Don't Resyndicate") | |
.appendTo("select[name='action'], select[name='action2']"); | |
}); | |
</script> | |
<?php | |
} | |
function haruair_feedwordpress_bulk_action_zap() | |
{ | |
$posts = $_REQUEST['post']; | |
$sendback = wp_get_referer(); | |
if ( | |
! $sendback | |
or strpos( $sendback, 'post.php' ) !== false | |
or strpos( $sendback, 'post-new.php' ) !== false | |
) : | |
if ( 'attachment' == $post_type ) : | |
$sendback = admin_url( 'upload.php' ); | |
else : | |
$sendback = admin_url( 'edit.php' ); | |
$sendback .= ( ! empty( $post_type ) ) ? '?post_type=' . $post_type : ''; | |
endif; | |
else : | |
$sendback = esc_url( remove_query_arg( array('trashed', 'untrashed', 'deleted', 'zapped', 'unzapped', 'ids'), $sendback ) ); | |
endif; | |
foreach($posts as $post_id) { | |
$post = get_post( $post_id ); | |
if( !$post ) wp_die( __( 'The item you are trying to zap no longer exists.' ) ); | |
if ( ! current_user_can( 'delete_post', $post_id ) ) : | |
wp_die( __( 'You are not allowed to zap this item.' ) ); | |
endif; | |
if ( $user_id = wp_check_post_lock( $post_id ) ) : | |
$user = get_userdata( $user_id ); | |
wp_die( sprintf( __( 'You cannot retire this item. %s is currently editing.' ), $user->display_name ) ); | |
endif; | |
$p = get_post($post_id); | |
FeedWordPress::diagnostic('syndicated_posts', 'Zapping existing post # '.$p->ID.' "'.$p->post_title.'" due to user request.'); | |
$old_status = $post->post_status; | |
set_post_field('post_status', 'fwpzapped', $post_id); | |
wp_transition_post_status('fwpzapped', $old_status, $post); | |
# Set up the post to have its content blanked on | |
# next update if you do not undo the zapping. | |
add_post_meta($post_id, '_feedwordpress_zapped_blank_me', 1, /*unique=*/ true); | |
add_post_meta($post_id, '_feedwordpress_zapped_blank_old_status', $old_status, /*unique=*/ true); | |
} | |
wp_redirect( esc_url_raw( add_query_arg( array('zapped' => 1, 'ids' => $post_id), $sendback ) ) ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment