Last active
October 7, 2018 17:15
-
-
Save ms-studio/aa8c7a99618d447bb0518ad15225794d to your computer and use it in GitHub Desktop.
Shortcode for the Formidable WordPress plugin, that returns the name of the current form (based on the entry ID).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Form Name Shortcode | |
* For usage in confirmation email | |
* Returns name of current form | |
* Use the shortcode like this: [frm-form-name id=[id]] | |
* The [id] parameter will produce the ID of current entry | |
* See https://formidableforms.com/help-desk/using-form_name-shortcode-in-email-notification/ | |
*/ | |
function my_frm_name_shortcode( $atts ) { | |
global $wpdb; | |
$a = shortcode_atts( array( | |
'id' => '', | |
), $atts ); | |
if (!empty($a['id'])) { | |
// get the Form ID, based on Entry ID | |
$form_id = $wpdb->get_row( $wpdb->prepare( | |
" | |
SELECT form_id | |
FROM ". $wpdb->prefix ."frm_items | |
WHERE id = %d | |
", | |
$a['id']) | |
); | |
// get the Form name, based on Form ID | |
$form_name = $wpdb->get_row( $wpdb->prepare( | |
" | |
SELECT name | |
FROM ". $wpdb->prefix ."frm_forms | |
WHERE id = %d | |
", | |
$form_id->form_id ) | |
); | |
return $form_name->name; | |
} | |
} | |
add_shortcode( 'frm-form-name', 'my_frm_name_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this... works perfectly!