In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Xiaobian to share with you how to achieve WordPress for updating pseudo-static rules PHP code, I believe most people do not know how, so share this article for your reference, I hope you read this article after a great harvest, let us go to understand it!
The flush_rewrite_rules() function is used to delete and then rewrite pseudo-static rules based on existing conditions, i.e. refresh pseudo-static rules once.
First of all, it is usually called when the theme or plug-in adds a new custom article type to prevent the new custom article type article from appearing 404, or many times we need to execute some code when the theme is enabled, such as arranging some database forms, jumping to the settings page, etc. WordPress itself does not provide related hooks, and there are many various implementation methods on the Internet. After my research, I found out that it may be the best way to share it with you below:
/** *WordPress executes some code when the theme is enabled *http://www.endskin.com/theme-activation-action/*/function Bing_theme_activation(){ if( $GLOBALS ['pagenow '] != 'themes.php' || ! isset( $_GET ['activated ']) return; /* Here you can place the code to be executed when the theme is enabled, such as jumping to the settings interface: wp_redirect( admin_url ('options-general.php'));//Note to modify the page address die; */}add_action ('load-themes.php','Bing_theme_activation');
This code works both in themes and plugins.
Also note that updating pseudo-static rules is very time-consuming and efficient, so don't call it every time you execute code, call it only when necessary (such as enabling themes and plugins), and it's extremely incorrect to hang flush_rewrite_rules() on the init hook.
usage
flush_rewrite_rules( $hard );
parameters
$hard
(Boolean)(Optional) If True, refresh the.htaccess file together (hard flush); if False, update only pseudo-static rules in the database (soft flush).
Default: True (hard flush).
example
Update pseudo-static rules when theme is enabled:
function Bing_theme_activation(){ if( $GLOBALS['pagenow'] != 'themes.php' || ! isset( $_GET['activated'] ) ) return; flush_rewrite_rules();}add_action( 'load-themes.php', 'Bing_theme_activation' );
Update pseudo-static rules when plug-ins are enabled:
function Bing_myplugin_activate(){ flush_rewrite_rules();}register_activation_hook( __FILE__, 'Bing_myplugin_activate'); Above is "How to implement PHP code for updating pseudo-static rules in WordPress" All the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 298
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.