Skip to content

Instantly share code, notes, and snippets.

View hearvox's full-sized avatar

Barrett Golding hearvox

View GitHub Profile
@hearvox
hearvox / wp-jp-downloads-form.php
Last active March 16, 2018 14:19
WordPress: Use Jetpack's Contact form to protect download links by providing links in form's success message.
<?php
/**
* Use Jetpack's Contact form to provide download links (in success message).
*
* Filter the Jetpack Contact Form's message returned after a successful submission.
* Put download links in a custom field to display in success message.
*
* @param string $r_success_message Success message.
* @return string $r_success_message Success message.
*/
@hearvox
hearvox / wp_email_antispam_shortcode.php
Created February 24, 2018 20:12
WordPress: Shortcode to hide email address from Spam Bots
<?php
/**
* Shortcode to hide email address from Spam Bots.
*
* Example: [email]me@mysite.com[/email]
*
* @uses antispambot() Wordpress native function
*
* @param array $atts Shortcode attributes. Not used.
@hearvox
hearvox / wp_posts_without_keyword.php
Last active February 8, 2018 17:35
Find WordPress posts that don't contain a specific search term.
<?php
/* Get IDs of posts with content that doesn't contain a search term. */
$keyword = 'search term here';
$max_posts = 400; // More than the total number of posts.
$query_ids = new WP_Query( array( 'post_type' => 'post', 'fields' => 'ids', 'posts_per_page' => $max_posts ) );
$query_search = new WP_Query( array( 'post_type' => 'post', 'fields' => 'ids', 'posts_per_page' => $max_posts, 's' => $keyword ) );
$ids_not_found = array_diff( $query_ids->posts, $query_search->posts );
sort( $ids_not_found );
print_r( $ids_not_found );
@hearvox
hearvox / wp_make_related_posts_from_content_links.php
Last active February 8, 2018 17:34
Get site links in WordPress post content to use as related posts.
@hearvox
hearvox / wp-yoast-hooks.php
Last active March 6, 2021 13:02
Hooks to disable Yoast SEO plugin features and admin screen controls.
<?php
/*******************************
=Yoast SEO Hooks (includes Premium)
******************************/
/* Remove default redirects feature, for posts and term.
* @link https://kb.yoast.com/kb/how-to-disable-automatic-redirects/
*/
add_filter('wpseo_premium_post_redirect_slug_change', '__return_true' );
add_filter('wpseo_premium_term_redirect_slug_change', '__return_true' );
@hearvox
hearvox / wp-audio-custom.php
Last active February 8, 2018 17:31
Customizations for default WordPress audio shortcode and embed.
<?php
/**
* Change attribute for WP audio shortcode and embed.
*
* Default preload attribute is 'none' which shows time as 'O:OO'.
* Setting attribute to 'metadata' displays time upon page load.
*
* @param string $html Default audio shortcode HTML output.
* @return string $html Filtered audio shortcode HTML output.
*/
<ol>
<?php
/* Remove duplicate meta, in this case Author and Contact (custom tax) */
// Get all posts assigned a term in a specific custom taxonomy.
$tax = 'contact';
$args = array(
'post_type' => 'post',
'posts_per_page' => 1000,
'orderby' => 'ID',
@hearvox
hearvox / advent-calendar.php
Created November 8, 2017 23:13
Advent calender displays one new audio piece per day
<?php
/*
* Display a new item every day of current month (like an Advent calendar).
* If day has arrived: display the article HTML.
* If day hasn't arrived, print default HTML.
* Restrict numbers to total days in current month.
*
* Compares an array's key (day number) to current day of month.
* Made for Hearing Voices page "Xmas: HV Holiday Stories" (2016).
@hearvox
hearvox / php-checks.php
Created October 25, 2017 14:23
Checking php extensions, functions, version, etc.
<?php
echo $check_fn = ( function_exists( 'http_parse_message' ) ) ? 'yo' : 'no';
echo ' ';
echo $check_ext = ( extension_loaded( 'pecl_http' ) ) ? 'yo' : 'no';
if ( class_exists('My_Class') ) {
$my_class = new My_Class();
}
echo 'Current PHP version: ' . phpversion();
@hearvox
hearvox / wp-admin-urls.md
Last active May 1, 2024 12:04
WordPress admin URLs.

Admin or login to a site:
/admin
For some webhosts, inc. Media Temple:
/wp-admin

All Settings list (wp_options database table):
/wp-admin/options.php

Jetpack modules settings (old admin page):
/wp-admin/admin.php?page=jetpack_modules