Skip to content

Instantly share code, notes, and snippets.

View kasparsd's full-sized avatar

Kaspars Dambis kasparsd

View GitHub Profile
@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 / 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....
@kasparsd
kasparsd / extract-twitter-username.php
Created August 6, 2015 13:34
Extract Twitter username from links to Twitter profiles
<?php
$html = file_get_contents( 'http://example.com' );
preg_match_all( '/https?:\/\/(?:www.)?twitter.com\/#?([a-zA-Z0-9_]+)\/?(?![\/a-z]+)/i', $html, $maybe_twitters );
if ( ! empty( $maybe_twitters[1] ) ) {
printf( 'Found %s', $maybe_twitters[1][0] );
} else {
print( 'Nothing found!' );
@kasparsd
kasparsd / prepare-commit-msg
Last active September 23, 2015 18:27
Prepend the current Git branch name and the JIRA parent issue to every commit message
#!/bin/bash
#
# Prepend the current branch name to every commit message.
# Prepend the parent issue from JIRA, if found.
#
# Save this to .git/hooks/prepare-commit-msg and make it exacutable:
# chmod +x .git/hooks/prepare-commit-msg
#
# Extract the current working branch
@kasparsd
kasparsd / disable-capture.php
Created October 2, 2015 05:38
Disable form submissions storage for a form ID
<?php
add_action( 'wpcf7_before_send_mail', function( $cf7 ) {
// Disable form submission for form ID 123
if ( 123 == $cf7->id() ) {
remove_action( 'wpcf7_before_send_mail', array( cf7_storage::instance(), 'storage_capture' ) );
}
}, 5, 1 );