Skip to content

Instantly share code, notes, and snippets.

View n8kowald's full-sized avatar

Nathan n8kowald

  • Australia
  • 16:56 (UTC +09:30)
View GitHub Profile
@n8kowald
n8kowald / edit-post-or-page.js
Last active November 18, 2022 04:11
Edit current WordPress Post or Page
javascript:(function () {
const pageOrPostClass = Array.from(document.body.classList).filter(function (item) {
return item.includes("page-id-") || item.includes("postid-");
});
const id = pageOrPostClass.length ? pageOrPostClass[0].replace(/page-id-|postid-/, '') : 0;
if (!id) {
alert('No WordPress post found');
return;
}
let wpDomain = document.querySelector('link[rel="https://api.w.org/"]');
@n8kowald
n8kowald / functions.php
Last active March 21, 2022 21:57
If elseif else shortcode example
<?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 August 23, 2021 01:14
Tribe Tickets Plus - echo_attendee_meta
<?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 April 23, 2021 01:57
Useful WordPress Code

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 July 4, 2022 06:58
Enable Create and Update Gravity Form User Registrations
<?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 November 5, 2019 22:28
Download a full backup of a website
# --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
@n8kowald
n8kowald / font-size-detective.js
Created May 29, 2019 00:40
Font size detective
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 August 10, 2018 01:54
"Email Subscribers & Newsletters" WordPress Plugin - Add ability to subscribe/unsubscribe from backend
<?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 03:15
Bootstrap 4 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 February 5, 2019 16:38
Wordpress snippets
<?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' );