Shared Files Shortcodes

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:

Plugin Icon
Shared Files – Advanced File Sharing & Download Manager with Frontend Uploads

"Shared Files is a superior plugin for advanced file sharing & download management. It also supports frontend uploads, making file sharing an effortless task."

★★★★✩ (27) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [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:

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:

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:

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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *