• Resolved Zbynek Nedoma

    (@domaneni)


    Hi,
    I am trying to put your plugin on my page which is running on bedrock, trellis and sage. I have my uploads folder link outside to shared folder currenct release. By few changes I was able to convers files in uploads but themes give me a struggle.

    This is code I am using now

    
    add_filter('webpc_dir_path', function ($path, $directory) {
        $divided_path =  explode('/', dirname(__FILE__));
        $site_path= implode('/', array_slice($divided_path, 0, 7));
    
        switch ($directory) {
            case 'uploads':
                return $site_path.'/uploads';
            case 'webp':
                return $site_path.'/uploads/uploads-webpc';
            case 'themes':
                return $site_path.'/themes';
            case 'plugins':
                return $site_path.'/plugins';
        }
    
        return ABSPATH;
    }, 10, 2);
    
    add_filter( 'webpc_uploads_prefix', function( $prefix ) {
        return '/';
    } );
    
    add_filter( 'webpc_site_root', function( $path ) {
        $divided_path =  explode('/', dirname(__FILE__));
        $site_path= implode('/', array_slice($divided_path, 0, 7));
        return $site_path; // your valid path to root
    } );
    
    add_filter('webpc_dir_name', function ($path, $type) {
    
        switch ($type) {
            case 'themes':
                return 'themes';
            case 'plugins':
                return 'plugins';
        }
    
        return ABSPATH;
    }, 10, 2);
    

    WebP images are saved to uploads/uploads-webpc and then normal uploads structure. But theme files don’t follow this and are saved like this uploads/uploads-webpc/srv/www/test.com/current/web/app/themes/test-theme/resources/assets/images/XYZ.
    I would like to save them to structure uploads/uploads-webpc/themes/test-theme/resources/assets/images/XYZ.

    Is this somehou possible?

    I did some investigation and what I need is to have option to change output of this piece of code str_replace( realpath( $uploads_root ) ?: '', '', realpath( $path ) ?: '' );.
    It is in OuputPath::get_directory_path function. If you can add some filter there, it will be really helpfull.

    This is my config code

    
    location ~ /app/(?<dir>uploads)/(?<path>.+)\.(?<ext>jpe?g|png|gif)$ {
        if ($http_accept !~* "image/webp") {
         break;
        }
        add_header Vary Accept;
        expires 365d;
        try_files /app/uploads/uploads-webpc/$path.$ext.webp $uri =404;
      }
    
      location ~ /app/(?<dir>plugins|themes)/(?<path>.+)\.(?<ext>jpe?g|png|gif)$ {
        if ($http_accept !~* "image/webp") {
         break;
        }
        add_header Vary Accept;
        expires 365d;
        try_files /app/uploads/uploads-webpc/$dir/$path.$ext.webp $uri =404;
      }
    

    Thank you for answer,
    Zbynek

    • This topic was modified 2 years, 10 months ago by Zbynek Nedoma.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hello @domaneni,

    Thanks for your message.

    You can also use the webpc_dir_path filter. Did you read the instructions in the plugin FAQ on how to change directory paths?

    Best,
    Mateusz

    Thread Starter Zbynek Nedoma

    (@domaneni)

    Hi,
    thank you for the quick answer. Yes I read it, but you have there a note

    Note that the /uploads-webpc directory must be at the same nesting level as the /uploads, /plugins and /themes directories.

    But my setup is not following that. My /uploads-webpc directory is in /uploads directory.

    I am not sure, how webpc_dir_path can help me with that.

    Sorry if I don’t understand something correctly ??

    • This reply was modified 2 years, 10 months ago by Zbynek Nedoma.
    • This reply was modified 2 years, 10 months ago by Zbynek Nedoma.
    • This reply was modified 2 years, 10 months ago by Zbynek Nedoma.
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @domaneni Unfortunately, it cannot be changed, which is stated in the note. The /uploads-webpc directory cannot be in the /uploads directory.

    Thread Starter Zbynek Nedoma

    (@domaneni)

    @mateuszgbiorczyk That is why I was asking, if you can add a filter there, which I can overide.

    With my setup /uploads-webpc can be in /uploads folder.

    If you change
    $output_path = str_replace( realpath( $uploads_root ) ?: '', '', realpath( $path ) ?: '' );
    to something like this
    $output_path = apply_filters( 'webpc_output_path', str_replace( realpath( $uploads_root ) ?: '', '', realpath( $path ) ?: '' ), $uploads_root, $path);

    I can then write my filter, that will look like this and it is working fine.

    add_filter('webpc_output_path', function ($output_path, $uploads_root, $path) {
        if (strpos($output_path,'/themes/') !== false) {
            $output_path = str_replace('/srv/www/test.com/current/web/app/', '', $output_path);
        }
        return $output_path;
    }, 10, 3);
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @domaneni I cannot add such a filter because then the redirect convention in the .htaccess file and the Nginx configuration plugin suggested in the plugin FAQ will not be correct.

    Thread Starter Zbynek Nedoma

    (@domaneni)

    Oh ok, I thought that the settings will be still same until somebody changes the filter. Then he needs to know what he is doing and how to change htaccess file and Nginx configuration correctly.

    But it is your plugin and you know what is best for it :). Thank you or your time.

    By the way, the plugin is awesome

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @domaneni I would like to help you, but you must remember that the plug-in is for everyone. If I add a filter that only you can use, I still have to assume that more people are using it. You change your Nginx configuration, but most people don’t, so I can’t implement such solutions.

    Thread Starter Zbynek Nedoma

    (@domaneni)

    Yes, I completely understand. Thank you again.

    • This reply was modified 2 years, 10 months ago by Zbynek Nedoma.
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Change theme output path’ is closed to new replies.