Can I run a slow action in a seperate thread?

Techcrunch has released a library to spawn an asynchronous task within WordPress. https://github.com/techcrunch/wp-async-task Essentially, you can take any process that is triggered by an action hook, and you can defer the processing on that hook to run asynchronously. You extend the class to define which action you are triggering and a couple of functions to … Read more

Which action hook to update custom field at network/site-info.php in multisite on update site info

After some more research I found a solution, turned out that I had to use admin_init.. function pg_save_custom_site_options(){ global $pagenow; if( ‘site-info.php’ == $pagenow && isset($_REQUEST[‘action’]) && ‘update-site’ == $_REQUEST[‘action’] ) { if ( isset( $_POST[‘blog’][‘custom_limit_amount’] ) ) { $new_field_value = intval( $_POST[‘blog’][‘custom_limit_amount’] ); if( is_int($new_field_value) ){ update_blog_option( $_POST[‘id’], ‘custom_limit_amount’, $new_field_value ); } } } … Read more

Keep br tags from stripping

Since any attribute added to <br> tag, including class names and data-attrs keeps them from stripping, quick and incomplete way could be: function filter_function_name( $content, $post_id ) { $content = str_replace(‘<br>’, ‘<br data-x>’, $content); $content = str_replace(‘<br >’, ‘<br data-x>’, $content); $content = str_replace(‘<br />’, ‘<br data-x>’, $content); $content = str_replace(‘<br/>’, ‘<br data-x>’, $content); return … Read more

How can i take all ids from untrash_post action?

You can use transition_post_status: add_action(‘transition_post_status’, ‘wpse_handle_untrash’); function wpse_handle_untrash($new_status, $old_status, $post) { // if the post was in the trash, but now is not if($old_status == ‘trash’) { // if you want, you can do something only for a certain post type if($post->post_type == ‘my-desired-post-type’) { // do something echo ‘<script>alert(‘ . $post->ID . ‘);</script>’; } … Read more