As Milo hints at in their comment, custom post types can only be registered on the init hook. Therefore, if you are trying to get all the public but not builtin post types before init, then get_post_types() will return an empty array. (You can use get_post_types() to get the builtin post types before init.)
What you need to do is hook in after init and then get the post types. I’d use wp_loaded since at this point, WordPress is fully loaded.
add_action( 'wp_loaded', 'wpse290170_wp_loaded' );
function wpse290170_wp_loaded() {
$types = get_post_types( [
'public' => true,
'_builtin' => false
] );
foreach ( $types as $type ){
add_action( "publish_" . $type, 'duplicate_title_buwp_bc' ) ;
}
}
Related Posts:
- Passing a parameter to filter and action functions
- Get a list of all registered actions
- How can I edit post data before it is saved?
- Manually set global $post vars with an ID, in order to use template tags
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- Deactivate plugin for a specific user group
- Auto Load Plugin Hooks inside Must Use Plugin
- Ways to have multiple front-page.php templates that can be swapped out?
- Removing an action from an external plugin class
- How can I limit functionality in one version of a plugin?
- Shortcode display outside the div
- How can I let users to access plugin functions based on roles?
- Template for custom post type shows all posts instead of just one
- Fastest way to loop through all posts?
- How to prepend to the_title for admin-side plugin’s use
- How can I enqueue a style only when a particular widget is active?
- Add custom buttons with custom actions in Edit Post screen in WordPress?
- How to filter content post only on save
- Filter or action hook to insert content on admin pages before tag
- What is the purpose of $merged_filters?
- template_redirect not being called when using ajax
- Can’t get custom posts of taxonomy to show
- add action wp_head not working
- Plugin custom Action Hook not working
- add_action in functions.php, do_action in plugin?
- Display content from custom post type if match to main post category
- how do i remove posts from a WP_Query so the pagination is right?
- Get posts from WP_Query and format them on admin_head
- Override global query results without hooks
- Automatically add attributes to woocommerce product?
- Calling plugin function inside custom plugin for onclick event
- Insert content of a post into another
- Custom plugin init action causing general slowness
- Is there a hook to Intercept al urls from a webpage and redirect to a page
- Inject HTML meta tag inside wordpress tag using add_shortcode
- How to get post ID with hooks publish_post, new_to_publish, etc
- register_activation_hook in oop approach
- Problem with removing plugin action
- edit_user_profile and show_user_profile are not firing inside a class
- do add_action on condition
- get gravity form ID from backend/wordpress admin
- How to pass variables to a function argument using add_action [duplicate]
- How to trace SUBMIT button
- Get User_id outside wordpress,
- publish_post action doesn’t work
- Import Instagram post to WordPress blog post
- the_post hook is not firing for me
- do_action Nested List
- How to get a list of bundled products using wp_query in woocommerce
- Where to find the code used to render a page that has a shortcode and a template defined?
- Create a post builder skin in a plugin
- Plugin Development – Functions or Hooks?
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Basic function call on init failing
- How to create Admin Notice from Plugin with argument? [duplicate]
- Hook for page Request?
- Editing wp-config.php
- New bulk action to resend welcome emails
- Loop in elementor custom widget not working
- get_users(); Is an Undefined Function When Used in Cron Job
- How to remove a class function from a plugin by using remove_action()?
- Get post content from outside the loop with plugin shortcode usability
- Action on WordPress Install
- wp_ajax action responds with 0
- Retrieve options set through a plugin
- override function from my plugin [closed]
- What hook can I use to modify custom post data before it is displayed on the page?
- Output after specific post in the loop
- Plugin is creating posts twice
- Running a function with args in add_action()
- Multiple images per post – Show random image elsewhere
- I cannot include a file in my plugin settings page
- Displaying page content from plugin, inside exising empty WP page
- Callback hooked to post_updated firing on new posts as well
- The function called on the wp head hook becomes null
- Discern a specific plugin’s action hooks
- How to remove default action from a plugin?
- How to Unhook actions/filters in within Class in plugin
- Nested Actions and Filters
- Get post content inside plugin class method
- Ajax call to php function doesn’t work PHP code
- Frontend AJAX Request causes Error: ‘Call to undefined function add_action’
- echo plugin results on pages
- What action or filter can I use to change all the html returned from server for a page?
- What action/hook do I need to register to have my plugin handle front-end editing?
- wp_login_form() ignoring login_form action hook
- how to repeat taxonomy in different places on wordpress
- AJAX login without a plugin does not work. when add a action to function.php
- Remove action working on functions.php but not in a plugin. Why?
- change output location of plugin function using a custom hook
- Removing this filter added by a plugin
- ‘all’ hook and add_action issue (class based plugin)
- Which filters or actions involve with index page for plugin?
- single.php fires more than once after clicking on any post to view with different post id each time
- How can I save a setting field with multiple checkbox options generated by a foreach loop on a custom wordpress admin page?
- Call a function with href
- WooCommerce Order Status Displays Twice on Order Page
- Outputting custom field query from a plugin to the website header
- FacetWP custom display based on post type [closed]
- Remove 3rd party plugin notices from within own plugin