Advertisement
chrishajer

Add "Edit this form" to a page with a form embedded

Oct 23rd, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2. // add an "Edit this form" link to a post or page with a form embedded
  3. // filter the content looking for the gravityform shortcode
  4. add_filter('the_content', 'add_gf_edit_link');
  5. function add_gf_edit_link($content) {
  6.         // be sure the logged in user has capability to edit forms
  7.         if(GFCommon::current_user_can_any('gravityforms_edit_forms')){
  8.                 // not sure if $ajax is needed the way we are calling get_embedded_forms
  9.                 $ajax = false;
  10.                 // use a Gravity Forms function to parse the content for forms
  11.                 $embeddedforms = GFFormDisplay::get_embedded_forms($content, $ajax);
  12.                 // since this will be used on single posts and pages only, we are going to return the first form ID only
  13.                 $formid = $embeddedforms[0]['id'];
  14.                 // build the URL for the edit link
  15.                 $editlink = '<span class="edit-form-link"><a href="' . admin_url() . 'admin.php?page=gf_edit_forms&id=' . $formid . '">Edit this form</a></span>';
  16.                 return $content . $editlink;
  17.         }
  18.         // if user does not have the capability, just return the content
  19.         else {
  20.                 return $content;
  21.         }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement