Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add customizable message above password form. #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ public function password_protected_settings() {
'password_protected'
);

add_settings_field(
'password_protected_message',
__( 'Message to display above the password form', 'password-protected' ),
array( $this, 'password_protected_message_field' ),
$this->options_group,
'password_protected'
);

register_setting( $this->options_group, 'password_protected_status', 'intval' );
register_setting( $this->options_group, 'password_protected_feeds', 'intval' );
register_setting( $this->options_group, 'password_protected_rest', 'intval' );
Expand All @@ -172,6 +180,7 @@ public function password_protected_settings() {
register_setting( $this->options_group, 'password_protected_allowed_ip_addresses', array( $this, 'sanitize_ip_addresses' ) );
register_setting( $this->options_group, 'password_protected_remember_me', 'boolval' );
register_setting( $this->options_group, 'password_protected_remember_me_lifetime', 'intval' );
register_setting( $this->options_group, 'password_protected_message', 'wp_filter_post_kses' );

}

Expand Down Expand Up @@ -311,6 +320,24 @@ public function password_protected_remember_me_lifetime_field() {

}

/**
* Output the form element to collect the message input.
*
* @since 3.0
*
* @return string HTML to display.
*/
public function password_protected_message_field() {

$settings = apply_filters( 'password_protected_message_editor_settings', array(
'textarea_rows' => 5,
) );
$saved_option = wp_unslash( get_option( 'password_protected_message' ) );

wp_editor( $saved_option, 'password_protected_message', $settings );

}

/**
* Pre-update 'password_protected_password' Option
*
Expand Down
17 changes: 17 additions & 0 deletions password-protected.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function __construct() {
add_filter( 'rest_authentication_errors', array( $this, 'only_allow_logged_in_rest_access' ) );
add_action( 'init', array( $this, 'compat' ) );
add_action( 'password_protected_login_messages', array( $this, 'login_messages' ) );
add_action( 'password_protected_before_login_form', array( $this, 'display_custom_message' ) );
add_action( 'login_enqueue_scripts', array( $this, 'load_theme_stylesheet' ), 5 );

// Available from WordPress 4.3+
Expand Down Expand Up @@ -742,6 +743,22 @@ public function login_messages() {

}

/**
* Add a message above the "password protected" form, if set.
*
* @since 3.0
*
* @return string HTML to display.
*/
function display_custom_message() {

$message = get_option( 'password_protected_message' );
if ( $message ) {
echo apply_filters( 'the_content', wp_unslash( $message ) );
}

}

/**
* Load Theme Stylesheet
*
Expand Down