Mbsm.tn, Plugins wordpress 2024, List Folder Contents with Enhanced SEO, with pagination , Programmation Mbsmgroup

WordPress plugin that lists the contents of a specific folder on the server and displays them in a single-column list. The contents are displayed with clickable links, and each link also includes searchable word links for the filename split into individual words. Additionally, the plugin includes improvements for SEO and styling, including pagination.

Here’s a breakdown of what the code does:

Main Features:

  1. Shortcode for Listing Folder Contents:

    • The function list_folder_contents_shortcode takes a folder path as an attribute and generates a list of files within that folder.
    • It checks for invalid or inaccessible folder paths.
    • It allows filtering by file type, if specified in the plugin settings (lfc_file_types option).
    • It paginates the list of files to avoid loading too many files at once, based on the lfc_files_per_page option.
    • Each item in the list is clickable and links to a URL corresponding to that file.

  2. SEO Improvements:

    • The plugin splits the filenames into words and creates links for each word. This helps search engines index the individual words in the filenames, potentially improving SEO.
    • It uses title and alt attributes for SEO, making sure that the file names and their related words are indexed properly.

  3. Security Improvements:

    • The target="_blank" attribute is used for opening links in a new tab, along with rel="noopener noreferrer" to improve security when opening external links.
    • URLs are sanitized using esc_url(), and file names are sanitized using esc_html() and esc_attr().

  4. Styling:

    • Custom styles are added to the list of folder contents and pagination. The wp_head action hook is used to inject CSS directly into the head of the page.
    • Pagination controls are styled to ensure they are user-friendly and visually consistent.

Notes:

  1. Folder Path:

    • The folder path is relative to the WordPress installation directory (ABSPATH). The plugin ensures that the path is valid and accessible. If the path is invalid or not a directory, it returns an error message.

  2. Pagination:

    • The pagination is based on the paged query variable and the lfc_files_per_page option. This ensures that large directories are displayed over multiple pages rather than all at once.

  3. File Type Filtering:

    • The plugin can filter files based on specific extensions. These extensions are specified by the user in the plugin settings under lfc_file_types. The plugin splits the string by commas and filters files accordingly.

Possible Improvements or Considerations:

  • Security: The plugin checks for the validity of the folder path, but depending on where it’s used, you may want to further restrict access to specific directories to avoid potential misuse or unauthorized access to sensitive files.
  • Error Handling: The plugin currently returns a simple error message if the folder is invalid or inaccessible. You could enhance this by adding logging or more detailed error handling for debugging purposes.
  • Caching: If the folder contents do not change frequently, you may want to add a caching mechanism to speed up performance, especially if the plugin is used on a site with large directories.
  • Customization: You might want to allow users to customize the appearance further by adding more style options or enabling a custom CSS file.

Overall Summary:

This plugin provides a useful way to display folder contents in WordPress with SEO enhancements and simple pagination. The implementation is solid, and it’s easily extensible for further customization or improvement if necessary.

Installation Instructions

To use this plugin, simply add the shortcode [list_folder_contents path=”your/path/here”] to any post or page.

Notes

  • Ensure that the specified path is accessible and contains files.
  • You can specify file types to filter the displayed files.