• Resolved Support

    (@nikelschubert)


    Hi, i am not sure what kind of issue this is, or if i have just missed something.

    I am developing a plugin with an upload feature. The error occurs on:
    WP Version 5.3-alpha-46162 and WP Version 5.2.3

    I use the function sanitize_file_name() to clean the uploaded file name.

    If I upload a file with a name like: as.com.pdf i get the following error:

    Uncaught Error: Call to undefined function wp_get_current_user() in wordpress/src/wp-includes/capabilities.php:648
    Stack trace:
    #0 wordpress/src/wp-includes/functions.php(3012): current_user_can('unfiltered_html')
    #1 wordpress/src/wp-includes/formatting.php(2048): get_allowed_mime_types()
    #2 wordpress/src/wp-content/plugins/easy-pdf-restaurant-menu-upload/class/class_admin_easy_pdf_restaurant_menu.php(34): sanitize_file_name('as')
    #3 wordpress/src/wp-content/plugins/easy-pdf-restaurant-menu-upload/nsc_easy-pdf-restaurant-menu.php(48): nsc_easy_pdf_restaurant_menu->nsc_eprm_save_menu('lunch', Array)
    #4 wordpress/src/wp-settings.php(360): include_once('/var/ in wordpress/src/wp-includes/capabilities.php on line 648

    if i upload as.pdf it works.

    usage:
    sanitize_file_name($uploadedFile["name"]);

    • This topic was modified 5 years, 2 months ago by Support.
    • This topic was modified 5 years, 2 months ago by Support.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Support

    (@nikelschubert)

    Probably i found the answer already:
    I assume it is a timing issue: at that time the upload is processed, the user is not loaded yet.

    with as.pdf it is not a problem because with only one extension the function get_allowed_mime_types() is not called.

    this function is only called for multiple extensions.

    But why do you need a loaded user for sanitizing?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    I’m not seeing a reported bug at https://core.trac.www.ads-software.com/search?q=sanitize_file_name&noquickjump=1&ticket=on. You may wish to write this up as a ticket.

    Thread Starter Support

    (@nikelschubert)

    Hi,

    thanks for your answer. But i think it is not a bug.. was just a timing issue: the upload was saved too early. I changed the timing and now it works.

    So i will close this issue.

    Regards

    • This reply was modified 5 years, 2 months ago by Support.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Bug? sanitize_file_name and Call to undefined function wp_get_current_user()’ is closed to new replies.