From 697d49a9a8290c73cfd5089b5109a9d973649191 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 15 Dec 2016 14:56:45 -0500 Subject: [PATCH] made CF7 renaming code backward-compatible --- modules/acceptance.php | 14 +++++++++----- modules/checkbox.php | 14 +++++++++----- modules/count.php | 14 +++++++++----- modules/date.php | 14 +++++++++----- modules/file.php | 14 +++++++++----- modules/number.php | 14 +++++++++----- modules/quiz.php | 14 +++++++++----- modules/really-simple-captcha.php | 14 +++++++++----- modules/recaptcha.php | 14 +++++++++----- modules/select.php | 14 +++++++++----- modules/submit.php | 14 +++++++++----- modules/text.php | 14 +++++++++----- modules/textarea.php | 14 +++++++++----- 13 files changed, 117 insertions(+), 65 deletions(-) diff --git a/modules/acceptance.php b/modules/acceptance.php index eeb5eb2..6287e7f 100755 --- a/modules/acceptance.php +++ b/modules/acceptance.php @@ -7,22 +7,26 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_acceptance' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_acceptance' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_acceptance', 11 ); function cf7bs_add_shortcode_acceptance() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'acceptance' ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_acceptance_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_acceptance_shortcode_handler', true ); } function cf7bs_acceptance_shortcode_handler( $tag ) { - $tag = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag = new $classname( $tag ); if ( empty( $tag->name ) ) { return ''; diff --git a/modules/checkbox.php b/modules/checkbox.php index c37824a..644e08f 100755 --- a/modules/checkbox.php +++ b/modules/checkbox.php @@ -7,24 +7,28 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_checkbox' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_checkbox' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_checkbox', 11 ); function cf7bs_add_shortcode_checkbox() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'checkbox', 'checkbox*', 'radio', ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_checkbox_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_checkbox_shortcode_handler', true ); } function cf7bs_checkbox_shortcode_handler( $tag ) { - $tag = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag = new $classname( $tag ); if ( empty( $tag->name ) ) { return ''; diff --git a/modules/count.php b/modules/count.php index e40ef19..8dde304 100755 --- a/modules/count.php +++ b/modules/count.php @@ -7,22 +7,26 @@ * @since 1.2.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_count' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_count' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_count', 11 ); function cf7bs_add_shortcode_count() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'count' ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_count_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_count_shortcode_handler', true ); } function cf7bs_count_shortcode_handler( $tag ) { - $tag_obj = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag_obj = new $classname( $tag ); if ( empty( $tag_obj->name ) ) { return ''; diff --git a/modules/date.php b/modules/date.php index 211e5dd..0ae3b04 100755 --- a/modules/date.php +++ b/modules/date.php @@ -7,23 +7,27 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_date' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_date' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_date', 11 ); function cf7bs_add_shortcode_date() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'date', 'date*', ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_date_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_date_shortcode_handler', true ); } function cf7bs_date_shortcode_handler( $tag ) { - $tag = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag = new $classname( $tag ); if ( empty( $tag->name ) ) { return ''; diff --git a/modules/file.php b/modules/file.php index 81b59dc..868f2c6 100755 --- a/modules/file.php +++ b/modules/file.php @@ -7,23 +7,27 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_file' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_file' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_file', 11 ); function cf7bs_add_shortcode_file() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'file', 'file*', ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_file_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_file_shortcode_handler', true ); } function cf7bs_file_shortcode_handler( $tag ) { - $tag = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag = new $classname( $tag ); if ( empty( $tag->name ) ) { return ''; diff --git a/modules/number.php b/modules/number.php index ec99b3d..2cd42ef 100755 --- a/modules/number.php +++ b/modules/number.php @@ -7,10 +7,12 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_number' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_number' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_number', 11 ); function cf7bs_add_shortcode_number() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'number', 'number*', @@ -18,14 +20,16 @@ function cf7bs_add_shortcode_number() { 'range*', ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_number_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_number_shortcode_handler', true ); } function cf7bs_number_shortcode_handler( $tag ) { - $tag = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag = new $classname( $tag ); if ( empty( $tag->name ) ) { return ''; diff --git a/modules/quiz.php b/modules/quiz.php index f73ea1c..e836b76 100755 --- a/modules/quiz.php +++ b/modules/quiz.php @@ -7,22 +7,26 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_quiz' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_quiz' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_quiz', 11 ); function cf7bs_add_shortcode_quiz() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'quiz' ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_quiz_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_quiz_shortcode_handler', true ); } function cf7bs_quiz_shortcode_handler( $tag ) { - $tag = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag = new $classname( $tag ); if ( empty( $tag->name ) ) { return ''; diff --git a/modules/really-simple-captcha.php b/modules/really-simple-captcha.php index 2f74817..259614f 100755 --- a/modules/really-simple-captcha.php +++ b/modules/really-simple-captcha.php @@ -7,23 +7,27 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_captcha' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_captcha' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_captcha', 11 ); function cf7bs_add_shortcode_captcha() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'captchac', 'captchar', ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_captcha_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_captcha_shortcode_handler', true ); } function cf7bs_captcha_shortcode_handler( $tag ) { - $tag_obj = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag_obj = new $classname( $tag ); if ( 'captchac' == $tag_obj->type && ! class_exists( 'ReallySimpleCaptcha' ) ) { return '' . __( 'To use CAPTCHA, you need Really Simple CAPTCHA plugin installed.', 'bootstrap-for-contact-form-7' ) . ''; diff --git a/modules/recaptcha.php b/modules/recaptcha.php index f17cb6e..492f6d3 100755 --- a/modules/recaptcha.php +++ b/modules/recaptcha.php @@ -8,26 +8,30 @@ */ if ( function_exists( 'wpcf7_recaptcha_add_shortcode_recaptcha' ) ) { - remove_action( 'wpcf7_init', 'wpcf7_recaptcha_add_shortcode_recaptcha' ); - add_action( 'wpcf7_init', 'cf7bs_recaptcha_add_shortcode_recaptcha' ); + add_action( 'wpcf7_init', 'cf7bs_recaptcha_add_shortcode_recaptcha', 11 ); function cf7bs_recaptcha_add_shortcode_recaptcha() { $recaptcha = WPCF7_RECAPTCHA::get_instance(); if ( $recaptcha->is_active() ) { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'recaptcha' ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_recaptcha_shortcode_handler' ); + call_user_func( $add_func, $tags, 'cf7bs_recaptcha_shortcode_handler' ); } } function cf7bs_recaptcha_shortcode_handler( $tag ) { - $tag_obj = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag_obj = new $classname( $tag ); $field = new CF7BS_Form_Field( cf7bs_apply_field_args_filter( array( 'name' => wpcf7_recaptcha_shortcode_handler( $tag ), diff --git a/modules/select.php b/modules/select.php index 82efb19..a62e39f 100755 --- a/modules/select.php +++ b/modules/select.php @@ -7,23 +7,27 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_select' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_select' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_select', 11 ); function cf7bs_add_shortcode_select() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'select', 'select*', ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_select_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_select_shortcode_handler', true ); } function cf7bs_select_shortcode_handler( $tag ) { - $tag = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag = new $classname( $tag ); if ( empty( $tag->name ) ) { return ''; diff --git a/modules/submit.php b/modules/submit.php index f3645dc..082f743 100755 --- a/modules/submit.php +++ b/modules/submit.php @@ -7,22 +7,26 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_submit' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_submit' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_submit', 11 ); function cf7bs_add_shortcode_submit() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'submit' ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_submit_shortcode_handler' ); + call_user_func( $add_func, $tags, 'cf7bs_submit_shortcode_handler' ); } function cf7bs_submit_shortcode_handler( $tag ) { - $tag = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag = new $classname( $tag ); $class = wpcf7_form_controls_class( $tag->type ); diff --git a/modules/text.php b/modules/text.php index 6afac55..419bf6e 100755 --- a/modules/text.php +++ b/modules/text.php @@ -7,10 +7,12 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_text' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_text' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_text', 11 ); function cf7bs_add_shortcode_text() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'text', 'text*', @@ -22,14 +24,16 @@ function cf7bs_add_shortcode_text() { 'tel*', ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_text_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_text_shortcode_handler', true ); } function cf7bs_text_shortcode_handler( $tag ) { - $tag_obj = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag_obj = new $classname( $tag ); if ( empty( $tag_obj->name ) ) { return ''; diff --git a/modules/textarea.php b/modules/textarea.php index 0e12ada..2a35780 100755 --- a/modules/textarea.php +++ b/modules/textarea.php @@ -7,23 +7,27 @@ * @since 1.0.0 */ -remove_action( 'wpcf7_init', 'wpcf7_add_shortcode_textarea' ); -add_action( 'wpcf7_init', 'cf7bs_add_shortcode_textarea' ); +add_action( 'wpcf7_init', 'cf7bs_add_shortcode_textarea', 11 ); function cf7bs_add_shortcode_textarea() { + $add_func = function_exists( 'wpcf7_add_form_tag' ) ? 'wpcf7_add_form_tag' : 'wpcf7_add_shortcode'; + $remove_func = function_exists( 'wpcf7_remove_form_tag' ) ? 'wpcf7_remove_form_tag' : 'wpcf7_remove_shortcode'; + $tags = array( 'textarea', 'textarea*', ); foreach ( $tags as $tag ) { - wpcf7_remove_form_tag( $tag ); + call_user_func( $remove_func, $tag ); } - wpcf7_add_form_tag( $tags, 'cf7bs_textarea_shortcode_handler', true ); + call_user_func( $add_func, $tags, 'cf7bs_textarea_shortcode_handler', true ); } function cf7bs_textarea_shortcode_handler( $tag ) { - $tag_obj = new WPCF7_FormTag( $tag ); + $classname = class_exists( 'WPCF7_FormTag' ) ? 'WPCF7_FormTag' : 'WPCF7_Shortcode'; + + $tag_obj = new $classname( $tag ); if ( empty( $tag_obj->name ) ) { return '';