Skip to content

Instantly share code, notes, and snippets.

@ngearing
ngearing / members.php
Created August 17, 2018 01:56
Create a MemberPress Member
<?php
/**
* Create a MemberPress Member trans and subscr record to activate a user.
*
* @param int $user_id WP_User id.
* @param int $membership_id WP_Post id.
* @return void
*/
function create_memberpress_member( $user_id, $membership_id ) {
@ngearing
ngearing / filters.php
Last active August 28, 2018 04:03
WordPress add sub-menu toggle buttons to any menu.
<?php
function render_sub_menu_toggle( $item_output, $item, $depth, $args ) {
$children = false;
// If menu is using a walker.
// Walker class has children method.
if ( $args->walker->has_children ) {
$children = true;
@ngearing
ngearing / .htaccess
Created July 26, 2018 23:04
apache .htaccess https redirect
RewriteEngine On
# This will enable the Rewrite capabilities
RewriteOptions InheritDownBefore
# This prevents the rule from being overrided by .htaccess files in subdirectories.
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [QSA,R,L]
@ngearing
ngearing / managewp.php
Last active June 20, 2018 00:08
Bulk update WordPress options on ManageWP
<?php
$options = [
'theme_my_login' => [
'allow_update' => true,
'dismissed_notices' => true,
],
'wordpress_api_key' => '1', // Akismet API Key.
'akismet_comment_form_privacy_notice' => 'hide',
'akismet_strictness' => true,
@ngearing
ngearing / functions.php
Last active June 8, 2018 05:42
Get list of terms for a post.
<?php
/**
* Get an array of WP_Term objects for a post.
*
* @param integer $post_id The post id.
* @return array
*/
function get_post_terms( $post_id ) {
$terms_array = [];
@ngearing
ngearing / functions.php
Created June 8, 2018 04:31
Exclude posts from child categories on archive pages
<?php
/**
* Filter the archive posts to only display posts of the current Term not child Terms.
*
* @param WP_Query $query The query instance.
* @return void
*/
function filter_archive_posts( $query ) {
@ngearing
ngearing / functions.php
Created June 8, 2018 02:48
Add media and images to rss feed in WordPress.
<?php
/**
* Add 'Featured Image' to a rss feed.
*
* @return void
*/
function add_feed_item() {
$query = get_queried_object();
@ngearing
ngearing / functions.php
Created June 8, 2018 01:38
Remove Missing Attachment text from WordPress feed
<?php
/**
* Remove text from rss feed content and excerpt.
*
* @param string $content
* @return string
*/
function remove_feed_text( $content ) {
@ngearing
ngearing / functions.php
Last active June 8, 2018 00:05
Exclude terms in term lists from non Admins in WordPress
<?php
/**
* Exclude some terms from the term lists.
*
* @param WP_Term_Query $term_query The class instance instance.
* @return void
*/
function exclude_terms( $term_query ) {
if (
is_feed() ||
@ngearing
ngearing / wordpress-style-script-queue.php
Created February 21, 2018 00:16
List the current queue of styles and scripts for WordPress
<?php
global $wp_styles;
global $wp_scripts;
echo '<pre>' . print_r( $wp_styles->queue, true ) . '</pre>';
echo '<pre>' . print_r( $wp_scripts->queue, true ) . '</pre>';