Skip to content

Instantly share code, notes, and snippets.

Avatar
🤘
Rocking this project.

Mike Garrett MikeNGarrett

🤘
Rocking this project.
View GitHub Profile
@MikeNGarrett
MikeNGarrett / wp-config.php
Last active Nov 25, 2020
All those damned wp-config constants you can never remember.
View wp-config.php
<?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
MikeNGarrett / siege
Last active Nov 25, 2020
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" 'http://domain.com/path/to/json.php POST {"ids": ["1","2","3"]}'
@MikeNGarrett
MikeNGarrett / terminus-quick-tips.sh
Last active Oct 19, 2020
Quick tips for Pantheon's implementation of WordPress CLI.
View terminus-quick-tips.sh
# Pantheon's Terminus is awesome, but it can be frustrating when you're first getting used to the syntax.
# Some quick tips follow.
#
# The following applies for Terminus v1.4+
#
# When specifying WP CLI commands to run, separate the terminus commands from the wp cli commands with 2 dashes:
terminus remote:wp sitename.env -- command-name --flag=value "wp-content/path/to/file-name.ext"
# It also helps to wrap paths in double quotes.
@MikeNGarrett
MikeNGarrett / redirect-wp-multisite-activation.php
Last active Aug 17, 2020
Redirect WordPress Multisite User Upon Activation
View redirect-wp-multisite-activation.php
<?php
// add do_action('my_do_active_user_message_hook'); where you want the welcome message to display after redirect
add_action( 'activate_header', 'check_activation_key_redirect_to_page' );
/**
* Check the wp-activate key and redirect the user to the apply page
* based on http://www.vanbodevelops.com/tutorials/how-to-skip-the-activation-page-and-send-the-user-straight-to-the-home-page-for-wordpress-multisite
*/
function check_activation_key_redirect_to_page() {
// We check if the key is not empty
@MikeNGarrett
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
<?php
if(
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" );
die;
@MikeNGarrett
MikeNGarrett / post-list.sql
Created Jun 18, 2019
Mysql query to list all WordPress posts with categories and tags
View post-list.sql
SELECT
cat_posts.ID as ID,
cat_posts.post_title as Title,
cat_posts.post_date as Published,
CASE
WHEN cat_term_taxonomy.taxonomy = 'category' THEN GROUP_CONCAT(DISTINCT cat_terms.name SEPARATOR ', ')
ELSE ""
END
as Categories,
CASE
@MikeNGarrett
MikeNGarrett / wp-better-side-nav.php
Last active Apr 22, 2019
Instead of wp_list_pages where all children and grandchildren of the current page are listed out this method lists the parent page, siblings of the current page (in menu order) and when it gets to the current page it lists out the children.
View wp-better-side-nav.php
<?php /* Not as simple as it sounds */ ?>
<div class="side-nav">
<div class="holder">
<ul>
<?php
if (isset($post->post_parent) && $post->post_parent > 0) {
$permalink = get_permalink($post->post_parent);
$parent_title = get_the_title($post->post_parent);
print('<li class="page_item page-parent"><a href="'.$permalink.'">'.$parent_title.'</a></li>');
$parent = $post->post_parent;
@MikeNGarrett
MikeNGarrett / event-category-list.php
Created Aug 5, 2012 — forked from jo-snips/event-category-list.php
The Events Calendar: List Event Categories
View event-category-list.php
<?php // If you'd rather have category drop downs ?>
<form action="#" method="get" id="event-change">
<?php
$current = get_query_var('tribe_events_cat');
$terms = get_terms($tribe_ecp->get_event_taxonomy());
$count = count($terms);
if ( $count > 0 ){
echo '<select class="events-cat-menu"><option value="-1">All Events</option>';
// print_r($terms);
$selected = '';
@MikeNGarrett
MikeNGarrett / phpcs-config.sh
Last active Mar 22, 2019
PHPCS config for multiple installed paths - WordPress, Drupal, PHP Compatibility
View phpcs-config.sh
# Set multiple install paths for phpcs.
# This example adds configs for WordPress, Drupal, and PHP compatibility.
# NOTE: change `/full/path/to/` to the path to your composer directory.
phpcs --config-set installed_paths "/full/path/to/.composer/vendor/wp-coding-standards/wpcs/,/full/path/to/.composer/vendor/drupal/coder/,/full/path/to/composer/vendor/phpcompatibility/php-compatibility/"
# Solves the error: PHPCS Response ERROR: Referenced sniff "WordPress-Extra" does not exist. Run "phpcs --help" for usage information
@MikeNGarrett
MikeNGarrett / phpcs-compatibility.sh
Last active Jan 28, 2019
Test site compatibility with a specific version of PHP
View phpcs-compatibility.sh
# Test site compatibility with a specific version of PHP.
# Requires phpcs and PHPCompatibility config installed.
phpcs --standard=PHPCompatibility --runtime-set testVersion 7.2 ./
# Configuration I use most:
phpcs -p ./ --standard=PHPCompatibility --runtime-set testVersion 7.2 --report-full=~/petitions-7.2.txt --ignore="*.js|css"
You can’t perform that action at this time.