Skip to content

Instantly share code, notes, and snippets.

View simplistik's full-sized avatar

Lucas Williams simplistik

View GitHub Profile
@KevinBatdorf
KevinBatdorf / gutenberg-helpers.js
Last active March 22, 2024 20:00
WordPress check Gutenberg editor is ready
import { select, subscribe } from '@wordpress/data'
export function whenEditorIsReady() {
return new Promise((resolve) => {
const unsubscribe = subscribe(() => {
// This will trigger after the initial render blocking, before the window load event
// This seems currently more reliable than using __unstableIsEditorReady
if (select('core/editor').isCleanNewPost() || select('core/block-editor').getBlockCount() > 0) {
unsubscribe()
resolve()
@akshuvo
akshuvo / geo-search-wp-query.php
Created April 11, 2020 16:31
Sort by distance WordPress post meta/ WordPress Query / pre_get_posts
<?php if(!defined('ABSPATH')) { die(); } // Include in all php files, to prevent direct execution
/**
* Plugin Name: WP Geo Query
* Plugin URI: https://gschoppe.com/wordpress/geo-searches/
* Description: Adds location search support to WP_Query, making it easy to create completely custom "Find Location" pages.
* Author: Greg Schoppe
* Author URI: https://gschoppe.com
* Version: 1.0.0
**/
@Xilonz
Xilonz / field.php
Created June 21, 2019 11:13
Sage 9 Carbon Field Blocks
<?php
namespace App;
use Carbon_Fields\Field;
use Carbon_Fields\Block;
Block::make( __( 'Gutenberg Block' ) )
->set_icon( 'format-chat')
->add_fields( array(
Field::make( 'rich_text', 'text', __( 'text', 'my-theme' ) )
@Shelob9
Shelob9 / script.js
Created January 25, 2016 23:30
Simple select2 for posts via WP API
$( '#search' ).select2( {
ajax: {
url: API.root + '/wp/v2/posts',
processResults: function( data, page ) {
console.log( data );
return {
//do something results
}
},
cache: false,
this.$el.find( '.taxonomy-terms' ).select2({
multiple: true,
ajax: {
url: WP_API_Settings.root + 'wp/v2/terms/' + this.options.taxonomy.slug,
data: function( term, page ) {
return {
search: term,
page: page,
_envelope: true
}
@jplhomer
jplhomer / disable-comments.sh
Created February 25, 2015 16:38
Disable all comments/pings in WordPress with WP-CLI
$ wp post list --format=ids | xargs wp post update --comment_status=closed
# Output:
# Success: Updated post 2514.
# Success: Updated post 2511.
# Success: Updated post 2504.
# Success: Updated post 2499.
# Success: Updated post 2441.
# etc...
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@DrewAPicture
DrewAPicture / clean_404_emails.php
Last active September 27, 2023 09:03
Original snippet by wp-mix.com at http://wp-mix.com/wordpress-404-email-alerts/ With the improved OOP style, implementation is a lot more straightforward, just add <?php new Clean_404_Email; to the top of your 404.php template.
<?php
// Just require() this class via your theme's functions.php file.
/* Then instantiate this at the top of your 404.php file with:
if ( class_exists( 'Clean_404_Email' ) )
new Clean_404_Email;
*/
class Clean_404_Email {
var $time, $request, $blog, $email, $theme, $theme_data, $site, $referer, $string, $address, $remote, $agent, $message;
@cam-gists
cam-gists / phone.php
Created November 28, 2012 21:33
PHP: format Phone Number
function format_phone($phone)
{
$phone = preg_replace("/[^0-9]/", "", $phone);
if(strlen($phone) == 7)
return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
elseif(strlen($phone) == 10)
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
else
return $phone;
@nateware
nateware / nginx.conf
Last active November 23, 2021 10:54
Nginx sample config for EC2
#
# Sample nginx.conf optimized for EC2 c1.medium to xlarge instances.
# Also look at the haproxy.conf file for how the backend is balanced.
#
user "nginx" "nginx";
worker_processes 10;
error_log /var/log/nginx_error.log info;