Below, you’ll find a detailed guide on how to add the Shared Files 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 Shared Files Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Shared Files Plugin and the shortcodes it provides:
"Shared Files is a superior plugin for advanced file sharing & download management. It also supports frontend uploads, making file sharing an effortless task."
- [shared_files]
- [shared_files_simple]
- [shared_files_info]
Shared Files [shared_files] Shortcode
The Shared Files shortcode is a dynamic tool that allows users to access a variety of shared files. It provides a platform for file sharing, uploads, and downloads within the WordPress ecosystem. The shortcode manages file accessibility, categorization, and searchability. It incorporates options for email requests and contact information capture, ensuring secure file sharing. It also supports pagination and file deletion, contributing to an organized file system. Shortcode: [shared_files]
Shortcode: [shared_files]
Parameters
Here is a list of all possible shared_files shortcode parameters and attributes:
embed_id
– The unique identifier for the embedded shared files.ask_for_email
– If set to 1, prompts the user to provide their email address.ask_for_contact_info
– If set to 1, prompts the user to provide their contact information.file_upload
– If set, allows users to upload files.only_uploaded_files
– If set, only displays the files uploaded by the user.file_id
– Displays a specific file using its unique identifier.hide_file_list
– If set, hides the list of shared files.category
– Filters the shared files based on their assigned category.hide_search
– If set, hides the search function.hide_description
– If set, hides the description of the shared files.layout
– Changes the layout of the shared files display. Options include ‘minimal’.hide_files_first
– If set, hides the files on the first load of the page.upload_id
– Filters the shared files based on their upload id.hide_search_for_all_files
– If set, hides the search function for all files.show_tag_dropdown
– If set, shows a dropdown menu for file tags.
Examples and Usage
Basic example – Display a shared file using its file id.
[shared_files file_id=1 /]
Advanced examples
Display a shared file and ask for email before download.
[shared_files file_id=1 ask_for_email=1 /]
Display a shared file and ask for contact info before download.
[shared_files file_id=1 ask_for_contact_info=1 /]
Display a shared file and enable file upload for logged in users.
[shared_files file_id=1 file_upload=1 /]
Display a shared file, enable file upload for logged in users, and hide file list.
[shared_files file_id=1 file_upload=1 hide_file_list=1 /]
Display a shared file, enable file upload for logged in users, hide file list, and ask for email before download.
[shared_files file_id=1 file_upload=1 hide_file_list=1 ask_for_email=1 /]
Display a shared file, enable file upload for logged in users, hide file list, ask for email before download, and ask for contact info before download.
[shared_files file_id=1 file_upload=1 hide_file_list=1 ask_for_email=1 ask_for_contact_info=1 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [shared_files]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'shared_files', array( 'ShortcodeSharedFiles', 'shared_files' ) );
Shortcode PHP function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | function shared_files( $atts = array (), $content = null, $tag = '' ) { $html = '' ; $post_id = intval ( get_the_id() ); // normalize attribute keys, lowercase $atts = array_change_key_case ( ( array ) $atts , CASE_LOWER ); $s = get_option( 'shared_files_settings' ); $elem_class = SharedFilesHelpers::createElemClass(); $meta_query = []; $meta_query_full = []; $custom_fields_active = 0; $embed_id = ( isset( $atts [ 'embed_id' ] ) ? sanitize_title( $atts [ 'embed_id' ] ) : 'default' ); if ( isset( $atts [ 'ask_for_email' ] ) && $atts [ 'ask_for_email' ] == 1 || isset( $atts [ 'ask_for_contact_info' ] ) && $atts [ 'ask_for_contact_info' ] == 1 ) { if ( is_super_admin() ) { $html .= SharedFilesPublicContacts::askForEmailInfo(); } else { if ( isset( $_POST [ 'shared-files-add-contact' ] ) ) { SharedFilesPublicContacts::saveEmail( $embed_id , $atts ); } else { $html = SharedFilesPublicContacts::askForEmail( $embed_id , $atts ); return $html ; } } } $pagination_active = 0; if ( isset( $_GET [ '_paged' ] ) && $_GET [ '_paged' ] == $embed_id ) { $pagination_active = 1; } $tag_slug = '' ; if ( isset( $_GET [ 'sf_tag' ] ) && $_GET [ 'sf_tag' ] != '0' ) { $tag_slug = sanitize_title( $_GET [ 'sf_tag' ] ); } $limit_posts = 0; $meta_query_hide_not_public = array ( 'relation' => 'OR' , ); $meta_query_hide_not_public [] = array ( 'key' => '_sf_not_public' , 'compare' => '=' , 'value' => '' , ); $meta_query_hide_not_public [] = array ( 'key' => '_sf_not_public' , 'compare' => 'NOT EXISTS' , ); // $meta_query_hide_not_public = array(); $html .= '<div class="' . $elem_class . ' shared-files-main-container" data-elem-class="' . $elem_class . '">' ; if ( isset( $_GET ) && isset( $_GET [ 'shared-files-update' ] ) ) { $html .= '<div class="shared-files-upload-complete">' . sanitize_text_field( __( 'File successfully updated.' , 'shared-files' ) ) . '</div>' ; } elseif ( isset( $_GET ) && isset( $_GET [ '_sf_delete_editable_file' ] ) && isset( $_GET [ 'sc' ] ) ) { $html .= '<div class="shared-files-file-deleted">' . sanitize_text_field( __( 'File successfully deleted.' , 'shared-files' ) ) . '</div>' ; } if ( isset( $atts [ 'file_upload' ] ) && (is_user_logged_in() || !isset( $s [ 'only_logged_in_users_can_add_files' ] )) ) { if ( isset( $atts [ 'only_uploaded_files' ] ) ) { $meta_query_hide_not_public = array ( 'relation' => 'AND' , ); $meta_query_hide_not_public [] = array ( 'key' => '_sf_embed_post_id' , 'compare' => '=' , 'value' => $post_id , ); $meta_query_hide_not_public [] = array ( 'key' => '_sf_not_public' , 'compare' => 'EXISTS' , ); } else { $meta_query_hide_not_public = array ( 'relation' => 'OR' , ); $meta_query_hide_not_public [] = array ( 'key' => '_sf_embed_post_id' , 'compare' => '=' , 'value' => $post_id , ); $meta_query_hide_not_public [] = array ( 'key' => '_sf_not_public' , 'compare' => '=' , 'value' => '' , ); $meta_query_hide_not_public [] = array ( 'key' => '_sf_not_public' , 'compare' => 'NOT EXISTS' , ); } $html .= SharedFilesFileUpload::fileUploadMarkup( $atts ); } if ( isset( $atts [ 'file_id' ] ) ) { $file_id = (int) $atts [ 'file_id' ]; $wpb_all_query = new WP_Query( array ( 'post_type' => 'shared_file' , 'post_status' => 'publish' , 'posts_per_page' => -1, 'p' => $file_id , ) ); $filetypes = SharedFilesHelpers::getFiletypes(); $external_filetypes = SharedFilesHelpers::getExternalFiletypes(); $html .= '<div class="shared-files-search">' ; $html .= '<ul class="shared-files-main-file-list">' ; if ( $wpb_all_query ->have_posts() ) { while ( $wpb_all_query ->have_posts() ) { $wpb_all_query ->the_post(); $id = get_the_id(); $c = get_post_custom( $id ); $external_url = ( isset( $c [ '_sf_external_url' ] ) ? esc_url_raw( $c [ '_sf_external_url' ][0] ) : '' ); $filetype = '' ; $imagefile = SharedFilesHelpers::getImageFile( $id , $external_url ); $hide_description = ( isset( $atts [ 'hide_description' ] ) ? sanitize_text_field( $atts [ 'hide_description' ] ) : '' ); if ( isset( $atts [ 'layout' ] ) && $atts [ 'layout' ] == 'minimal' ) { $html .= SharedFilesPublicFileCardMinimal::fileListItem( $c , $imagefile , $hide_description , 2, $atts ); } else { $html .= SharedFilesPublicFileCardDefault::fileListItem( $c , $imagefile , $hide_description , 2, $atts ); } } wp_reset_postdata(); } else { $html .= '<div class="sf_error">' . esc_html__( 'File not found' , 'shared-files' ) . '</div>' ; } $html .= '</ul>' ; $html .= '</div>' ; // .shared-files-main-container $html .= '</div>' ; return $html ; } elseif ( isset( $atts [ 'hide_file_list' ] ) ) { // .shared-files-main-container $html .= '</div>' ; return $html ; } else { $layout = SharedFilesHelpers::getLayout( $s , $atts ); $type = 'basic' ; if ( isset( $atts [ 'category' ] ) ) { $type = 'category' ; } $container_embed_id = '' ; if ( $embed_id == 'default' ) { $container_embed_id = 'id="' . esc_attr( 'shared-files-default' ) . '"' ; } elseif ( $embed_id ) { $container_embed_id = 'id="' . esc_attr( $embed_id ) . '"' ; } $html .= '<div ' . $container_embed_id . ' class="shared-files-container shared-files-type-' . $type . ' ' . (( $layout ? 'shared-files-' . esc_attr( $layout ) : '' )) . '">' ; $html .= '<div class="shared-files-search">' ; if ( !isset( $s [ 'hide_search_form' ] ) && !isset( $atts [ 'hide_search' ] ) ) { $html .= '<div class="shared-files-search-form-container"><form class="shared-files-ajax-form" onsubmit="return false;" data-elem-class="' . $elem_class . '">' ; if ( !isset( $atts [ 'hide_search_for_all_files' ] ) ) { $html .= '<div class="shared-files-search-input-container"><input type="text" class="shared-files-search-files-input shared-files-search-files" placeholder="' . esc_attr__( 'Search files...' , 'shared-files' ) . '" value="" data-elem-class="' . $elem_class . '" /></div>' ; } $is_premium = 0; if ( isset( $s [ 'show_tag_dropdown' ] ) || isset( $atts [ 'show_tag_dropdown' ] ) ) { $tag_selected = ( isset( $_GET [ 'sf_tag' ] ) ? sanitize_title( $_GET [ 'sf_tag' ] ) : '' ); $tags_orderby = '' ; $tags_order = 'ASC' ; if ( isset( $s [ 'sort_tags_by' ] ) && $s [ 'sort_tags_by' ] ) { $tags_orderby = sanitize_title( $s [ 'sort_tags_by' ] ); } $tag_args = array ( 'taxonomy' => SHARED_FILES_TAG_SLUG, 'name' => 'sf_tag' , 'show_option_none' => esc_attr__( 'Choose tag' , 'shared-files' ), 'hierarchical' => true, 'class' => 'shared-files-tag-select select_v2' , 'echo' => false, 'value_field' => 'slug' , 'selected' => $tag_selected , 'option_none_value' => '' , 'orderby' => $tags_orderby , 'order' => $tags_order , ); $html .= '<div class="shared-files-tag-select-container">' ; $html .= wp_dropdown_categories( $tag_args ); $html .= '</div>' ; } // .shared-files-search-form-container $html .= '</form>' ; // .shared-files-ajax-form $html .= '</div>' ; } if ( $custom_fields_active ) { $meta_query_full = array ( 'relation' => 'AND' , ); $meta_query_full [] = $meta_query_hide_not_public ; $meta_query_full [] = $meta_query ; } else { $meta_query_full = $meta_query_hide_not_public ; } $taxonomy_query = [ 'relation' => 'AND' , ]; if ( $tag_slug ) { $taxonomy_query [] = array ( 'taxonomy' => SHARED_FILES_TAG_SLUG, 'field' => 'slug' , 'terms' => $tag_slug , ); } if ( isset( $atts [ 'category' ] ) ) { if ( SharedFilesHelpers::isPremium() == 0 ) { $html = SharedFilesPublicHelpers::proFeaturePublicMarkup(); return $html ; } } else { if ( isset( $_GET [ 'sf_category' ] ) && $_GET [ 'sf_category' ] != '0' ) { $term_slug = sanitize_title( $_GET [ 'sf_category' ] ); if ( $term_slug ) { $taxonomy_query [] = array ( 'taxonomy' => 'shared-file-category' , 'field' => 'slug' , 'terms' => $term_slug , 'include_children' => true, ); } $wpb_all_query = new WP_Query( array ( 'post_type' => 'shared_file' , 'post_status' => 'publish' , 'posts_per_page' => -1, 'tax_query' => $taxonomy_query , 'orderby' => SharedFilesHelpers::getOrderBy( $atts ), 'order' => SharedFilesHelpers::getOrder( $atts ), 'meta_key' => SharedFilesHelpers::getMetaKey( $atts ), 'meta_query' => $meta_query_full , ) ); $wpb_all_query_all_files = new WP_Query( array ( 'post_type' => 'shared_file' , 'post_status' => 'publish' , 'posts_per_page' => -1, 'tax_query' => array ( array ( 'taxonomy' => 'shared-file-category' , 'field' => 'slug' , 'terms' => $term_slug , 'include_children' => true, ) ), 'orderby' => SharedFilesHelpers::getOrderBy( $atts ), 'order' => SharedFilesHelpers::getOrder( $atts ), 'meta_key' => SharedFilesHelpers::getMetaKey( $atts ), 'meta_query' => $meta_query_hide_not_public , ) ); } else { if ( isset( $_GET [ 'c' ] ) && $_GET [ 'c' ] != 'all_files' ) { $term_slug = sanitize_title( $_GET [ 'c' ] ); if ( $term_slug ) { $taxonomy_query [] = array ( 'taxonomy' => 'shared-file-category' , 'field' => 'slug' , 'terms' => $term_slug , 'include_children' => true, ); } $wpb_all_query = new WP_Query( array ( 'post_type' => 'shared_file' , 'post_status' => 'publish' , 'posts_per_page' => -1, 'tax_query' => $taxonomy_query , 'orderby' => SharedFilesHelpers::getOrderBy( $atts ), 'order' => SharedFilesHelpers::getOrder( $atts ), 'meta_key' => SharedFilesHelpers::getMetaKey( $atts ), 'meta_query' => $meta_query_full , ) ); $wpb_all_query_all_files = new WP_Query( array ( 'post_type' => 'shared_file' , 'post_status' => 'publish' , 'posts_per_page' => -1, 'tax_query' => array ( array ( 'taxonomy' => 'shared-file-category' , 'field' => 'slug' , 'terms' => $term_slug , 'include_children' => true, ) ), 'orderby' => SharedFilesHelpers::getOrderBy( $atts ), 'order' => SharedFilesHelpers::getOrder( $atts ), 'meta_key' => SharedFilesHelpers::getMetaKey( $atts ), 'meta_query' => $meta_query_hide_not_public , ) ); } else { $paged = 1; if ( $pagination_active ) { if ( isset( $_GET [ '_page' ] ) && $_GET [ '_page' ] ) { $paged = (int) $_GET [ '_page' ]; } elseif ( get_query_var( 'paged' ) ) { $paged = absint( get_query_var( 'paged' ) ); } } $posts_per_page = ( isset( $s [ 'pagination' ] ) && $s [ 'pagination' ] ? (int) $s [ 'pagination' ] : 20 ); if ( $limit_posts ) { $posts_per_page = $limit_posts ; } $tax_query = [ 'relation' => 'AND' , ]; if ( isset( $atts [ 'upload_id' ] ) ) { $upload_id = sanitize_text_field( $atts [ 'upload_id' ] ); $meta_query_full = array ( 'relation' => 'AND' , ); $meta_query_full [] = array ( 'key' => '_sf_upload_id' , 'compare' => '=' , 'value' => $upload_id , ); $meta_query_hide_not_public = array ( 'relation' => 'AND' , ); $meta_query_hide_not_public [] = array ( 'key' => '_sf_upload_id' , 'compare' => '=' , 'value' => $upload_id , ); } if ( $tag_slug ) { $tax_query [] = array ( 'taxonomy' => SHARED_FILES_TAG_SLUG, 'field' => 'slug' , 'terms' => $tag_slug , ); } $wpb_all_query = new WP_Query( array ( 'post_type' => 'shared_file' , 'post_status' => 'publish' , 'paged' => $paged , 'posts_per_page' => $posts_per_page , 'orderby' => SharedFilesHelpers::getOrderBy( $atts ), 'order' => SharedFilesHelpers::getOrder( $atts ), 'meta_key' => SharedFilesHelpers::getMetaKey( $atts ), 'meta_query' => $meta_query_full , 'tax_query' => $tax_query , ) ); $wpb_all_query_all_files = new WP_Query( array ( 'post_type' => 'shared_file' , 'post_status' => 'publish' , 'posts_per_page' => -1, 'orderby' => SharedFilesHelpers::getOrderBy( $atts ), 'order' => SharedFilesHelpers::getOrder( $atts ), 'meta_key' => SharedFilesHelpers::getMetaKey( $atts ), 'meta_query' => $meta_query_hide_not_public , 'tax_query' => $tax_query , ) ); } } } $filetypes = SharedFilesHelpers::getFiletypes(); $external_filetypes = SharedFilesHelpers::getExternalFiletypes(); $html .= '<div class="shared-files-files-found"></div>' ; $html .= '<span class="shared-files-one-file-found">' . sanitize_text_field( __( 'file found.' , 'shared-files' ) ) . '</span><span class="shared-files-more-than-one-file-found">' . sanitize_text_field( __( 'files found.' , 'shared-files' ) ) . '</span>' ; $hide_description = ( isset( $atts [ 'hide_description' ] ) ? sanitize_text_field( $atts [ 'hide_description' ] ) : '' ); /* CATEGORY PASSWORD END */ if ( $tag_slug ) { $html .= SharedFilesHelpers::tagTitleMarkup( $tag_slug , 'shared-files-non-ajax' , $hide_description ); } if ( $wpb_all_query_all_files ->have_posts() ) { $html .= '<ul class="shared-files-main-file-list shared-files-ajax-list">' ; if ( isset( $atts [ 'hide_files_first' ] ) ) { // ... } else { while ( $wpb_all_query ->have_posts() ) { $wpb_all_query ->the_post(); $id = intval ( get_the_id() ); $c = get_post_custom( $id ); $external_url = ( isset( $c [ '_sf_external_url' ] ) ? esc_url_raw( $c [ '_sf_external_url' ][0] ) : '' ); $filetype = '' ; $imagefile = SharedFilesHelpers::getImageFile( $id , $external_url ); if ( isset( $atts [ 'file_upload' ] ) ) { $html .= SharedFilesPublicFileCardDefault::fileListItem( $c , $imagefile , $hide_description , 1, $atts ); } elseif ( isset( $atts [ 'category' ] ) ) { $html .= SharedFilesPublicFileCardDefault::fileListItem( $c , $imagefile , $hide_description , 0, $atts ); } else { $html .= SharedFilesPublicFileCardDefault::fileListItem( $c , $imagefile , $hide_description , 1, $atts ); } } } $html .= '</ul>' ; } elseif ( !isset( $atts [ 'file_upload' ] ) ) { $html .= '<ul class="shared-files-main-file-list shared-files-ajax-list"><li>' ; $html .= '<div class="shared-files-files-not-found">' . sanitize_text_field( __( 'No files found.' , 'shared-files' ) ) . '</div>' ; $html .= '</li></ul>' ; } if ( !isset( $s [ 'hide_search_form' ] ) && !isset( $atts [ 'hide_search_for_all_files' ] ) ) { $show_tags = 0; if ( isset( $s [ 'show_tags_on_search_results' ] ) ) { $show_tags = 1; } $html .= '<ul class="shared-files-all-files">' ; if ( isset( $wpb_all_query_all_files ) && $wpb_all_query_all_files ->have_posts() ) { while ( $wpb_all_query_all_files ->have_posts() ) { $wpb_all_query_all_files ->the_post(); $id = intval ( get_the_id() ); $c = get_post_custom( $id ); $external_url = ( isset( $c [ '_sf_external_url' ] ) ? esc_url_raw( $c [ '_sf_external_url' ][0] ) : '' ); $filetype = '' ; $hide_description = ( isset( $atts [ 'hide_description' ] ) ? sanitize_text_field( $atts [ 'hide_description' ] ) : '' ); $imagefile = SharedFilesHelpers::getImageFile( $id , $external_url ); $html .= SharedFilesPublicFileCardDefault::fileListItem( $c , $imagefile , $hide_description , $show_tags , $atts ); } } $html .= '</ul>' ; } if ( !isset( $atts [ 'hide_files_first' ] ) ) { if ( ! $limit_posts ) { $html .= SharedFilesPublicPagination::getPagination( $pagination_active , $wpb_all_query , $embed_id ); } } $html .= '<div class="shared-files-nothing-found">' ; $html .= sanitize_text_field( __( 'No files found.' , 'shared-files' ) ); $html .= '</div>' ; // .shared-files-search $html .= '</div>' ; // .shared-files-container $html .= '</div>' ; // .shared-files-main-container $html .= '</div>' ; $html .= '<hr class="clear" />' ; wp_reset_postdata(); return $html ; } } |
Code file location:
shared-files/shared-files/public/class-sf-public.php
Shared Files [shared_files_simple] Shortcode
The Shared Files Simple shortcode is a feature of the Shared Files plugin. It displays a list of shared files in a simplified form. This shortcode generates HTML output for shared files using the ‘view’ function from the ‘ShortcodeSharedFilesSimple’ class. It accepts attributes for customization, offering flexibility.
Shortcode: [shared_files_simple]
Examples and Usage
Basic example – Here is a simple usage of the ‘shared_files_simple’ shortcode. This example will display the shared files with default settings.
[shared_files_simple /]
Advanced examples
1. Using the shortcode with a specific ID. This will display the shared file with the given ID.
[shared_files_simple id=123 /]
2. Using the shortcode with a custom title. This will display the shared file with the specified title. If the file with the given title is not found, it will display an error message.
[shared_files_simple title="My Shared File" /]
3. Using the shortcode with multiple parameters. This example will display the shared file with the given ID and title. If the file with the specified ID is not found, it will try to load the file with the given title.
[shared_files_simple id=123 title="My Shared File" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [shared_files_simple]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'shared_files_simple', array( 'Shared_Files_Public', 'shared_files_simple' ) );
Shortcode PHP function:
1 2 3 4 5 6 | function shared_files_simple( $atts = array (), $content = null, $tag = '' ) { $html = '' ; $html .= ShortcodeSharedFilesSimple::view( $atts ); return $html ; } |
Code file location:
shared-files/shared-files/public/class-sf-public.php
Shared Files [shared_files_info] Shortcode
The Shared Files shortcode allows users to upload, update, or delete files. It displays a confirmation message upon successful file operation. It checks for specific GET parameters to determine the operation performed. If a file is uploaded or updated, a success message is displayed. Similarly, if a file is deleted, a deletion confirmation is shown.
Shortcode: [shared_files_info]
Examples and Usage
Basic example – A simple usage of the shortcode to display a success message after a file upload.
[shared_files_info shared-files-upload=true /]
Advanced examples
Utilizing the shortcode to show a success message after updating a file. The shortcode checks if the ‘shared-files-update’ parameter is set and if true, it displays the success message.
[shared_files_info shared-files-update=true /]
Using the shortcode to display a message after a file has been successfully deleted. The shortcode checks if the ‘_sf_delete_editable_file’ and ‘sc’ parameters are set and if true, it displays the deletion success message.
[shared_files_info _sf_delete_editable_file=true sc=true /]
PHP Function Code
In case you have difficulties debugging what causing issues with [shared_files_info]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'shared_files_info', array( 'ShortcodeSharedFilesInfo', 'shared_files_info' ) );
Shortcode PHP function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function shared_files_info( $atts = [], $content = null, $tag = '' ) { $html = '' ; if (isset( $_GET ) && isset( $_GET [ 'shared-files-upload' ])) { $html .= '<div class="shared-files-upload-complete">' . sanitize_text_field( __( 'File successfully uploaded.' , 'shared-files' ) ) . '</div>' ; } elseif (isset( $_GET ) && isset( $_GET [ 'shared-files-update' ])) { $html .= '<div class="shared-files-upload-complete">' . sanitize_text_field( __( 'File successfully updated.' , 'shared-files' ) ) . '</div>' ; } elseif (isset( $_GET ) && isset( $_GET [ '_sf_delete_editable_file' ]) && isset( $_GET [ 'sc' ])) { $html .= '<div class="shared-files-file-deleted">' . sanitize_text_field( __( 'File successfully deleted.' , 'shared-files' ) ) . '</div>' ; } return $html ; } |
Code file location:
shared-files/shared-files/public/class-sf-public.php
Conclusion
Now that you’ve learned how to embed the Shared Files 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