• adventurequalifications

    (@adventurequalifications)


    Hi – I am brand new to this and am trying to self teach whilst in lockdown.

    I am trying to stop specific files from offloaded by WP Offload Media as they are needed on the server. I am using WP Offload Media Tweaks, but I am new to coding. As in this is my first try…

    I need any file that has KEEP in the filename from offloading and it must stay on the server. What I have been trying does not work. Any ideas? The code I tried in the tweaks plugin after lots of internet searching is:

    function pre_upload_attachment( $abort, $post_id, $metadata ) {

    $file = get_post_meta( $post_id, ‘_wp_attached_file’, true );
    $filename = is_string( $file ) ? pathinfo( $file, PATHINFO_FILENAME ) : false;
    if ( is_string( $filename ) && in_array( $filename, array( ‘KEEP’ ) ) ) {
    $abort = true;
    }

    What am I doing wrong?
    Thanx
    Andrew

Viewing 1 replies (of 1 total)
  • Plugin Contributor ianmjones

    (@ianmjones)

    Try something like…

    function pre_upload_attachment( $abort, $post_id, $metadata ) {
        $file = get_post_meta( $post_id, '_wp_attached_file', true );
    
        if ( is_string( $file ) && false !== strpos( $file, 'KEEP' ) ) {
            $abort = true;
        }
    
        return $abort;
    }

    Make sure to uncomment the associated add_filter( 'as3cf_pre_upload_attachment' ... line in the Tweaks plugin’s constructor.

Viewing 1 replies (of 1 total)
  • The topic ‘Stop specific file offloading’ is closed to new replies.