Converting core modification to a plugin
-
25-01-2021 - |
题
I needed to change two strings shown to the user on the site upon clicking the confirmation links in the email (not to modify the emails sent out). I made the following modifications and it worked.:
--- wp-activate.bak 2017-02-28 13:01:03.883175677 +0530
+++ wp-activate.php 2017-02-28 13:47:35.000000000 +0530
@@ -13,6 +13,10 @@ require( dirname(__FILE__) . '/wp-load.p
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
+// Changes the header
+
+require( dirname(__FILE__) . '/wp-custommsg.php' );
+
if ( !is_multisite() ) {
wp_redirect( wp_registration_url() );
die();
@@ -128,7 +132,7 @@ get_header( 'wp-activate' );
$url = isset( $result['blog_id'] ) ? get_home_url( (int) $result['blog_id'] ) : '';
$user = get_userdata( (int) $result['user_id'] );
?>
- <h2><?php _e('Your account is now active!'); ?></h2>
+ <h2><?php _e($active_page_title); ?></h2>
<div id="signup-welcome">
<p><span class="h3"><?php _e('Username:'); ?></span> <?php echo $user->user_login ?></p>
@@ -147,7 +151,7 @@ get_header( 'wp-activate' );
<?php else: ?>
<p class="view"><?php
/* translators: 1: login URL, 2: network home URL */
- printf( __( 'Your account is now activated. <a href="%1$s">Log in</a> or go back to the <a href="%2$s">homepage</a>.' ), network_site_url( 'wp-login.php', 'login' ), network_home_url() );
+ printf( __( $active_page_msg ), network_site_url( 'wp-login.php', 'login' ), network_home_url() );
?></p>
<?php endif;
}
And wp-custommsg.php contains:
<?php
$active_page_title = 'My custom title';
$active_page_msg = 'My custom message';
?>
I tried to read about hooks and actions but can't seem to wrap my head around them. How can I convert my changes into a plugin so that it survives a wordpress version update?
To clarify, these modifications reside in html code outside of the php content in wp-activate.php, and as far as I can see, do not have hooks.
解决方案
I haven't done this kind of a hook yet but I did find this page in the wordpress codex
https://codex.wordpress.org/Function_Reference/wpmu_welcome_user_notification
They do explain a bit their about how you can modify the content of the activation and notifcation emails
I will try to explain a bit here In Wordpress an Action is a type of hook. You get Action Hooks and Filter Hooks
Actions are triggered by specific events that happen in Wordpress like when a post is published you can trigger a custom action. Linked to a function that handles what you need it to do. An idea here is say for instance you would like to update a third party database when a specific post is updated you could link that to an action. Actions are hooks to Wordpress using add_action()
Filters are functions defined for Wordpress to run data through as it is displayed. So say for instance you would like to change some text on a post without affecting the database you would use a filter. That way when you change the filter you don't have to edit the actual database values of the posts. Filters are hooked into wordpress using add_filter()
For more information I think have a read at this page https://codex.wordpress.org/Plugin_API which explains more in details about Hooks.