Skip to content

Instantly share code, notes, and snippets.

@sheabunge
sheabunge / uninstall.php
Created January 13, 2013 05:03
WordPress multisite plugin uninstall
<?php
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
exit();
if ( is_multisite() ) {
$blogs = $wpdb->get_results( "SELECT blog_id FROM $wpdb->blogs", ARRAY_A );
if ( $blogs ) {
foreach ( $blogs as $blog ) {
switch_to_blog( $blog['blog_id'] );
@WerdsWords
WerdsWords / the_editor_content.php
Last active December 20, 2015 01:49
#14: the_editor_content
<?php
/**
* Inject a post template into the post editor
*
* @see _WP_Editors::editor(), wp_editor()
*
* @param string $content The editor content.
*
* @return string The filtered editor content.
*/
@retgef
retgef / psuedo-static-js.php
Last active April 7, 2017 22:00
Add a pseudo static JS file to WordPress
<?php
#Add a query var to sniff requests
add_filter( 'query_vars', 'my_query_var_callback', 10, 1 );
function my_query_var_callback( $vars ){
$vars[] = 'dynamic_js';
return $vars;
}
#Dynamic JavaScript
add_rewrite_rule( '^assets/js/dynamic\.js$', 'index.php?dynamic_js=1', 'top' ); //Note the hidden query variable
<?php
function bit_crp_add_fields( $fields, $post_id ) {
global $wpdb;
$match_title = strip_tags( get_the_title( $post_id ) );
$match_content = bit_get_the_matcher($post_id);
$field_score = ", ( ( MATCH($wpdb->posts.post_title) AGAINST ('%s') *5 ) + ( MATCH($wpdb->postmeta.meta_value) AGAINST ('%s') *10 ) ) as score ";
$field_score = $wpdb->prepare( $field_score, $match_title, $match_content ) ;
@dsmy
dsmy / wptaxmecheckbox.php
Last active June 26, 2019 10:39
Taxonomy checkbox list
/**
* returns taxonomy lists that have children with checkboxes
*
*/
function get_subject_list($taxonomy){
// Sets the taxonomy to pull a list of terms from.
// Throws them into a nifty object for referencing and counting
$terms = get_terms($taxonomy,array('parent' => 0));
if ($terms) {
@MikeRogers0
MikeRogers0 / backup-to-s3.sh
Last active May 19, 2020 15:33
A method of backing up your website to Amazon S3.
#!/bin/bash
## Email Variables
EMAILDATE=`date --date="today" +%y-%m-%d`
EMAIL="you@yourdomain.com"
SUBJECT="[servername] Backup Script Started! - "$EMAILDATE
EMAILMESSAGE="/tmp/emailmessage1.txt"
echo "Just to let you know that the backup script has started."> $EMAILMESSAGE
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
@archonic
archonic / wp_geo_products.php
Created May 22, 2015 22:16
WordPress Geo Products. Depends on ACF for location meta. Replaces product search to include distance query.
class WP_Query_Geo extends WP_Query {
private $lat = NULL;
private $lng = NULL;
private $distance = NULL;
/**
* Constructor - adds necessary filters to extend Query hooks
*/
public function __construct( $args = array() ) {
// Extract Latitude

Custom Gutenberg Block

This is a basic custom Gutenberg block. Files explained below.

  • block.js — We register Custom Gutenberg block here.
  • editor.css _ Block CSS for the editor.
  • style.css — Block CSS for the front end.
  • index.php — Enqueue block's assets for editor and the front end.
@jdevalk
jdevalk / logging-helper.php
Last active December 9, 2021 16:25
This little hack enables fatal error logging for your site, without creating an error log that is insanely big.
<?php
/**
* This changes logging to only log fatal errors. This file should go in your mu-plugins directory.
*/
// Set the error logging to only log fatal errors
error_reporting( E_ERROR );
// Optional: change the location of your error log, it might be wise to put it outside your WP content dir.
// If you don't change it, the default place for this log is debug.log in your WP_CONTENT_DIR.

How to install php7.2-fpm with EasyEngine (Ubuntu)


Add php7.2 repository

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Install php7.2-fpm