Skip to content

Instantly share code, notes, and snippets.

View birgire's full-sized avatar

Birgir Erlendsson birgire

View GitHub Profile
@birgire
birgire / get_the_category_list.php
Last active October 13, 2019 04:47
WordPress: Draft idea on how one could simplify the get_the_category_list() to address code duplication - WP 4.4.2
/**
* 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 / method1.php
Last active October 13, 2019 04:46
Change Parent Name with wp_list_pages?
<?php
/**
* Method 1: Use the the_title() filter to modify the first link name in wp_list_pages().
*
* @see http://wordpress.stackexchange.com/questions/156742/change-parent-name-with-wp-list-pages
*/
// -----------------------------------------
// Place this wpse_title() function definition into
// the functions.php file in the current theme directory.
@birgire
birgire / comment-reply-mod.js
Last active February 11, 2019 16:55
WordPress: Modified addComment Javascript function.
var addComment = {
moveForm : function(commId, parentId, respondId, postId) {
var t = this, div, comm = t.I(commId), respond = t.I(respondId), cancel = t.I('cancel-comment-reply-link'), parent = t.I('comment_parent'), post = t.I('comment_post_ID');
if ( ! comm || ! respond || ! cancel || ! parent )
return;
t.respondId = respondId;
postId = postId || false;
@birgire
birgire / functions.php
Last active February 9, 2019 11:42
Inject Ads To WordPress Comments - See https://wordpress.stackexchange.com/a/328155/26350
/**
* 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;
@birgire
birgire / functions.php
Last active December 4, 2018 16:44
WordPress: The Sponsor Posts Injector plugin
/**
* The Sponsor Posts Injector - Usage Example
*
* @version 0.0.3
* @uses content-sponsor.php
* @file functions.php
* @see http://wordpress.stackexchange.com/q/158133/26350
*/
/**
@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 / json-api-custom-fields-support-for-create-post.php
Last active August 31, 2017 05:12
WordPress plugin: JSON API - Custom fields support for the create_post method
<?php
/**
* Plugin Name: JSON API - Custom fields support for the create_post method
* Version: 0.0.1
* Author: Birgir Erlendsson (birgire)
* Author URI: https://github.com/birgire
* Plugin URI: https://gist.github.com/birgire/02dfadbcb0ddc3fdb064
* Description: Extension to the JSON API plugin, to enable custom fields to be added with the "create_post" method
* Licence: GPLv2+
*/
<?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 / 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 ) ) );