Skip to content

Instantly share code, notes, and snippets.

View birgire's full-sized avatar

Birgir Erlendsson birgire

View GitHub Profile
@birgire
birgire / wpse.php
Created December 27, 2015 17:43
Must Use WordPress Plugin - Print the clean basedomain in the admin footer
<?php
/**
* Print the clean basedomain in the admin footer
*
* Place the file under /wp-content/mu-plugins/wpse.php
*
* @uses get_clean_basedomain()
*/
add_action( 'in_admin_footer', function(){
if( function_exists( 'get_clean_basedomain' ) )
@birgire
birgire / functions.php
Last active October 13, 2015 02:29
WordPress: Redirect visits to the attachment pages to the parent page or the home page
/**
* Redirect attachment page visits to the parent page, else the home page.
*/
add_action( 'template_redirect', function()
{
if( ! is_attachment() )
return;
if( $parent_id = wp_get_post_parent_id() )
wp_safe_redirect( esc_url( get_permalink( $parent_id ) ) );
<?php
/**
* Plugin Name: Change the size of the Image preview on the media edit page
* Author: Birgir Erlendsson (birgire)
* Plugin URI: http://wordpress.stackexchange.com/questions/204280/change-the-size-of-the-image-preview-on-the-media-edit-page
*
* ------------------------------------------------------------------------------------
* Possible workaround, without core modifications,
* but note that the javascript crop-selection numbers will not be accurate,
* when $inf <> 400
@birgire
birgire / actions_and_filters.log
Last active December 13, 2021 22:27
WordPress: Here we list all (exl. gettext) actions & filters that run when the `edit.php` (post) screen is loaded without any plugins and with a default theme activated:
Here we list all do_action, do_action_ref_array, apply_filters and apply_filters_ref_array calls (excluding gettext) for the edit.php (post) screen.php:
---
muplugins_loaded - do_action
pre_site_option_siteurl - apply_filters
default_site_option_siteurl - apply_filters
pre_option_siteurl - apply_filters
option_siteurl - apply_filters
site_option_siteurl - apply_filters
@birgire
birgire / hueman-theme-sharrre-sharing-bar-on-pages.php
Last active September 10, 2015 09:51
WordPress: Add the Hueman theme's sharing bar to pages. (Fix for those who don't have a recommended child theme)
<?php
/**
* Plugin Name: Hueman Theme - Sharrre Sharing Bar On Pages
* Description: Add the Hueman theme's sharing-bar to pages. (Fix for those who don't have a recommended child theme)
* Plugin URI: https://gist.github.com/birgire/be3dc8174e227233fa70
* Author: Birgir Erlendsson (birgire)
* Author URI: https://github.com/birgire
* Version: 0.0.1
* Licence: MIT
*/
@birgire
birgire / export-single-day.php
Last active May 14, 2023 13:24
WordPress Plugin: Enhance the native XML export - with a single day selection
<?php
/**
* Plugin Name: Single Day Posts Export
* Plugin URL: http://wordpress.stackexchange.com/a/199527/26350
* Plugin Author: Birgir Erlendsson (birgire)
* Version: 0.0.1
*/
/**
* Add our extra HTML
@birgire
birgire / field_query.php
Last active January 17, 2018 14:37
WordPress: Nested field queries - An idea for a plugin to support the "field_query" argument in the WP_Query class
<?php
/**
* Plugin Name: Field Query
* Description: Support the "field_query" argument in the WP_Query class
* Plugin URI: https://gist.github.com/birgire/ebf79ab6b12258a0e489
* Plugin Author: Birgir Erlendsson (birgire)
* Version: Proposal (2015-07-28)
**/
/**
@birgire
birgire / woo-product-attributes-bulk-modifier.php
Last active March 4, 2024 10:09
WordPress: WooCommerce Product Attributes - Bulk Modifier ( from custom meta attributes to taxonomy attributes)
<?php
/**
* Plugin Name: WooPAM: Woo Product Attributes Modifier
* Description: Bulk update 'custom meta product attributes' to 'taxonomy product attributes' in WooCommerce. Supports the GET variables, like: woopam_mode=run&woopam_from_attribute_meta=colour&woopam_to_attribute_tax=pa_colour&woopam_keep_attribute_meta&woopam_posts_per_page=10&woopam_paged=0&woopam_post_type=product&woopam_post_status=any. WARNING: Backup DB first!!!
* Plugin Author: birgire
* Author URI: https://github.com/birgire
* Plugin URI: https://gist.github.com/birgire/0ed300ae4436fcaf508c
* Version: 1.0.0
* License: GPL2+
* Text Domain: woopam
@birgire
birgire / functions.php
Last active August 29, 2015 14:15
Match any numbers in given a meta-key for WP_Query (PHP 5.2+ )
/**
* Match any numbers in given a meta-key for WP_Query (PHP 5.2+)
*
* @see http://wordpress.stackexchange.com/a/177331/26350
*/
! is_admin() && add_filter( 'posts_where', 'wpse_posts_where' );
function wpse_posts_where( $where )
{
@birgire
birgire / simple-redirections.php
Last active August 29, 2015 14:09
WordPress Plugin: Redirect to the newest or the latest post via a GET parameter
<?php
/**
* Plugin Name: Simple Redirections
* Plugin URI: https://gist.github.com/birgire/b1c8b3b94da4ee2f94ba
* Author: Birgir Erlendsson (birgire)
* Version: 0.0.1
* Licence: GPLv2+
* Description: Redirect to the newest or the latest post with a GET parameter
*/