Skip to content

Instantly share code, notes, and snippets.

View fgilio's full-sized avatar

Franco Gilio fgilio

View GitHub Profile
@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 / 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-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 / 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 / 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 / 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 / .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 / 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 / microtime-benchmarking.php
Created February 7, 2016 20:22
PHP - Use microtime to benchmark scripts
<?php
$time_start = microtime(true);
// Run code here
$time_end = microtime(true);
$time = $time_end - $time_start;
echo '<br> <h1> Time = '.$time.' seconds. </h1> <br>';
@fgilio
fgilio / wp-update_post-on-save_post.php
Last active April 17, 2024 22:34
WordPress - Update post programmatically when a post is saved
<?php
function update_on_post_saved( $post_id ) {
if ( wp_is_post_revision( $post_id ) ) return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
// if ('NNN' !== $_POST['post_type']) return; return if post type is not NNN
// unhook this function so it doesn't loop infinitely
remove_action('save_post', 'update_on_post_saved');