Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / add.php
Last active July 7, 2025 10:26
How to Add Custom Fields to WordPress Taxonomies | http://www.ibenic.com/custom-fields-wordpress-taxonomies
<?php
do_action( "{$taxonomy}_add_form_fields", string $taxonomy );
var calculateDistance = function(lat1, lon1, lat2, lon2) {
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
@igorbenic
igorbenic / att.html
Last active July 11, 2017 06:01
Extending the WordPress Media Uploader: Custom Fields | http://www.ibenic.com/extending-wordpress-media-uploader-custom-fields
<input type="text" name="attachments[123][field_name]" />
@igorbenic
igorbenic / admin_footer.php
Last active March 3, 2017 00:15
Extending the WordPress Media Uploader: Embed Options | http://www.ibenic.com/extending-wordpress-media-uploader-embed-options
<?php
add_filter( 'media_send_to_editor', 'ibenic_media_send_to_editor', 10, 3 );
/**
* Changing the HTML to the editor
* @param string $html
* @param number $id
* @param array $attachment
* @return string
@igorbenic
igorbenic / example.php
Last active February 21, 2024 21:32
Taxonomy Rewrite Example
<?php
function rewriting_resources($wp_rewrite) {
$rules = array();
$terms = get_terms( array(
'taxonomy' => 'resource_type',
'hide_empty' => false,
) );
$post_type = 'resources';
@igorbenic
igorbenic / admin.js
Last active September 2, 2021 12:29
Extending the WordPress Media Uploader: Custom Tab | http://ibenic.com/extending-wordpress-media-uploader-custom-tab
var Library = wp.media.controller.Library;
var oldMediaFrame = wp.media.view.MediaFrame.Post;
// Extending the current media library frame to add a new tab
wp.media.view.MediaFrame.Post = oldMediaFrame.extend({
initialize: function() {
// Calling the initalize method from the current frame before adding new functionality
oldMediaFrame.prototype.initialize.apply( this, arguments );
@igorbenic
igorbenic / add_role.php
Last active June 21, 2019 15:39
How to Manage WordPress User Roles & Capabilities with Code | http://www.ibenic.com/how-to-manage-wordpress-user-roles-capabilities-with-code
<?php
add_role(
'new_user_role',
__( 'New User Role', 'yourtextdomain' ),
array(
'read' => true,
'edit_posts' => true,
// Various Capabilities
));
@igorbenic
igorbenic / add.php
Last active February 21, 2024 21:34
How to Hook in WordPress Metadata | http://www.ibenic.com/hook-wordpress-metadata
<?php
// Should this data be added?
apply_filters( "add_{$meta_type}_metadata", null, $object_id, $meta_key, $meta_value, $unique );
// Do something before we add the data
do_action( "add_{$meta_type}_meta", $object_id, $meta_key, $_meta_value );
// Do Something after the data has been added
do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );
@igorbenic
igorbenic / metabox.php
Created April 20, 2017 12:02
Add a Custom Menu Panel with Easy Digital Download Pages | http://www.ibenic.com/custom-menu-panel-edd-pages
<?php
add_action( 'load-nav-menus.php', 'ibenic_add_edd_menu_panel' );
/**
* Adding the menu panel metabox
*/
function ibenic_add_edd_menu_panel() {
add_meta_box(
'edd-menu-panel',