Below, you’ll find a detailed guide on how to add the WP24 Domain Check 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 WP24 Domain Check Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the WP24 Domain Check Plugin and the shortcodes it provides:
"WP24 Domain Check is a handy WordPress plugin offering users the ability to check domain availability instantly on their website. A must-have tool for hosting companies."
- [wp24_domaincheck]
WP24 Domain Check [wp24_domaincheck] Shortcode
The wp24_domaincheck shortcode is designed to check domain availability. It integrates with the WP24 Domain Check plugin to provide a dynamic experience for users. This shortcode takes various attributes like ‘id’, ‘mode’, ‘tlds’, and ‘output_type’, which allow for customization. It also handles reCAPTCHA for added security. It’s a versatile tool for any WordPress site dealing with domain-related operations.
Shortcode: [wp24_domaincheck]
Parameters
Here is a list of all possible wp24_domaincheck shortcode parameters and attributes:
id
– A unique identifier for multiple uses of the shortcode.mode
– Defines the mode of operation, default is ‘check’.tlds
– Specifies the top-level domains to be checked.output_type
– Determines the type of output, can be ‘results’ or ‘check_form’.display_type
– Sets the way results are displayed, takes values from the plugin’s options.html_form
– Controls if the output should be in HTML form, true or false.addjs
– If set to 1, additional JavaScript is added to the output.
Examples and Usage
Basic example – A simple usage of the wp24_domaincheck shortcode with no additional parameters. This will display the domain check form with default settings.
[wp24_domaincheck /]
Advanced examples
Displaying the domain check form with a specific set of top-level domains (TLDs) for selection. The ‘tlds’ attribute is used to specify the TLDs.
[wp24_domaincheck tlds="com,net,org" /]
Changing the mode of the domain check form to ‘results’ which means it will only return the result container. The ‘mode’ and ‘output_type’ attributes are used to achieve this.
[wp24_domaincheck mode="check" output_type="results" /]
Displaying the domain check form with a unique ID. This is useful when you want to use the shortcode multiple times on the same page. The ‘id’ attribute is used to specify the unique ID.
[wp24_domaincheck id="uniqueID" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [wp24_domaincheck]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wp24_domaincheck', array( $this, 'shortcode' ) );
Shortcode PHP function:
function shortcode( $atts = [], $content = NULL, $tag = '' ) {
// normalize attribute keys, lowercase
$atts = array_change_key_case( (array)$atts, CASE_LOWER );
// set selection type from unlimited to freetext if tlds definded in shortcode
$selectionType = $this->options['selectionType'];
if ( isset( $atts['tlds'] ) && '' != $atts['tlds'] && 'unlimited' == $this->options['selectionType'] )
$selectionType = 'freetext';
// override default attributes with user attributes
$atts = shortcode_atts( [
'id' => $this->options['multipleUse'] ? uniqid() : '1',
'mode' => 'check',
'tlds' => $this->options['tlds'],
'output_type' => '',
'display_type' => $this->options['displayType'],
'html_form' => $this->options['htmlForm'],
'addjs' => 1,
], $atts, $tag );
// id to use shortcode multiple times (accept only alphanumeric characters)
$id = preg_replace( '/[^a-z0-9]/i', '', $atts['id'] );
// display type from shortcode attributes or options
$displayType = esc_attr( $atts['display_type'] );
// if output type set to results, only return result container
if ( 'results' == $atts['output_type'] )
return '<div id="dc-result-' . $id . '" class="wp24-dc"></div>';
// recaptcha
if ( in_array( $this->options['recaptcha']['type'], array( 'v2_check', 'v2_badge' ) ) ) {
// add "async defer" to recaptcha script tag
add_filter(
'script_loader_tag',
function( $tag, $handle ) {
if ( 'recaptcha' !== $handle )
return $tag;
return str_replace( '></', ' async defer></', $tag );
},
10,
2
);
wp_enqueue_script( 'recaptcha', 'https://www.google.com/recaptcha/api.js' );
}
if ( 'v3' == $this->options['recaptcha']['type'] )
wp_enqueue_script( 'recaptcha', 'https://www.google.com/recaptcha/api.js?render=explicit' );
$js =
"jQuery( function( $ ) {\n".
" $( '#wp24-dc-" . $id . "' ).wp24_domain_check( {\n";
$js .=
" id: '" . $id . "',\n".
" mode: '" . esc_attr( $atts['mode'] ) . "',\n".
" path: '" . plugins_url( '/', dirname( __FILE__ ) ) . "',\n".
" ajaxurl: '" . ( $this->options['useNonces'] ? wp_nonce_url( admin_url( 'admin-ajax.php' ), 'domain_check', 'n' ) : admin_url( 'admin-ajax.php' ) ) . "',\n".
" fieldLabel: '" . $this->translate( 'fieldLabel', $this->options['fieldLabel'] ) . "',\n".
" fieldPlaceholder: '" . $this->translate( 'fieldPlaceholder', $this->options['fieldPlaceholder'] ) . "',\n".
" fieldWidth: '" . intval( $this->options['fieldWidth'] ) . $this->options['fieldUnit'] . "',\n".
" fieldnameDomain: '" . $this->options['fieldnameDomain'] . "',\n".
" fieldnameTld: '" . $this->options['fieldnameTld'] . "',\n".
" selectionType: '" . $selectionType . "',\n".
" tlds: '" . ( 'unlimited' == $selectionType ? '' : esc_attr( $atts['tlds'] ) ) . "',\n".
" checkAll: " . ( $this->options['checkAll'] && 'unlimited' != $selectionType ? "true" : "false" ) . ",\n".
" checkAllLabel: '" . $this->translate( 'checkAllLabel', $this->options['checkAllLabel'] ) . "',\n".
" checkAllDefault: " . ( $this->options['checkAllDefault'] ? "true" : "false" ) . ",\n".
" multicheck: " . ( $this->options['multicheck'] ? "true" : "false" ) . ",\n".
" textButton: '" . $this->translate( 'textButton', $this->options['textButton'] ) . "',\n".
" showWhois: " . ( $this->options['showWhois'] ? "true" : "false" ) . ",\n".
" textWhois: '" . $this->translate( 'textWhois', $this->options['textWhois'] ) . "',\n".
" displayType: '" . $displayType . "',\n";
if ( 'gradual_loading' == $displayType ) {
$js .=
" excludeRegistered: " . ( $this->options['excludeRegistered'] ? "true" : "false" ) . ",\n".
" textNoResults: '" . $this->translate( 'textNoResults', $this->options['textNoResults'] ) . "',\n".
" displayLimit: " . intval( $this->options['displayLimit'] ) . ",\n".
" textLoadMore: '" . $this->translate( 'textLoadMore', $this->options['textLoadMore'] ) . "',\n";
}
$js .=
" textAvailable: '" . $this->translate( 'textAvailable', $this->options['textAvailable'] ) . "',\n".
" colorAvailable: '" . $this->options['colorAvailable'] . "',\n".
" textRegistered: '" . $this->translate( 'textRegistered', $this->options['textRegistered'] ) . "',\n".
" colorRegistered: '" . $this->options['colorRegistered'] . "',\n".
" textError: '" . $this->translate( 'textError', $this->options['textError'] ) . "',\n".
" colorError: '" . $this->options['colorError'] . "',\n".
" textInvalid: '" . $this->translate( 'textInvalid', $this->options['textInvalid'] ) . "',\n".
" colorInvalid: '" . $this->options['colorInvalid'] . "',\n".
" textLimit: '" . $this->translate( 'textLimit', $this->options['textLimit'] ) . "',\n".
" colorLimit: '" . $this->options['colorLimit'] . "',\n".
" textWhoisserver: '" . $this->translate( 'textWhoisserver', $this->options['textWhoisserver'] ) . "',\n".
" colorWhoisserver: '" . $this->options['colorWhoisserver'] . "',\n".
" textUnsupported: '" . $this->translate( 'textUnsupported', $this->options['textUnsupported'] ) . "',\n".
" colorUnsupported: '" . $this->options['colorUnsupported'] . "',\n".
" textTldMissing: '" . $this->translate( 'textTldMissing', $this->options['textTldMissing'] ) . "',\n".
" colorTldMissing: '" . $this->options['colorTldMissing'] . "',\n".
" textEmptyField: '" . $this->translate( 'textEmptyField', $this->options['textEmptyField'] ) . "',\n".
" colorEmptyField: '" . $this->options['colorEmptyField'] . "',\n".
" textInvalidField: '" . $this->translate( 'textInvalidField', $this->options['textInvalidField'] ) . "',\n".
" colorInvalidField: '" . $this->options['colorInvalidField'] . "',\n".
" prefixes: '" . $this->options['prefixes'] . "',\n".
" suffixes: '" . $this->options['suffixes'] . "',\n".
" linkRegistered: " . ( $this->options['linkRegistered'] ? "true" : "false" ) . ",\n".
" dotInSelect: " . ( $this->options['dotInSelect'] ? "true" : "false" ) . ",\n".
" htmlForm: " . ( boolval( $atts['html_form'] ) ? "true" : "false" ) . ",\n";
if ( $this->options['woocommerce']['enabled'] ) {
$js .=
" textPurchase: '" . $this->translate( '[woocommerce]textPurchase', $this->options['woocommerce']['textPurchase'] ) . "',\n".
" textTransfer: '" . $this->translate( '[woocommerce]textTransfer', $this->options['woocommerce']['textTransfer'] ) . "',\n".
" addToCartBehaviour: " . intval( $this->options['woocommerce']['addToCartBehaviour'] ) . ",\n";
if ( intval( $this->options['woocommerce']['addToCartBehaviour'] ) == 2 && '' != $this->options['woocommerce']['customPageLink'] )
$js .= " customPageLink: '" . $this->options['woocommerce']['customPageLink'] . "',\n";
if ( intval( $this->options['woocommerce']['addToCartBehaviour'] ) == 3 )
$js .= " addToCartText: '" . $this->translate( '[woocommerce]addToCartText', $this->options['woocommerce']['addToCartText'] ) . "',\n";
$js .=
" addedToCartText: '" . $this->translate( '[woocommerce]addedToCartText', $this->options['woocommerce']['addedToCartText'] ) . "',\n";
}
else {
$js .=
" textPurchase: '" . $this->translate( 'textPurchase', $this->options['textPurchase'] ) . "',\n".
" textTransfer: '" . $this->translate( 'textTransfer', $this->options['textTransfer'] ) . "',\n".
" addToCartBehaviour: 0,\n";
}
if ( $this->options['unsupported']['enabled'] ) {
$js .=
" unsupported: {\n".
" enabled: true,\n".
" text: '" . $this->translate( '[unsupported]text', $this->options['unsupported']['text'] ) . "',\n".
" color: '" . $this->options['unsupported']['color'] . "',\n".
" verify: " . ( $this->options['unsupported']['verify'] ? "true" : "false" ) . ",\n".
" verifyText: '" . $this->translate( '[unsupported]verifyText', $this->options['unsupported']['verifyText'] ) . "',\n".
" },\n";
}
else {
$js .=
" unsupported: {\n".
" enabled: false,\n".
" },\n";
}
if ( 'none' != $this->options['recaptcha']['type'] ) {
$js .=
" recaptcha: {\n".
" type: '" . $this->options['recaptcha']['type'] . "',\n".
" siteKey: '" . $this->options['recaptcha']['siteKey'] . "',\n".
" theme: '" . $this->options['recaptcha']['theme'] . "',\n".
" size: '" . $this->options['recaptcha']['size'] . "',\n".
" position: '" . $this->options['recaptcha']['position'] . "',\n".
" text: '" . $this->translate( '[recaptcha]text', $this->options['recaptcha']['text'] ) . "',\n".
" color: '" . $this->options['recaptcha']['color'] . "',\n".
" },\n";
}
else {
$js .=
" recaptcha: {\n".
" type: '" . $this->options['recaptcha']['type'] . "',\n".
" },\n";
}
if ( 'check_form' == $atts['output_type'] ) {
$js .=
" hideResults: true,\n";
}
$js .=
" } );\n".
"} );";
// compress js code a little bit
$js = preg_replace( '/\s\s+|\n|\t/', '', $js );
// enqueue scripts only when shortcode is used
if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) {
wp_enqueue_script( 'jquery' );
// block theme does not support "wp_add_inline_script"
$html = '<script src="' . plugins_url( 'assets/js/domaincheck.js', dirname( __FILE__ ) ) . '" id="wp24-domaincheck-js"></script>' . PHP_EOL;
if ( boolval( $atts['addjs'] ) )
$html .= '<script id="wp24-domaincheck-js-after">' . $js . '</script>' . PHP_EOL;
// add html script code to footer
add_action( 'wp_footer', function() use ( $html ) {
echo $html;
} );
}
else {
wp_enqueue_script( 'wp24-domaincheck' );
if ( boolval( $atts['addjs'] ) )
wp_add_inline_script( 'wp24-domaincheck', $js );
}
// add style
wp_enqueue_style(
'wp24-domaincheck',
plugins_url( 'assets/css/domaincheck.css', dirname( __FILE__ ) ),
'',
WP24_DOMAIN_CHECK_VERSION
);
// enqueue script and style for modal window
if ( $this->options['showWhois'] || 'overlay' == $displayType ) {
wp_enqueue_script(
'jquery-modal',
plugins_url( 'assets/js/jquery-modal.min.js', dirname( __FILE__ ) ),
array( 'jquery' ),
'0.9.2'
);
wp_enqueue_style(
'jquery-modal',
plugins_url( 'assets/css/jquery-modal.min.css', dirname( __FILE__ ) ),
'',
'0.9.2'
);
}
return '<div id="wp24-dc-' . $id . '" class="wp24-dc"></div>';
}
Code file location:
wp24-domain-check/wp24-domain-check/includes/class-wp24-domaincheck.php
Conclusion
Now that you’ve learned how to embed the WP24 Domain Check 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