Skip to content

Instantly share code, notes, and snippets.

View mgratch's full-sized avatar

Marc Gratch mgratch

View GitHub Profile
<?php
/*
Plugin Name: CSV URL Processor
Plugin URI: https://gist.github.com/mgratch/ec801047eee7ae3bc06d717200c4196a
Description: A WP-CLI command to process URLs from a CSV file.
Version: 1.0
Author: Marc Gratch
Author URI: https://marcgratch.com
*/
@mgratch
mgratch / kill-comments.php
Created June 15, 2023 21:12
This code will disable comments everywhere on your site, and remove all comment-related functionality from the WordPress admin area. It's a nuclear option, but if you want to ensure comments are completely disabled, it should do the trick.
<?php
/**
* Disable support for comments and pingbacks in post types
*/
function suntraxfl_disable_comments_post_types_support(): void {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
if ( post_type_supports( $post_type, 'comments' ) ) {
remove_post_type_support( $post_type, 'comments' );
@mgratch
mgratch / add-noindex-to-posts.php
Created May 18, 2023 17:43
Use WP-CLI to enter `wp shell`, enter the following class, and then run `(new SEO_Update_Command())->__invoke()` to start the process.
if (class_exists('WP_CLI')) { class SEO_Update_Command { public function __invoke() { global $wpdb; $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'salary_market_data' AND post_parent != 0"); $progress = \WP_CLI\Utils\make_progress_bar( 'Updating...', count($post_ids)); foreach($post_ids as $post_id) { update_post_meta($post_id, "_yoast_wpseo_meta-robots-noindex", 1); $progress->tick(); } $progress->finish(); WP_CLI::success('Meta values updated successfully.'); }} WP_CLI::add_command('seo_update', 'SEO_Update_Command');}
@mgratch
mgratch / package.json
Last active February 1, 2023 22:47
Webpack setup at their project root that: Builds theme assets. Builds all blocks
{
"name": "client-plugins-and-theme",
"version": "1.0.0",
"description": "A Client Project with custom Plugins and theme.",
"main": "index.js",
"scripts": {
"build": "webpack --mode=production",
"dev": "webpack --watch",
"eslint": "eslint \"src/**/*.{js,jsx}\" --quiet",
"eslint:fix": "eslint \"src/**/_.{js,jsx}\" --quiet --fix",
@mgratch
mgratch / wc-unique-billing.php
Created June 15, 2021 21:34
Try to ensure billing company is unique when checking out or saving from myaccount.
<?php
/**
* Check for existing billing companies when updating my account data.
*
* @param WP_Error $errors Errors already added.
* @param stdClass $user Current User data.
*/
function wc_myaccount_validate_billing_company( $errors, $user ) {
@mgratch
mgratch / create-sponsor-email-links.sh
Created February 4, 2020 06:00
Create a sponsor-emails.txt file with all the sponsor emails, 1 on each row. In that same folder run this command from the terminal. This will create an html document with links that will allow you to easily open each on and email sponsors directly.
@mgratch
mgratch / functions.php
Created March 11, 2019 22:24
Use Elementor Pro & Elementor Hello Theme Customization on Attendee Registration Page with Modern Tribe Event Tickets.
<?php
/**
* Load Elementor template if available.
*
* @param $template
*
* @return string
*/
function redirect_virtual_templates_to_index( $template ) {
@mgratch
mgratch / replace-shortcodes-with-html.sh
Created August 3, 2018 16:52
Declare an array of shortcodes and replacement values, iterate over each and search and replace all instances in the DB.
declare -A array=([x-large]='h1' [large]='h2' [medium]='h3' [small]='h4' [x-small]='h5' [xx-smal]='h6');
for key in ${!array[@]};do
printf "Start [$key] Search\n";
wp search-replace "[$key]" "<${array[$key]} class='headline headline--slab headline-get-page-color'>" --all-tables --precise --recurse-objects --format=count;
printf "Start [/$key] Search\n";
wp search-replace "[/$key]" "</${array[$key]}>" --all-tables --precise --recurse-objects --format=count;
printf "Next Search\n";
done;
@mgratch
mgratch / fix-migrate-live-data-on-staging.sh
Created August 3, 2018 16:45
Bring current broken live data local and fix it run locally and enter appropriate ssh information for the live site. Make sure live is running at least wp-cli version X.X
// Bring current broken live data local and fix it
// run locally and enter appropriate ssh information for the live site.
// make sure live is running at least wp-cli version X.X
rm _live_posts_export.xml; // make sure we are starting clean
// pull the live sites posts and export them into a local xml file
wp export --post_type=post --with_attachments --stdout --ssh=vagrant@localhost/srv/www/wordpress-default/public_html > _live_posts_export.xml;
// delete all the posts off the local site (we could delete only based on guid if necessary?)
wp post delete $(wp post list --post_type='post' --post-status=all --format=ids) --force;
@mgratch
mgratch / delete-all-posts.sh
Created August 3, 2018 16:43
Delete all the posts.
// delete all the posts
wp post delete $(wp post list --format=ids) --yes