Skip to content

Instantly share code, notes, and snippets.

@cfxd
cfxd / rakuten_for_woocommerce.php
Last active August 11, 2021 19:54
Rakuten code for WooCommerce using WordPress actions & hooks
<?php
namespace Roots\Sage\Rakuten;
function assets() {
wp_register_script('sage/rakuten', '//tag.rmp.rakuten.com/124013.ct.js', [], null, false);
wp_enqueue_script('sage/rakuten');
}
add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\assets', 10);
@cfxd
cfxd / bs3-contact-form-7.less
Last active June 8, 2021 07:29
Bootstrap 3 default styles for Contact Form 7
/*
*
* Bootstrap 3 reset for CF7
*
*/
input, textarea {
&.wpcf7-form-control {
&:extend(.form-control all);
&.wpcf7-validates-as-required.wpcf7-not-valid {
@cfxd
cfxd / clear_jetpack_published.php
Last active February 21, 2021 18:33
Clear Jetpack's Publicized data to re-Publicize posts. See http://cfxdesign.com/how-to-re-publicize-posts-with-jetpack/
<?php
function clear_jetpack_published() {
if(empty($_REQUEST['post'])) {
wp_die(__('Invalid post ID or action'));
}
global $wpdb;
$id = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : '';
@cfxd
cfxd / gist:9ddbba4607ceec5a2a2e
Last active February 2, 2021 10:02
Install The CSS3 Font Converter (http://www.useragentman.com/blog/the-css3-font-converter/) on OS X Yosemite for on demand @font-face conversion on the command line. Also see http://cfxdesign.com/css3-font-converter-is-a-command-line-font-face-converter
1. $ brew install fontforge ttf2eot ttfautohint
2. $ brew tap bramstein/webfonttools && brew install sfnt2woff
3. Download/clone https://github.com/google/woff2 into any handy dir
cd into dir and:
$ git submodule init
$ git submodule update
$ make clean all
then:
@cfxd
cfxd / cf7-input-group.less
Last active December 3, 2020 00:15
Bootstrap 3 input group for Contact Form 7 (only tested with 1 input field and 1 submit button)
/*
*
* Bootstrap 3 input group form for Contact Form 7
*
* In the shortcode, you must use html_id="my-id"
* or html_class="my-class" to target a specific form
*
* Actual form sample:
* <label for="your-email">Email:</label>
* [email* your-email 0/ placeholder "enter your email"]
@cfxd
cfxd / sortby-es6.js
Last active October 18, 2020 13:57
Add a sort by dropdown in Shopify (the right way). See https://cfxdesign.com/add-a-sort-by-dropdown-in-shopify-the-right-way
// Save existing sort parameters
Shopify.queryParams = {};
if(location.search.length) {
for(var aKeyValue, i = 0, aCouples = location.search.substr(1).split('&'); i < aCouples.length; i++) {
aKeyValue = aCouples[i].split('=');
if (aKeyValue.length > 1) {
Shopify.queryParams[decodeURIComponent(aKeyValue[0])] = decodeURIComponent(aKeyValue[1]);
}
}
}
function apple_news_remove_empty_p_tags($content, $post_id) {
$new_content = preg_replace('/<span[^>]*>[\s\040\t\r\n\W]*<\/span>/', '', $content);
$new_content = preg_replace('/<span[^>]*>&nbsp;*<\/span>/', '', $new_content);
$new_content = preg_replace('/<span[^>]*> <\/span>/', '', $new_content);
$new_content = preg_replace('/<p[^>]*>[\s\040\t\r\n\W]*<\/p>/', '', $new_content);
$new_content = preg_replace('/<p[^>]*>&nbsp;*<\/p>/', '', $new_content);
$new_content = preg_replace('/<p[^>]*> <\/p>/', '', $new_content);
return $new_content;
function mailpoet_enable_wpmail(){
if(class_exists('WYSIJA')){
$model_config = WYSIJA::get('config','model');
$model_config->save(array('allow_wpmail' => true));
}
}
add_action('init', 'mailpoet_enable_wpmail');
@cfxd
cfxd / Gruntfile.js
Last active April 24, 2019 03:59
Remove Unused CSS from WordPress Automatically with Grunt. See http://cfxdesign.com/remove-unused-css-from-roots-theme-automatically-with-grunt/
'use strict';
module.exports = function(grunt) {
// Load all tasks
require('load-grunt-tasks')(grunt);
// Show elapsed time
require('time-grunt')(grunt);
var jsFileList = [
'assets/vendor/bootstrap/js/transition.js',
'assets/vendor/bootstrap/js/alert.js',