Skip to content

Instantly share code, notes, and snippets.

View tradesouthwest's full-sized avatar
Working remotely

Larry tradesouthwest

Working remotely
View GitHub Profile
@tradesouthwest
tradesouthwest / noncetest.php
Created January 6, 2019 02:07
use snippet to test for ajax or admin referer nonce
function tradesouthwest_nonce_test()
{
do_action( 'check_admin_referer', $action, $result);
if( !$result && ! ( -1 == $action && strpos( $referer, $adminurl ) === 0 ) ) {
wp_nonce_ays( $action );
die();
}
return $result;
}
@tradesouthwest
tradesouthwest / wp_custom_search_query.php
Created February 22, 2019 03:55
modifies the main WordPress query to include an array of post types
<?php
/**
* This function modifies the main WordPress query to include an array of
* post types instead of the default 'post' post type.
*
* @param object $query The original query.
* @return object $query The amended query.
*/
function trunkline_custom_search_query( $query ) {
@tradesouthwest
tradesouthwest / maybe-show-nickname.php
Created February 25, 2019 23:51
Only show nickname if not admin in a wordPress plugin
<?php
/**
* Only show nickname if not admin
*
* @since 1.0.0
*
* TODO option to toggle
*/
function vertycal_maybe_show_nickname( $author )
{
@tradesouthwest
tradesouthwest / list-all-plugins.php
Created March 4, 2019 00:53
This snippet adds a shortcode to wordpress which will list all plugins in your wordpress plugins folder
<?php
// Check if get_plugins() function exists. This is required on the front end of the
// site, since it is in a file that is normally only loaded in the admin.
// This snippet adds a shortcode to wordpress which will list all plugins
function tradesouthwest_custom_listtall_plugins()
{
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
@tradesouthwest
tradesouthwest / wcmp-remove-qvon-vacation.php
Last active March 26, 2019 21:29
Woocommerce remove quick view button if vendor on vacation.
<?php
/**
* Footer script to remove quick view button if vendor on vacation.
* @param script
* @author Larry Judd | Tradesouthwest
* The first one works the best across all browsers. The other two are for testing against other plugins.
*/
/*
* If you use the .css combinator method add this to CSS stylesheet:
******************************************************************
@tradesouthwest
tradesouthwest / wp_selected-dropdown.php
Last active April 1, 2019 00:47
wordpress use selected in a dropdown list for custom post type
<?php
/**
* Demonstration uses all cpt posts in a dropdown field to select
* a featured listings to callback in a function
* @param $wpselected_ string References a plugin option Setting.
*/
function wpselected_featured_listing_cb()
{
$post_type = 'wpselected_post';
@tradesouthwest
tradesouthwest / meta-box-select-dropdown.php
Last active April 1, 2019 00:43
wp select options dropdown for meta box
<?php
/**
* Add meta box to editor
*
* @strings $id, $title, $callback, $screen, $context, $priority, $args
* function's action_added in register cpt
*/
function vertycal_date_time_meta_box()
{
add_meta_box(
@tradesouthwest
tradesouthwest / php-version-stop.php
Created April 1, 2019 16:47
prevents theme activation on a server that's PHP version is below 5.6.
<?php
/**
* Set a constant that holds the theme's minimum supported PHP version.
*/
define( 'THEMESLUG_MIN_PHP_VERSION', '5.6' );
/**
* Immediately after theme switch is fired we we want to check php version and
* revert to previously active theme if version is below our minimum.
<?php
/**
* This code retrieves course data from an external API and displays it in the user's
* My Account area. A merchant has noticed that there's a delay when loading the page.
*
* 1) What changes would you suggest to reduce or remove that delay?
* 2) Is there any other code changes that you would make?
*/
//improvements
/**
@tradesouthwest
tradesouthwest / user-meta-list.php
Created May 6, 2019 20:12
Shortcode to print all user meta on a wordpress page.
<?php
/**
* Get list of all user meta
* @package WordPress
* @uses shortcode [bnsw_userprint="user_id"] Or whatever name you register
*/
function bnswfields_user_list_meta($atts)
{
if ( !isset( $atts['user_id'] ) ){