Skip to content

Instantly share code, notes, and snippets.

View wpscholar's full-sized avatar
😀
Happy

Micah Wood wpscholar

😀
Happy
View GitHub Profile
@wpscholar
wpscholar / wp-enqueue-scripts.php
Created August 18, 2023 18:07
Example Enqueue
<?php
add_action(
'wp_enqueue_scripts',
function() {
...
}
);
@wpscholar
wpscholar / add-featured-image-to-rss-feed.php
Last active August 16, 2023 14:02
Add the featured image to RSS feed(s)
@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
<?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 / array-insert-after.php
Created November 7, 2015 13:04
Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended to the end of the array.
<?php
/**
* Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
* to the end of the array.
*
* @param array $array
* @param string $key
* @param array $new
*
@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.
<?php
/**
* University Customer Role Assignment
*
* @package UniversityCustomerRoleAssignment
* @author Micah Wood
* @copyright Copyright 2023 by Micah Wood - All rights reserved.
* @license GPL2.0-or-later
*
<?php
/**
* Ensure that a specific plugin is never updated. This works by removing the
* plugin from the list of available updates.
*/
add_filter( 'http_request_args', function ( $response, $url ) {
if ( 0 === strpos( $url, 'https://api.wordpress.org/plugins/update-check' ) ) {
$basename = plugin_basename( __FILE__ );
<?php
/**
* Drop this code into your main plugin file to hide plugin deactivation from the WordPress admin.
*/
add_filter( 'plugin_action_links', function ( $actions, $plugin_file ) {
if ( plugin_basename( __FILE__ ) === $plugin_file ) {
unset( $actions['deactivate'] );
}
<?php
/**
* Ensure that a specific theme is never updated. This works by removing the
* theme from the list of available updates.
*/
add_filter( 'http_request_args', function ( $response, $url ) {
if ( 0 === strpos( $url, 'https://api.wordpress.org/themes/update-check' ) ) {
$themes = json_decode( $response['body']['themes'] );
@wpscholar
wpscholar / defer-async-scripts.php
Last active November 18, 2022 02:41
Class that allows you to async and defer scripts in WordPress by adding data.
<?php
class WP_Scholar_Defer_Scripts {
public static function initialize() {
add_filter( 'script_loader_tag', array( __CLASS__, 'defer_scripts' ), 10, 2 );
add_filter( 'script_loader_tag', array( __CLASS__, 'async_scripts' ), 10, 2 );
}
public static function defer_scripts( $tag, $handle ) {
@wpscholar
wpscholar / connect-tech-demo.cy
Created November 7, 2022 16:53
A Chrome recording converted into a Cypress test.
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");