flush_rewrite_rules() should be called very early within the WordPress initialization. The reason is that the entpoints cannot be changed afterwards.
A solution could look like this:
function updateMySlugOption($old_value, $value, $option) {
if( $old_value != $value ) {
set_transient('update_slugs', 1);
}
}
add_action( 'update_option_mySlug', 'updateMySlugOption', 10, 3);
function update_slugs() {
if( get_transient('update_slugs') ) {
flush_rewrite_rules();
delete_transient('update_slugs');
}
}
add_action('init', 'update_slugs');
Related Posts:
- How to call a plugin function from index.php
- Rewriting every url
- Passing URL parameters to WordPress pages and pretty url
- Publish Post After Click On A Link
- How to get the custom page get_permalink?
- Custom url structure for custom template
- Add a Custom Permalink option in the Permalink Admin Screen?
- How to get the permalink of a page when loading my plugin
- How do I add a custom sub menu menu under Woo-commerce marketing?
- How to change custom post type pemalink Hierarcy
- Modifying Author Link to add Author Meta in URL
- SEO Friendly URL on dynamic product page produced via shortcode
- Perform internal redirect in WordPress?
- How to get the permanent link in a plugin?
- Add_rewrite_endpoint doesn’t work with post name permalink structure
- How to embed a new string in url?
- Make get_permalink() work outside the Loop using filters
- help intercepting save_post through plugin
- WordPress Frontend Page using Plugin
- Child theme modifications not showing up
- Create new page in wordpress plugin which doesn’t exist
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- Changing author slug for a custom role without using plugin
- Custom author page for custom role
- Custom role not listed
- Is it possible to change plugin’s Admin Panel Url?
- Coming soon pages with rest of site in maintenance mode
- claim a permalink and all sublinks in plugin
- Pass PHP variable to javascript
- Does the number of downloads displayed for a plug-in in the WordPress.org plug-in directory include automatic updates?
- Namespaces in WordPress – How do I initiate the main class?
- What areas to Unit test while building a plugin?
- Which method is best to enqueue scripts
- Function to activate WordPress theme inside a plugin
- What is the correct way to check if WP_Filesystem can write to a directory without aking for username / password?
- WP get_permalink Return Wrong URL
- Pass A Value From Outside To A Plugin Variable
- shortcode doesn’t work
- Built in admin ajax hooks?
- Could someone please help me to add category id with in this query so this will return posts from a certain category?
- How to handle autoloading with composer by keeping the WordPress naming conventions?
- Current user in plugin returns NULL
- What are the benefit in adding hook in the init() hook?
- Minimum PHP Required for WordPress
- building plugin and it is displaying above plugins page
- load_theme_textdomain path
- Dynamic CSS Vs Inline Issues in Code any Way around in a WordPress Themes?
- plugin development: problem with functions
- Create entire wordpress as a github repositery?
- Building plugin with changeable custom post type values…advice needed
- Change permalinks of custom post type ‘question’ as post id or any random number once
- Conditional attributes and logic per product category
- Why Is This Code Causing The Admin Bar to Disappear?
- Displaying Custom Sidebar Without Modifying Theme’s Core File?
- Stop Plugin from Getting Styles from Other Plugin
- Default taxonomy template in plugin, override in theme
- rewrite_rules() not applying rules on plugin activation only after permalinks menu is clicked
- Why Does The `auto_update_plugin` Hook Disable Management?
- Is there a way to add custom endpoint to specific page only
- IF condition based on wp_remote_get output
- Add User Role: Pre-saved in User-Meta [SOLVED]
- Is there a script to collect all hooks and filters provided by a plugin?
- How WordPress core manage the plugin installation
- Why is my WordPress Plugin page requesting my FTP Login Credentials?
- Post status doesn’t update to ‘future’ every time?
- Unable to give correct path in wordpress
- Disable variations on woo commerce if out of stock
- How to add img into a plugin?
- count the number of views of a post excluding own views
- How To Create A File Archive in WordPress?
- How to hide plugin submenu title in drop down in admin panel in wordpress?
- How to set Google Analytics tracking code on WordPress plugin directory page?
- Show Custom Post on Frontend
- Problem with checked box on wp car manager plugin
- Create a link that calls our custom function in WordPress
- WordPress Ajax request “Failed to load resource: the server responded with a status of 400 ()”
- Load my Inline js footer area
- Remove action added in plugin class from theme
- wc_get_product_terms() throws “Notice: Undefined offset: 0”
- Woocommerce list variations that are added already to cart in Single Product
- Using multi-dimensional array with filter
- WordPress Admin sub-level menu issue
- How do I add a textarea (multirow) option to my WordPress plugin?
- PHP header() not available to use in my plugin
- Passing ajax variable to more than one wordpress plugin function
- How to insert category name above post title in a featured pages plugin?
- Displaying friend’s posts only
- Why isn’t my plugin seeing other classes?
- How to add submenu to WordPress plugin in the same Directory of main Plugin?
- How to add jquery to my custom post type wp plugin
- Update post meta not working on wp_postmeta
- Check if user is in a group of another site within multisite network [closed]
- Synch Custom Post Types (and Custom Fields, Cats, etc.) Between WordPress Sites
- Redirect url in plugin to somewhere else?
- wp_insert_post_data filter to set category
- Site is setup statically – how to make it content managable?
- is there a way I can add or remove some plugin options?
- Modifying lightbox plugin to allow for quoting, Does this exist? [closed]
- What can I do to customize a widget provided with this plugin? from where have I to start?
- How to escape html code?