Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Crisoforo Gaspar Hernández mitogh

:octocat:
View GitHub Profile
@mitogh
mitogh / endpoint.php
Created Apr 4, 2022
Creates a custom image size with the provided dimensions
View endpoint.php
add_action( 'rest_api_init', function () {
register_rest_route(
'wp/v2',
'/media/(?P<id>[\d]+)/custom',
array(
'methods' => 'GET',
'args' => array(
'id' => array(
'validate_callback' => function ( $id ) {
if ( ! is_numeric( $id ) ) {
@mitogh
mitogh / examples.md
Last active Mar 22, 2022
Filter description
View examples.md

Usages examples

Filter: webp_uploads_img_url_mime_type

add_filter(
	'webp_uploads_img_url_mime_type',
	function ( $replacement, $attachment_id, $size_name, $mime_type, $image_tag ) {
 // Plugin is interested only on WebP.
View translations.php
<?php
/*
* EXAMPLE OF CHANGING ANY TEXT (STRING) IN THE EVENTS CALENDAR
* See the codex to learn more about WP text domains:
* http://codex.wordpress.org/Translating_WordPress#Localization_Technology
* Example Tribe domains: 'tribe-events-calendar', 'tribe-events-calendar-pro'...
*/
function tribe_custom_theme_text( $translation, $text, $domain ) {
// If this text domain doesn't start with "tribe-", "the-events-", or "event-" bail.
if ( ! ( strpos( $domain, 'tribe-' ) !== false || strpos( $domain, 'the-events-' ) !== false || strpos( $domain, 'event-' ) !== false ) ) {
@mitogh
mitogh / functions.php
Last active Sep 19, 2017
Upload assets to Wordpress
View functions.php
<?php
function upload_asset( $location, $post_id ) {
$timeout_seconds = MINUTE_IN_SECONDS * 10;
$tmp_file = download_url( $location, $timeout_seconds );
if ( is_wp_error( $tmp_file ) ) {
@unlink( $tmp_file );
return false;
}
$type = wp_check_filetype( $tmp_file );
@mitogh
mitogh / states.txt
Last active Jan 23, 2016
US States
View states.txt
AL : Alabama
AK : Alaska
AZ : Arizona
AR : Arkansas
CA : California
CO : Colorado
CT : Connecticut
DE : Delaware
FL : Florida
GA : Georgia
View gist:b07ec1febcac9007f95e
Interesting Javascript puzzle (from a recent programming contest):
How do you create a number 100000000000000000000 in Javascript using only these four characters: '+', '!', '[', ']' and you can only use at most 60 such characters?
Some hints:
+!![] is equal to number 1
+!![]+!![] is equal to number 2
(don't answer if you participated in that contest)
FYI, the answer is super tricky and close to "cheating".
@mitogh
mitogh / clearHistory.sh
Last active Aug 29, 2015
Clean the history of your downloads, (MAC)
View clearHistory.sh
#!/bin/bash
# Show all the current LOG of your history.
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent'
# Delete all the entries from the history.
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
# Credits:
# http://lifehacker.com/your-mac-logs-everything-you-download-heres-how-to-cle-1658394180
@mitogh
mitogh / changeLocationScreenshots.sh
Created Sep 19, 2014
Change default location for the screenshots in Mac
View changeLocationScreenshots.sh
defaults write com.apple.screencapture location ~/Pictures
killall SystemUIServer
# Where ~/Pictures is the current location where the screenshots
# are going to be saved.
@mitogh
mitogh / changeFormatScreenshot.sh
Created Sep 19, 2014
Change format of the screenshots in Mac.
View changeFormatScreenshot.sh
defaults write com.apple.screencapture type png
killall SystemUIServer
# Different formats
# png: Portable Network Graphic
# pdf: Portable Document Format
# jpg: Joint Photographic Experts Group (JPEG)
# tif: Tagged Image File Format (TIFF)
# gif: Graphics Interchange Format
# pct: Macintosh QuickDraw Picture (PICT)