Skip to content

Instantly share code, notes, and snippets.

@eduardozulian
eduardozulian / wp-taxonomy-dropdown.php
Last active May 5, 2024 14:45
Callback function for 'meta_box_cb' argument inside register_taxonomy() that replaces the regular checkboxes with a plain dropdown list
<?php
/**
* Callback function for taxonomy meta boxes
*
* A simple callback function for 'meta_box_cb' argument
* inside register_taxonomy() that replaces the regular
* checkboxes with a plain dropdown list
*
* @param [type] $post [description]
* @param [type] $box [description]
@eduardozulian
eduardozulian / wp-unprotected-meta.php
Last active February 21, 2024 11:01
WordPress filter to replace the default "_" (underscore) with "-" (hyphen) in protected custom fields for debugging purposes
<?php
/**
* Replace the default "_" (underscore) with "-" (hyphen) in protected custom fields for debugging purposes
*
* @param bool $protected The default value
* @param string $meta_key The meta key
* @return bool True for meta keys starting with "-" (hyphen), false otherwise
*/
function unprotected_meta( $protected, $meta_key ) {
  graph TD;
      A-->B;
      A-->C;
      B-->D;
      C-->D;
@eduardozulian
eduardozulian / wp-customize-image-reloaded.php
Last active November 16, 2023 02:50
Extend WP_Customize_Image_Control class allowing access to files uploaded within the same context.
<?php
/**
* Customize Image Reloaded Class
*
* Extend WP_Customize_Image_Control allowing access to uploads made within
* the same context
*/
class My_Customize_Image_Reloaded_Control extends WP_Customize_Image_Control {
/**
* Constructor.
@eduardozulian
eduardozulian / wp-get-image-sizes.php
Created September 6, 2013 18:23
Get all the registered image sizes along with their dimensions
<?php
/**
* Get all the registered image sizes along with their dimensions
*
* @global array $_wp_additional_image_sizes
*
* @link http://core.trac.wordpress.org/ticket/18947 Reference ticket
* @return array $image_sizes The image sizes
*/
function _get_all_image_sizes() {
@eduardozulian
eduardozulian / btt-spotify-itunes.json
Last active June 30, 2018 00:41
BetterTouchTool: show Spotify/iTunes tracks currently playing
{
"BTTWidgetName" : "Now Playing",
"BTTTriggerType" : 639,
"BTTTriggerTypeDescription" : "Apple Script Widget",
"BTTTriggerClass" : "BTTTriggerTypeTouchBar",
"BTTPredefinedActionType" : 172,
"BTTPredefinedActionName" : "Run Apple Script (blocking)",
"BTTInlineAppleScript" : "if application \"Spotify\" is running then\r\ttell application \"Spotify\"\r\t\tif player state is playing then\r\t\t\tnext track\r\t\tend if\r\tend tell\rend if\r",
"BTTScriptType" : "AppleScript",
"BTTEnabled2" : 1,
@eduardozulian
eduardozulian / wp-taxonomy-checkbox.php
Created September 24, 2013 13:31
Use checkbox term selection for non-hierarchical taxonomies.
<?php
// Change this to your own taxonomy and post type
new Tag_Checklist( 'taxonomy_name', 'post_type' );
/**
* Use checkbox term selection for non-hierarchical taxonomies
*
* @author Hugh Lashbrooke
@eduardozulian
eduardozulian / wp-get-attachment-id.php
Created September 30, 2013 13:24
Retrieve the attachment ID from the file URL
<?php
/**
* Retrieve the attachment ID from the file URL
*
* @link http://pippinsplugins.com/retrieve-attachment-id-from-image-url/
*/
function horizonte_rural_get_attachment_id( $image_url ) {
global $wpdb;
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE guid='%s';", $image_url ) );
@eduardozulian
eduardozulian / wp-featured-video.php
Last active January 5, 2016 21:58
Create a custom field with the first embed URL found in a post format video. Can be used for featuring a video wherever is necessary.
@eduardozulian
eduardozulian / plugin-init.php
Created December 19, 2013 20:45
WordPress plugin initialization
<?php
/*
Plugin Name:
Plugin URI:
Description:
Version: 0.1
Author: Eduardo Zulian
Author URI:
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html