Viewing 1 replies (of 1 total)
  • Thread Starter Diiamo

    (@luislu)

    From AI, it works. After pasting it here, the code format is chaotic

    add_filter( ‘upload_dir’, ‘fix_the_paste_upload_dir’ );
    function fix_the_paste_upload_dir( $uploads ) {
    if ( ! is_admin() || ! defined( ‘DOING_AJAX’ ) || ! DOING_AJAX ) {
    return $uploads;
    }
    if ( ! isset( $_POST[‘action’] ) || $_POST[‘action’] !== ‘upload-attachment’ ) {
    return $uploads;
    }
    $referer = wp_get_referer();
    if ( $referer && ( strpos( $referer, ‘post.php’ ) !== false || strpos( $referer, ‘post-new.php’ ) !== false ) ) {
    $ym = current_time( ‘Y/m’ );
    $subdir = ‘/’ . $ym;

        $uploads['subdir'] = $subdir;
        $uploads['path']   = $uploads['basedir'] . $subdir;
        $uploads['url']    = $uploads['baseurl'] . $subdir;
    }
    return $uploads;

    }

    • This reply was modified 2 months, 3 weeks ago by Diiamo.
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.