if is_page() is not working with wp_redirect

In the case of a plugin template, you might find the slug is more reliable for a condition – see below for alternate approach. When using is_page_template() the parameter passed is anypath/filename.php. Without knowing your file system specifics or the name of the plugin, it is impossible to give you the correct relative path for … Read more

Updating page template pragmatically

Use the body_class filter to change the <body> CSS classes. You can copy the same logic into your hooked function (like below), or make it neater by copying the logic into another new function and make this function return a boolean (and then use that new function with the body_class filter and within your template_redirect … Read more

Restrict specific private page to a specific user

I assume you’re using wp_insert_post() to create the private page for the user. The function returns the ID of the created page. You can use this ID as part of a custom capability you grant to the user. // create the new $user // create private page $private_page_id = wp_insert_post( $postarr, $wp_error = false ); … Read more

How to get an array of pages ID by some page’s slug and all its children pages in get_posts() function?

You can use get_page_by_path() to get a Page’s WP_Post object using its slug (ie, its path), and then use that object to then get the array of child page IDs using get_children(). // First we’ll create the list of posts (pages) to exclude. $exclude = array(); $parent_page_obj = get_page_by_path( ‘abc’ ); if ( ! empty( … Read more