Skip to content

Instantly share code, notes, and snippets.

@richaber
richaber / abus_switch_to_url.php
Created June 20, 2022 16:09
Admin Bar User Switching remove port number which causes issues in Local by Flywheel admin under HTTPS
<?php
/**
* Plugin Name: Admin Bar User Switching Remove Port Number From Redirect URL
* Description: Removes the port number from the Admin Bar User Switching redirect URL, as the port number causes issues in Local By Flywheel running under HTTPS.
* Version: 0.1.0
* Author: Richard Aber
* Author URI: https://richaber.com/
*/
add_filter(
@richaber
richaber / WP_Screen.md
Last active June 27, 2022 15:24
WordPress var_export
<?php
// Function `parse_yturl()` from <http://stackoverflow.com/a/10524505/624466>
/**
* Check if the input string is a valid YouTube URL
* and try to extract the YouTube Video ID from it.
*
* @author Stephan Schmitz <[email protected]>
* @param $url string The string that shall be checked.
@richaber
richaber / local-dev.php
Last active September 14, 2023 09:40 — forked from pbiron/enable-disable-plugins-when-doing-local-dev.php
MU plugin to enable/disable other plugins during local development.
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Plugin Name: RA Local Dev Plugin
* Description: Install as an mu-plugin to enable and disable other plugins during local development.
* Version: 0.1.0
* License: GPL version 2 or any later version
* Author: Mark Jaquith, Andrey Savchenko, Paul Biron, Richard Aber
*
* Inspired by Paul Biron https://gist.github.com/pbiron/52bb63042cf220256ece89bc07fb57b0,
@richaber
richaber / local-bootstrap.php
Created November 18, 2021 15:59
Local By Flywheel v 6.1.5+5536 (macO) bootstrap file located at /Applications/Local.app/Contents/Resources/extraResources/local-bootstrap.php
<?php
/**
* This is a PHP script that is auto-added to Local's PHP Lightning Service php.ini's
* via auto_prepend_script to add relevant constants.
*
* @copyright Copyright (c) 2020, WP Engine
*/
define( 'WP_ENVIRONMENT_TYPE', 'local' );
function localwp_auto_login() {
@richaber
richaber / typoTolerance.md
Created October 16, 2020 19:00
Custom WP Search with Algolia typoTolerance settings (indices and clients)

Algolia accepts the following values for the typoTolerance setting (from the Algolia "Configuring Typo Tolerance" documentation):

  1. true: Activate typo-tolerance (default, suggested value).
  2. false: Disable typo-tolerance.
  3. min: Only keep results with the lowest number of typos. This means that if you have 1 or more records that match, you’ll only receive those records; but if you have no records that match, you’ll receive records with typo counts of 1 (or 2 if there are none with 1).
  4. strict: Similar to 3, but keep the 2 lowest number of typos. This is useful when you want to ensure more results.

WP Search with Algolia can be customized through the use of PHP filters, and customizing the autocomplete.php and instantsearch.php templates.

There is additional documentation about customizing index settin

@richaber
richaber / README.md
Last active July 16, 2024 10:05
Integrate WPML and WP Search with Algolia, customize labels in autocomplete.php per language

First, make sure you have you read and followed the instructions for WPML integration found at https://community.algolia.com/wordpress/wpml.html

Following those instructions will ensure that the content itself has a wpml.locale attribute in the index for faceting, and will expose a window.current_locale JS variable in the page, which you can use for further customization.

From there you should be able to customize the Algolia JS widgets in the autocomplete.php and instantsearch.php templates for your use case.

There is additional documentation about customizing those templates here https://community.algolia.com/wordpress/customize-autocomplete.html and here https://community.algolia.com/wordpress/customize-search-page.html.

The following example(s) extend what is described in the references above, to provide translations for the labels in the autocomplete drop down.

@richaber
richaber / findStyles.js
Created November 22, 2019 01:03 — forked from macbookandrew/findStyles.js
List unique CSS properties for all DOM elements
/**
* List unique CSS properties for all DOM elements
* Initially created to list unique font stacks on a page
* @see {@link http://stackoverflow.com/a/35022690/ Inspired by this StackOverflow answer}
*
* @see {@link https://gist.github.com/macbookandrew/f33dbbc0aa582d0515919dc5fb95c00a/ URL for this file}
*
* @author AndrewRMinion Design (https://andrewrminion.com)
* @version 1.1
*
@richaber
richaber / wp-list-utils.php
Last active July 13, 2022 20:12
WP List Utils wp_list_pluck wp_list_filter wp_list_sort wp_parse_list wp_parse_id_list wp_parse_slug_list wp_array_slice_assoc wp_filter_object_list wp_extract_urls
<?php
$people = [
[
'name' => 'John Doe',
'email' => '[email protected]',
'occupation' => 'Software Developer',
],
[
'name' => 'Jane Doe',
@richaber
richaber / README.md
Created October 12, 2017 21:06
Don't try adding SVG support to WordPress yourself

Don't do this:

/**
 * Enable SVG mime types.
 *
 * @param array $mimes Current allowed mime types.
 * @return array Updated allowed mime types.
 */
function prfx_custom_mime_types( $mimes ) {