Skip to content

Instantly share code, notes, and snippets.

View alexanderdejong's full-sized avatar

Alexander de Jong alexanderdejong

View GitHub Profile
@alexanderdejong
alexanderdejong / trim_characters
Created December 20, 2017 14:41
Trim a string in WordPress to a specified number of characters, gracefully stopping at white spaces.
/**
* Trims a string of words to a specified number of characters, gracefully stopping at white spaces.
* Also strips HTML tags, to prevent breaking in the middle of a tag.
*
* @param string $text The string of words to be trimmed.
* @param int $length Maximum number of characters; defaults to 45.
* @param string $append String to append to end, when trimmed; defaults to ellipsis.
*
* @return String of words trimmed at specified character length.
*
@alexanderdejong
alexanderdejong / image_optimize-wordpress.php
Created January 10, 2018 15:30 — forked from wycks/image_optimize-wordpress.php
Remove WordPress full size images from being inserted into a post + option to and add max size to to prevent users from inserting massive images.
<?php
/**
*
* This removes the ability to add the FULL image size into a post, it does not alter or delete the image
* Add whataever extra image sizes to the insert dropdown in WordPress you create via add_image_size
*
* For now we have to do it this way to make the labels translatable, see trac ref below.
*
* If your theme has $content_width GLOBAL make sure and remove it
function ajax_add_to_cart(e) {
if (jQuery(this).hasClass('disabled')) {
// do nothibng
} else {
e.preventDefault();
e.stopPropagation();
/**
** Check what else is hooking into the_content();
**
**/
add_action('template_redirect', 'wpse_44152_template_redirect');
function wpse_44152_template_redirect(){
global $wp_filter;
print_r($wp_filter['the_content']);
}
@alexanderdejong
alexanderdejong / test.php
Last active May 1, 2019 14:24
My first Gistpen
echo 'dafdsagmdagafas fda ga fadfs das f';
@alexanderdejong
alexanderdejong / Controller.php
Created May 10, 2019 09:23 — forked from gmazzap/Controller.php
WordPress plugin to ease the creation of virtual pages.
<?php
namespace GM\VirtualPages;
/**
* @author Giuseppe Mazzapica <giuseppe.mazzapica@gmail.com>
* @license http://opensource.org/licenses/MIT MIT
*/
class Controller implements ControllerInterface {
private $pages;
<?php
/**
* @package Smashing_plugin
* @version 1.0
*/
/*
Plugin Name: Smashing plugin
Plugin URI: https://www.smashingmagazine.com/2016/03/advanced-wordpress-search-with-wp_query/
Description: This is an example plugin for Smashing Magazine readers.
Author: Carlo Daniele
<?php
/**
* @package Smashing_plugin
* @version 1.0
*/
/*
Plugin Name: Smashing plugin
Plugin URI: https://www.smashingmagazine.com/2016/03/advanced-wordpress-search-with-wp_query/
Description: This is an example plugin for Smashing Magazine readers.
Author: Carlo Daniele
@alexanderdejong
alexanderdejong / matty-double-post-type-rewrite-rule-example.php
Created May 15, 2019 09:40 — forked from mattyza/matty-double-post-type-rewrite-rule-example.php
A WordPress custom rewrite rule example, combining two post types.
<?php
/**
* Plugin Name: Double Post Type Rewrite Rule Example
* Plugin URI: https://gist.github.com/mattyza/7dfd156992f23835f68e
* Description: Adds a custom rewrite rule to mimic http://domain.com/post-type-01/post-type-02/.
* Author: Matty Cohen
* Author URI: http://matty.co.za/
* Version: 1.0.0
* Stable tag: 1.0.0
* License: GPL v3 - http://www.gnu.org/licenses/old-licenses/gpl-3.0.html
@alexanderdejong
alexanderdejong / customer-centric-from-details.php
Created May 15, 2019 09:40 — forked from mattyza/customer-centric-from-details.php
Use the customer's details as the "From" information for "New Order" emails in WooCommerce.
function custom_use_customer_from_address ( $from_email, $obj ) {
if ( is_a( $obj, 'WC_Email_New_Order' ) ) {
$address_details = $obj->object->get_address( 'billing' );
if ( isset( $address_details['email'] ) && '' != $address_details['email'] ) {
$from_email = $address_details['email'];
}
}
return $from_email;
}
add_filter( 'woocommerce_email_from_address', 'custom_use_customer_from_address', null, 2 );