Skip to content

Instantly share code, notes, and snippets.

@jasondavis
Forked from mandava/get_forms_list.php
Created June 21, 2016 18:17
Show Gist options
  • Select an option

  • Save jasondavis/89f6a5c40739723f7fa754f643995232 to your computer and use it in GitHub Desktop.

Select an option

Save jasondavis/89f6a5c40739723f7fa754f643995232 to your computer and use it in GitHub Desktop.
Get Forms List for Ninja Forms, Gravity Forms and Contact Form 7 WordPress Plugins
<?php
/** Ninja Forms */
function delight_ninja_forms() {
if ( function_exists('ninja_forms_get_all_forms') ) {
$nfs = ninja_forms_get_all_forms();
}
$nforms = array( '' => __('Select a Form', 'TEXT-DOMAIN') );
if( !empty( $nfs ) ) {
foreach($nfs as $form){
$title = $form['data']['form_title'];
$id = $form['id'];
$nforms[$id] = strip_tags($title);
}
}
return $nforms;
}
/** Gravity Forms */
function delight_gravity_forms() {
if( class_exists('RGFormsModel') ) {
$gfs = GFFormsModel::get_forms();
}
$gforms = array( '' => __('Select a Form', 'TEXT-DOMAIN') );
if( !empty( $gfs ) ) {
foreach ($gfs as $form) {
$title = $form->title;
$id = $form->id;
$gforms[$id] = strip_tags($title);
}
}
return $gforms;
}
/** Contact Form 7 Forms */
function delight_cf7_forms() {
if ( function_exists('wpcf7') ) {
$cfs = get_posts(array(
'post_type' => 'wpcf7_contact_form',
'posts_per_page' => -1,
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'title'
)
);
}
$cf7_forms = array( '' => __('Select a Form', 'TEXT-DOMAIN') );
if( !empty( $cfs ) ) {
foreach ( $cfs as $cf ) {
$cf7_forms[absint( $cf->ID )] = strip_tags($cf->post_title);
}
}
return $cf7_forms;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment