0
[amazon_s3 bucket=my_bucket_name object=my_file_name.ext]

Hi all i need to know how to fetch the parameter value in the above shortcode. For Example: Object is the attributes then how can i fetch the object value my_file_name.ext. I am using the woocommerce s3 plugin. I am not sure i customized the woocommerce to fetch the file name show in my account page here is the code.

 function filename_wc_downloads( $link, $download )
    {
           $order = new WC_Order( $download['order_id'] );
        $download_file_urls = $order->get_downloadable_file_urls( 
            $download['product_id'], 
            null, 
            $download['download_id'] 
        );

        foreach( $download_file_urls as $key => $value )
        {
            if( $value == $download['download_url'] )
            {
                $url_parts = explode( '/', parse_url( $key, PHP_URL_PATH ) );
                $file_name = end( $url_parts );
                $link = '<a href="' 
                    . esc_url( $download['download_url'] ) 
                    . '">' 
                    . $download['download_name'] 
                    . '</a> <small>( ' 
                    . $file_name 
                    . ' )</small>';
            }               
        }
        return $link;
    }

In a Woocommerce all products are uploaded into the media library of upload folder. The above code is to fetch the filename show in my account page if they using direct file path. If i pasted the above shortcode in the product url, that above code doesn't help to fetch the filename. so i need to know from the shortcode how can i get the object value based on this to show the file name.

1 Answer 1

1

amazon_s3 is your shortcode containing $atts bucket and object

when you use wordpress function add_shortcode('amazon_s3', 'your_function_name');

it automatically converts your attributes defined in [amazan_s3 .... to $atts

e.g.

function your_funnction_name($atts) {
    extract(shortcode_atts(array(
        'bucket' => '',
        'object' => ''
    ), $atts));

   return $object;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.