Skip to content

Instantly share code, notes, and snippets.

@awps
awps / get_page_by_title_wp_query.php
Created June 25, 2023 23:39
Alternative to the deprecated `get_page_by_title`, using WP_Query
<?php
function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
$query = new WP_Query(
array(
'post_type' => $post_type,
'title' => $page_title,
'post_status' => 'all',
'posts_per_page' => 1,
'no_found_rows' => true,
'ignore_sticky_posts' => true,
@lennardv2
lennardv2 / archivedl.php
Created June 1, 2023 13:39 — forked from divinity76/archivedl.php
Fork of archivedl.php to make it work with php8.2
#!/usr/bin/php
<?php
declare(strict_types = 1);
// require_once ('hhb_.inc.php');
hhb_init ();
if ($argc !== 3) {
fprintf ( STDERR, "usage: %s timestamp url\n", $argv [0] );
fprintf ( STDERR, "example: %s 20091012061648 http://www.p4w.se\n", $argv [0] );
die ( 1 );
}
<?php
/**
* Optimize Loading Separate Core Block Assets in Classic Themes Plugin.
*
* @package OptimizeLoadingSeparateCoreBlockAssetsInClassicThemes
* @author Weston Ruter
* @link https://gist.github.com/westonruter/25187db63a7666f08b151ca53497ffb5
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*
@interactiveRob
interactiveRob / wp-tag-processor-add-class.php
Created April 7, 2023 02:54
WP_HTML_Tag_Processor add_class
<?php
$hook = "render_block_someBlock";
add_filter( $hook, function($block_content, $block, $instance) {
$selector = explode(',', $blockInfo['selector'] ?? '');
$content = new WP_HTML_Tag_Processor( $block_content );
$content->next_tag( $selector );
$content->add_class( 'g-rich-text' );
@todgru
todgru / elasticsearch-setup-apple-macbook-pro-m1.md
Created February 9, 2023 23:52
Install Elasticsearch 7.x on Apple Macbook Pro M1 Ventura 13.2

Elasticsearch Setup Apple MacBook Pro M1

Apple MacBook Pro M1, 32 GB, Ventura 13.2

Documentation based on comments in this Github Elasticsearch issue.

Install Homebrew

@interactiveRob
interactiveRob / visibilityToggle.js
Created January 18, 2023 21:18
Simple on/off toggle Intersection Observer ES6 method
createObserver() {
let intersectionObserver = new IntersectionObserver((entries) => {
if (entries[0].intersectionRatio <= 0) {
//do something when hidden
console.log('hidden');
} else {
//do something when visible
console.log('visible');
}
@carlodaniele
carlodaniele / CustomSidebar.js
Created January 2, 2023 17:24
A custom Gutenberg block with a custom sidebar to add and manage custom meta fields in WordPress
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post';
import { PanelBody, PanelRow, TextControl, DateTimePicker } from '@wordpress/components';
const CustomSidebar = ( { postType, metaFields, setMetaFields } ) => {
if ( 'post' !== postType ) return null;
@carlodaniele
carlodaniele / edit.js
Created January 2, 2023 16:21
A custom Gutenberg block to add and manage custom meta fields in WordPress
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/
*/
import { __ } from '@wordpress/i18n';
/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
@kwcjr
kwcjr / Trigger-Elementor-DB-Update.snippet
Last active February 17, 2023 14:37
Trigger Elementor DB Update
<?php
/**
* Snippet Action: Trigger Elementor DB Update.
* Snippet Type: Return info from Child Sites. ( IMPORTANT! This will make it run one time )
* Snippet Author: Keith Crain ( Kronoslabs.io )
*/
add_action( 'plugins_loaded', 'klbs2345_trigger_elementor_db_update' );
function klbs2345_trigger_elementor_db_update() {
<?php
/**
* Title: Content-only Test
* Slug: prefix/content-only-test
*/
?>
<!-- wp:group {"templateLock": "contentOnly", "align":"wide","layout":{"type":"constrained","wideSize":"2000px"}} -->
<div class="wp-block-group alignwide"><!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:image {"id":231,"sizeSlug":"large","linkDestination":"none"} -->