admin管理员组文章数量:1122846
What is the difference between manage_{$post_type}_posts_columns
and manage_edit-{$post_type}_columns
?
Could somebody explain what is the difference between these two approaches?
What is the difference between manage_{$post_type}_posts_columns
and manage_edit-{$post_type}_columns
?
Could somebody explain what is the difference between these two approaches?
Share Improve this question edited Dec 16, 2013 at 5:22 Mayeenul Islam 12.9k21 gold badges85 silver badges169 bronze badges asked Dec 15, 2013 at 22:05 DerfderDerfder 2,07212 gold badges34 silver badges57 bronze badges2 Answers
Reset to default 0It has to do with the way the admin post table is constructed. WordPress uses a class WP_Posts_List_Table
to generate and handle that table. You'll notice that there are a few tables in the admin area similar: Plugins, Terms, Users, etc. They each are their own class, but they all extend from a base class of WP_List_Table
.
manage_edit-{$post_type}_columns
is a more generic filter that is set (but not called) in WP_List_Table
. And, it is actually manage_{$screen->id}_columns
. The callback is the get_columns
method for the table object.
add_filter( "manage_{$this->screen->id}_columns", array( &$this, 'get_columns' ), 0 );
This filter is used by the get_column_headers()
function for retrieving the columns.
So where does manage_{$post_type}_posts_columns
then? Remember the method get_columns()
that is call for the filter manage_{$screen->id}_columns
, the WP_Posts_List_Table
class over-rides the base method from WP_List_Table
. In WP_Posts_List_Table::get_columns()
is where the filter manage_{$post_type}_posts_columns
is called.
To recap:
- A
WP_Posts_List_Table
object is created - It's parent class
WP_List_Table
adds$this->get_columns()
to the hookmanage_{$screen->id}_columns
- The function
get_column_headers()
calls the filtermanage_{$screen->id}_columns
WP_Posts_List_Table
has over-ridden the methodget_columns()
- Inside of
WP_Posts_List_Table::get_columns()
, it calls the filtermanage_{$post_type}_posts_columns
This is where your manage_{$post_type}_posts_columns hook would run WP_Posts_List_Table::get_columns()
will return the columns and then run the remaining filters formanage_{$screen->id}_columns
Which one should you use? I don't know. We know that manage_{$post_type}_posts_columns
can only be called for post types, whereas manage_edit-{$post_type}_columns
may match a different admin page (although I'm not sure if it would).
They both essentially do the same thing.
manage_edit-{$post_type}_columns
used to be the old recommended hook used to create or change columns for custom posts types.
With WordPress 3.1 (23 February 2011), manage_{$post_type}_posts_columns
was added and is now the recommended hook to use.
Here is a quote from the Codex:
In WP 3.1, manage_edit-{$post_type}_columns has been supplanted by manage_{$post_type}_posts_columns.
supplant = supersede and replace.
Although the old hook is not deprecated, the new hook is the one to use now.
本文标签:
版权声明:本文标题:query posts - What is the difference between "manage_{$post_type}_posts_columns" and "manage_edit-{$p 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736289405a1928298.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论