我已经将我的Wordpress版本从4.3.1更新到了4.5.2,显然它打破了我过去所做的自定义功能
What it does: 在后端的“批准/回答/编辑/垃圾邮件/删除”旁边的“注释”下方显示锚定。单击anchor,它会将我重定向到“wp admin/cust\\u comment.php?c=ID和action=(un)highlightcomment&;\\u wpnance=HASH”。从这一点开始,它应该将注释meta\\u键“highlight”更新为1或0。但我收到的只是一张空白页。
cust\\u注释。php
自定义“wp admin/comment.php”
<?php
require_once( dirname( __FILE__ ) . \'/admin.php\' );
wp_reset_vars( array(\'action\') );
$comment_id = absint( $_GET[\'c\'] );
switch( $action ) {
case \'highlightcomment\' :
case \'unhighlightcomment\' :
$noredir = isset($_REQUEST[\'noredir\']);
if ( !$comment = get_comment($comment_id) )
comment_footer_die( __( \'Invalid comment ID.\' ) . sprintf(\' <a href="%s">\' . __(\'Go back\') . \'</a>.\', \'edit-comments.php\') );
if ( !current_user_can( \'edit_comment\', $comment->comment_ID ) )
comment_footer_die( __(\'You are not allowed to edit comments on this post.\') );
if ( \'\' != wp_get_referer() && ! $noredir && false === strpos(wp_get_referer(), \'comment.php\') )
$redir = wp_get_referer();
elseif ( \'\' != wp_get_original_referer() && ! $noredir )
$redir = wp_get_original_referer();
elseif ( in_array( $action, array( \'highlightcomment\', \'unhighlightcomment\' ) ) )
$redir = admin_url(\'edit-comments.php?p=\' . absint( $comment->comment_post_ID ) );
else
$redir = admin_url(\'edit-comments.php\');
$redir = remove_query_arg( array(\'highlighted\', \'unhighlighted\'), $redir );
switch ($action) {
case \'highlightcomment\' :
update_comment_meta($comment_id, \'highlight\', 1);
$redir = add_query_arg( array(\'highlighted\' => \'1\'), $redir );
break;
case \'unhighlightcomment\' :
update_comment_meta($comment_id, \'highlight\', 0);
$redir = add_query_arg( array(\'unhighlighted\' => \'1\'), $redir );
break;
}
wp_redirect( $redir );
die;
break;
default:
wp_die( __(\'Unknown action.\') );
} // end switch
功能。php
add_filter(\'comment_row_actions\', \'cust_hightlight_comment_action\', 10, 2);
function cust_hightlight_comment_action($actions, $comment) {
$highlight_nonce = esc_html( \'_wpnonce=\' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
$url = "cust_comment.php?c=$comment->comment_ID";
$highlight_url = $url . "&action=highlightcomment&$highlight_nonce";
$unhighlight_url = $url . "&action=unhighlightcomment&$highlight_nonce";
if (!get_comment_meta( $comment->comment_ID, \'highlight\', true) )
$actions[\'highlighter\'] = "<a href=\'$highlight_url\' class=\'vim-a\'>" . _x( \'Highlight\' ) . \'</a>\';
else
$actions[\'unhighlighter\'] = "<a href=\'$unhighlight_url\' class=\'vim-u\'>" . _x( \'Don\\\'t highlight\') . \'</a>\';
return $actions;
}