wp_stateless_file_name

wp_stateless_file_name

Hook Type: filter
See hook in action

See hook in core

Displaying hooks found in version: wp-stateless.4.1.2

apply_filters('wp_stateless_file_name') is found 33 times:

  • /lib/classes/class-bootstrap.php line 1585
            /* Determine if the media file has GS data at all. */
            if (is_multisite() && $_file) {
              $blog_id = get_current_blog_id();
              $uploads = wp_get_upload_dir();
              $_file = apply_filters('wp_stateless_file_name', $_file, false);
              $file_path_fix = $uploads['basedir'] . "/sites/$blog_id/$_file";
    
              if (file_exists($file_path_fix)) {
                return $file_path_fix;
              }
            } elseif (empty($sm_cloud) && $this->get('sm.mode') == 'stateless' && $_file) {
    
  • /lib/classes/class-bootstrap.php line 1814
                  $url = $uploads['baseurl'] . '/' . $_file;
                } else {
                  $uploads = wp_get_upload_dir();
                  $default_dir = false;
                  $_file = apply_filters('wp_stateless_file_name', $_file, false);
                  $blog_id = get_current_blog_id();
                  $file_path_fix = $uploads['basedir'] . "/sites/$blog_id/$_file";
    
                  if (file_exists($file_path_fix)) {
                    $url = $uploads['baseurl'] . "/sites/$blog_id/$_file";
                  }
    
  • /lib/classes/class-gs-client.php line 202
     
              $object_id = isset($args['metadata']['object-id']) ? $args['metadata']['object-id'] : (isset($args['metadata']['child-of']) ? $args['metadata']['child-of'] : "");
              $object_size = isset($args['metadata']['size']) ? $args['metadata']['size'] : "";
    
              $args['name'] = apply_filters('wp_stateless_file_name', $args['name'], $args['use_root'], $object_id, $object_size);
              $args = apply_filters('wp_stateless_add_media_args', $args);
              $name = $args['name'];
    
              // If media exists we just return it
              if (!$args['force'] && $media = $this->media_exists($name)) {
                if ($media->getCacheControl() != $args['cacheControl']) {
    
  • /lib/classes/class-gs-client.php line 393
           * @return bool
           */
          public function remove_media($name, $id = "", $use_root = true, $size = "", $is_webp = false) {
            try {
              $name = apply_filters('wp_stateless_file_name', $name, $use_root, $id, $size);
              if ($is_webp && substr($name, -4) !=  "webp") $name .= ".webp";
    
              $this->service->objects->delete($this->bucket, $name);
            } catch (Exception $e) {
              return new WP_Error('sm_error', $e->getMessage());
            }
    
  • /lib/classes/class-sync-non-media.php line 128
     
              if ($sm_mode == 'stateless' && !wp_doing_ajax()) {
                global $gs_client;
    
                $gs_name = apply_filters('wp_stateless_file_name', $name, $args['name_with_root']);
    
                //Bucket
                $bucket = ud_get_stateless_media()->get('sm.bucket');
    
                $bucket = $gs_client->bucket($bucket);
                $object = $bucket->object($gs_name);
    
  • /lib/classes/class-utility.php line 444
            $gs_name_path = array();
            $full_size_path = get_attached_file($attachment_id);
            $base_dir = dirname($full_size_path);
    
            $gs_name = apply_filters('wp_stateless_file_name', $full_size_path, true, $attachment_id, '');
            $gs_base_dir = dirname($gs_name) == '.' ? '' : trailingslashit(dirname($gs_name));
    
            if (!isset($metadata['width']) && file_exists($full_size_path)) {
              try {
                $_image_size = getimagesize($full_size_path);
                if ($_image_size !== false && is_array($_image_size)) {
    
  • /lib/classes/class-utility.php line 475
              foreach ($metadata['sizes'] as $image_size => $data) {
                if (empty($data['file'])) continue;
                $absolutePath = wp_normalize_path($base_dir . '/' . $data['file']);
                $gs_name = $gs_base_dir . $data['file'];
                $gs_name = apply_filters('wp_stateless_file_name', $gs_name, true, $attachment_id, $image_size);
    
                $gs_name_path[$image_size] = array(
                  'gs_name'   => $gs_name,
                  'path'      => $absolutePath,
                  'sm_meta'   => true,
                  'is_thumb'  => true,
    
  • /lib/classes/class-utility.php line 980
            // If no file found
            if (false === $fullsizepath || !file_exists($fullsizepath)) {
    
              // Try get it and save
              $result_code = ud_get_stateless_media()->get_client()->get_media(apply_filters('wp_stateless_file_name', $fullsizepath, true, "", ""), true, $fullsizepath);
    
              if ($result_code !== 200) {
                if (!Utility::sync_get_attachment_if_exist($image->ID, $fullsizepath)) {
                  throw new UnprocessableException(sprintf(__('Both local and remote files are missing. Unable to process. (%s)', ud_get_stateless_media()->domain), $image->guid));
                }
              }
    
  • /lib/classes/class-utility.php line 1037
     
            if (false === $fullsizepath || !$local_file_exists) {
    
              // Try get it and save
              $result_code = ud_get_stateless_media()->get_client()->get_media(apply_filters('wp_stateless_file_name', $fullsizepath, true, "", ""), true, $fullsizepath);
    
              if ($result_code !== 200) {
                if (!Utility::sync_get_attachment_if_exist($file->ID, $fullsizepath)) { // Save file to local from proxy.
                  throw new UnprocessableException(sprintf(__('File not found (%s)', ud_get_stateless_media()->domain), $file->guid));
                } else {
                  $local_file_exists = true;
    
  • /lib/classes/class-utility.php line 1052
            }
    
            if ($local_file_exists) {
    
              if (!ud_get_stateless_media()->get_client()->media_exists(apply_filters('wp_stateless_file_name', $fullsizepath, true, "", ""))) {
    
                if (!function_exists('wp_generate_attachment_metadata')) {
                  require_once ABSPATH . '/wp-admin/includes/media.php';
                  require_once ABSPATH . '/wp-admin/includes/image.php';
                }
                $metadata = wp_generate_attachment_metadata($file->ID, $fullsizepath);
    
  • /lib/classes/compatibility/ewww.php line 39
           * @param $fullsize
           */
          public function pre_optimization( $file, $type, $fullsize ) {
            // wp_stateless_file_name filter will remove the basedir from the path and prepend with root dir.
            $name = apply_filters( 'wp_stateless_file_name', $file );
            do_action( 'sm:sync::syncFile', $name, $file, true, array( 'ephemeral' => false, 'download' => true, 'use_root' => true ) );
          }
    
          /**
           * If image size not exist then upload it to GS.
           *
    
  • /lib/classes/compatibility/ewww.php line 52
           * @param $fullsize
           */
          public function post_optimization( $file, $type, $fullsize ) {
            // wp_stateless_file_name filter will remove the basedir from the path and prepend with root dir.
            $name = apply_filters( 'wp_stateless_file_name', $file );
            do_action( 'sm:sync::syncFile', $name, $file, true, array( 'use_root' => true ) );
    
    
            // if($fullsize && file_exists($file . '.bak'))
            //     do_action( 'sm:sync::syncFile', $name . '.bak', $file . '.bak', true);
    
    
  • /lib/classes/compatibility/imagify.php line 146
            /**
             * Try to get all missing files from GCS
             */
            if (!file_exists($file)) {
              ud_get_stateless_media()->get_client()->get_media(apply_filters('wp_stateless_file_name', $meta_data['file']), true, $file);
            }
    
            if (!empty($meta_data['sizes']) && is_array($meta_data['sizes'])) {
              $upload_basedir = trailingslashit(dirname($file));
              foreach ($meta_data['sizes'] as $image) {
                if (!empty($image['gs_name']) && !file_exists($file = $upload_basedir . $image['file'])) {
    
  • /lib/classes/compatibility/imagify.php line 153
            if (!empty($meta_data['sizes']) && is_array($meta_data['sizes'])) {
              $upload_basedir = trailingslashit(dirname($file));
              foreach ($meta_data['sizes'] as $image) {
                if (!empty($image['gs_name']) && !file_exists($file = $upload_basedir . $image['file'])) {
                  ud_get_stateless_media()->get_client()->get_media(apply_filters('wp_stateless_file_name', $image['gs_name']), true, $file);
                }
              }
            }
          }
    
          /**
    
  • /lib/classes/compatibility/imagify.php line 198
              $backup_path = get_imagify_attachment_backup_path($file_path);
              if (file_exists($backup_path)) {
                $overwrite = apply_filters('imagify_backup_overwrite_backup', false, $file_path, $backup_path);
                // wp_stateless_file_name filter will remove the basedir from the path and prepend with root dir.
                $name = apply_filters('wp_stateless_file_name', $backup_path);
                do_action('sm:sync::syncFile', $name, $backup_path, $overwrite);
              }
            }
          }
    
          /**
    
  • /lib/classes/compatibility/imagify.php line 214
            $backup_path = get_imagify_attachment_backup_path($file_path);
            if (!file_exists($backup_path)) {
              $upload_dir = wp_upload_dir();
              $name = str_replace(trailingslashit($upload_dir['basedir']), '', $backup_path);
              $name = apply_filters('wp_stateless_file_name', $name);
              do_action('sm:sync::syncFile', $name, $backup_path, true);
            }
          }
    
          /**
           * Check if backup exists in GCS.
    
  • /lib/classes/compatibility/imagify.php line 227
           * @return bool
           */
          public function imagify_has_backup($return, $has_backup) {
            if (!$return && $has_backup) {
              $name = apply_filters('wp_stateless_file_name', $has_backup);
              $return = (bool) apply_filters('sm:sync::queue_is_exists', $name);
            }
            return $return;
          }
    
          /**
    
  • /lib/classes/compatibility/imagify.php line 245
            if ($wp_stateless_imagify_mode == 'ephemeral') {
              ud_get_stateless_media()->set('sm.mode', 'ephemeral');
            }
    
            $name = apply_filters('wp_stateless_file_name', basename($file));
    
            if (file_exists($file)) {
              add_filter('upload_mimes', array($this, 'add_webp_mime'), 10, 2);
              /**
               * Media already on GCS, so only replacing data on it. For webp format adding path and status to wp_stateless_files table
               */
    
  • /lib/classes/compatibility/imagify.php line 273
            try {
              $attachment_id = $this->getProperties($this->getProperties($this->getProperties($process)['data'])['media'])['id'];
    
              $full_size_path = $file->get_path();
              $name = apply_filters('wp_stateless_file_name', basename($full_size_path), true, $attachment_id);
              do_action('sm:sync::syncFile', $name, $full_size_path, true, ['download' => true]);
              // error_log("\n\ndo_action( 'sm:sync::syncFile', $name, $full_size_path, true, ['download' => true] );");
            } catch (\Throwable $th) {
              //throw $th;
            }
            return $return;
    
  • /lib/classes/compatibility/shortpixel.php line 133
                $wp_uploads_dir = wp_get_upload_dir();
                $gs_name = str_replace(trailingslashit($wp_uploads_dir['basedir']), '', $path);
                $gs_name = str_replace(trailingslashit($wp_uploads_dir['baseurl']), '', $gs_name);
                $gs_name = str_replace(trailingslashit(ud_get_stateless_media()->get_gs_host()), '', $gs_name);
                $gs_name = apply_filters('wp_stateless_file_name', $gs_name);
                if ($media = ud_get_stateless_media()->get_client()->media_exists($gs_name)) {
                  $return = true;
                }
              }
              set_transient($key, $return, 10 * MINUTE_IN_SECONDS);
            }
    
  • /lib/classes/compatibility/shortpixel.php line 161
            $backup_path = SHORTPIXEL_BACKUP_FOLDER . '/' . $fullSubDir;
    
            foreach ($paths as $key => $path) {
              // Removing backup
              $name = apply_filters('wp_stateless_file_name', SHORTPIXEL_BACKUP . '/' . $fullSubDir . basename($path));
              do_action('sm:sync::deleteFile', $name);
    
              // Removing WebP
              $backup_images = \WPShortPixelSettings::getOpt('wp-short-create-webp');
              if ($backup_images) {
                $name = str_replace($sp__uploads['basedir'], '', $path);
    
  • /lib/classes/compatibility/shortpixel.php line 168
              // Removing WebP
              $backup_images = \WPShortPixelSettings::getOpt('wp-short-create-webp');
              if ($backup_images) {
                $name = str_replace($sp__uploads['basedir'], '', $path);
                $name = apply_filters('wp_stateless_file_name', $name . '.webp');
                do_action('sm:sync::deleteFile', $name);
              }
            }
    
            if (ud_get_stateless_media()->get('sm.mode') == 'ephemeral') {
              return true;
    
  • /lib/classes/compatibility/shortpixel.php line 291
                $args = array('ephemeral' => false);
              }
    
              $absolutePath = trailingslashit($backup_path) . basename($metadata['file']);
              $name = apply_filters('wp_stateless_file_name', SHORTPIXEL_BACKUP . '/' . $fullSubDir . basename($metadata['file']));
              do_action('sm:sync::syncFile', $name, $absolutePath, $force, $args);
    
              foreach ((array) $metadata['sizes'] as $image_size => $data) {
                $absolutePath = trailingslashit($backup_path) . $data['file'];
                $name = apply_filters('wp_stateless_file_name', SHORTPIXEL_BACKUP . '/' . $fullSubDir . $data['file']);
    
    
  • /lib/classes/compatibility/shortpixel.php line 296
              do_action('sm:sync::syncFile', $name, $absolutePath, $force, $args);
    
              foreach ((array) $metadata['sizes'] as $image_size => $data) {
                $absolutePath = trailingslashit($backup_path) . $data['file'];
                $name = apply_filters('wp_stateless_file_name', SHORTPIXEL_BACKUP . '/' . $fullSubDir . $data['file']);
    
                do_action('sm:sync::syncFile', $name, $absolutePath, $force, $args);
              }
            }
          }
    
    
  • /lib/classes/compatibility/shortpixel.php line 387
              $_contentDisposition = \wpCloud\StatelessMedia\Utility::getContentDisposition($attachment_id, $metadata, null);
              $_metadata = array("width" => isset($metadata['width']) ? $metadata['width'] : null, "height" => isset($metadata['height']) ? $metadata['height'] : null, 'object-id' => $attachment_id, 'source-id' => md5($attachment_id . ud_get_stateless_media()->get('sm.bucket')), 'file-hash' => md5($metadata['file']));
    
              if (file_exists($fullsizepath)) {
                $file = apply_filters('wp_stateless_file_name', $file);
    
                /* Add default image */
                $media = $client->add_media($_mediaOptions = array_filter(array('force' => true, 'name' => $file, 'absolutePath' => wp_normalize_path(get_attached_file($attachment_id)), 'cacheControl' => $_cacheControl, 'contentDisposition' => $_contentDisposition, 'mimeType' => get_post_mime_type($attachment_id), 'metadata' => $_metadata)));
    
                // ephemeral mode: we don't need the local version.
                if (ud_get_stateless_media()->get('sm.mode') === 'ephemeral') {
    
  • /lib/classes/compatibility/shortpixel.php line 402
              /* Now we go through all available image sizes and upload them to Google Storage */
              if (!empty($metadata['sizes']) && is_array($metadata['sizes'])) {
    
                $path = wp_normalize_path(dirname(get_attached_file($attachment_id)));
                $mediaPath = apply_filters('wp_stateless_file_name', trim(dirname($metadata['file']), '\/\\'));
    
                foreach ((array) $metadata['sizes'] as $image_size => $data) {
    
                  $absolutePath = wp_normalize_path($path . '/' . $data['file']);
    
                  if (!file_exists($absolutePath)) {
    
  • /lib/classes/compatibility/simple-local-avatars.php line 71
            // Replace local urls with corresponding GCS urls
            if (!empty($user_meta[0]) && is_array($user_meta[0])) {
              foreach ($user_meta[0] as $key => &$value) {
                if (is_numeric($key)) {
                  $value = trailingslashit($bucketLink) . apply_filters('wp_stateless_file_name', str_replace($upload['baseurl'], '', $value), true);
                }
              }
            }
    
            // Return filtered data back
            return $user_meta;
    
  • /lib/classes/compatibility/woo-extra-product-options.php line 54
            $type = $upload['type'];
    
            $client = ud_get_stateless_media()->get_client();
    
            $file_path = apply_filters('wp_stateless_file_name', $file, 0);
            $file_info = @getimagesize($file);
    
            if ($file_info) {
              $_metadata = array(
                'width'  => $file_info[0],
                'height' => $file_info[1],
    
  • /lib/classes/compatibility/wp-smush.php line 120
              $metadata = wp_get_attachment_metadata($attachment_id);
              if (!empty($metadata['gs_name'])) {
                $image_sizes = Utility::get_path_and_url($metadata, $attachment_id);
                foreach ($image_sizes as $size => $img) {
                  $client->get_media(apply_filters('wp_stateless_file_name', $img['gs_name']), true, $img['path']);
                }
    
                $gs_name = dirname($metadata['gs_name']) . '/' . basename($file_path);
                // We need to remove backup from GCS if it's a restore action
                // @todo revise this code
                if ($this->hook_from_restore_image()) {
    
  • /lib/classes/compatibility/wp-smush.php line 127
                $gs_name = dirname($metadata['gs_name']) . '/' . basename($file_path);
                // We need to remove backup from GCS if it's a restore action
                // @todo revise this code
                if ($this->hook_from_restore_image()) {
                  $client->remove_media(apply_filters('wp_stateless_file_name', $gs_name));
                }
              }
            }
          }
    
          /**
    
  • /lib/classes/compatibility/wp-smush.php line 152
              foreach ($backup_paths as $key => $data) {
                $gs_name = $gs_dir . '/' . basename($data['file']);
                // Path of backup image
                $backup_path = $base_dir . '/' . basename($data['file']);
                do_action('sm:sync::deleteFile', apply_filters('wp_stateless_file_name', $gs_name), $backup_path);
                delete_transient('sm-wp-smush-backup-exists-' . $attachment_id);
              }
            }
          }
    
          /**
    
  • /lib/classes/compatibility/wp-smush.php line 175
     
              $metadata = wp_get_attachment_metadata($attachment_id);
              if (!empty($metadata['gs_name'])) {
                $gs_name = dirname($metadata['gs_name']) . '/' . basename($backup_path);
                if (ud_get_stateless_media()->get_client()->media_exists(apply_filters('wp_stateless_file_name', $gs_name))) {
                  set_transient('sm-wp-smush-backup-exists-' . $attachment_id, true, HOUR_IN_SECONDS);
                  return true;
                }
              }
            }
    
    
  • /lib/classes/compatibility/wp-smush.php line 211
                $gs_name = $gs_dir . '/' . basename($data['file']);
                // Path of backup image
                $backup_path = $base_dir . '/' . basename($data['file']);
                // Sync backup image with GCS
                do_action('sm:sync::syncFile', apply_filters('wp_stateless_file_name', $gs_name), $backup_path);
                delete_transient('sm-wp-smush-backup-exists-' . $attachment_id);
              }
            }
          }
    
          /**
    

See this hook used in plugins: