从“帖子标题"下方移动自定义列管理链接 [英] Move custom column admin links from below "post title"

查看:22
本文介绍了从“帖子标题"下方移动自定义列管理链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎不知道如何将编辑、删除、查看等添加到 wordpress 后端的自定义列之一.这个想法是在将鼠标悬停在标题上时将附加到标题的链接附加到不同的列.

It seems I can't figure out how to add the edit, remove, view, etc... to one of my custom columns in the backend of wordpress. The idea is to get the links that are attached to title when one hovers over the title, to be attached to a different column.

这是以下代码输出的内容.

This is what the below code outputs.

当鼠标悬停在作者上方时,这就是我希望作者列中的链接具有的内容,就像您将鼠标悬停在此屏幕截图中的标题上一样;所有编辑链接.

This is what I want the link in the authors column have when mouse is hovered over the authors, just like when you hover over the title in this screenshot; all the edit links.

这是我目前所拥有的:

add_filter( 'manage_edit-testimonial-quotes_columns', 'view_columns' ) ;
function view_columns( $columns ) {
  $columns = array(
    'cb' => '',
    'date' => __( 'Date' ),
    'tq_author' => __( 'Author' ),
    'tq_quote' => __( 'Testimonial' ),
  );
  return $columns;
}
add_action('manage_testimonial-quotes_posts_custom_column', 'custom_view_columns', 10, 2);
function custom_view_columns($column, $post_id){
global $post;
  switch ($column){
  case 'tq_author':
    echo '<a href="post.php?post=' . $post->ID . '&action=edit">';
    $column_content = the_field('tq_author');
    echo $column_content;
    echo '</a>';
    break;
  case 'tq_quote':
    $column_content = the_field('tq_quote');
    echo $column_content;
    break;
  default:
    break;
  }
}

推荐答案

真的怀疑是否有解决方案.所以,我什至不会检查核心并直接进入肮脏的解决方案:

I really doubt that there's a hook to deal with that. So, I'll not even check the core and go straight to the dirty solution:

add_action( 'admin_head-edit.php', 'so_13418722_move_quick_edit_links' );

function so_13418722_move_quick_edit_links()
{
    global $current_screen;
    if( 'post' != $current_screen->post_type )
        return;

    if( current_user_can( 'delete_plugins' ) )
    {
        ?>
        <script type="text/javascript">
        function so_13418722_doMove()
        {
            jQuery('td.post-title.page-title.column-title div.row-actions').each(function() {
                var $list = jQuery(this);
                var $firstChecked = $list.parent().parent().find('td.author.column-author');

                if ( !$firstChecked.html() )
                    return;

                $list.appendTo($firstChecked);
            }); 
        }
        jQuery(document).ready(function ($){
            so_13418722_doMove();
        });
        </script>
        <?php
    }
}

结果:

注意事项:

  • 调整你的帖子类型:'post' != $current_screen->post_type
  • 调整你的列类:find('td.author.column-author')
  • adjust your post_type: 'post' != $current_screen->post_type
  • adjust your column classes: find('td.author.column-author')

错误和解决方案:
您会注意到,更新后,快速编辑菜单返回到其原始位置.下面的 AJAX 拦截处理它.有关详细信息,请参阅此 WordPress 开发人员回答.

add_action( 'wp_ajax_inline-save', 'so_13418722_ajax_inline_save' , 0 );

/**
 Copy of the function wp_ajax_inline_save()
 http://core.trac.wordpress.org/browser/tags/3.4.2/wp-admin/includes/ajax-actions.php#L1315

 Only Modification marked at the end of the function with INTERCEPT
*/
function so_13418722_ajax_inline_save()
{
    global $wp_list_table;

    check_ajax_referer( 'inlineeditnonce', '_inline_edit' );

    if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) )
        wp_die();

    if ( 'page' == $_POST['post_type'] ) {
        if ( ! current_user_can( 'edit_page', $post_ID ) )
            wp_die( __( 'You are not allowed to edit this page.' ) );
    } else {
        if ( ! current_user_can( 'edit_post', $post_ID ) )
            wp_die( __( 'You are not allowed to edit this post.' ) );
    }

    set_current_screen( $_POST['screen'] );

    if ( $last = wp_check_post_lock( $post_ID ) ) {
        $last_user = get_userdata( $last );
        $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
        printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ),    esc_html( $last_user_name ) );
        wp_die();
    }

    $data = &$_POST;

    $post = get_post( $post_ID, ARRAY_A );
    $post = add_magic_quotes($post); //since it is from db

    $data['content'] = $post['post_content'];
    $data['excerpt'] = $post['post_excerpt'];

    // rename
    $data['user_ID'] = $GLOBALS['user_ID'];

    if ( isset($data['post_parent']) )
        $data['parent_id'] = $data['post_parent'];

    // status
    if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
        $data['post_status'] = 'private';
    else
        $data['post_status'] = $data['_status'];

    if ( empty($data['comment_status']) )
        $data['comment_status'] = 'closed';
    if ( empty($data['ping_status']) )
        $data['ping_status'] = 'closed';

    // update the post
    edit_post();

    $wp_list_table = _get_list_table('WP_Posts_List_Table');

    $mode = $_POST['post_view'];
    $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ) );

    // INTERCEPT: Check if it is our post_type, if not, do nothing  
    if( 'post' == $_POST['post_type'] )
    {
    ?>
        <script type="text/javascript">so_13418722_doMove();</script>
    <?php       
    }
    // end INTERCEPT    

    wp_die();

}

这篇关于从“帖子标题"下方移动自定义列管理链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆