udx / wp-stateless

WP-Stateless is a WordPress plugin that uploads and serves your WordPress media from Google Cloud Storage.
https://stateless.udx.io
MIT License
261 stars 63 forks source link

The content filter error if upload folder path manage by pattern "Year/Month" #594

Open hungud opened 3 years ago

hungud commented 3 years ago

`

public function the_content_filter($content) {

    if ($upload_data = wp_upload_dir()) {

      if (!empty($upload_data['url']) && !empty($content)) {
        $url = preg_replace('/https?:\/\//', '', $upload_data['url']);

        $root_dir = trim($this->get('sm.root_dir'), '/ '); // Remove any forward slash and empty space.
        $root_dir = apply_filters("wp_stateless_handle_root_dir", $root_dir);
        $root_dir = !empty($root_dir) ? $root_dir . '/' : false;
        $image_host = $this->get_gs_host();
        $file_ext = $this->replaceable_file_types();
        $content = preg_replace(
          '/(href|src)=(\'|")(https?:\/\/' . str_replace('/', '\/', $url) . ')\/(.+?)(' . $file_ext . ')(\'|")/i',
          '$1=$2' . $image_host . '/' . ($root_dir ? $root_dir : '') . '$4$5$6',
          $content
        );
      }
    }

`

wp_upload_dir() => return with current date => /wp-content/uploads/2021/01

=> so, it do wrong, it should show by current post date!

Please correct it!

hungud commented 3 years ago

I send you bugsfix

/**

antonkorotkov commented 3 years ago

Please, create a Pull Request so we can review your fix.