So basically in The Wordpress Admin when you are editing a "post" you have a url slug like...
post.php?post=829&action=edit&classic-editor
I would like to know, is there a filter or way that I can add the post_type query arg to this url? Which would result in something like...
post.php?post=829&action=edit&classic-editor&post_type=product
I would like this to run for all post types (page, post, product, ...)
Why: I have a plugin that disables plugins from loading based on a string in the url.
My Goal: is to reveal the post_type=value
in the url when editing a post, so that I can disable plugins from loading when editing post types that those plugins do not need to load on.
Example: when editing a portfolio post type, I do not need Woocommerce or its addons to load. So I would like to disable them when editing portfolio posts.
This is entirely for performance reasons of a potential mu-site I might offer publicly.
Thank you.
So basically in The Wordpress Admin when you are editing a "post" you have a url slug like...
post.php?post=829&action=edit&classic-editor
I would like to know, is there a filter or way that I can add the post_type query arg to this url? Which would result in something like...
post.php?post=829&action=edit&classic-editor&post_type=product
I would like this to run for all post types (page, post, product, ...)
Why: I have a plugin that disables plugins from loading based on a string in the url.
My Goal: is to reveal the post_type=value
in the url when editing a post, so that I can disable plugins from loading when editing post types that those plugins do not need to load on.
Example: when editing a portfolio post type, I do not need Woocommerce or its addons to load. So I would like to disable them when editing portfolio posts.
This is entirely for performance reasons of a potential mu-site I might offer publicly.
Thank you.
Share Improve this question edited Jun 30, 2020 at 15:18 Trinity Branding asked Jun 30, 2020 at 14:36 Trinity BrandingTrinity Branding 134 bronze badges 4 |1 Answer
Reset to default 1there you go, i tested it in my current development and it works. it adds the post_type query parameter to all edit links, even on custom post types and also on the admin bar. this even works with preexisting query parameters and i also have other plugins currently running (f.ex. wpml).
function so370070_admin_url($url, $path)
{
if (strpos($path, "post.php") !== false) :
$post_type = get_post_type();
if ($post_type) :
$url = add_query_arg('post_type', $post_type, $url);
endif;
endif;
return $url;
}
add_filter('admin_url', 'so370070_admin_url', 10, 2);
and as solved by yourself, here is the links for attachments:
function so370070_register_post_type_args($args, $post_type)
{
if ($post_type == 'attachment') {
//NOTE: This "_edit_link" arg is noted for Wordpress's internal use only
//in /wp-includes/post.php around line 84
//However, we are using a dveloper's filter to adjust it, so use accordingly
//that you understand it may need tweaked if Wordpress itself makes changes
//Overall it should be generally safe... no issues so far :)
$args['_edit_link'] = add_query_arg('post_type', 'attachment', $args['_edit_link']);
}
return $args;
}
add_filter('register_post_type_args', 'so370070_register_post_type_args', 10, 2);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742279110a4414153.html
post
. It would be cached so there shouldn't be any additional database queries. Seeget_post_type()
. Even new posts should have aglobal $post
object to work with. – Howdy_McGee ♦ Commented Jun 30, 2020 at 15:24