If you hook into the hooks provided in update_post_meta()
function and still use this function in your callback, that would result in a loop which would probably end with the timeout..
As the per the comments:
add_action("wp_insert_post", function( $post_ID ) {
if ( ! $post_data = get_post( $post_ID ) ) return;
// try to make this run only once needed ( from the question, the content is empty and cPT is dlm_download )
if ( "dlm_download" == $post_data->post_type && ! $post_data->post_content ) {
update_option( "dlm_download_members_only_yes", $post_data->ID );
}
return;
}, 10);
add_action("init", function() {
if ( $pid = (int) get_option( "dlm_download_members_only_yes" ) ) {
update_post_meta( $pid, "_members_only", "yes" );
delete_option( "dlm_download_members_only_yes" );
} return;
});
init
hook is always there (page load, AJAX, etc) so this should always work and would work on multiple entries as well..
Related Posts:
- Using filters and actions for plugin API?
- Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?
- How to replace settings in WordPress plugin from a theme
- Does hooking into a plugin action / filter override the plugin’s function for that hook?
- Custom fields in the billing address section woocommerce
- Search: how to extend the existing search to include a custom table
- Is there documentation reference for forms in menu and setting pages?
- template_redirect or admin-ajax.php?
- WordPress custom taxonomy check box to dropdown
- Force HTTPS 301 redirect with hook
- I have 2 plugins using the same wp_login action hook and one is not working
- Add a new confirmation page before saving
- Enqueue script globally
- use of do_action() without any functions attached
- How dynamic action login_form_{action} is working
- How to modify files inside wp-includes directory in wordpress
- How should I go about registering JavaScript that isn’t a file? [duplicate]
- What happens when two or more plugins use the same hook?
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- Does admin_print_scripts-$hook_suffix work for nested paths to individual files?
- How to get all queries’s results after they have executed?
- Custom entity search and display
- How to set a cookie for logged in users to md5($user->ID . “my_secret”)?
- Plugin uninstall function is not working
- Plugin: database creation
- Loading Modernizr (or other JavaScript libraries) for use in a plugin
- Bug: Post needs to be updated twice when adding action for save_post hook
- flush rewrite rules after plugin update?
- When does save_post hook fire on post save/update
- Plugin does not add action
- Remove an action by extending class and replacing it
- Add child pages to submenu automatically
- Show message from backend
- After plugin activation hook
- How to replace default comments with custom HTML?
- Odd map_meta_cap $args on post edit — sometimes integer, sometimes string
- Trying to get class to instantiate ONCE (or, “why do I keep punching myself in the head?”)
- How can I create a custom plugin that allows anonymous users to signup without registering?
- hook filter after the_content on a specific page
- Bind a function with its own argument to show something dynamically after every content
- Why in this archive page that call query_posts() function show only the last 10 posts?
- Is there an admin hook that will let me read GET variable before it’s too late to set the header Location
- Why enqueue styles on hook?
- What’s the hook for filtering every texts of site?
- Create Widget or Enable Shortcodes in Sidebar
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- Associate multiple email addresses with the same user account, so they can log in with either
- WooCommerce change Tax Class programmatically when Recalculating an existing Order [closed]
- Run command “composer install” when activating wordpress plugin
- Update variable value via add_filter
- Add a check box in Menu Settings
- Logout after clicking URL link results in “headers already sent” error
- Custom filter not working
- hook update_option/updated_option empty $old_value and $value
- how to save wp_editor html content in options table
- Configure WordPress to Generate Scheme-less Relative URLs
- Hide one specific woocoomerce product
- How to find list of all functions bind to a particular hook from my plugin?
- Converting core modification to a plugin
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- How to use a WP_Customize_Control outside of the Customizer?
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- Ajax +wordpress onClick link redirect to new page and create html content
- Redirect returning users to a certain page?
- How to remove/replace current page template?
- Restrict certain actions to plugin-specific admin menu pages only
- Setting a post’s category
- Extract Information from post content (using regex?)
- How to determine which capability to use?
- Serial Number from custom table not appear in woocommerce_email_before_order_table action
- Customise Grouped Product display in Woocommerce with custom column
- Creating posts with links from a txt file
- Set the payment processor callbacks to a plugin
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- Why won’t this submenu page show? – My First WordPress Plugin
- Action / Hook when a new plugin is added
- apply_filters() and call_user_func() to define and call a function outside a class
- Getting Post ID at “stylesheet” and “template” hooks
- How to enhance a self developed plugin by its own plugin architecture
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- How to create a custom post-new.php page for plugin , no wp menu
- How to update global variables in plugin activation callback?
- Woocommerce get_term_by() in transition_post_status hook doesn’t works
- Add two button to page and post admin to redirect to : add new & list of (posts – pages) just after saving post or page
- Want to know how to reveal a WordPress theme, considering the theme name is hidden?
- `registration_errors` filter doesn’t seem to be called
- How to grab data after wp user search is complete
- Limit get_next_post to posts from the same author
- Save meta box data from selected dropdown list in bbpress reply form
- Metabox types list
- Any way, hook to add content right before the “read more” link?
- Is there any way to get post meta from publish_post hook?
- Where to save Gutenberg plugin data?
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- WordPress how do I echo SUM from a column of a MySQL table by user id AND type_operation
- Add a custom submenu under submenu in a Custom WordPress Plugin
- Rate limiting ajax requests in WordPress
- How do I ensure I can loop through every enqueued script and CSS?
- Hook for validating and rejecting frontend image upload