I solved it with the help of @PatJ’s comment.
add_filter('the_content', function ($content) use ($callback){
if (is_singular() && in_the_loop() && is_main_query()){
$id = get_the_ID();
if (in_array($id, array_values($this->pages))){
ob_start();
$callback();
return ob_get_clean();
}
}
return $content;
}, 1);
Note that in this solution the headers are already sent and only rendering is possible. If we want to send for example a location header to redirect the page, then we need a different solution, which is:
add_action('init', function (){
$id = url_to_postid($_SERVER['REQUEST_URI']);
if (in_array($id, array_values($this->pages)))
$callback();
});
So for example in the init we can do redirection if it is a POST and in the_content we can do rendering if it is a GET request.
Related Posts:
- Change the_title() of a page dynamically
- Adding more options to the instance of an image. (Attachment Display Settings)
- Plugin – create a page without it appearing in the side menu
- Is wp-content/install.php a Drop-in?
- Trouble with Transient API when W3TC is activated [closed]
- Using wp_filesystem in Plugins
- How to write testable classes in WordPress
- get_template_part from plugin
- Edit or Remove Plugin .htaccess Using The Admin Panel
- WordPress REST API call generates nonce twice on every call
- WordPress scheduled task is called but not executed
- How to create collections that are edited in admin?
- Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
- How to trap “Publish” button to check for meta box validation?
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- wp_mail not recognizing cc and bcc headers
- How can I call “preview post” from wp_remote_get with authentication?
- When is it too late to call the action wp_enqueue_scripts?
- Use js script from one plugin in another plugin
- Plugin Loading Scripts and Styles on Every Page – Even when not being used
- Build dynamic page from cURL (HTML page) response with plugin
- How to store accumulate multiple option values in a single array using Options_API
- template_redirect for single posts w/ custom fields
- can I prevent WP users (even admin) from deleting custom categories?
- set_sale_price in WooCommerce [closed]
- Adding extra pages to plugin that shouldn’t appear in the sidebar
- jquery document ready function not being called [closed]
- How do I include background images in my stylesheets in a plugin?
- How to deal with equal & similar arguments for a function?
- What parameter should I pass to wp_enqueue_style to depend on the themes stylesheet?
- Custom plugin icon not showing up
- I’m designing a plugin to create database indexes. Suggestions?
- need to get user ID after a user logs in
- Callback is not called in add_settings_field() when passed as part of an array, but recognises that it’s there. It’s passed Class to Class using OOP
- Plugin translations not installed but… strings are translated!
- $reverse_top_level works the opposite way according to Codex?
- Secure Pages Best Practice
- Plugin for Android Marketplace downloads?
- Does wp_login only trigger before an user signs in into the admin panel?
- How to export post meta with images in wordpress
- Parse form values before sending to options.php
- My WordPress plugin cannot load my JavaScript file
- Password field is empty when using wp_signon();
- Putting a resized image into media library with wp_get_image_editor(
- Using ReactJS in the WordPress admin for plugin development
- Show error message after exception handled
- How to use github to update my plugin
- wp_nonce_field displaying twice
- WP Cron being triggered but not working as expected
- Plugin Options Array Set to Undefined
- is pre_get_comments not working?
- How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?
- Settings API – format container of setting and setting’s description
- Delete option of a Plugin
- Automating the process of shortcode generation in a plugin – how is it done?
- Apply function to update_option Variable
- I am trying to make a page in the admin section similar to the appearance of the Profile page for users
- Proper way to include stylesheet for panels
- unregister_setting() vs delete_option() for plugin update
- How to make and save custom form in custom plugin page?
- Get thumbnails with array sizes parameter
- Why would someone use function_exists(‘add_action’) in a plugin?
- WordPress Gutenberg InnerBlocks renderAppender not showing with template
- How to add Plugin functionality in WordPress Frontend Menus
- Add a custom menu item that supports wildcards
- Best practice for plugin: always detect admin-ajax call?
- Adding another field to user table
- Brainstorm – Slow Query from Plugin Need to Speed It Up
- How to share user data across multiple WordPress websites?
- Load stylesheet in edit category page?
- How to properly create table in plugin
- Set the payment processor callbacks to a plugin
- Error code when migrate
- Add two button to page and post admin to redirect to : add new & list of (posts – pages) just after saving post or page
- How to add .ini file type to the plugin editor to read and edit?
- WordPress: I wanted to use Add rewrite rule multiple times for multiple CPT in my plugin
- How do I show how many products are remaining from the bought package
- WordPress Ajax not returning Response
- Group By in a Metaquery
- Where to store Plugin specific information in the database
- Add a Script button in W3 Total Cache plugin not working due to conflicting jQuery version
- Remove from a div by class name from post page if post author role is not administrator
- How to create session for user which is not an admin user
- Any way to make Apache’s internal redirect work?
- New Users are saved with no role selected
- get_option() is undefined in TinymceWindowManager
- Getting duplicate page when activating my plugin
- Enqueue script not working
- Modify request query string before plugins
- auto create only 1 wp page in activate custom plugin
- Plugin error on activation – breaks page encoding and prints the code of plugin php files
- Include add_post_meta in a plugin
- isset($_POST[‘submit’]) ignored on comment submission
- how to insert content into wp_head after loop_end
- WordPress simple ‘Hello World’ plugin – problems
- How do I display and edit other posts within the ‘Edit Post’ area of Wp-Admin Dashboard
- A better way of getting draft posts that has a particular post meta using get_posts function
- Save translation file of third party plugin in a custom plugin?
- Custom rewrite, url path with parameters to a page
- Developing an IP lookup function using an API