Skip to content

Instantly share code, notes, and snippets.

View bahiirwa's full-sized avatar
🏠
Working from home

Laurence Bahiirwa bahiirwa

🏠
Working from home
View GitHub Profile
@bahiirwa
bahiirwa / geblock.js
Created August 22, 2018 12:04
geblock
/**
* Internal block libraries
*/
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
const { RichText } = wp.editor;
/**
* Register block
*/
@bahiirwa
bahiirwa / push.php
Last active August 22, 2018 12:22
push notification to external URL
<?php
function wp_plugin_event_handler () {
global $post;
$url = 'https://us-central1-smackapp-7eab7.cloudfunctions.net/sendNotification';
if( get_post_type( $post->ID ) == 'post' ) {
@bahiirwa
bahiirwa / php-block.js
Created July 30, 2018 05:25 — forked from pento/php-block.js
Converting a shortcode to a block
// License: GPLv2+
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
InspectorControls = wp.editor.InspectorControls;
/*
* Here's where we register the block in JavaScript.
@bahiirwa
bahiirwa / curl.md
Created June 14, 2018 18:49 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
@bahiirwa
bahiirwa / README.md
Created April 17, 2018 09:49 — forked from ericclemmons/README.md
Hot take on Zach Silveira's Gutenblock Demo!
@bahiirwa
bahiirwa / block-template.php
Created March 9, 2018 11:26 — forked from zgordon/block-template.php
Example of how to add block templates to post types in WordPress
<?php
function mytheme_block_templates( $args, $post_type ) {
// Only add template to 'post' post type
// Change for your post type: eg 'page', 'event', 'product'
if ( 'post' == $post_type ) {
// Optionally lock templates from further changes
// Change to 'insert' to allow adding other blocks, but lock defined blocks
@bahiirwa
bahiirwa / wc-prevent-checkout-for-cart-with-specific-category.php
Created January 30, 2018 07:23 — forked from bekarice/wc-prevent-checkout-for-cart-with-specific-category.php
Prevents checkout if the WooCommerce cart only contains items from a specific category
<?php // only copy this line if needed
/**
* Renders a notice and prevents checkout if the cart
* only contains products in a specific category
*/
function sv_wc_prevent_checkout_for_category() {
// set the slug of the category for which we disallow checkout
$category = 'clothing';
@bahiirwa
bahiirwa / AdminPage.php
Created December 25, 2017 17:31 — forked from carlalexander/AdminPage.php
WordPress and the single responsibility principle
<?php
/**
* The WordPress Meme Shortcode admin page.
*
* @author Carl Alexander
*/
class WPMemeShortcode_AdminPage
{
/**
@bahiirwa
bahiirwa / functions.php
Created December 5, 2017 07:05 — forked from om4james/functions.php
Display product description on WooCommerce shop/category pages
<?php
/**
* Add the product's short description (excerpt) to the WooCommerce shop/category pages. The description displays after the product's name, but before the product's price.
*
* Ref: https://gist.github.com/om4james/9883140
*
* Put this snippet into a child theme's functions.php file
*/
function woocommerce_after_shop_loop_item_title_short_description() {
global $product;