如何在快速编辑中单击更新后重新加载仪表板?

时间:2012-09-14 作者:getWeberForStackExchange

如何刷新wp-admin/edit.php 用户单击后的页面Update 在快速编辑表单中?

2 个回复
最合适的回答,由SO网友:getWeberForStackExchange 整理而成

我翻遍了WordPress\'wp-admin/js/inline-edit-post-dev.js 并发现在快速编辑更新之后,没有任何用于执行JS代码的挂钩。

我决定推翻inlineEditPost.save 功能来自wp-admin/js/inline-edit-post-dev.js, 类似how WordPress recommends updating form data when the quick edit form is displayed (其中覆盖inlineEditPost.edit).

完整功能可在中找到wp-admin/js/inline-edit-post-dev.js. 我只是在post调用中更改了回调函数以重新加载页面,而不是隐藏快速编辑表单。

(function($) {
    inlineEditPost.save = function(id) {
        //...
        // make ajax request
        $.post( ajaxurl, params,
            function(r) {
                location.reload();
            }
        , \'html\');
        //...
    }
})(jQuery);

SO网友:brasofilo

我们必须拦截该操作的Ajax端点。文件wp-admin/admin-ajax.php 有所有可能的钩子吗$core_actions_post 大堆

功能wpse_65157_ajax_inline_save() 是Core的副本,末尾打印“强制重新加载”脚本。它必须使用Javascriptwp_redirect() 不起作用。

add_action( \'wp_ajax_inline-save\', \'wpse_65157_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 wpse_65157_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">
            document.location.reload(true);
        </script>
    <?php       
    }
    // end INTERCEPT

    wp_die();

}
参考Q&;答:How to enable comments for pending and draft posts?

结束

相关推荐

require.js to load javascript

虽然wp\\u enqueue\\u脚本似乎可以工作,但它并不是很优雅。我目前正在制作一个使用MVC(backbone.js)的WP前端,它有30多个独立的模型/视图/集合/控制器脚本,我一直在增加这个数量。我用过require。js以前很喜欢它,但它似乎完全打破了WordPress的逻辑。有谁能告诉我一个在wordpress中使用js脚本加载器的干净方法吗?还是这是一项没有希望的任务?谢谢