0

i am using a plugin (download monitor) to display downloads via shortcodes. also using an addon for download monitor - gravity forms lock. for that, the shortcode, which i must include in the same post is like this: [dlm_gf_form download_id="download-form-id"] where download-form-id would represent the post meta name.

i'd like to be able to modify the download form ID parameter within the shortcode via a custom field value.

i found this in the 'gravity forms lock' add-on for download monitor:

// hijack the download shortcode add_shortcode( 'dlm_gf_form', array( $this, 'shortcode_dlm_gf_form' ) );

i'm hoping there is a method to filter or hijack the shortcode for the forms as there is for the standard download shortcode.

thanks

1

// hijack the download shortcode add_shortcode( 'dlm_gf_form', array( $this, 'shortcode_dlm_gf_form' ) );

This line just adds a shortcode from a class. I checked this plugin's class and they didn't provide any actions or filter. You can try to modify original code of this plugin for your purposes only. I don't see any other solution. I don't know what this plugin even do, just looking at source code and trying to understand the logic, so my advice is not tested)

Open file dlm-gravity-forms.php
From the line 156 you will see this code:

// the download_id is a required attribute
if ( ! isset( $atts['download_id'] ) ) {
    return 'Download Monitor - Gravity Forms Error: No download_id set!';
}

It's a check if download_id is set. Just after this if statement you can add the same code from previous question with the same logic - if download_id is not a number - get post meta value from post meta with a name you pass in download_id attribute:

    if( !is_numeric($atts['download_id']) ):
        $post_meta = get_post_meta(get_queried_object_id(), $atts['download_id'], true);
        $post_meta ? $atts['download_id'] = $post_meta : null;
    endif;

Save changes ;)

4
  • that did it! hopefully they'll implement actions or filter, or will find a way to hijack it without modifying actual plugin. – vulgarbulgar May 7 at 21:21
  • thanks again!!! – vulgarbulgar May 7 at 21:22
  • 1
    Don't forget that if update for this plugin will be available and you update - this changes will be overriten – anton May 8 at 6:30
  • yes, aware of that, and contacted the plugin dev regarding future updates and the possibility of implementing a filter as in the core plugin. thanks! – vulgarbulgar May 14 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.