Skip to content

Instantly share code, notes, and snippets.

View fgilio's full-sized avatar

Franco Gilio fgilio

View GitHub Profile
@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');
@fgilio
fgilio / axios-catch-error.js
Last active April 11, 2024 19:02
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@fgilio
fgilio / remove-onclick.js
Created September 29, 2016 16:01
Remove onclick attribute from DOM element
document.getElementById('remove-onclick').removeAttribute("onclick");
@fgilio
fgilio / language-select-with-native-name.html
Created February 26, 2017 16:22
Language select with native names
<form class="languages go" method="get" action="#">
<label for="language">Other languages:</label>
<select id="language" class="autosubmit" name="lang">
<option title="English (US)" value="en-US">
English (US) (en-US)
</option>
<option title="Afrikaans" value="af">
Afrikaans (af)
</option>
<option title="Arabic" value="ar">
@fgilio
fgilio / .gitlab-ci.yml
Last active February 20, 2023 17:25
Override Laravel Vapor's Secrets management
stages:
- deploy
.setup_staging_env_file: &setup_staging_env_file |
echo "$STAGING_SECRETS" > staging_secrets.php
.setup_production_env_file: &setup_production_env_file |
echo "$PRODUCTION_SECRETS" > production_secrets.php
staging:
@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 / concurrent-pool.php
Last active February 22, 2022 13:08 — forked from tonysm/concurrent-pool.php
Laravel HTTP client concurrent requests pool
<?php
// 1. Register the routes
Route::get('test/{lorem}', function ($lorem) {
sleep(3);
return response()->json([
'message' => $lorem,
'token' => Str::random(),
]);
@fgilio
fgilio / mercadopago-payment-is-paid.php
Created December 11, 2018 23:13
MercadoPago check if a payment/merchant order is fully paid
<?php
/*
* Keep in mind that this is heavily tied to the Laravel Framework
*
* $client_id
* $client_secret
* $externalReference
*/
MercadoPago\SDK::setClientId($client_id);
@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
*/