Skip to content

Instantly share code, notes, and snippets.

View pdewouters's full-sized avatar
🌄
Working from home

Paul de Wouters pdewouters

🌄
Working from home
View GitHub Profile
@pdewouters
pdewouters / phpcs.xml
Created May 30, 2024 12:25
WP codesniffer config
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="MyConfig" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
<description>My Coding standards</description>
<file>.</file>
<arg name="extensions" value="php" />
<arg name="colors" />
<arg value="ps" />
function count_tags( string $html ) {
// save the tag count to an option so each call to this function use it for a global count across all posts.
$tag_count = get_option( 'tibi_tag_count', [] );
$tags = new \WP_HTML_Tag_Processor( $html );
while( $tags->next_tag()) {
$tag = $tags->get_tag();
if ( ! isset( $tag_count[ $tag ] ) ) {
$tag_count[ $tag ] = 0;
}
@pdewouters
pdewouters / gist:4143978
Created November 25, 2012 15:25
Numeric pagination from Genesis
function pdw_spine_numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
@pdewouters
pdewouters / youtube.js
Last active December 19, 2019 16:07
youtube
import React, { useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import { Waypoint } from 'react-waypoint';
function Youtube( { youtubeId } ) {
const playerRef = useRef( null );
const elementRef = useRef( null );
const loadVideo = () => {
const player = new window.YT.Player( elementRef.current, {
@pdewouters
pdewouters / new_gist_file
Created June 21, 2013 15:00
whitelist gitignore
# This is a template .gitignore file for git-managed WordPress projects.
#
# Fact: you don't want WordPress core files, or your server-specific
# configuration files etc., in your project's repository. You just don't.
#
# Solution: stick this file up your repository root (which it assumes is
# also the WordPress root directory) and add exceptions for any plugins,
# themes, and other directories that should be under version control.
#
# See the comments below for more info on how to add exceptions for your
find . -type d \( -name wordpress -o -name .bin -o -name .circleci -o -name .config -o -name .ebextensions -o -name .github -o -name __mocks__ -o -name node_modules -o -name chassis -o -name .tests -o -name vendor -o -name uploads \) -prune -o -name "*.php" -print0 | xargs -0 -n 1 -P 4 php -l > /dev/null
@pdewouters
pdewouters / gist:92af5d06f95fa201edf5b3c19809661b
Created February 8, 2019 16:34
Fetch from API with useEffect
import React, { useState, useEffect } from "react";
export default function QuoteBox() {
const API_URL = "http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1";
const [quote, setQuote] = useState({});
const [isLoading, setLoading] = useState(false);
async function queryAPI() {
setLoading(true);
const response = await fetch(API_URL);
@pdewouters
pdewouters / repos.sh
Created August 23, 2019 16:23
List repos for an org which dont have a readme
#!/bin/bash
hub api orgs/humanmade/repos --paginate | npx jq -r '.[] | select(.archived != true) | .full_name' | while read -r i; do
if [[ $(hub api repos/"$i"/readme | npx jq -r '.name') = 'null' ]]; then
echo "$i has no readme"
fi
done
// /content/plugins/multilingualpress3/src/multilingualpress/Cache/NavMenuItemsSerializer.php
$menuItem = $postArray['menu_item'] ?? [];
foreach (self::MENU_ITEM_ALLOWED_PROPERTIES as list($property, $type, $default)) {
if (!isset($post->{$property})) {
$post->{$property} = $this->extractValue($menuItem, $property, $type, $default);
}
}
$this->unserialized[] = $post;
}
// Update only a specific package with its dependencies
composer update --ignore-platform-reqs humanmade/coding-standards --with-dependencies
// Update packages (ignore platform requirements)
composer update --ignore-platform-reqs