Skip to content

Instantly share code, notes, and snippets.

@wkw
wkw / gravity-form.php
Last active Nov 16, 2020 — forked from OutThisLife/gravity-form.php
Custom: Gravity Forms WP API Submission and GF API form entry creation plus send notifications
View gravity-form.php
<?php
/**
* Add WP API endpoint for form submission, then create new
* Gravity Forms entry and send notifications.
*/
// rest api endpoint for forms submission
add_action( 'rest_api_init', function () {
register_rest_route( 'ahr/v1', '/forms', array(
'methods' => 'POST',
@justintadlock
justintadlock / font-awesome.php
Last active Oct 20, 2020
PHP array of Font Awesome icons.
View font-awesome.php
<?php
// Font Awesome v. 4.6.
function jt_get_font_icons() {
return array(
'fa-glass' => 'f000',
'fa-music' => 'f001',
'fa-search' => 'f002',
'fa-envelope-o' => 'f003',
@fgilio
fgilio / wp-update_post-on-save_post.php
Last active Jan 19, 2021
WordPress - Update post programmatically when a post is saved
View wp-update_post-on-save_post.php
<?php
function update_on_post_saved( $post_id ) {
if ( wp_is_post_revision( $post_id ) ) return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
// if ('NNN' !== $_POST['post_type']) return; return if post type is not NNN
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'update_on_post_saved');
@SGudbrandsson
SGudbrandsson / index.php
Last active Jul 10, 2020
Create a WordPress staging area from your live wordpress setup with a Click-of-a-button [TM] ..
View index.php
<?php
/**
*
* This script will copy your wordpress from public_html (or wherever)
* and place it in a staging folder.
* It will then clone the database, reconfigure the config file
* and replace URL's from the original URL to your staging URL.
* It will then make sure to NOT allow search engines to index the page.
*
* Use this script to clone your main wp in order to test maintenance work
@petenelson
petenelson / multiformat-wp-api-response.php
Last active Dec 4, 2019
WordPress: Example of returning non-JSON results from the WP-API
View multiformat-wp-api-response.php
<?php
// reference https://github.com/WP-API/WP-API/blob/develop/lib/infrastructure/class-wp-rest-server.php
// serve_request() function
add_filter( 'rest_pre_serve_request', 'multiformat_rest_pre_serve_request', 10, 4 );
function multiformat_rest_pre_serve_request( $served, $result, $request, $server ) {
// assumes 'format' was passed into the intial API route
// example: https://baconipsum.com/wp-json/baconipsum/test-response?format=text
@tammyhart
tammyhart / traverse_results.php
Last active Aug 29, 2015
Traverse WordPress Search Results
View traverse_results.php
<?php
/**
* Return search array
*/
function loopconf_search_array( $search_hash ) {
// check for existence of unique transient
if ( false === ( $search_array = get_transient( 'loopconf_search_' . $search_hash ) ) ) {
global $wpdb;
@jtsternberg
jtsternberg / ajax-endpoint.js
Last active Feb 1, 2021
Proof of concept for avoiding admin-ajax for ajax callback requests. Also see Thomas Griffin's excellent post: https://thomasgriffin.io/a-creative-approach-to-efficient-and-scalable-wordpress-api-endpoints/ AND Josh Pollock's excellent post: http://torquemag.io/improved-wordpress-front-end-ajax-processing/
View ajax-endpoint.js
jQuery(document).ready(function($){
$('body').on( 'click', '.some-button', function(){
$.ajax( ajax_endpoint_data.api_url, {
type : 'POST',
dataType : 'json',
data : {
action: 'ajax_action',
some_data: 'some_value'
}
@sbone
sbone / foundation-5-bookmarklet-styles.css
Last active Aug 29, 2015
CSS for JS bookmarklet that shows which breakpoint Foundation 5 is reading
View foundation-5-bookmarklet-styles.css
#foundation-breakpoint-indicator:before {
content: 'NULL';
display: block;
position: fixed;
top: 0;
left: 50%;
margin-left: -50px;
width: 100px;
background-color: blue;
text-align: center;
@tomazzaman
tomazzaman / codeable.io.conf
Created Feb 26, 2015
Codeable.io Nginx config
View codeable.io.conf
server {
include /home/webmaster/www/codeable.io.conf;
server_name codeable.io;
listen 443 ssl spdy default_server;
root /home/webmaster/www/codeable.io;
index index.php index.html;
error_log /var/log/nginx/codeable.io.error.log warn;
@mathetos
mathetos / smart-excerpts
Last active May 17, 2016
Smart Excerpts
View smart-excerpts
<?php
/*
* This asks first for a Yoast SEO meta description,
* If that's not present, then it asks for the excerpt of the post,
* If that's not present, then it strips the content
* In this case, I have an excerpt length setting in the Customizer
* Both the excerpt and content stripping, also strip shortcodes
* @author Matt Cromwell <reachme@mattcromwell.com>
* @copyright Copyright (c) 2014, Matt Cromwell
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License