• Resolved marcjc

    (@marcjc)


    Hopefully you can help… would like use your shortcode with the current logged in username. My site will have user directories auto created for each user and I’d like to use the shortcode to direct the user to their own files page for example, user=joe123 user folder is equal to /wp-content/uploads/folders/joe123

    [MMFileList folder=[current_user] format=”table” /].

    Is this possible with your plugin? For now I am doing this manually, but I’d like it to be automatic.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Adam Bissonnette

    (@mmanifesto)

    You could write a wrapper shortcode for it for dynamic folders. Something like this:

    <?php
    function ListUserFilesFunc($atts, $content="")
    {
        $output = "User is not logged in";
        $current_user = wp_get_current_user();
        if ( $current_user->exists() ) {
          $folder = '/wp-content/uploads/folders/' . $current_user->name;
          $shortcode_template = '[MMFileList folder="%s" format="table" /]';
    
          $output = do_shortcode(sprintf($shortcode_template, $folder));
        }
    
        return $output;
    }
    
    add_shortcode('ListUserFiles', 'ListUserFilesFunc');
    

    That could go into your functions.php file if you have a child theme – alternatively it’d be easy to put the above code into a mini plugin. Lemme know if this helps.

    Thread Starter marcjc

    (@marcjc)

    Thank you very much for the quick reply. I am going to take a look at your code, but I got it working with this (added the last line here to get the current user):

    function ListFiles($atts, $content="")
        {   
           ...
    	$current_user = wp_get_current_user();

    added the last line above. Then on the first $folder line (line 64) I did this:

    $folder = $this->_check_for_slashes($current_user->user_login);

    Then my shortcode I remove the folder completely since it is being forced to the current user:

    [MMFileList format=”table” /].

    • This reply was modified 2 years, 4 months ago by marcjc.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘logged in username’ is closed to new replies.