SecuPress Shortcode

Below, you’ll find a detailed guide on how to add the SecuPress Free — WordPress Security 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 SecuPress Free — WordPress Security Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the SecuPress Free — WordPress Security Plugin and the shortcodes it provides:

Plugin Icon
SecuPress Free — WordPress Security

SecuPress Free — WordPress Security is a robust plugin that safeguards your WordPress site against threats. It provides top-notch security features to protect your data and ensure smooth operations.

★★★★✩ (98) Active Installs: 40000+ Tested with: 6.2.3 PHP Version: 5.6
Included Shortcodes:
  • [secupress_check_ban_ips_form]

SecuPress Free [secupress_check_ban_ips_form] Shortcode

The SecuPress shortcode is used to manage IP bans. It creates a form that allows administrators to unban their IP if accidentally locked out.

Shortcode: [secupress_check_ban_ips_form]

Parameters

Here is a list of all possible secupress_check_ban_ips_form shortcode parameters and attributes:

  • time_ban – defines the ban duration in seconds, -1 means indefinite
  • ip – the IP address used for nonce check
  • action – url where the form data will be sent
  • error – an optional error message to be displayed in the form
  • content – any additional content to be included in the form

Examples and Usage

Basic example – A simple usage of the shortcode without any parameters. This will use the default values defined in the function.

[secupress_check_ban_ips_form /]

Advanced examples

Using the shortcode with a custom time ban and IP address. This will display a message saying that the specified IP address has been banned.

[secupress_check_ban_ips_form time_ban=1 ip="192.168.0.1" /]

Using the shortcode with a custom action URL and error message. This will create a form with the specified action URL and display the specified error message if there is an error.

[secupress_check_ban_ips_form action="http://yourwebsite.com/unlock" error="Invalid email address" /]

Using the shortcode with a custom content. This will display the custom content instead of the default content.

[secupress_check_ban_ips_form content="This is custom content" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'secupress_check_ban_ips_form', 'secupress_check_ban_ips_form' );

Shortcode PHP function:

function secupress_check_ban_ips_form( $args, $contents = '' ) {
	$args = wp_parse_args( $args, [
		'time_ban' => -1,
		'ip'       => 'admin', // use for nonce check, see action below v.
		'action'   => 'action="' . wp_nonce_url( admin_url( 'admin-post.php?action=secupress_unlock_admin' ), 'secupress-unban-ip-admin' ) . '"',
		'error'    => '',
		'content'  => '',
	] );

	switch ( true ) {
		case $args['time_ban'] >= 0:
			$content = '<p>' . sprintf( __( 'Your IP address <code>%s</code> has been banned.', 'secupress' ), esc_html( $args['ip'] ) ) . '</p>';
		break;
		default:
			$content = $args['content'];
	}
	$content .= '<p><form method="post" autocomplete="on" ' . $args['action'] . '>';
		$content .= '<p>' . __( 'If you are Administrator and have been accidentally locked out, enter your email address here to unlock yourself.', 'secupress' ) . '</p>';
		$content .= '<label for="email">';
			$content .= __( 'Your email address:', 'secupress' );
			$content .= ' <input id="email" type="email" name="email" value="" required="required" aria-required="true" />';
			$content .= $args['error'] ? '<br/><span class="error">' . $args['error'] . '</span>' : '';
		$content .= '</label>';
		$content .= '<p class="submit"><button type="submit" name="submit" class="button button-primary button-large">' . __( 'Submit', 'secupress' ) . '</button></p>';
		$content .= wp_nonce_field( 'secupress-unban-ip-' . $args['ip'], '_wpnonce', true , false );
	$content .= '</form></p>';

	return $content;
}

Code file location:

secupress/secupress/free/common.php

Conclusion

Now that you’ve learned how to embed the SecuPress Free — WordPress Security 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 *