analogwp / analogwp-templates

Style Kits for Elementor adds a number of intuitive styling controls in the Elementor editor that allow you to apply styles globally or per page.
https://analogwp.com
27 stars 7 forks source link

Upload template media files inside designated folder #371

Closed mauryaratan closed 2 years ago

mauryaratan commented 4 years ago

Currently, any images imported from templates/blocks are directly uploaded in the media library. Let's change that so all images are categorized with template ids inside a designated folder. Here's what it may look like:

Where 11 is site ID, 120 is Post ID, and hash is a unique generated string during import.

This makes cleanup easier if/when users decide to remove Style Kits plugin and also gives them an idea of what came from our plugin.

gvgvgvijayan commented 4 years ago

After analyzing the image import logic I believe that the file structure (template-11-120-hash) is not possible due to the following reasons

Post ID

The post id is generated after the media is uploaded.

In Elementor class Import_Images: Elementor wp_upload_bits call occur before attachment post creation

The same problem is applicable for our plugin class Import_Images: Analog wp_upload_bits occur before attachment post creation

Hash

The hash generation also mapped after the creation of Image and Image's post i.e. WP attachment post

Elementor source link: Image hash mapping to the attachment post

Analog source link: Image hash mapping to the attachment post

Current Implementation's Result

issue_371_a0827af

Suggestion

While exploring the three AJAX calls (Templates, Style Kits, and Blocks Imports) found that all these three commonly passing the following parameters in the request

  1. id
  2. site_id (In template & style kit import parameter named as site_id and in blocks named as siteID)
  3. title

so shall we make use of these values and suffix it like this mediaName(id)(site_id)_hash(title).jpg or else as we noted both in Elementor & Analog the hash generated using the remote URL so shall we make naming convention in remote URL itself to make media's name unique.

@mauryaratan kindly share your thoughts

mauryaratan commented 4 years ago

Hey @gvgvgvijayan,

Thanks for looking into it.

Here's what my initial thoughts are:

gvgvgvijayan commented 4 years ago

@mauryaratan I will check that.

gvgvgvijayan commented 4 years ago
  1. When import occurs in code
  2. Apply a filter on a hook that fires up when an image is uploaded
  3. Read that image attachment, and check for _elementor_source_image_hash or _analog_image_hash
  4. If true, add that post ID to a new options object
  5. Remove the filter once we’re finished importing
lushkant commented 2 years ago

This is no longer a requirement, let's close this!