Skip to content

Instantly share code, notes, and snippets.

View maddisondesigns's full-sized avatar

Anthony Hortin maddisondesigns

View GitHub Profile
@maddisondesigns
maddisondesigns / functions.php
Last active March 8, 2025 09:18
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
@maddisondesigns
maddisondesigns / create-wp-admin.php
Created October 4, 2017 01:10
Create a new WordPress Administrator User
<?php
// ADD NEW ADMIN USER TO WORDPRESS
// ----------------------------------
// Put this file in your Wordpress root directory and run it from your browser.
// Delete it when you're done.
// Original script by Joshua Winn - https://joshuawinn.com/create-a-new-wordpress-admin-user-from-php
require_once('wp-blog-header.php');
require_once('wp-includes/registration.php');
@maddisondesigns
maddisondesigns / CSV Product Import.csv
Last active October 15, 2020 08:20
WooCommerce Product CSV Import Schema
ID Type SKU Name Published Is featured? Visibility in catalog Short Description Description Date sale price starts Date sale price ends Tax Status Tax Class In stock? Backorders allowed? Sold individually? Weight (unit) Length (unit) Width (unit) Height (unit) Allow customer reviews? Purchase Note Price Regular Price Stock Categories Tags Shipping Class Attribute 1 Name Attribute 1 Value(s) Attribute 1 Default Attribute 1 Visible Images Download 1 Name Download 1 URL Download Limit Download Expiry Days Parent Upsells Cross-sells
id type sku name status featured catalog_visibility short_description description date_on_sale_from date_on_sale_to tax_status tax_class stock_status backorders sold_individually weight length width height reviews_allowed purchase_note price regular_price manage_stock / stock_quantity category_ids tag_ids shipping_class_id attributes attributes default_attributes attributes image_id / gallery_image_ids downloads downloads download_limit download_expiry parent_id upsell_ids cross_sell_
@maddisondesigns
maddisondesigns / migrateorders.php
Last active March 25, 2019 19:38
Migrate WooCommerce Orders
<?php
// Copies woocommerce orders and users over from source to target.
// I use this on my local machine - loading both db's up there side by side
// could easily adjust the connect strings to connect elsewhere if needed.
// will change order ids
// My use case for this is when I've got a staging/test version of a site with new posts/products/pages etc, that needs
// to go live without the loss of any orders placed on the site site since we copied it to the staging site.
@maddisondesigns
maddisondesigns / functions.php
Last active October 9, 2024 00:30
Remove the annoying Wordfence Notifications on plugin updates and plugin activation
<?php
/*
* Remove the annoying Wordfence Notifications. Tested with Wordfence v6.3.2
*/
class ahRWN_Remove_Wordfence_Notification {
private $wordfencePluginFile;
public function __construct() {
$this->wordfencePluginFile = "wordfence/wordfence.php";
register_activation_hook( $this->wordfencePluginFile, array( $this, 'rwn_remove_wordfence_notifications_on_activation' ) );
@maddisondesigns
maddisondesigns / functions.php
Last active March 25, 2019 19:38
Remove the WP REST API JSON Endpoints for everyone except Administrators
<?php
/*
* Only allow Admin users to view WP REST API JSON Endpoints
*/
function mytheme_only_allow_logged_in_rest_access( $access ) {
if( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'disable-json-api' ), array( 'status' => rest_authorization_required_code() ) );
}
return $access;
}
@maddisondesigns
maddisondesigns / functions.php
Last active March 25, 2019 19:38
Remove the WP REST API JSON Endpoints for non-logged in users
<?php
/*
* Remove the WP REST API JSON Endpoints for logged out users
*/
function mytheme_only_allow_logged_in_rest_access( $access ) {
if( ! is_user_logged_in() ) {
return new WP_Error( 'rest_cannot_access', __( 'Only authenticated users can access the REST API.', 'disable-json-api' ), array( 'status' => rest_authorization_required_code() ) );
}
return $access;
}
@maddisondesigns
maddisondesigns / functions.php
Last active April 12, 2023 06:20
Display the name of the current WordPress template being used
<?php
/**
* Debug function to show the name of the current template being used
*/
function mytheme_show_template() {
global $template;
if ( is_user_logged_in() ) {
echo '<div style="background-color:#000;color:#fff;z-index:9999;position:absolute;top:0;">';
print_r( $template );
if ( is_single() ) {
@maddisondesigns
maddisondesigns / functions.php
Created August 2, 2016 05:59
WordPress Child Theme Example
<?php
function mytheme_scripts_styles() {
// Enqueue the parent theme stylesheet
wp_enqueue_style( 'parent-style', trailingslashit( get_template_directory_uri() ) . 'style.css' );
// Ensure the default WordPress stylesheet is enqueued after the parent stylesheet
wp_enqueue_style( 'style', get_stylesheet_uri(), array( 'parent-style' ) );
}
add_action( 'wp_enqueue_scripts', 'mytheme_scripts_styles' );
@maddisondesigns
maddisondesigns / functions.php
Last active December 21, 2015 03:51
Filter the Gravity Forms button type to change it to a proper button
<?php
/*
* mytheme_form_submit_button
*
* Filter the Gravity Forms button type to change it to a proper button
*/
function mytheme_form_submit_button( $button, $form ) {
$button = str_replace( "input", "button", $button );
$button = str_replace( "/", "", $button );
$button .= "{$form['button']['text']}</button>";