Below, you’ll find a detailed guide on how to add the WordPress File Upload Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WordPress File Upload Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the WordPress File Upload Plugin and the shortcodes it provides:
"WordPress File Upload is a versatile plugin that enhances your site by allowing users to easily upload files. A must-have for interactive and engaging WordPress experiences."
- [wordpress_file_upload]
- [wfu_block_inline_js]
WordPress File Upload [wordpress_file_upload] Shortcode
The WordPress File Upload shortcode allows users to upload files to the server. It preprocesses attributes, assigns defaults if required, and executes the main function of the plugin.
Shortcode: [wordpress_file_upload]
Examples and Usage
Basic example – Uploads a file to the default directory.
[wordpress_file_upload]
PHP Function Code
In case you have difficulties debugging what causing issues with [wordpress_file_upload]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode("wordpress_file_upload", "wordpress_file_upload_handler");
Shortcode PHP function:
function wordpress_file_upload_handler($incomingfrompost) {
//replace old attribute definitions with new ones
$incomingfrompost = wfu_old_to_new_attributes($incomingfrompost);
//preprocess attributes
$incomingfrompost = wfu_preprocess_attributes($incomingfrompost);
//process incoming attributes assigning defaults if required
$defs_indexed = wfu_shortcode_attribute_definitions_adjusted($incomingfrompost);
$incomingfrompost = shortcode_atts($defs_indexed, $incomingfrompost);
//run function that actually does the work of the plugin
$wordpress_file_upload_output = wordpress_file_upload_function($incomingfrompost);
//send back text to replace shortcode in post
return $wordpress_file_upload_output;
}
Code file location:
wp-file-upload/wp-file-upload/wfu_loader.php
WordPress File Upload [wfu_block_inline_js] Shortcode
The WP-File-Upload plugin shortcode, “wfu_block_inline_js”, is designed to manage inline JavaScript. It sanitizes the instance ID, checks if it exists in the $WFU_BLOCK_INLINE_JS array, and returns the corresponding output. It also allows customization of the output through the “_wfu_block_inline_js_output” filter.
Shortcode: [wfu_block_inline_js]
Parameters
Here is a list of all possible wfu_block_inline_js shortcode parameters and attributes:
instanceid
– Identifies the combination of post ID and shortcode ID.
Examples and Usage
Basic example – Use the shortcode to block inline JavaScript for a specific instance of the WP File Upload plugin.
[wfu_block_inline_js instanceid="123__456b"]
By using the shortcode above, you are instructing the WP File Upload plugin to block inline JavaScript for the specific instance with the ID of “123__456b”. The instance ID is a combination of the post ID and the shortcode ID.
Advanced examples
Use the shortcode to block inline JavaScript for a specific instance of the WP File Upload plugin and customize the output using a filter.
function custom_wfu_block_inline_js_output($output, $params) {
return $output . "<script>console.log('Blocked inline JS for instance: " . $params["instanceid"] . "');</script>";
}
add_filter('_wfu_block_inline_js_output', 'custom_wfu_block_inline_js_output', 10, 2);
[wfu_block_inline_js instanceid="123__456b"]
In this advanced example, we are not only blocking inline JavaScript for the specific instance with the ID “123__456b”, but we are also adding a custom JavaScript console log message to the output. This is done using the “_wfu_block_inline_js_output” filter, which allows us to modify the output of the “wfu_block_inline_js” shortcode. In this case, we are appending a script tag that logs a message to the console indicating that inline JavaScript has been blocked for the specified instance.
PHP Function Code
In case you have difficulties debugging what causing issues with [wfu_block_inline_js]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode("wfu_block_inline_js", "wordpress_file_upload_block_inline_js_handler");
Shortcode PHP function:
function wordpress_file_upload_block_inline_js_handler($incomingfromhandler) {
$a = func_get_args(); $a = WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out); if (isset($out['vars'])) foreach($out['vars'] as $p => $v) $$p = $v; switch($a) { case 'R': return $out['output']; break; case 'D': die($out['output']); }
global $post;
global $WFU_BLOCK_INLINE_JS;
$output = "";
$params = wfu_plugin_parse_array($incomingfromhandler);
$instanceid = ( isset($params["instanceid"]) ? $params["instanceid"] : "" );
//validate instance ID; it is a combination of post ID and shortcode ID:
//instanceID = postID||shortcodeID (postID can be empty)
if ( !preg_match("/^[0-9]*__[0-9]+b?$/", $instanceid) ) $instanceid = "";
//params is filled with the sanitized instanceid, so that it is safer to use
//in filters
$params["instanceid"] = $instanceid;
if ( $instanceid != "" && is_array($WFU_BLOCK_INLINE_JS) && isset($WFU_BLOCK_INLINE_JS[$instanceid]) ) {
$output = $WFU_BLOCK_INLINE_JS[$instanceid];
}
/**
* Filter To Customise Block Inline JS Output.
*
* This filter is used to customise the returned output.
*
* @since 4.19.0
*
* @param string $output The HTML output.
* @param array $params An associative array with shortcode attributes.
*/
$output = apply_filters("_wfu_block_inline_js_output", $output, $params);
return $output;
}
Code file location:
wp-file-upload/wp-file-upload/wfu_loader.php
Conclusion
Now that you’ve learned how to embed the WordPress File Upload Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply