Last active
November 1, 2017 14:33
-
-
Save solepixel/8514cb409755be6cdbcf6064b74b3ce3 to your computer and use it in GitHub Desktop.
Enable Shortcode UI (Shortcake) for Gravity Forms
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 | |
/** | |
* Registers Shortcode UI for gravityforms shortcode | |
* | |
* @package theme | |
*/ | |
if ( ! function_exists( '_theme_gravityform_shortcode_ui' ) ) { | |
/** | |
* Shortcode UI function for gravityforms | |
* | |
* @return void | |
*/ | |
function _theme_gravityform_shortcode_ui() { | |
if ( ! class_exists( 'GFAPI' ) ) { | |
return; | |
} | |
$forms = array( | |
'' => __( 'Select a Form', 'gravityforms' ), | |
); | |
$all_forms = GFAPI::get_forms(); | |
foreach ( $all_forms as $form ) : | |
$forms[ $form['id'] ] = $form['title']; | |
endforeach; | |
$fields = array( | |
array( | |
'label' => esc_html__( 'Select a form from the list to add it to your post or page.', 'gravityforms' ), | |
'description' => esc_html__( 'Select a form below to add it to your post or page. Can\'t find your form? Make sure it is active.', 'gravityforms' ), | |
'attr' => 'id', | |
'type' => 'select', | |
'options' => $forms, | |
), | |
array( | |
'label' => esc_html__( 'Display form title', 'gravityforms' ), | |
'description' => esc_html__( 'Whether or not to display the form title.', 'gravityforms' ), | |
'attr' => 'title', | |
'type' => 'radio', | |
'options' => array( | |
'true' => __( 'Yes', 'gravityforms' ), | |
'false' => __( 'No', 'gravityforms' ), | |
), | |
), | |
array( | |
'label' => esc_html__( 'Display form description', 'gravityforms' ), | |
'description' => esc_html__( 'Whether or not to display the form description.', 'gravityforms' ), | |
'attr' => 'description', | |
'type' => 'radio', | |
'options' => array( | |
'true' => __( 'Yes', 'gravityforms' ), | |
'false' => __( 'No', 'gravityforms' ), | |
), | |
), | |
array( | |
'label' => esc_html__( 'Enable AJAX', 'gravityforms' ), | |
'description' => esc_html__( 'Specify whether or not to use AJAX to submit the form.', 'gravityforms' ), | |
'attr' => 'ajax', | |
'type' => 'radio', | |
'options' => array( | |
'true' => __( 'Yes', 'gravityforms' ), | |
'false' => __( 'No', 'gravityforms' ), | |
), | |
), | |
array( | |
'label' => esc_html__( 'Tabindex', 'gravityforms' ), | |
'description' => esc_html__( 'Specify the starting tab index for the fields of this form.', 'gravityforms' ), | |
'attr' => 'tabindex', | |
'type' => 'number', | |
), | |
); | |
/* | |
* Define the Shortcode UI arguments. | |
*/ | |
$shortcode_ui_args = array( | |
/* | |
* How the shortcode should be labeled in the UI. Required argument. | |
*/ | |
'label' => esc_html__( 'Gravity Form', 'gravityforms' ), | |
/* | |
* Include an icon with your shortcode. Optional. | |
* Use a dashicon, or full URL to image. | |
*/ | |
'listItemImage' => 'dashicons-feedback', | |
'attrs' => $fields, | |
); | |
shortcode_ui_register_for_shortcode( 'gravityform', $shortcode_ui_args ); | |
} | |
} | |
add_action( 'register_shortcode_ui', '_theme_gravityform_shortcode_ui' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment