Skip to content

Instantly share code, notes, and snippets.

Avatar
😀
Happy

Micah Wood wpscholar

😀
Happy
View GitHub Profile
@wpscholar
wpscholar / woo-add-cart-fee.php
Last active May 10, 2023 01:14
WooCommerce: Add a 4% Credit Card Processing Fee to the Checkout Page
View woo-add-cart-fee.php
<?php
/**
* WooCommerce Add Fee to the Checkout Page
*
* @package WooCommerceAddFeeToCheckout
* @author Micah Wood
* @copyright Copyright 2023 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
* @wordpress-plugin
@wpscholar
wpscholar / university-customer-role-assignment.php
Last active January 28, 2023 04:20
A WordPress plugin that changes the user role to "University Customer" if a user registers with a .edu email address.
View university-customer-role-assignment.php
<?php
/**
* University Customer Role Assignment
*
* @package UniversityCustomerRoleAssignment
* @author Micah Wood
* @copyright Copyright 2023 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
@wpscholar
wpscholar / connect-tech-demo.cy
Created November 7, 2022 16:53
A Chrome recording converted into a Cypress test.
View connect-tech-demo.cy
describe("Connect.tech Demo", () => {
it("tests Connect.tech Demo", () => {
cy.viewport(952, 976);
cy.visit("https://www.google.com/");
cy.get("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input").click();
cy.get("body > div.L3eUgb > div.o3j99.ikrT4e.om7nvf > form > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input").type("seo");
@wpscholar
wpscholar / connect-tech-demo.json
Created November 7, 2022 16:51
A Chrome recording that can be downloaded and replayed in the browser.
View connect-tech-demo.json
{
"title": "Connect.tech Demo",
"steps": [
{
"type": "setViewport",
"width": 952,
"height": 976,
"deviceScaleFactor": 1,
"isMobile": false,
"hasTouch": false,
@wpscholar
wpscholar / simple-website-redirect-not-homepage.php
Last active October 31, 2022 17:13
An add-on plugin for the "Simple Website Redirect" plugin that prevents redirects from happening on the homepage.
View simple-website-redirect-not-homepage.php
<?php
/**
* Simple Website Redirect - Not Homepage
*
* @package SimpleWebsiteRedirectNotHomepage
* @author Micah Wood
* @copyright Copyright 2022 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
@wpscholar
wpscholar / cypress.yml
Created April 29, 2022 21:01
Sample GitHub Action workflow for running Cypress tests with @wordpress/env
View cypress.yml
name: Cypress Tests
on:
push:
branches:
- master
pull_request:
types: [opened, edited, synchronize, reopened, ready_for_review]
pull_request_review:
types: [submitted, edited]
@wpscholar
wpscholar / commands.js
Created April 29, 2022 20:25
Cypress commands for conditionally logging into WordPress. Add to cypress/support/commands.js
View commands.js
Cypress.Commands.add('login', () => {
// Fetch username and password from the cypress.env.json file.
const username = Cypress.env('wpUsername');
const password = Cypress.env('wpPassword');
cy
.getCookies()
.then(cookies => {
let hasMatch = false;
@wpscholar
wpscholar / trimByCharacterAndWordCount.php
Created March 1, 2022 18:16
Truncate a string to a certain character length and make sure to only break at words.
View trimByCharacterAndWordCount.php
<?php
$strings = [
'One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua',
'Bacon ipsum dolor amet burgdoggen biltong pastrami, kielbasa sirloin strip steak cupim andouille tenderloin.',
'Hodor. Hodor hodor, hodor. Hodor hodor hodor hodor hodor. Hodor. Hodor! Hodor hodor, hodor; hodor hodor hodor.',
'Lorem Ipsum is the single greatest threat. We are not - we are not keeping up with other websites.',
'Cupcake ipsum dolor. Sit amet marshmallow topping cheesecake muffin.',
'This test is short.',
@wpscholar
wpscholar / maintenance-mode.php
Last active January 29, 2022 01:34
Enable maintenance mode via code
View maintenance-mode.php
<?php
/**
* Maintenance Mode
*
* @package MaintenanceMode
* @author Micah Wood
* @copyright Copyright 2022 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
* @wordpress-plugin
@wpscholar
wpscholar / menus.sh
Created August 25, 2021 19:21
WP-CLI Script menu creation
View menus.sh
wp menu create "Footer Primary Menu"
wp menu item add-custom footer-primary-menu "Item 1" "#"
wp menu item add-custom footer-primary-menu "Item 2" "#"
wp menu item add-custom footer-primary-menu "Item 3" "#"
wp menu location assign footer-primary-menu footer-primary