Skip to content

Instantly share code, notes, and snippets.

@pdclark
pdclark / pd-blocks-example-oop.php
Last active August 29, 2024 11:29
Short example OOP PHP-rendered WordPress blocks with attributes.
<?php
/**
* Plugin Name: PD Blocks — Example OOP with attributes
* Description: Single-file OOP PHP-rendered WordPress blocks with 5 example blocks.
* Author: Paul David Clark
* Author URI: https://pd.cm
* Plugin URI: https://pd.cm/oop-blocks
* Version: 30
*
* @package pd
@westonruter
westonruter / basic-site-caching.php
Last active December 16, 2020 07:15
⚠️ This plugin is obsolete as of PWA v0.6.0. See https://github.com/GoogleChromeLabs/pwa-wp/pull/338
<?php
/**
* Plugin Name: Basic Site Caching
*
* @package Basic_Site_Caching
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
* @wordpress-plugin
@tomjn
tomjn / tomjn_http2_push.php
Created January 25, 2019 23:43
A naive and incomplete, but functional approach to http2 push
<?php
/**
* Plugin name: HTTP2 Push scripts
* Author: Tom J Nowell
*/
function tomjn_get_dep_url( /*\WP_Dependency*/ $dep ) {
global $wp_version;
$relative = str_replace( site_url(), '', $dep->src );
$ver = $dep->ver;
@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.
@PatelUtkarsh
PatelUtkarsh / wp-config.php
Last active October 29, 2018 08:24
Valet share url fix for WordPress with https support
<?php
/**
* Add this block in wp-config.php file.
*
* Move any other `WP_HOME` or `WP_SITEURL` in else condition if present.
*/
if ( isset( $_SERVER['HTTP_X_ORIGINAL_HOST'] ) ) {
$is_ssl = isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] );
$actual_link = ( $is_ssl ? "https" : "http" ) . "://{$_SERVER[ 'HTTP_X_ORIGINAL_HOST' ]}";
define( 'WP_HOME', $actual_link );
@ahmadawais
ahmadawais / upload-a-file.MD
Created June 18, 2017 11:07 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

<?php
/**
* Class Customize_Postmeta_Setting.
*
* @package WPSE_257322
*/
namespace WPSE_257322;
/**
@PatelUtkarsh
PatelUtkarsh / ee-vip-go-local.sh
Created May 11, 2016 05:54
Setup vip-go in local environment for site which are already created with easyengine.
#!bin/bash
#
# NOTE:This file takes param as site name for
#
# This script currenty only works with easyengine.
#
# What this does essentially is clones mu-plugin repo of vip-mu-plugins-public
# and write nginx rule to handle static files via php.
#
# WARNING: This does not match extact vip go environment like php version and stuff
@danielbachhuber
danielbachhuber / import-cache.php
Created March 31, 2016 18:27
During `wp import`, cache remote files locally for subsequent imports
<?php
/**
* Run with `wp --require=import-cache.php import ...
*/
WP_CLI::add_hook( 'after_wp_load', function(){
// Only intercept HTTP requests when the importer is running
if ( ! defined( 'WP_IMPORTING') || ! WP_IMPORTING ) {
return;
@pradeepdotco
pradeepdotco / disable-wordpress-search.php
Created November 9, 2015 22:12
Disable WordPress Search
function fb_filter_query( $query, $error = true ) {
if ( is_search() ) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;
// to error
if ( $error == true )
$query->is_404 = true;