How do you permanently remove default rewrite rules from the wp_options table?

Rather than modifying stored rules it would be more reliable to modify rules before they are stored. flush_rewrite_rules() calls WP_Rewrite->flush_rules() WP_Rewrite->wp_rewrite_rules() WP_Rewrite->rewrite_rules() Inside last there are fitting hooks to modify rules (after which result they will be saved as usual on each flush): do_action_ref_array(‘generate_rewrite_rules’, array(&$this)); $this->rules = apply_filters(‘rewrite_rules_array’, $this->rules);

Hard Code Pages into a Theme for a Network (multisite) Installation

Hook into wpmu_new_blog and create your pages: add_action(‘wpmu_new_blog’, ‘create_my_pages’, 10, 2); function create_my_pages($blog_id, $user_id){ switch_to_blog($blog_id); // not really need, new blogs shouldn’t have any content if(get_page_by_title(‘About this Network’)) return; // create each page $page_id = wp_insert_post(array( ‘post_title’ => ‘About this Network’, ‘post_name’ => ‘about-this-network’, ‘post_content’ => ‘Co za asy…’, ‘post_status’ => ‘publish’, ‘post_author’ => $user_id, … Read more

Why do I get Fatal error: Call to undefined function get_most_recent_post_of_user()?

get_most_recent_post_of_user() is for multisite installs to get the most recent post of the user from each blog. Here is a comparable function you can use that will return the post object of the defined users most recent post. function wpse_get_user_recent( $user ) { global $wpdb; $recent = $wpdb->get_row( $wpdb->prepare(“SELECT ID, post_date_gmt FROM {$prefix}posts WHERE post_author … Read more

How to prevent deleting of comments when deleting a post

To prevent the comment deletion hook into before_delete_post, and filter the query for associated comments so the deletion routine cannot find and delete those. PHP 5.3 required: add_action( ‘before_delete_post’, function( $post_id ) { add_filter( ‘query’, function( $query ) use ( $post_id ) { $find = ‘WHERE comment_parent=”; FALSE !== strpos( $query, $find . $post_id ) … Read more

How to display error messages using WP_Error class?

With that in functions.php you’d probably have to declare $error to be global like so : if (‘POST’ == $_SERVER[‘REQUEST_METHOD’] && !empty($_POST[‘action’]) && $_POST[‘action’] == ‘registration’) { global $error; $error = new WP_Error(); // the rest of your code And then do global $error; again on your registration page before trying to use it. But … Read more

Generate Advanced Custom Fields box in custom admin menu page

Interesting exercise, a one page plugin that believes it deserves a first level menu page is wrong, IMO. I use the same technique with Jetpack. To create sub-pages in the Options Page add-on, read the documentation. The logic of this menu/sub-menu swapping is: Add multiple ACF Options Pages Create our menu first level page Remove … Read more