Skip to content

Instantly share code, notes, and snippets.

@lgedeon
lgedeon / theme.css
Created September 5, 2022 12:13
Split page content into columns. Reset columns at the (approximate) end of each page. Scroll to top of each page.
.wp-site-blocks {
column-width: 12em;
column-gap: 2em;
line-height: 1.1em;
}
.horizontal-break {
column-span: all;
height: 100px;
}
@lgedeon
lgedeon / yoast.php
Created March 15, 2022 12:47
All the things you can hide in Yoast
<?php
/**
* Remove Settings submenu in admin bar
*/
add_action(
'admin_bar_menu',
function() {
global $wp_admin_bar;
$nodes = array_keys( $wp_admin_bar->get_nodes() );
@lgedeon
lgedeon / ilog
Created January 20, 2022 12:59
My favorite logger so far
function ilog( $label = '', $value = null, $dump = false ) {
static $logs = [];
if ( true === $dump ) {
echo "\n<h1>Log Report</h1>\n";
foreach ( $logs as $log ) {
echo "<br/>\n{$log['label']}: ";
var_export( $log['value'] );
echo "\n<br/>";
}
@lgedeon
lgedeon / ohwell.php
Created November 19, 2021 07:31
Wrapper that ended up being a huge fail.
public function add_notice_and_transparency( $widget_area ) {
$limit = $this->widget_area_limits()[$widget_area] ?? null;
$style = ".ione-module-widget-limit-$limit div:nth-child(n+" . ($limit + 2) . "){opacity:50%}";
if ( $limit ) {
printf(
'<p class="description">This widget area (sidebar) will only display the first %d widgets.</p><section class="ione-module-widget-limit-%d"><style>%s</style>',
absint( $limit ),
absint( $limit ),
$style
@lgedeon
lgedeon / class-wp-hook.php
Created July 21, 2021 18:08
When you need to know what filter is changing your content, try adding this to wp-includes/class-wp-hook.php
<?php
/**
* Calls the callback functions that have been added to a filter hook.
*
* @since 4.7.0
*
* @param mixed $value The value to filter.
* @param array $args Additional parameters to pass to the callback functions.
* This array is expected to include $value at index 0.
* @return mixed The filtered value after all hooked functions are applied to it.
@lgedeon
lgedeon / multidimensional_normalizer.php
Created July 14, 2020 02:36
One way to normalize one particular type of multi-dimensional array.
<?php
return array_merge(
... array_map(
function( $key, $values ) {
if ( ! is_array( $values ) ) {
return [];
}
return array_map(
function ( $value ) use ( $key ) {
@lgedeon
lgedeon / contentsearch.php
Created March 3, 2020 23:32
Search post_content for keywords across entire database. Ugly but fast.
<?php
add_action(
'after_setup_theme',
function() {
global $wpdb;
foreach ( [ 'twitter.com', 'facebook.com', 'instagram.com', 'youtube.com', 'soundcloud.com' ] as $s ) {
echo "\n$s";
$results = $wpdb->get_results( "SELECT * FROM `wp_3_posts` WHERE `post_content` LIKE '%$s%' ORDER BY `ID` DESC LIMIT 200;" );
@lgedeon
lgedeon / GoogleAnalyticsController.php
Created February 25, 2020 06:51
GA partial replacement for tightly coupled legacy code.
<?php
namespace IOne\IOne3\Core\Controllers;
use IOne\IOne3\Core\Entities\GoogleAnalyticsDimension;
/**
* Class GoogleAnalyticsController
*
* Consolidate multiple messages that should go into a single dimension.
@lgedeon
lgedeon / LogEntries.php
Last active February 25, 2020 05:15
Logging system
<?php
namespace IOne\IOne3\Core\Entities;
/**
* Class LogEntries
*
* Represent all log entries when they need to be gathered before output.
*/
class LogEntries {
<?php
/**
* Create a multidimensional array from supplied array keys.
*
* Accepts a variable number of parameters that can be strings or arrays of
* strings. Each parameter represents another level of nesting.
*
* Each leaf node is an empty array.
*