Skip to content

Instantly share code, notes, and snippets.

View kasparsd's full-sized avatar

Kaspars Dambis kasparsd

View GitHub Profile
@kasparsd
kasparsd / metroshare-legacy-fb.php
Created January 17, 2014 15:23
Fix Metroshare to use the legacy sharer URL that doesn't require an App ID
<?php
/**
* Apperantly we need to use the legacy URL instead, because the new one
* doesn't work without a valid App ID
*/
add_filter( 'metroshare_destinations', 'fix_fb_sharing_location' );
function fix_fb_sharing_location( $destinations ) {
@kasparsd
kasparsd / href-domain-menu-item.php
Created January 21, 2014 15:31
Add destination domain as sanitized CSS class to every WordPress menu item
<?php
add_filter( 'nav_menu_css_class', 'menu_item_href_css_class', 10, 2 );
function menu_item_href_css_class( $classes, $item ) {
$url_domain = parse_url( $item->url, PHP_URL_HOST );
if ( $url_domain )
$classes[] = 'link-' . sanitize_title( $url_domain );
@kasparsd
kasparsd / capture-cf7.php
Created November 16, 2014 18:01
Capture form submissions from Contact Form 7 plugin for WordPress
<?php
add_action( 'wpcf7_before_send_mail', 'capture_entry' );
function capture_entry( $cf7 ) {
$posted_fields = array();
$submission = WPCF7_Submission::get_instance();
$posted_data_raw = $submission->get_posted_data();
@kasparsd
kasparsd / widget-cache-bump.php
Last active August 29, 2015 14:12
Invalidate widget output cache when updating posts, categories, terms, menus, etc.
<?php
add_action( 'init', 'widget_cache_register_bump' );
function widget_cache_register_bump() {
// Invalidate widget cache during these action calls
$purge_actions = array(
'clean_post_cache',
'edit_term',
@kasparsd
kasparsd / widget-cache-ttl.php
Created December 31, 2014 12:28
Set custom widget cache expiration (TTL) time in Widget Output Cache plugin.
<?php
add_filter( 'widget_output_cache_ttl', 'widget_cache_custom_ttl', 10, 2 );
function widget_cache_custom_ttl( $ttl, $widget_args ) {
// Set custom expiration time in seconds for each widget
$map_ttl = array(
'your_widget_id' => 3600,
'another_widget_id' => 87700
@kasparsd
kasparsd / metroshare-remove-via.php
Created January 9, 2015 12:24
Remove empty via attribute from Metro Share
<?php
// Remove empty via attribute from Metro Share links
add_filter( 'the_content', 'metroshare_strip_empty_via', 198 );
function metroshare_strip_empty_via( $content ) {
return str_replace( '&via&text', '&text', $content );
}
@kasparsd
kasparsd / prepend-page-parent-nav-item.php
Created March 31, 2015 15:40
Prepend parent page title to page list in the menu builder
<?php
add_action( 'admin_head-nav-menus.php', 'enable_menu_page_selector_filter' );
function enable_menu_page_selector_filter() {
// Unfortunately Walker_Nav_Menu_Checklist relies on a filter that
// is used also elsewhere and can't be filtered reliably.
add_filter( 'the_title', 'prepend_page_parent', 10, 2 );
}
@kasparsd
kasparsd / menu-update-warning.php
Created April 20, 2015 07:15
Notify WordPress menu update exceeding max_input_vars
<?php
/*
* Plugin Name: Menu Update Warning
* Plugin URI:
* Description:
* Version: 0.1
* Author:
* Author URI:
*/
@kasparsd
kasparsd / make.log
Created April 23, 2015 14:09
Building APCu with PHP 7 on Debian Wheezy
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....