Protected Posts Logout Button Shortcode

Below, you’ll find a detailed guide on how to add the Protected Posts Logout Button Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Protected Posts Logout Button Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Protected Posts Logout Button Plugin and the shortcodes it provides:

Plugin Icon
Protected Posts Logout Button

"Protected Posts Logout Button is a WordPress plugin that enhances security by adding a logout button to your protected posts, ensuring restricted access."

★★★★☆ (13) Active Installs: 2000+ Tested with: 6.1.4 PHP Version: false
Included Shortcodes:
  • [logout_btn]

Protected Posts Logout Button [logout_btn] Shortcode

The Protected Posts Logout Button (PPLB) shortcode is designed to generate a logout button for password-protected posts. When a post is password-protected, the shortcode checks if the password has been provided. If it has, the shortcode retrieves the button’s class and text from the plugin’s options. It then applies any existing filters to the text and generates the HTML for the logout button. If no text is provided, it defaults to ‘logout’. The HTML is then returned, rendering the logout button on the post.

Shortcode: [logout_btn]

Examples and Usage

Basic example – Here is a simple usage of the shortcode to add a logout button to your post.

[logout_btn /]

Advanced examples – In this example, we are using the ‘pplb_button_class’ and ‘pplb_button_text’ options to customize the button. We’ve set the class to ‘my-logout-button’ and the text to ‘Sign Out’.


// In your functions.php
add_filter('pplb_button_html', function($html, $class, $options) {
    $class = 'my-logout-button';
    $text = 'Sign Out';
    return ' ';
}, 10, 3);

Please note that the above PHP code should be added to your theme’s functions.php file. After that, you can use the [logout_btn /] shortcode in your posts and it will display a logout button with the class ‘my-logout-button’ and the text ‘Sign Out’.

PHP Function Code

In case you have difficulties debugging what causing issues with [logout_btn] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('logout_btn', array( $this, 'pplb_logout_button' ) );					// adds the shortcode.

Shortcode PHP function:

function pplb_logout_button(){
			$qid = get_queried_object_id();
			$qpost = get_post($qid);
			$html = '';
			// Check if the post has a password
			if ( !empty( $qpost->post_password ) ) {
				// Check to see if the password has been provided.
				if ( !post_password_required( $qid ) ) {
					$options = get_option( 'pplb_options', array() );
					$class = ( array_key_exists('pplb_button_class', $options) ) ? $options['pplb_button_class'] : '';
					$text = ( array_key_exists('pplb_button_text', $options) ) ? $options['pplb_button_text'] : 'logout';
					
					$text = apply_filters( 'pplb_button_text', $text, $options );
					
					if ( empty( $text ) ) {
						$text = 'logout';
					}
					
					$html = apply_filters( 'pplb_button_html',' <input type="button" class="button logout '.esc_attr($class).'" value="'.esc_attr( $text ).'">', $class, $options );
				}
			}
			return $html;
			
		}

Code file location:

protected-posts-logout-button/protected-posts-logout-button/pplb_logout_button.php

Conclusion

Now that you’ve learned how to embed the Protected Posts Logout Button Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *