Skip to content

Instantly share code, notes, and snippets.

Birgir Erlendsson birgire

View GitHub Profile
View functions.php
/**
* Inject Ads To WordPress Comments - end-callback for wp_list_comments().
*
* The Ads HTML is sanitized through wp_kses_post().
*
* @version 1.0.11
* @see https://wordpress.stackexchange.com/a/328155/26350
*/
function wpse_comments_ads_injection( $comment, $args, $depth ) {
static $instance = 0;
View so-38602177.php
<?php
/**
* @version: 1.0.3
* @see http://stackoverflow.com/questions/38551606/do-not-submit-form-after-wrong-code/38602177
*/
add_filter( 'login_form', function()
{
$options = get_option( 'authcode_settings' );
@birgire
birgire / get_the_category_list.php
Last active Mar 7, 2016
WordPress: Draft idea on how one could simplify the get_the_category_list() to address code duplication - WP 4.4.2
View get_the_category_list.php
/**
* Retrieve category list in either HTML list or custom format.
*
* @since 1.5.1
*
* @global WP_Rewrite $wp_rewrite
*
* @param string $separator Optional, default is empty string. Separator for between the categories.
* @param string $parents Optional. How to display the parents.
* @param int $post_id Optional. Post ID to retrieve categories.
@birgire
birgire / wpse.php
Created Dec 27, 2015
Must Use WordPress Plugin - Print the clean basedomain in the admin footer
View wpse.php
<?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 Oct 13, 2015
WordPress: Redirect visits to the attachment pages to the parent page or the home page
View functions.php
/**
* 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 ) ) );
View wpse-change-image-preview-size.php
<?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 Jan 11, 2016
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:
View actions_and_filters.log
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 Sep 10, 2015
WordPress: Add the Hueman theme's sharing bar to pages. (Fix for those who don't have a recommended child theme)
View hueman-theme-sharrre-sharing-bar-on-pages.php
<?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 Aug 29, 2015
WordPress Plugin: Enhance the native XML export - with a single day selection
View export-single-day.php
<?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 Jan 17, 2018
WordPress: Nested field queries - An idea for a plugin to support the "field_query" argument in the WP_Query class
View field_query.php
<?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)
**/
/**
You can’t perform that action at this time.