Skip to content

Instantly share code, notes, and snippets.

Rocking this project.

Mike Garrett MikeNGarrett

Rocking this project.
View GitHub Profile
MikeNGarrett / wp-config.php
Last active Jan 16, 2023
All those damned wp-config constants you can never remember.
View wp-config.php
// PHP memory limit for this site
define( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' ); // Increase admin-side memory limit.
// Database
define( 'WP_ALLOW_REPAIR', true ); // Allow WordPress to automatically repair your database.
define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true ); // Don't make database upgrades on global tables (like users)
// Explicitely setting url
MikeNGarrett /
Created Nov 22, 2022
Export Keybase teams messages and download attachments
# Forked:
#To export a chat from the ZorkInc team, run:
# ./ ZorkInc
# It will create a folder ZorkInc in which you'll find a JSON file containing raw logs, a .log file containing human-readable export of the chat. It'll also download all attachments of the chat and put them in that same folder.
# Note: defaults to "general" channel in your team. Change references to this channel below under "topic_name" (3).
import json
import sys
import os
MikeNGarrett / wp-config.php
Created Oct 14, 2017
Disable admin-ajax on the front-end of WordPress sites and cache the resulting 404.
View wp-config.php
strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) === false &&
strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) !== false
) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', strtotime( '+5000 minutes' ) ) . ' GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', strtotime( '-5000 minutes' ) ) . ' GMT' );
header( $_SERVER["SERVER_PROTOCOL"]." 404 Not Found" );
MikeNGarrett / siege
Last active Nov 10, 2022
Siege with JSON POST data
View siege
# Changed to use content-type flag instead of header: -H 'Content-Type: application/json'
siege -c50 -t60S --content-type "application/json" ' POST {"ids": ["1","2","3"]}'
MikeNGarrett / module.module.php
Last active Nov 2, 2022
Drupal curated autocomplete field
View module.module.php
use Drupal\Core\Form\FormStateInterface;
function hook_field_widget_complete_entity_reference_autocomplete_form_alter(&$field_widget_complete_form, $form_state, $context)
if($field_widget_complete_form['widget']['#field_name'] !== 'field_test') {
$storage = Drupal::getContainer()->get('entity_type.manager')->getStorage('node');
MikeNGarrett / mysql(wp)-commands.txt
Created Oct 31, 2022 — forked from vishalkakadiya/mysql(wp)-commands.txt
WordPress(or any mysql database) - Convert special characters(eg. Latin-1) to UTF-8 in mysql database
View mysql(wp)-commands.txt
The actual step-by-step WordPress / MySQL fix…
1. Back up all your stuff first (likely using phpMyAdmin / CPANEL)
Before doing any of the following it strongly encouraged to back up all your data and files. Just to be safe. At the very least, your full database and the WordPress config file: wp-config.php
2. Note the settings that your WordPress is currently using (from wp-config.php)
Specifically, your MySQL database configuration, including DB_NAME, DB_USER, DB_PASSWORD, and also DB_CHARSET and DB_COLLATE
// ** MySQL settings - You can get this info from your web host ** //
MikeNGarrett / functions.php
Created Oct 13, 2017
Set cache headers on WordPress 404 pages.
View functions.php
* Force cache headers on 404 pages and prevent WordPress from handling 404s.
* @param bool $preempt determines who handles 404s.
* @param obj $wp_query global query object.
function change_404_headers( $preempt, $wp_query ) {
if ( ! is_admin() && ! is_robots() && count( $wp_query->posts ) < 1 ) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
MikeNGarrett / functions.php
Created Jun 10, 2014
Grant Super Admin to WordPress user in theme's functions.php
View functions.php
include(ABSPATH . 'wp-admin/includes/ms.php');
$user = get_userdatabylogin('YOUR_USERNAME');
MikeNGarrett / wp_ajax_request
Created Jan 28, 2014
Simple WordPress ajax structure example
View wp_ajax_request
// in functions.php
add_action('wp_ajax_testing_axaj', 'ajax_function_to_execute', 1, 2);
add_action('wp_ajax_nopriv_testing_axaj', 'ajax_function_to_execute', 1, 2);
function ajax_function_to_execute() {
MikeNGarrett / post-list.sql
Created Jun 18, 2019
Mysql query to list all WordPress posts with categories and tags
View post-list.sql
cat_posts.ID as ID,
cat_posts.post_title as Title,
cat_posts.post_date as Published,
WHEN cat_term_taxonomy.taxonomy = 'category' THEN GROUP_CONCAT(DISTINCT SEPARATOR ', ')
as Categories,