Skip to content

Instantly share code, notes, and snippets.

View JiveDig's full-sized avatar

Mike Hemberger JiveDig

View GitHub Profile
@JiveDig
JiveDig / class-user-role-base.php
Last active May 30, 2024 14:06
A PHP class for WordPress that allows you to change the author base by user role.
<?php
// Prevent direct file access.
defined( 'ABSPATH' ) || die;
if ( ! class_exists( 'Mai_User_Role_Base' ) ):
/**
* The User Role Base class.
*
* @version 0.2.0
@felixarntz
felixarntz / prevent-jetpack-subscriptions-thickbox.php
Created September 27, 2023 04:08
Jetpack uselessly enqueues Thickbox JS (which itself enqueues jQuery!) when rendering the Subscriptions block, even though it doesn't even use Thickbox. I use this snippet on my own site to fix it.
<?php
/**
* Fix Jetpack Subscriptions block to not uselessly enqueue Thickbox, which in turn enqueues jQuery.
*/
function felixarntz_stop_jetpack_subscriptions_from_enqueuing_thickbox_without_any_usage() {
if ( wp_script_is( 'jetpack-block-subscriptions' ) && isset( wp_scripts()->registered['jetpack-block-subscriptions'] ) ) {
$script = wp_scripts()->registered['jetpack-block-subscriptions'];
$index = array_search( 'thickbox', $script->deps, true );
if ( false !== $index ) {
@clarklab
clarklab / block-helpers.php
Last active August 3, 2021 15:58
Wordpress check if block is used first
<?php
/**
* Block helpers
* add special classes when certain blocks appear, put this in your functions.php file or include it somewhere
*/
// add block classes in body and post class
function blocks_body_class( $classes ) {
global $post;
@vielhuber
vielhuber / README.MD
Last active November 3, 2024 16:22
domdocument domxpath xpath #php

setup

$DOMDocument = new \DOMDocument();
$DOMDocument->loadHTML('<div>foo</div>');
$DOMXPath = new \DOMXPath($DOMDocument);

load html file

$DOMDocument->loadHTML(file_get_contents('tpl.html'));
@nickcernis
nickcernis / add-editor-layout-classes.js
Last active February 20, 2020 09:09
Add Genesis layout class to Gutenberg editor pages (admin)
// Add genesis layout classes to the Block Editor.
// File lives in the theme's /js/ folder.
wp.domReady(function () {
yourTheme.updateLayoutClass();
var layouts = document.querySelector(".genesis-layout-selector");
if( layouts ) {
layouts.addEventListener("input", function (e) {
yourTheme.updateLayoutClass();
@brianhogg
brianhogg / gist:b87c216dde537ecaccdc5063858d0c3f
Last active October 30, 2018 21:16 — forked from davekiss/gist:e2b5beb37b3a1a93a3dddcf43ce51ce9
Display notice in EDD if email already exists and not logged in
<?php
/*
Plugin Name: EDD Prompt Login On Checkout
Plugin URI: http://brianhogg.com/
Description: Prompt login if email exists
Author: Dave Kiss
Version: 1.0.0
Author URI: http://brianhogg.com
License: GPL2
*/
@pento
pento / php-block.js
Last active September 5, 2024 01:58
Converting a shortcode to a block: this method is fast to do, but a mediocre UX. You should only use this as a stopgap until you can implement a full block UI.
// License: GPLv2+
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
InspectorControls = wp.editor.InspectorControls;
/*
* Here's where we register the block in JavaScript.
@kellenmace
kellenmace / class-download-remote-image.php
Last active October 13, 2022 13:24
Download and Insert a Remote Image File into the WordPress Media Library
<?php
/**
* This class handles downloading a remote image file and inserting it
* into the WP Media Library.
*
* Usage:
* $download_remote_image = new KM_Download_Remote_Image( $url );
* $attachment_id = $download_remote_image->download();
*
@robincornett
robincornett / functions.php
Created October 31, 2017 15:16
Code to remove landing pages from site search results. Assumes that templates are in the templates directory inside the theme.
<?php
add_action( 'pre_get_posts', 'leaven_search_hide_landing_page' );
/**
* Remove landing pages from the search results.
*
* @param $query \WP_Query
*
* @return mixed
*/
@glueckpress
glueckpress / wp_rocket__wp_get_attachment_image__lazyload.php
Last active January 6, 2020 08:18
[WordPress][WP Rocket] [deprecated] Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
<?php
/**
* Wrapper function: Applies WP Rocket’s LazyLoad to wp_get_attachment_image()
*
* @link https://developer.wordpress.org/reference/functions/wp_get_attachment_image/
* @link https://github.com/wp-media/wp-rocket/blob/v2.10.9/inc/front/lazyload.php#L24-L47
*
* @param int $attachment_id (Required) Image attachment ID.
* @param string|array $size (Optional) Image size. Accepts any
* valid image size, or an array of width