Skip to content

Instantly share code, notes, and snippets.

View kingkool68's full-sized avatar
💻
Coding.

Russell Heimlich kingkool68

💻
Coding.
View GitHub Profile
@kingkool68
kingkool68 / fluid-math-sass-function.scss
Last active March 14, 2024 16:29
Sass function for calculating fluid values using clamp() for padding or font-sizes or anything really. Example: font-size: fluid(16px, 32px) --> font-size: clamp( 1rem, 0.143rem + 2.857vw, 2rem );
@use "sass:math";
// via https://css-tricks.com/snippets/sass/px-to-em-functions/
$browser-context: 16;
@function rem($pixels) {
@if (unitless($pixels)) {
$pixels: $pixels * 1px;
}
@kingkool68
kingkool68 / get_attachment_id_by_filename.php
Created December 29, 2023 04:00
Get a WordPress attachment ID by it's filename. Searches '_wp_attached_file' post_meta values looking for matching filenames. If multiple are found the most recent ID by post_date is returned.
<?php
/**
* Search post attachments where the given filename matchs the attached file path
*
* @link https://wordpress.stackexchange.com/a/405142/2744
*
* @param string $filename The filename to search
*
* @return int The attachment ID of the first result sorted by post_date in reverse chronological order (most recent first)
*/
@kingkool68
kingkool68 / index.php
Created October 23, 2023 00:55
Log $_GET or $_POST data to a CSV file. Example: index.php?bar=bar&foo=foo&baz=baz&bad-data=dont-save would append the following to the data.csv file: 1698022463,foo,bar,baz
<?php
// Merge the expected data with the data recieved
$expected_data = array(
'timestamp' => '',
'foo' => '',
'bar' => '',
'baz' => '',
);
$data = array_merge( $expected_data, $_REQUEST );
<?php
function rh_filter_the_content( $the_content = '' ) {
$blocks = parse_blocks( $the_content );
$new_block = array(
'blockName' => 'core/paragraph',
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '<p>Hello World</p>',
'innerContent' => array(
'<p>Hello World</p>',
<?php
function rh_filter_the_content( $the_content = '' ) {
$blocks = parse_blocks( $the_content );
$new_block = array(
'blockName' => 'core/paragraph',
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '<p>Hello World</p>',
'innerContent' => array(
'<p>Hello World</p>',
<?php
function rh_filter_the_content( $the_content = '' ) {
$blocks = parse_blocks( $the_content );
$new_block = array(
'blockName' => 'core/paragraph',
'attrs' => array(),
'innerBlocks' => array(),
'innerHTML' => '<p>Hello World</p>',
'innerContent' => array(
'<p>Hello World</p>',
@kingkool68
kingkool68 / Dockerfile
Last active September 27, 2023 16:40
Compiling Photon OpenCV PHP extension via Docker
FROM php:8.1-apache
RUN apt-get update --fix-missing \
&& apt-get install -y --no-install-recommends \
vim \
git \
subversion \
libopencv-dev \
libwebp-dev \
libgif-dev \
@kingkool68
kingkool68 / all-post-type-archives.php
Created June 2, 2023 14:49
Adds /all/ URL after a post type archive to be able to show all items for that archive.
<?php
/**
* Plugin Name: Show All Post Type Archives
* Description: Add support for /all/ after a post type archive
* Version: 0.0.1
* Plugin URI: https://gist.github.com/kingkool68/efa01ecff91bc722cd3f667ae509a37b
* Author: Russell Heimlich
* Author URI: https://github.com/kingkool68
*/
class RH_Show_All_Archives {
@kingkool68
kingkool68 / .htaccess
Last active October 12, 2022 17:50
Remove the User endpoints from the WordPress Rest API
<IfModule mod_rewrite.c>
RewriteEngine On
# Block _method=GET query string used for compatibility in the REST API
# See https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_method-or-x-http-method-override-header
RewriteCond %{QUERY_STRING} \b_method=GET\b [NC]
RewriteRule ^ - [F]
</IfModule>
@kingkool68
kingkool68 / README.MD
Last active July 15, 2022 14:39
Configure WordPress Coding Standards Linting/Formatting in VSCode

This assumes you're editing a WordPress theme which is the root of your VSCode workspace. In other words if your theme lived in /wp-content/themes/my-awesome-theme. You would drag the directory my-awesome-theme into VSCode and start editing files from there. This also assumes you're using Composer.

If this doesn't work for you check out https://www.edmundcwm.com/setting-up-wordpress-coding-standards-in-vs-code/ which details installing the PHP Code Sniffer tools globally instead of in a project.

We need to require dependencies in our project.

composer require --dev squizlabs/php_codesniffer
composer require --dev dealerdirect/phpcodesniffer-composer-installer
composer require --dev wp-coding-standards/wpcs