post meta value as shortcode parameter

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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 😉


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x