Skip to content

Instantly share code, notes, and snippets.

View trey8611's full-sized avatar
💭
listening to n*sync

Trey trey8611

💭
listening to n*sync
View GitHub Profile
@trey8611
trey8611 / assign-images-to-folders-in-media-library-organizer.md
Created February 6, 2025 21:08
Assign imported images to folders in the Media Library Organizer plugin
@trey8611
trey8611 / wp-update-image-asset-id-php-5-to-8.php
Created December 31, 2024 19:12 — forked from jeremytarpley/wp-update-image-asset-id-php-5-to-8.php
WP All Import Pro, update image asset IDs after migrating - using DOMDocument::loadHTML
<?php
// Update image asset IDs after migrating using WP All Import Pro.
// Use in the WP All Import Pro Function Editor: https://www.wpallimport.com/documentation/inline-php/
// Uses DOMDocument::loadHTML for PHP 5-8.
// Code provided by Trey Mills, [email protected]. Updated to support UTF-8 characters.
function my_update_images_in_content( $import_id ) {
global $wpdb;
$imported_posts = $wpdb->get_results( "SELECT `post_id` FROM `" . $wpdb->prefix . "pmxi_posts` WHERE `import_id` = '" . $import_id . "'" );
foreach ( $imported_posts as $x_post ) {
<?php
// Update image asset IDs after migrating using WP All Import Pro.
// Use in the WP All Import Pro Function Editor: https://www.wpallimport.com/documentation/inline-php/
// Uses the Dom\HTMLElement class for PHP 8.4.0+. https://www.php.net/manual/en/class.dom-htmlelement.php#class.dom-htmlelement
// Code provided by Trey Mills, [email protected]. Updated to use the Dom\HTMLElement class and support UTF-8 characters.
function my_update_images_in_content( $import_id ) {
global $wpdb;
$imported_posts = $wpdb->get_results( "SELECT `post_id` FROM `" . $wpdb->prefix . "pmxi_posts` WHERE `import_id` = '" . $import_id . "'" );
foreach ( $imported_posts as $x_post ) {
@trey8611
trey8611 / media-export-import.md
Created October 30, 2024 16:52
Media Export / Import - Add "Media" to the WP All Export and WP All Import Drop-Downs

This code will add "Media" to WP All Export and WP All Import's drop-down options when choosing a post type to export/import. This allows you to directly edit specific fields for media library items, but it does not allow you to import new media library items.

The code needs to be saved in your child theme's functions.php file, or in a Code Snippets plugin.

 // Add "Media" to export drop-down
 
 add_filter( 'wpallexport_custom_types', 'my_add_custom_type', 10, 1 );
 
@trey8611
trey8611 / import-into-yith-swatches.md
Created July 17, 2024 18:40
Import swatches image into YITH WooCommerce Color, Image & Label Variation Swatches Premium

This snippet sets the swatch image for the "pa_shade" attribute assigned to each variation. Read the comments for tips on customizing it for other attributes and restricting it to a certain import ID.

# ************************************************************************************************************
# * Import swatches image for the "YITH WooCommerce Color, Image & Label Variation Swatches Premium" plugin. *
# ************************************************************************************************************

add_action( 'wp_all_import_variable_product_imported', 'wpai_wp_all_import_variable_product_imported', 10, 1 );
function wpai_wp_all_import_variable_product_imported( $post_parent ) {
@trey8611
trey8611 / export-jetengine-relations.md
Created March 20, 2024 20:14 — forked from juanlistab/export-jetengine-relations.md
Export JetEngine Relations with WP All Import

How to Export JetEngine Relations

This function will use the default "jet_rel_default" table in JetEngine to look for the post_id of the parent and return its relations from the "child_object_id" column. If you're using a separate table for your relations, you can change the $table_name value.

Instructions:

  • Add a New Field in WP All Export (see https://d.pr/i/OW9dze).
  • Set a name for the column and use "ID" for the field to export (see https://d.pr/i/v5Mq98).
  • Modify the function as needed, paste it in the Function Editor and paste the name of the function in the "Export the value returned by a PHP function" field (see https://d.pr/i/2c6c07).
  • The function will return a list of IDs separated with pipes by default, but if you want to export the titles instead, you need to change the $mode in "function my_export_je_relation ($post_id, $mode = 'id')" to "title".
@trey8611
trey8611 / import-jetengine-relations.md
Created March 20, 2024 20:13 — forked from juanlistab/import-jetengine-relations.md
Import Data to JetEngine Relations

How to Import JetEngine Relations

This snippet will work for One to One, One to Many and Many to Many relationships:

Instructions:

  • Create a "_temp_child" temporary field to store the values of the relations you want to import (see https://d.pr/i/cIooGf). It will accept multiple values separated with commas, and you can use either the ID or the Title.
  • Edit the snippet using the instructions below and paste it in the Function Editor inside WP All Import.
  • The "jet_rel_default" table is the default table used for relations in JetEngine. If you're using a separate table, you'll need to set that table's name instead.
  • You'll need to specify the relationship ID in 'rel_id’; you can find it here (see https://d.pr/i/eSVZ32).
@trey8611
trey8611 / remove-image-sizes-from-url.md
Last active April 17, 2024 17:24
Remove image sizes from image URLs in content

Remove -000x000.ext from image URLs in content by passing the content to a custom PHP function:

[my_fix_images({content[1]})]

Code (save in the Function Editor at All Import › Settings):

function my_fix_img( $img = '' ) {
@trey8611
trey8611 / remove-duplicats-xpath.md
Created July 15, 2022 20:03
[Remove Duplicates via XPath 1.0]

If you have a variations XPath like this:

{variations/variant[*]}
<variations>
  <variant>
 V1
@trey8611
trey8611 / chain-imports-exports-together.md
Created March 12, 2022 14:59
[Chain Cron Imports / Exports Together] Sequential Cron Imports/Exports

Cron Job Imports: http://www.wpallimport.com/documentation/recurring/cron/.

If you want to run imports or exports sequentially, you can use this workaround:

  • Set up the "trigger" cron job and "processing" cron job for the import/export that should run first.
  • Set up "processing" cron jobs for all of the imports/exports that are going to run.
  • Modify the following code by adding your own URL and import/export IDs then save the code inside the Function Editor:
function my_run_cron_after_import( $import_id ) {