Skip to content

Instantly share code, notes, and snippets.

View camtheperson's full-sized avatar

Cameron Hermens camtheperson

View GitHub Profile
@camtheperson
camtheperson / add_wp_admin.sql
Created January 22, 2019 19:29
Add WordPress Administrator user through SQL
/* create new user */
INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES (NULL, 'username', MD5('password'), 'User Nicename', 'email@domain.com', '', '0000-00-00 00:00:00.000000', '', '0', 'Full Name');
/* add capabilities for user (ID 8) */
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '8', 'wp_capabilities', 'a:1:{s:13:\"administrator\";s:1:\"1\";}');
/* add wp user level for user (ID 8) */
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '8', 'wp_user_level', '10');
@camtheperson
camtheperson / wp-cli-multisite-command.sh
Created November 14, 2018 21:36
Run a WP-CLI command one or more sites on WordPress multisite
/*
* Run a WP-CLI command one or more sites on WordPress multisite
*
* Reference: https://danielbachhuber.com/tip/run-wp-cli-command-wordpress-multisite/
*/
wp site list --field=url | xargs -n1 -I % wp --url=% option update my_option my_value
@camtheperson
camtheperson / WordPress - Update post type SQL query.sql
Last active July 13, 2018 22:42
WordPress - Update post type SQL query
/* The following query updates the wp_posts table to a certain post type based on being a page and not having a particular post ID. */
UPDATE `wp_posts`
SET `post_type` = 'resource-center'
WHERE `post_type` = 'page' AND `ID` NOT IN (6364, 6382, 6371, 6403, 6521, 6418);
@camtheperson
camtheperson / extras.php
Created May 8, 2018 22:23
WordPress: Remove <p> tags from images
/**
* Remove <p> tags from images
*/
function filter_ptags_on_images($content) {
$content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
return preg_replace('/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content);
}
add_filter('acf_the_content', __NAMESPACE__ . '\\filter_ptags_on_images');
add_filter('the_content', __NAMESPACE__ . '\\filter_ptags_on_images');
@camtheperson
camtheperson / extras.php
Created February 5, 2018 21:32
Remove All Yoast HTML Comments
// Remove All Yoast HTML Comments
// https://gist.github.com/paulcollett/4c81c4f6eb85334ba076
if (defined('WPSEO_VERSION')){
add_action('get_header',function (){ ob_start(function ($o){
return preg_replace('/^<!--.*?[Y]oast.*?-->$/mi','',$o); }); });
add_action('wp_head',function (){ ob_end_flush(); }, 999);
}
@camtheperson
camtheperson / extras.php
Created February 5, 2018 21:30
Gravity Forms jQuery Fix
/**
* Gravity Forms jQuery fix
*/
function gc_deregister_default_jquery() {
wp_deregister_script('jquery');
}
add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\gc_deregister_default_jquery');
function inject_jquery_above_gravity_form($content = '') {
@camtheperson
camtheperson / extras.php
Created February 2, 2018 18:21
Gravity Forms submit input <span>
/**
* Add <span> around GF submit input to add caret
*/
function gf_caret($button, $form) {
return '<span class="caret">' . $button . '</span>';
}
add_filter( 'gform_submit_button', __NAMESPACE__ . '\\gf_caret', 10, 2 );
@camtheperson
camtheperson / extras.php
Created January 18, 2018 21:07
Blog Feed Issue - extras.php
<?php
namespace Roots\Sage\Extras;
use Roots\Sage\Setup;
/**
* Add <body> classes
*/
function body_class($classes) {
@camtheperson
camtheperson / functions.php
Created January 8, 2018 22:52
WordPress dashicon front end support
/**
* WordPress dashicon support in front end
*/
function load_dashicons_front_end() {
wp_enqueue_style('dashicons');
}
add_action('wp_enqueue_scripts', 'load_dashicons_front_end');
@camtheperson
camtheperson / functions.php
Last active January 8, 2018 22:52
WordPress SVG Upload support
/**
* WordPress SVG Upload support
*/
function wp_add_svg_mime_support($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'wp_add_svg_mime_support');