Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
damiencarbery / acf-create-options-page.php
Last active May 14, 2017 22:04
Use Advanced Custom Fields PRO Repeater field to use data in multiple places.
<?php
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'PR Services',
'menu_title' => 'PR Services',
'menu_slug' => 'pr-services',
'capability' => 'edit_posts',
'position' => 35,
'redirect' => false
));
@damiencarbery
damiencarbery / polylang-get-woocommerce-translated-page-id.php
Created May 17, 2017 12:46
Return ID of translated WooCommerce page
<?php
/*
Plugin Name: Return translated WooCommerce page
Plugin URI: http://www.damiencarbery.com
Description: Required Polylang plugin. Returns ID of translated page.
Author: Damien Carbery
Version: 0.1
*/
// A safe version of code suggested at:
@damiencarbery
damiencarbery / years-since-hardcoded.php
Last active June 5, 2017 22:54
Display years/days/weeks since a certain date.
<?php
/*
Plugin Name: Years Since Shortcode (Hardcoded)
Plugin URI: http://www.damiencarbery.com
Description: Shortcode to display years since a date specified in the code.
Author: Damien Carbery
Version: 0.1
*/
// '[years_since]' shortcode to display number of years since 1st Jan 2010.
@damiencarbery
damiencarbery / change-caps-to-allow-order-views.php
Last active January 9, 2018 17:00
Allow Viewing of Other Customer Orders in WooCommerce
<?php
add_filter( 'user_has_cap', 'cci_check_view_order_capability', 10, 3 );
function cci_check_view_order_capability( $allcaps, $caps, $args ) {
if ( isset( $caps[0] ) ) {
switch ( $caps[0] ) {
case 'view_order' :
// Check that the current user billing_company and order billing company match.
$current_user = wp_get_current_user();
$current_user_billing_company = get_user_meta( $current_user->ID, 'billing_company', true );
$order = wc_get_order( $args[2] );
@damiencarbery
damiencarbery / how-not-to-use-wp-filter.php
Last active September 15, 2022 21:52
Use $wp_filter global to view functions attached to actions and filters
<?php
/*
Plugin Name: wp_filter functions
Plugin URI: http://www.damiencarbery.com/2017/06/list-functions-attached-to-an-action/
Description: List functions attached to all actions and filters. DON'T DO IT!
Author: Damien Carbery
Version: 0.1
*/
add_action( 'wp_head', 'wp_filter_the_wrong_way' );
@damiencarbery
damiencarbery / post-meta-transients-almost-identical.php
Last active June 26, 2017 10:52
Using Post Meta instead of Transients
<?php
// Use transients.
if ( false === ( $transient_data = get_transient( 'transient_name' ) ) ) {
// Regenerate transient.
}
// Use post meta.
if ( false === ( $post_meta_data = get_post_meta(1, 'post_meta_name', true ) ) ) {
// Regenerate post meta.
@damiencarbery
damiencarbery / class-wc-check-availability-email.php
Last active October 25, 2017 10:32
Add custom email to WooCommerce
<?php
/**
* An email to ask the vendor to check availability of a booking.
*
* @extends \WC_Email
*
* Code copied from: https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@damiencarbery
damiencarbery / wpms-delete-sample-content.php
Last active July 17, 2017 07:55
WordPress Multisite: Delete sample content after a new site is created.
<?php
/*
Plugin Name: WordPress MultiSite Delete Sample Content
Plugin URI: http://www.damiencarbery.com/2017/07/multisite-delete-sample-content/
Description: Delete the sample post, page and comment that is created for a new site in a WordPress MultiSite installation. Network Activate this plugin.
Author: Damien Carbery
Version: 0.1
*/
@damiencarbery
damiencarbery / ms-upgrade-http-authentication.php
Created August 20, 2017 15:45
WordPress Multisite - Allow for password protected site
<?php
/*
Plugin Name: MultiSite Upgrade - Set HTTP authentication
Plugin URI: http://www.damiencarbery.com/2017/08/multisite-allow-for-password-protected-site/
Description: Set the basic authentication username and password during multisite upgrades.
Author: Damien Carbery
Version: 1.0
Author URI: http://www.damiencarbery.com/
*/
<?php
// Do not load CSS that we don't need on this page.
add_action( 'wp_enqueue_scripts', 'sc_landing_remove_unused_styles', 100 );
function sc_landing_remove_unused_styles() {
wp_dequeue_style( 'dashicons' );
wp_dequeue_style( 'hctpc_desktop_style' );
wp_dequeue_style( 'popup-maker-site' );
wp_dequeue_style( 'wordpress-countdown-timer-plugin-styles' );
}