Skip to content

Instantly share code, notes, and snippets.

@cfxd
cfxd / add_initial_file_size_postmeta.php
Last active November 15, 2023 10:26
Create a sortable admin column for attachment (Media Library) file size. See https://cfxdesign.com/display-file-size-as-a-sortable-column-in-the-media-library/
<?php
// Adds initial meta to each attachment
function add_initial_file_size_postmeta($column_name, $post_id) {
static $query_ran;
if($query_ran !== null) {
$all_imgs = new WP_Query(array(
'post_type' => 'attachment',
'post_status' => 'inherit',
<?php
if(!function_exists('wc_get_products')) {
return;
}
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$ordering = WC()->query->get_catalog_ordering_args();
$ordering['orderby'] = array_shift(explode(' ', $ordering['orderby']));
$ordering['orderby'] = stristr($ordering['orderby'], 'price') ? 'meta_value_num' : $ordering['orderby'];
@cfxd
cfxd / httpdfwd.plist
Created November 28, 2021 02:57
httpdfwd.plist for M1 MacBook Pro LEMP stack
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>httpdfwd</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
@cfxd
cfxd / .htaccess
Last active June 2, 2022 11:53
Deploy WordPress (Bedrock) with Capistrano to a Shared Host (Bluehost). See http://cfxdesign.com/deploy-wordpress-with-capistrano-on-bluehost/
RewriteEngine on
#change dev.example.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?dev.example.com$
RewriteCond %{REQUEST_URI} !^/current/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /current/web/$1
#change dev.example.com to your domain name
RewriteCond %{HTTP_HOST} ^(www.)?dev.example.com$
RewriteRule ^(/)?$ current/web/index.php [L]
@cfxd
cfxd / hide_toptal_linkedin_jobs_spam.js
Created November 21, 2021 17:11
How to hide Toptal LinkedIn jobs spam. Open your Chrome Dev Tools console and copy/paste this JS.
document.querySelectorAll('button[aria-label*="Hide"]').forEach(function(el, index) {
if(el.closest('.job-card-list__entity-lockup').querySelector('.job-card-container__company-name').innerHTML.trim() == 'Toptal') {
el.click();
}
});
@cfxd
cfxd / filter.php
Last active May 7, 2022 07:13
Efficient Responsive Images in WordPress. See https://cfxdesign.com/efficient-responsive-images-in-wordpress
<?php
/*
* THE FILTER
*
*/
function custom_responsive_image_sizes($sizes, $img_name, $attachment_id) {
$sizes = wp_get_attachment_image_sizes($attachment_id, 'original');
$meta = wp_get_attachment_metadata($attachment_id);
$width = $meta['width'];
@cfxd
cfxd / nginx.conf
Created November 28, 2021 01:35
nginx.conf file for LEMP stack on MacBook Pro M1
#replace all instances of <YOUR_USERNAME> with your local username
#place this file in /opt/homebrew/etc/nginx (overwrite the existing default file there)
user <YOUR_USERNAME> staff;
worker_processes 1;
error_log /Users/<YOUR_USERNAME>/Sites/nginx.log;
error_log /Users/<YOUR_USERNAME>/Sites/nginx.log notice;
error_log /Users/<YOUR_USERNAME>/Sites/nginx.log info;
error_log /Users/<YOUR_USERNAME>/Sites/nginx.log warn;
@cfxd
cfxd / shortcode.css
Last active November 17, 2021 05:53
How to Make the WordPress Video Shortcode Responsive. See http://cfxdesign.com/how-to-make-the-wordpress-video-shortcode-responsive
.wp-video, video.wp-video-shortcode, .mejs-container, .mejs-overlay.load {
width: 100% !important;
height: 100% !important;
}
.mejs-container {
padding-top: 56.25%;
}
.wp-video, video.wp-video-shortcode {
max-width: 100% !important;
}
find
var t=window.location.protocol+"//"+window.location.host+window.location.pathname+"?variant="+e.id;
replace with
var newUrlRegex=/variant=\d*/g;var newUrlExt='?variant='+e.id;if(window.location.search!=''){if(window.location.search.includes('variant=')){newUrlExt=window.location.search.replace(newUrlRegex,'variant='+e.id);}else{newUrlExt=window.location.search+'&variant='+e.id;}}var t=window.location.protocol+"//"+window.location.host+window.location.pathname+newUrlExt;