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 / gist:3dcca4d76d681c05342b131d65de8e1d
Created July 26, 2017 21:02
Get all image src values from HTML
// Get all image src from HTML content
function my_get_images_from_content( $html ) {
$doc = new DOMDocument();
@$doc->loadHTML( $html );
$imageTags = $doc->getElementsByTagName( 'img' );
$all_images = array();
foreach( $imageTags as $tag ) {
$all_images[] = $tag->getAttribute( 'src' );
}
@trey8611
trey8611 / imagediff.txt
Last active August 9, 2017 14:52
Check if images are different
function are_images_diff( $img1, $img2 ) {
$md5image1 = md5( file_get_contents( $img1 ) );
$md5image2 = md5( file_get_contents( $img2 ) );
if ( $md5image1 == $md5image2 ) {
return "They are the same.";
} else {
return "They are different.";
}
}
<?php
add_action( 'pmxi_saved_post', 'my_update_stock', 10, 3 );
function my_update_stock( $order_id, $xml_data, $is_update ) {
$import_id = ( isset( $_GET['id'] ) ) ? $_GET['id'] : $_GET['import_id'];
if ( $import_id == "7" && $is_update == false ) { // change "7" to your import ID
if ( $order = wc_get_order( $order_id ) ) {
$items = $order->get_items();
@trey8611
trey8611 / data_feed.php
Last active January 18, 2019 19:47
#proxyscript
<?php
/*
################### READ ME #################################
You must create a proxy file that retrieves your import file from FTP and then returns it.
You will then call that file with the 'Download from URL' option in WP All Import.
This is an example of such a proxy file. This is provided in the hopes it is useful, but without any support.
###############################################################
Instructions:
* Copy the code below to a new php file in the root of your WP site
* Update the FTP server details
@trey8611
trey8611 / how-to-delete-empty-files-after-export.php
Last active April 30, 2020 13:51
WP All Export - How to delete empty export files after the export | pmxe_after_export
/*
################### READ ME #################################
Hooks into pmxe_after_export and deletes the export files if no posts were found.
This is provided in the hopes it is useful, but without any support.
###############################################################
Instructions:
The code needs to be added to your theme functions.php or by using a plugin like Code Snippets:
https://wordpress.org/plugins/code-snippets/
###############################################################
*/
@trey8611
trey8611 / get-random-wordpress-post.php
Created July 19, 2020 15:38
[Get Random WordPress Post ID] #WordPress #General #Snippets
<?php
function my_get_random_post_id() {
global $wpdb;
$post_type = 'post';
$table = $wpdb->posts;
$query = "SELECT `ID` FROM " . $table . " WHERE `post_type` = '" . $post_type . "' AND `post_status` = 'publish' ORDER BY RAND() LIMIT 1";
$post = $wpdb->get_row( $query );
@trey8611
trey8611 / view-post-meta.php
Created July 19, 2020 16:23
[View WordPress Post Meta] #Snippets #Troubleshooting
<?php
// View post meta function
// Posts: [my_view_meta("43788772")]
// Terms: [my_view_meta("4378872","term")]
// Users: [my_view_meta("4378872","user")]
function my_view_meta( $id, $post_type = 'post' ) {
$func = 'get_post_meta';
if ( $post_type == 'term' ) $func = 'get_term_meta';
if ( $post_type == 'user' ) $func = 'get_user_meta';
@trey8611
trey8611 / emails.php
Created August 12, 2020 17:48 — forked from tameemsafi/emails.php
Send an email programmatically in wordpress with wp_mail using the woocommerce transaction emails template.
<?php
// Define a constant to use with html emails
define("HTML_EMAIL_HEADERS", array('Content-Type: text/html; charset=UTF-8'));
// @email - Email address of the reciever
// @subject - Subject of the email
// @heading - Heading to place inside of the woocommerce template
// @message - Body content (can be HTML)
function send_email_woocommerce_style($email, $subject, $heading, $message) {
@trey8611
trey8611 / WP All Import Geo Mashup Integration.md
Created September 8, 2020 20:49
WP All Import | Integration with Geo Mashup plugin

Import into Geo Mashup Plugin

First, install Geo Mashup from here: https://wordpress.org/plugins/geo-mashup/.

Then, go to Settings -> Geo Mashup and:

  • Put in your Google API Key
  • in the "Geocode Custom Field" field, put: geo_latitude,geo_longitude
  • Update the options

In the import, add 2 custom fields "_my_geo_latitude" and "_my_geo_longitude" and import the latitude/longitude into those: https://d.pr/i/cs2MXG.