Skip to content

Instantly share code, notes, and snippets.

View edmundcwm's full-sized avatar

edmundcwm edmundcwm

View GitHub Profile
@edmundcwm
edmundcwm / phpcs.xml.dist
Last active December 18, 2023 00:11
PHPCS Config for WordPress development
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WordPress" namespace="WordPressCS\WordPress" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<description>Default WordPress Coding Standards</description>
<!-- Lint all PHP files in the project directory by default. -->
<file>.</file>
<rule ref="WordPress-Core">
<exclude name="Generic.Arrays.DisallowShortArraySyntax" />
<exclude name="Generic.Commenting.DocComment.MissingShort" />
@edmundcwm
edmundcwm / unfiltered-html-toggle.php
Last active March 28, 2022 14:38
Add a checkbox to toggle the "Unfiltered html" capability for Administrators in a multisite.
<?php
/**
* Add a checkbox to toggle the "Unfiltered html" capability for Administrators in a multisite.
*/
/**
* Re-enable unfiltered_html for Administrators only on a Multisite.
*
* @see https://core.trac.wordpress.org/browser/tags/5.8/src/wp-includes/capabilities.php#L421
*/
@edmundcwm
edmundcwm / edm-disable-wc-single-product-page.php
Last active March 22, 2024 00:17
Woocommerce: Remove single product page link in archive page and redirect single product page to shop page
<?php
/**
* Removes single product link in archive page and enable template redirect
*
* A snippet that removes the <a href="(single product permalink)"> in the archive page
* and redirects user back to the shop page when they try to access the single page directly
*
* WC tested up to: 3.4.3
*
@edmundcwm
edmundcwm / edm-reduce-product-title-length.php
Last active August 23, 2018 01:15
Reduce length of Woocommerce product title
<?php
/**
* Reduce length of Woocommerce product title
*
* @param string $title product title
* @param int $id product id
* @return string modified product title
*
* Hook ref: https://codex.wordpress.org/Plugin_API/Filter_Reference/the_title
@edmundcwm
edmundcwm / edm-display-product-thumbnail-in-emails.php
Last active August 4, 2018 09:46
Woocommerce: Display order item thumbnails in transaction emails
<?php
/*
* Enable order item thumbnail display in emails
* Change order item thumbnail size
* @see woocommerce/includes/wc-template-functions.php for hook
*/
function edm_display_product_thumbnail_in_emails( $args ) {
/* Display image thumbnail in emails */
$args['show_image'] = true;
@edmundcwm
edmundcwm / edm-product-custom-labels.php
Last active August 3, 2018 15:56
Woocommerce: Display custom labels for products in selected categories (e.g., "New In", "Flash Sale")
<?php
/**
* Display custom labels for products in selected categories
*
* @param array $labels Array labels
*
* - Instructions -
* 1) Create a product category 'Flash Sale'
* 2) Assign products to that category
*