Skip to content

Instantly share code, notes, and snippets.

View fgilio's full-sized avatar

Franco Gilio fgilio

View GitHub Profile
@fgilio
fgilio / output-buffer-to-string.php
Created February 7, 2016 20:24
PHP - Save Output Buffer to $string
<?php
ob_start();
// Run code with here, must include 'echo' or alike
$output = ob_get_contents();
ob_end_clean();
@fgilio
fgilio / .env.example
Last active July 7, 2022 20:04
Roots Bedrock variable webroot folder name
DB_NAME=database_name
DB_USER=database_user
DB_PASSWORD=database_password
DB_HOST=database_host
WP_ENV=development
WEBROOT_FOLDER_NAME=if_necessary
WP_HOME=http://example.com
WP_SITEURL=${WP_HOME}/wp
@fgilio
fgilio / Disable trackbacks in WordPress.sql
Created March 1, 2016 15:37
Disable trackbacks in WordPress
# As stated here: https://www.siteground.com/kb/how_to_disable_trackbacks_in_wordpress/
UPDATE wp_options SET option_value = 'closed' WHERE wp_options.option_id =20 AND wp_options.blog_id =0;
@fgilio
fgilio / WordPress-bulk-disable-comments.sql
Created March 2, 2016 01:11
WordPress bulk disable comments
UPDATE wp_posts SET comment_status = 'closed', ping_status = 'closed';
@fgilio
fgilio / blockusers_init.php
Created June 13, 2016 18:21
WordPress block user from /wp-admin
add_action( 'init', function () {
global $current_user;
$username = $current_user->user_login;
if ( ($username == 'the-username') ) {
if ( is_admin() && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
@fgilio
fgilio / WP-Defer-&-Async.php
Created June 19, 2016 20:13
Add Defer & Async Attributes to WordPress Scripts
<?php
/**
* Add Defer & Async Attributes to WordPress Scripts
* @author Matthew Horne - http://matthewhorne.me/defer-async-wordpress-scripts/
*/
/**
* Defer
*/
@fgilio
fgilio / testing-carbon-fields.php
Created July 27, 2016 14:58
Testing Carbon Fields
<?php
use Carbon_Fields\Container;
use Carbon_Fields\Field;
Container::make('theme_options', 'thisThing Options')
->add_fields([
Field::make('complex', 'thisThing_options')
->set_min(1)
->set_max(1)
->add_fields('Basic', [
@fgilio
fgilio / wp_post_char_lenght_monthly.sql
Created August 2, 2016 13:53
WordPress average post character length for a given month
SET @start = '2016-1-01';
SELECT AVG(CHAR_LENGTH(post_content)) AS avgLength
FROM wp_posts
WHERE post_type = 'post'
AND post_status = 'publish'
AND post_date >= @start
AND post_date < @start + INTERVAL 1 MONTH;
@fgilio
fgilio / wp-delete-transients.sql
Created August 16, 2016 18:11
WordPress - Deletes all Transients
DELETE FROM `wp_options` WHERE `option_name` LIKE ('%\_transient\_%')
@fgilio
fgilio / gitcheats.txt
Created September 26, 2016 15:34 — forked from chrismccoy/gitcheats.txt
git cheats
# shortform git commands
alias g='git'
# get most modified files and counts
git log --all -M -C --name-only --format='format:' "$@" | sort | grep -v '^$' | uniq -c | sort | awk 'BEGIN {print "count\tfile"} {print $1 "\t" $2}' | sort -g
# Locally checkout all remote branches of a repository
git branch -r | cut -d '/' -f2 | grep -Ev '( |master)' | xargs -Ibranch git checkout -b branch origin/branch
# Open current Git repository URL