Here's how to get links of uploads, but how to pass links to shortcode?
-
More specifically: I am able to retrieve the links of uploads but how can I pass a variable from fu_after_upload to a shortcode that is placed on the upload redirect page?
When the Frontend Uploader is used to upload files, I’ve made some progress on capturing the links of uploads and echoing them to the screen. However, I am unsure how to pass the links to the page that the upload form redirects to. I’ve tried to set $clickable_links to a global variable and pass it to a shortcode function, but I am unable to access the variable in this way.
After an upload completes, the following code allows me to capture the URLs of the new media attachments that have been created. The URLs are stored in an array of clickable links.
add_action( 'fu_after_upload', 'my_fu_after_upload', 10, 3 ); function my_fu_after_upload( $attachment_ids, $success, $post_id ) { global $clickable_links; $count = count($attachment_ids); for($i=0; $i<=$count; $i++) { $fu_download_links[$i] = wp_get_attachment_url($attachment_ids[$i]); $clickable_links[$i] = '<p><a href="' . $fu_download_links[$i] . '">' . $fu_download_links[$i] . '</a></p>'; // echo $clickable_links[$i]; } }
Note: The echo line will output the links to the screen, but it is commented out because the end goal is to move the $clickable_links array to a shortcode that is placed on the redirect page. Here’s what I have so far:
add_shortcode( 'fu-display-links', 'display_fu_links_shortcode' ); function display_fu_links_shortcode ($atts) { global $clickable_links; $count = count($clickable_links); for($i=0; $i<=$count; $i++) { echo $clickable_links[$i]; } }
The global doesn’t seem to work for this, is it being used incorrectly? Can I pass the variable to the shortcode via a parameter? Do I need to use a PHP Session? Or is there an easier way?
Thanks for your help.
- The topic ‘Here's how to get links of uploads, but how to pass links to shortcode?’ is closed to new replies.