Below, you’ll find a detailed guide on how to add the Pirate Forms 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 Pirate Forms Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Pirate Forms Plugin and the shortcodes it provides:
"PirateForms is a Contact Form & SMTP Plugin for WordPress. It simplifies the process of creating and managing contact forms and seamlessly integrates with your email SMTP for efficient communication."
- [pirate_forms]
Pirate Forms [pirate_forms] Shortcode
The Pirate Forms shortcode is used to display a form in your WordPress site. It allows customization of form elements like name, email, subject, message, and more.
Shortcode: [pirate_forms]
Parameters
Here is a list of all possible pirate_forms shortcode parameters and attributes:
id
– Unique identifier for the contact form.from
– Indicates if the form is from a widget.ajax
– Enables or disables ajax form submission.
Examples and Usage
Basic example – Displaying a simple contact form using the Pirate Forms plugin
[pirate_forms]
Advanced examples
Displaying a specific form by referencing its ID. This will load the form with the specified ID.
[pirate_forms id="2"]
Enabling AJAX for the form. This will allow the form to submit without requiring a page reload.
[pirate_forms ajax="yes"]
Displaying a form from a widget. This allows you to display a form that was created in a widget.
[pirate_forms from="widget"]
Combining multiple parameters. This example shows a form with a specific ID, enabled AJAX, and is displayed from a widget.
[pirate_forms id="3" ajax="yes" from="widget"]
PHP Function Code
In case you have difficulties debugging what causing issues with [pirate_forms]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'pirate_forms', array( $plugin_public, 'display_form' ) );
Shortcode PHP function:
function display_form( $atts, $content = null ) {
wp_enqueue_style( 'pirate_forms_front_styles' );
PirateForms_Util::session_start();
$atts = shortcode_atts(
array(
'from' => '',
'id' => '',
'ajax' => 'no',
), $atts
);
do_action( 'themeisle_log_event', PIRATEFORMS_NAME, sprintf( 'displaying shortcode %s', print_r( $atts, true ) ), 'debug', __FILE__, __LINE__ );
$form_id = isset( $atts['id'] ) && ! empty( $atts['id'] ) ? intval( $atts['id'] ) : 0;
$from_widget = ! empty( $atts['from'] );
$elements = array();
$pirate_form = new PirateForms_PhpFormBuilder();
$pirate_forms_options = PirateForms_Util::get_form_options( $form_id );
if ( ! empty( $pirate_forms_options['pirateformsopt_recaptcha_secretkey'] ) && ! empty( $pirate_forms_options['pirateformsopt_recaptcha_sitekey'] ) && ! empty( $pirate_forms_options['pirateformsopt_recaptcha_field'] ) && ( 'yes' === $pirate_forms_options['pirateformsopt_recaptcha_field'] ) ) {
wp_enqueue_script( 'google-recaptcha' );
}
wp_enqueue_script( 'pirate_forms_scripts' );
$ajax = 'yes' === $atts['ajax'];
$elements[] = array(
'type' => 'hidden',
'id' => 'pirate_forms_ajax',
'name' => 'pirate_forms_ajax',
'value' => $ajax ? 1 : 0,
);
$elements[] = array(
'type' => 'text',
'id' => 'form_honeypot',
'name' => 'honeypot',
'slug' => 'honeypot',
'wrap' => array(
'type' => 'div',
'class' => 'form_field_wrap hidden',
'style' => 'display: none',
),
);
$elements[] = array(
'type' => 'hidden',
'id' => 'pirate_forms_from_widget',
'value' => $from_widget ? 1 : 0,
);
$pirate_forms_options = PirateForms_Util::get_option();
if ( $form_id > 0 ) {
$pirate_forms_options = apply_filters( 'pirateformpro_get_form_attributes', $pirate_forms_options, $form_id );
if ( isset( $pirate_forms_options['id'] ) ) {
// add the form id to the form so that it can be used when we are processing the form
$elements[] = array(
'type' => 'hidden',
'id' => 'pirate_forms_form_id',
'value' => $form_id,
);
}
}
$nonce_append = $from_widget ? 'yes' : 'no';
$error_key = wp_create_nonce( get_bloginfo( 'admin_email' ) . ( $from_widget ? 'yes' : 'no' ) );
$new_error_key = $nonce_append . '.' . $form_id;
$thank_you_message = '';
if ( isset( $_GET['done'] ) && ! empty( $_SESSION[ 'success' . $new_error_key ] ) ) {
$thank_you_message = $_SESSION[ 'success' . $new_error_key ];
}
$pirate_form->set_element( 'thank_you_message', $thank_you_message );
/**
******** FormBuilder */
if ( 'yes' === PirateForms_Util::get_option( 'pirateformsopt_nonce' ) ) {
$elements[] = array(
'type' => 'hidden',
'id' => 'wordpress-nonce',
'value' => wp_create_nonce( get_bloginfo( 'admin_email' ) . $nonce_append ),
);
}
if ( ! empty( $pirate_forms_options ) ) {
$field = $pirate_forms_options['pirateformsopt_name_field'];
$label = $pirate_forms_options['pirateformsopt_label_name'];
$subjectField = $pirate_forms_options['pirateformsopt_subject_field'];
/**
****** Name field */
if ( ! empty( $field ) && ! empty( $label ) ) {
$required = $field === 'req' ? true : false;
$wrap_classes = array(
( ! empty( $subjectField ) ? 'col-xs-12 col-sm-6' : 'col-xs-12' ) . ' contact_name_wrap pirate_forms_three_inputs form_field_wrap',
);
// If this field was submitted with invalid data
if ( isset( $_SESSION[ $error_key ]['contact-name'] ) ) {
$wrap_classes[] = 'error';
}
$elements[] = array(
'front_end' => true,
'placeholder' => stripslashes( sanitize_text_field( $label ) ),
'required' => $field === 'req' ? true : false,
'required_msg' => $pirate_forms_options['pirateformsopt_label_err_name'],
'type' => 'text',
'id' => 'pirate-forms-contact-name',
'value' => empty( $thank_you_message ) && isset( $_REQUEST['pirate-forms-contact-name'] ) ? $_REQUEST['pirate-forms-contact-name'] : '',
'wrap_class' => implode( ' ', $wrap_classes ),
);
}
$field = $pirate_forms_options['pirateformsopt_email_field'];
$label = $pirate_forms_options['pirateformsopt_label_email'];
/**
****** Email field */
if ( ! empty( $field ) && ! empty( $label ) ) {
$required = $field === 'req' ? true : false;
$wrap_classes = array(
( ! empty( $subjectField ) ? 'col-xs-12 col-sm-6' : 'col-xs-12' ) . ' contact_email_wrap pirate_forms_three_inputs form_field_wrap',
);
// If this field was submitted with invalid data
if ( isset( $_SESSION[ $error_key ]['contact-email'] ) ) {
$wrap_classes[] = 'error';
}
$elements[] = array(
'front_end' => true,
'placeholder' => stripslashes( sanitize_text_field( $label ) ),
'required' => $field === 'req' ? true : false,
'required_msg' => $pirate_forms_options['pirateformsopt_label_err_email'],
'type' => 'email',
'id' => 'pirate-forms-contact-email',
'value' => empty( $thank_you_message ) && isset( $_REQUEST['pirate-forms-contact-email'] ) ? $_REQUEST['pirate-forms-contact-email'] : '',
'wrap_class' => implode( ' ', $wrap_classes ),
);
}
$field = $pirate_forms_options['pirateformsopt_subject_field'];
$label = $pirate_forms_options['pirateformsopt_label_subject'];
/**
****** Subject field */
if ( ! empty( $field ) && ! empty( $label ) ) {
$required = $field === 'req' ? true : false;
$wrap_classes = array(
'col-xs-12 contact_subject_wrap pirate_forms_three_inputs form_field_wrap',
);
// If this field was submitted with invalid data
if ( isset( $_SESSION[ $error_key ]['contact-subject'] ) ) {
$wrap_classes[] = 'error';
}
$elements[] = array(
'front_end' => true,
'placeholder' => stripslashes( sanitize_text_field( $label ) ),
'required' => $field === 'req' ? true : false,
'required_msg' => $pirate_forms_options['pirateformsopt_label_err_subject'],
'type' => 'text',
'id' => 'pirate-forms-contact-subject',
'value' => empty( $thank_you_message ) && isset( $_REQUEST['pirate-forms-contact-subject'] ) ? $_REQUEST['pirate-forms-contact-subject'] : '',
'wrap_class' => implode( ' ', $wrap_classes ),
);
}
$field = $pirate_forms_options['pirateformsopt_message_field'];
$label = $pirate_forms_options['pirateformsopt_label_message'];
/**
****** Message field */
if ( ! empty( $field ) && ! empty( $label ) ) {
$required = $field === 'req' ? true : false;
$wrap_classes = array(
'col-xs-12 contact_message_wrap pirate_forms_three_inputs form_field_wrap',
);
// If this field was submitted with invalid data
if ( isset( $_SESSION[ $error_key ]['contact-message'] ) ) {
$wrap_classes[] = 'error';
}
$elements[] = array(
'front_end' => true,
'placeholder' => stripslashes( sanitize_text_field( $label ) ),
'required' => $field === 'req' ? true : false,
'required_msg' => $pirate_forms_options['pirateformsopt_label_err_no_content'],
'type' => 'textarea',
'id' => 'pirate-forms-contact-message',
'value' => empty( $thank_you_message ) && isset( $_REQUEST['pirate-forms-contact-message'] ) ? $_REQUEST['pirate-forms-contact-message'] : '',
'wrap_class' => implode( ' ', $wrap_classes ),
);
}
$field = $pirate_forms_options['pirateformsopt_attachment_field'];
/**
****** Attachment field */
if ( ! empty( $field ) && 'no' !== $field ) {
$required = $field === 'req' ? true : false;
$wrap_classes = array( 'col-xs-12 form_field_wrap contact_attachment_wrap' );
// If this field was submitted with invalid data
if ( isset( $_SESSION[ $error_key ]['contact-attachment'] ) ) {
$wrap_classes[] = 'error';
}
$elements[] = array(
'front_end' => true,
'required' => $field === 'req' ? true : false,
'required_msg' => $pirate_forms_options['pirateformsopt_label_err_no_attachment'],
'type' => 'file',
'title' => __( 'Upload file', 'pirate-forms' ),
'id' => 'pirate-forms-attachment',
'wrap_class' => implode( ' ', $wrap_classes ),
);
}
if ( array_key_exists( 'pirateformsopt_checkbox_field', $pirate_forms_options ) ) {
$field = $pirate_forms_options['pirateformsopt_checkbox_field'];
$label = $pirate_forms_options['pirateformsopt_label_checkbox'];
/**
****** checkbox field */
if ( ! empty( $field ) && ! empty( $label ) ) {
$required = $field === 'req' ? true : false;
$wrap_classes = array( 'col-xs-12 form_field_wrap contact_checkbox_wrap ' );
// If this field was submitted with invalid data
if ( isset( $_SESSION[ $error_key ]['contact-checkbox'] ) ) {
$wrap_classes[] = 'error';
}
$elements[] = array(
'front_end' => true,
'required' => $required,
'required_msg' => $pirate_forms_options['pirateformsopt_label_err_no_checkbox'],
'type' => 'checkbox',
'id' => 'pirate-forms-contact-checkbox',
'wrap' => array(
'type' => 'div',
'class' => implode( ' ', apply_filters( 'pirateform_wrap_classes_checkbox', $wrap_classes ) ),
),
'value' => isset( $_REQUEST['pirate-forms-contact-checkbox'] ) ? $_REQUEST['pirate-forms-contact-checkbox'] : '',
'options' => array(
'yes' => stripslashes( $label ),
),
);
}
}
/**
******* ReCaptcha */
if ( ! empty( $pirate_forms_options['pirateformsopt_recaptcha_secretkey'] ) && ! empty( $pirate_forms_options['pirateformsopt_recaptcha_sitekey'] ) && ! empty( $pirate_forms_options['pirateformsopt_recaptcha_field'] ) && 'yes' === $pirate_forms_options['pirateformsopt_recaptcha_field'] ) {
$pirateformsopt_recaptcha_sitekey = $pirate_forms_options['pirateformsopt_recaptcha_sitekey'];
$pirateformsopt_recaptcha_secretkey = $pirate_forms_options['pirateformsopt_recaptcha_secretkey'];
$elements[] = array(
'front_end' => true,
'id' => 'pirate-forms-captcha',
'placeholder' => stripslashes( sanitize_text_field( $label ) ),
'type' => 'captcha',
'custom' => array( 'data-sitekey' => $pirateformsopt_recaptcha_sitekey ),
'id' => 'pirate-forms-captcha',
'wrap' => array(
'type' => 'div',
'class' => implode( ' ', apply_filters( 'pirateform_wrap_classes_captcha', array( 'col-xs-12 ' . ( $pirate_forms_options['pirateformsopt_recaptcha_field'] !== 'yes' ? 'col-sm-6 ' : '' ) . 'form_field_wrap form_captcha_wrap' ) ) ),
),
);
}
if ( ! empty( $pirate_forms_options['pirateformsopt_recaptcha_field'] ) && 'custom' === $pirate_forms_options['pirateformsopt_recaptcha_field'] ) {
$elements[] = array(
'front_end' => true,
'type' => 'spam',
'id' => 'pirate-forms-maps-custom',
);
}
/**
****** Submit button */
$pirateformsopt_label_submit_btn = '';
if ( ! empty( $pirate_forms_options['pirateformsopt_label_submit_btn'] ) ) {
$pirateformsopt_label_submit_btn = $pirate_forms_options['pirateformsopt_label_submit_btn'];
}
if ( empty( $pirateformsopt_label_submit_btn ) ) {
$pirateformsopt_label_submit_btn = __( 'Submit', 'pirate-forms' );
}
$elements[] = array(
'front_end' => true,
'type' => 'button',
'id' => 'pirate-forms-contact-submit',
'name' => 'pirate-forms-contact-submit',
'class' => 'pirate-forms-submit-button btn btn-primary ' . ( $ajax ? 'pirate-forms-submit-button-ajax' : '' ),
'wrap' => array(
'type' => 'div',
'class' => implode( ' ', apply_filters( 'pirateform_wrap_classes_submit', array( 'col-xs-12 ' . ( ( ! empty( $pirate_forms_options['pirateformsopt_recaptcha_field'] ) && ( $pirate_forms_options['pirateformsopt_recaptcha_field'] !== 'yes' ) ) ? 'col-sm-6 ' : '' ) . 'form_field_wrap contact_submit_wrap' ) ) ),
),
'value' => $pirateformsopt_label_submit_btn,
);
}
/* Referring site or page, if any */
if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
$elements[] = array(
'type' => 'hidden',
'id' => 'pirate-forms-contact-referrer',
'value' => $_SERVER['HTTP_REFERER'],
);
}
/* Referring page, if sent via URL query */
if ( ! empty( $_REQUEST['src'] ) || ! empty( $_REQUEST['ref'] ) ) {
$elements[] = array(
'type' => 'hidden',
'id' => 'referring-page',
'value' => ! empty( $_REQUEST['src'] ) ? $_REQUEST['src'] : $_REQUEST['ref'],
);
}
/* Are there any submission errors? */
if ( ! empty( $_SESSION[ 'error' . $new_error_key ] ) ) {
$pirate_form->set_element( 'errors', $_SESSION[ 'error' . $new_error_key ] );
unset( $_SESSION[ 'error' . $new_error_key ] );
}
$elements = apply_filters( 'pirate_forms_get_custom_elements', $elements, $pirate_forms_options );
do_action( 'themeisle_log_event', PIRATEFORMS_NAME, sprintf( 'displaying elements %s', print_r( $elements, true ) ), 'debug', __FILE__, __LINE__ );
$output = $pirate_form->build_form( apply_filters( 'pirate_forms_public_controls', $elements, $pirate_forms_options, $from_widget ), $pirate_forms_options, $from_widget );
unset( $_SESSION[ 'success' . $new_error_key ] );
unset( $_SESSION[ 'error' . $new_error_key ] );
return $output;
}
Code file location:
pirate-forms/pirate-forms/includes/class-pirateforms.php
Conclusion
Now that you’ve learned how to embed the Pirate Forms 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.
Leave a Reply