Skip to content

Commit

Permalink
made CF7 renaming code backward-compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Arntz committed Dec 15, 2016
1 parent c30bf26 commit 697d49a
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 65 deletions.
14 changes: 9 additions & 5 deletions modules/acceptance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
14 changes: 9 additions & 5 deletions modules/checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
14 changes: 9 additions & 5 deletions modules/count.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
14 changes: 9 additions & 5 deletions modules/date.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
14 changes: 9 additions & 5 deletions modules/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
14 changes: 9 additions & 5 deletions modules/number.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@
* @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*',
'range',
'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 '';
Expand Down
14 changes: 9 additions & 5 deletions modules/quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
14 changes: 9 additions & 5 deletions modules/really-simple-captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<em>' . __( 'To use CAPTCHA, you need <a href="http://wordpress.org/extend/plugins/really-simple-captcha/">Really Simple CAPTCHA</a> plugin installed.', 'bootstrap-for-contact-form-7' ) . '</em>';
Expand Down
14 changes: 9 additions & 5 deletions modules/recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down
14 changes: 9 additions & 5 deletions modules/select.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
14 changes: 9 additions & 5 deletions modules/submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
14 changes: 9 additions & 5 deletions modules/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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*',
Expand All @@ -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 '';
Expand Down
Loading

0 comments on commit 697d49a

Please sign in to comment.