Skip to content

Instantly share code, notes, and snippets.

@n8kowald
n8kowald / functions.php
Last active Mar 21, 2022
If elseif else shortcode example
View functions.php
<?php
// See this comment: https://www.nathankowald.com/blog/2019/06/wordpress-shortcode-if-elseif-else-statements/comment-page-1/#comment-222167
/**
* Add this code into your theme's functions.php file (or custom plugin).
*/
add_filter( 'query_vars', function( $vars ) {
// Add any other $_GET params you want to use.
$vars[] = 'paramName';
@n8kowald
n8kowald / echo_attendee_meta.php
Created Aug 23, 2021
Tribe Tickets Plus - echo_attendee_meta
View echo_attendee_meta.php
<?php
// nkowald - The only way to hide Ticket ID and Security Code is using the tribe_tickets_plus_woo_meta_data_enabled filter.
/**
* Echoes attendee meta for every attendee in selected order
*
* @since 5.2.7
*
* @param string $order_id Order or RSVP post ID.
* @param string $ticket_id The specific ticket to output attendees for.
@n8kowald
n8kowald / uwpc.md
Last active Apr 23, 2021
Useful WordPress Code
View uwpc.md

Useful SQL queries

Show how much autoload data is being used

SELECT 'autoloaded data in KiB' as name, ROUND(SUM(LENGTH(option_value))/ 1024) as value FROM wp_options WHERE autoload='yes'
  UNION SELECT 'autoloaded data count', count(*) FROM wp_options WHERE autoload='yes'
  UNION (SELECT option_name, length(option_value) FROM wp_options WHERE autoload='yes' ORDER BY length(option_value) DESC LIMIT 10);

Delete all posts from a certain post type including meta and term relationships (change CUSTOM_POST_TYPE)

@n8kowald
n8kowald / gravity-forms-user-registration.php
Last active Jun 15, 2021
Enable Create and Update Gravity Form User Registrations
View gravity-forms-user-registration.php
<?php
/**
* This class gets around a limitation of the Gravity Forms User Registration Add-On that limits you to
* one type of User Registration feed per form: Create OR Update.
* https://www.gravityforms.com/add-ons/user-registration/.
*
* We use this plugin in membership application forms.
* Membership application forms are used by both logged-in and logged-out users.
* Being able to use a Create AND Update feed allows us share one membership form.
@n8kowald
n8kowald / backup-website.sh
Created Nov 5, 2019
Download a full backup of a website
View backup-website.sh
# --mirror: Turn on options suitable for mirroring. This option turns on recursion and time-stamping, sets infinite recursion depth and keeps FTP directory listings
# --page-requisites: This option causes Wget to download all the files that are necessary to properly display a given HTML page. This includes such things as inlined images, sounds, and referenced stylesheets.
# --adjust-extension: If a file of type application/xhtml+xml or text/html is downloaded and the URL does not end with the regexp \.[Hh][Tt][Mm][Ll]?, this option will cause the suffix .html to be appended to the local filename.
# --convert-links: After the download is complete, convert the links in the document to make them suitable for local viewing. This affects not only the visible hyperlinks, but any part of the document that links to external content, such as embedded images, links to style sheets, hyperlinks to non-HTML content, etc.
wget --mirror --page-requisites --adjust-extension --convert-links https://www.website.com
View font-size-detective.js
javascript:(function () {
window.fsd = {};
const TOO_MANY_FONT_SIZES = 10;
fsd.nukeResults = () => {
let $result = document.querySelector('.fs-result');
if ($result !== null) {
$result.style.display = 'none';
}
@n8kowald
n8kowald / functions.php
Last active Aug 10, 2018
"Email Subscribers & Newsletters" WordPress Plugin - Add ability to subscribe/unsubscribe from backend
View functions.php
<?php
/* Email Subscribers & Newsletters - by Icegram (https://wordpress.org/plugins/email-subscribers)
These functions allow you to subscribe/unsubscribe a user to an email group without using a signup form. */
/**
* Subscribe a user to a given newsletter group
*
* @param $user_id
* @param $group
* @throws Exception
@n8kowald
n8kowald / responsive-embeds.css
Created May 29, 2018
Bootstrap 4 responsive embeds CSS
View responsive-embeds.css
/* Compiled CSS from Bootstrap 4's responsive embeds */
.embed-responsive {
position: relative;
display: block;
width: 100%;
padding: 0;
overflow: hidden
}
.embed-responsive::before {
display: block;
@n8kowald
n8kowald / functions.php
Last active Feb 5, 2019
Wordpress snippets
View functions.php
<?php
// --- Create a shortcode
// @Usage: [shortcode_name count="1"]
function theme_shortcode_add_name($args) {
$html = '';
$count = !empty($args['count']) ? $args['count'] : 5;
return $html;
}
add_shortcode( 'shortcode_name', 'theme_shortcode_add_name' );
@n8kowald
n8kowald / wordpress-queries.sql
Last active Nov 2, 2017
Wordpress SQL queries
View wordpress-queries.sql
-- Delete all of posts of custom post type
DELETE FROM `wp_posts` WHERE `post_type` = 'post-type';
-- Delete all unpublished of custom post type
DELETE FROM `wp_posts` WHERE `post_status` = 'draft' and `post_type` = 'post-type';