Find us on Facebook

LightBlog
Responsive Ads Here

Thứ Sáu, 29 tháng 12, 2017

Function like is_registration_page to check if current page is registration page

Question:

You can use is_admin to check to see if the current web page is part of WordPress' administrator interface.
Is there a way to see if the page being processed is the registration page?

Answer:

How about attempting to intercept the registration page via hooks. Here's an example of how hooks can be used to add a field to the registration form (below)... Depending on your situation, you can use this (and the hook to intercept a submitted form) as a means to achieve what you're looking for.
I added in a line: $GLOBALS['is_registration'] = TRUE;
But note, this global variable may not be available at the point you require it. You will have to test to see.
<?php
add_action( 'register_form', 'myplugin_add_registration_fields' );
function myplugin_add_registration_fields() {

    $GLOBALS['is_registration'] = TRUE;

    //Get and set any values already sent
    $user_extra = ( isset( $_POST['user_extra'] ) ) ? $_POST['user_extra'] : '';
?>
    <label for="user_extra"><?php _e( 'Extra Field', 'myplugin_textdomain' ) ?>
    <input type="text" name="user_extra" id="user_extra" class="input" value="<?php echo esc_attr( stripslashes( $user_extra ) ); ?>" size="25" /></label>
<?php
}
?>
You can read more about these action/filter hooks at:https://codex.wordpress.org/Plugin_API/Action_Reference/register_form

Không có nhận xét nào:

Đăng nhận xét