Skip to content

Instantly share code, notes, and snippets.

View jmslbam's full-sized avatar
💭
Available for (WordPress) work

Jaime Martínez jmslbam

💭
Available for (WordPress) work
View GitHub Profile
@m-thomson
m-thomson / import-image-fix.md
Last active February 14, 2025 09:47
WP All Import duplicate image problem

When an image is imported, the name used in the media library is derived from the URL "basename". This can cause problems, especially when using the option "Search through the Media Library for existing images before importing new images". For example, even though they are different images, these URLs all have the same "basename" (in bold). They will generate the same file my-image.jpg in the WordPress library:

http:// example.com/ my-image.jpg
http:// example.com/ my-image?id=1
http:// example.com/subfolder/ my-image.jpg

The solution is to put this PHP code in your function editor:

function fix_img_url($url){
@wgroenewold
wgroenewold / Force all traffic for Wordpress over SSL
Last active February 8, 2024 10:51
Force all traffic for Wordpress over SSL
define('FORCE_SSL_ADMIN', true);
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
$_SERVER['HTTPS']='on';
}
@harrilehtisaari
harrilehtisaari / gist:394d3ee57bc35eaf2548c738ab90ee98
Created August 27, 2016 12:04
Save ACF-fields in taxonomy terms as term_meta
/**
* Save all acf fields in terms as term meta (for easy query purposes [get_terms(meta_query)])
* Field names have to be prefixed with "meta_"
* URL: https://support.advancedcustomfields.com/forums/topic/how-to-use-wp-term-meta-on-acf-the-easy-way/
* Update term meta based on ACF term meta fields
*/
function namespace_acf_update_term_meta( $value, $post_id, $field ) {
$term_id = intval( filter_var( $post_id, FILTER_SANITIZE_NUMBER_INT ) );
if( substr( $field['name'], 0, 5 ) === 'meta_' ) {
@remcotolsma
remcotolsma / locations.php
Created June 8, 2016 08:39
WordPress custom table with post locations and query to select posts within distance.
<?php
function wkd_sync_location_to_table( $post_id ) {
// Sync locations
global $wpdb;
$location_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->wkd_post_locations WHERE post_id = %d;", $post_id ) );
$format = array(
'post_id' => '%d',
@arubacao
arubacao / latlong.php
Last active November 13, 2024 02:32
Latitude Longitude Regular Expression Validation PHP
<?php
/**
* Validates a given latitude $lat
*
* @param float|int|string $lat Latitude
* @return bool `true` if $lat is valid, `false` if not
*/
function validateLatitude($lat) {
return preg_match('/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/', $lat);
@mboynes
mboynes / trait-alley-cli-bulk-task.php
Last active November 16, 2022 18:09
WP-CLI methods to iterate over any number of posts efficiently and reliably
<?php
// DEPRECATED. See https://github.com/alleyinteractive/wp-bulk-task as the successor to this trait.
/**
* Chunk up the task when you need to iterate over many posts.
*
* For instance, to iterate over every post on the site and add post meta:
*
* $this->bulk_task( function( $post ) {
@onnimonni
onnimonni / rename-uploads.php
Created February 25, 2016 14:20
Remove accents from Wordpress uploads. This renames all files and replaces corresponding attachment in WordPress database. You probably use linux in production and might run OS X in development. This helps to avoid possible problems with filenames. To avoid this in future install mu-plugin which hooks in 'sanitize_file_name'
<?php
/*
* Replace-uploads.php
* This replaces all accents from your uploads
* you can run this with wp-cli: $ wp eval-file replace-uploads.php
*/
/**
* cd to right path before changes
*/
(function($) {
$(document).on('facetwp-refresh', function() {
// if pageload and no facets are active
if (! FWP.loaded && '' == FWP.build_query_string()) {
// if on an archive page
if ($('body').hasClass('tax-job_listing_category')) {
// extract the term from the URI, and set it as the facet value
@TwistedTabby
TwistedTabby / anonymize_wp_useremails.sql
Last active December 2, 2020 16:39
Anonymize wordpress user email addresses for cloning purposes. Exclude specific domain names to keep admin/selected users intact. Prefix so that addresses are still unique.
SET @domains='domain1.com|domain2.com';
UPDATE wp_users prod_users,
( select ID FROM wp_users WHERE user_email NOT REGEXP @domains) clone_users
SET prod_users.user_email = CONCAT('DC_', prod_users.ID, '@example.org')
WHERE prod_users.user_email NOT REGEXP @domains;
@daneden
daneden / Instructions.md
Created December 1, 2015 00:25
Remap Caps Lock to Emoji on Mac

How to remap the caps lock key to the emoji selector on Mac

  1. Go to System Preferences -> Keyboard -> Modifier Keys...
  2. Change “Caps Lock” to “No action”
  3. Install Seil
  4. Change the Caps Lock key in Seil to keyCode 80 (F19)
  5. Install Karabiner
  6. Open Karabiner and go to Misc & Uninstall -> Open private.xml
  7. Copy the contents of this gist's example to the XML file and save
  8. In Karabiner, go to Change Keys -> Reload XML