Skip to content

Instantly share code, notes, and snippets.

View MikeNGarrett's full-sized avatar
🤘
Rocking this project.

Mike Garrett MikeNGarrett

🤘
Rocking this project.
View GitHub Profile
@MikeNGarrett
MikeNGarrett / functions.php
Created June 10, 2014 15:10
Grant Super Admin to WordPress user in theme's functions.php
<?php
include(ABSPATH . 'wp-admin/includes/ms.php');
$user = get_userdatabylogin('YOUR_USERNAME');
grant_super_admin($user->ID);
?>
@MikeNGarrett
MikeNGarrett / wp_ajax_request
Created January 28, 2014 23:34
Simple WordPress ajax structure example
<?php
// 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() {
print_r($_REQUEST);
die();
@MikeNGarrett
MikeNGarrett / post-list.sql
Created June 18, 2019 20:02
Mysql query to list all WordPress posts with categories and tags
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 / redirect-wp-multisite-activation.php
Last active August 25, 2021 16:00
Redirect WordPress Multisite User Upon Activation
<?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-cli-install-rec-plugins
Last active July 12, 2021 07:18
Chained WordPress CLI commands to install and activate recommended plugins.
# wordpress-seo provides ability to edit meta information and provides sitemap.
# w3-total-cache provides advanced caching no matter the server technology available.
# better-wp-security provides brute force protection and a number of WordPress enhancements.
# google-analytics-for-wordpress provides robust Google Analytics integration through the Google API.
# redirection detects 404s and 301s and allows admins to set up redirects in the WP admin.
# ewww-image-optimizer provides automatic optimization of uploaded images with local libraries instead of cloud-based services.
# backupwordpress simple backup solution that can store backups above web root.
# relevanssi provides better site search using a local index.
# cloudflare is the best. Free automatic CDN and security solution.
# jarvis is a quick search for the WordPress admin. Indespensible.
@MikeNGarrett
MikeNGarrett / terminus-quick-tips.sh
Last active October 19, 2020 12:48
Quick tips for Pantheon's implementation of WordPress CLI.
# 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 / wp-better-side-nav.php
Last active April 22, 2019 10:00
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.
<?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 August 5, 2012 23:45 — forked from jo-snips/event-category-list.php
The Events Calendar: List Event Categories
<?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 March 22, 2019 15:23
PHPCS config for multiple installed paths - WordPress, Drupal, PHP Compatibility
# 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 January 28, 2019 20:31
Test site compatibility with a specific version of PHP
# 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"