Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // add an "Edit this form" link to a post or page with a form embedded
- // filter the content looking for the gravityform shortcode
- add_filter('the_content', 'add_gf_edit_link');
- function add_gf_edit_link($content) {
- // be sure the logged in user has capability to edit forms
- if(GFCommon::current_user_can_any('gravityforms_edit_forms')){
- // not sure if $ajax is needed the way we are calling get_embedded_forms
- $ajax = false;
- // use a Gravity Forms function to parse the content for forms
- $embeddedforms = GFFormDisplay::get_embedded_forms($content, $ajax);
- // since this will be used on single posts and pages only, we are going to return the first form ID only
- $formid = $embeddedforms[0]['id'];
- // build the URL for the edit link
- $editlink = '<span class="edit-form-link"><a href="' . admin_url() . 'admin.php?page=gf_edit_forms&id=' . $formid . '">Edit this form</a></span>';
- return $content . $editlink;
- }
- // if user does not have the capability, just return the content
- else {
- return $content;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement