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 / 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 / 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 / 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 / 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 / memberpress-subscr-dropdown.php
Created November 29, 2018 18:35
Memberpress gets all products to put in dropdown in admin settings page
<?php
//gets all products to put in dropdown in admin settings page
function meprprorata_products_dropdown_cb($args, $access= array())
{
//$available = new MeprCouponsHelper::products_dropdown();
$access = is_array($access) ? $access : array();
$contents = array();
$posts = MeprCptModel::all('MeprProduct');
@tradesouthwest
tradesouthwest / learndash-code-in-answer.php
Created November 18, 2018 04:02
LearnDash cloze answer accept case sensitive
<?php
/**
* LearnDash filter to prevent converting answer values to lowercase
*
* @possibly use ld_adv_quiz_pro_ajax()
* @uses stripslashes( strtolower( trim( $userResponse ) ) ) Default
* @since 1.0
* @from WpProQuiz_View_FrontQuiz.php
* post_type=sfwd-quiz
*/
@tradesouthwest
tradesouthwest / retrieve-id-of-post-from-any-meta.php
Last active November 12, 2018 17:52
Retrieve post id from any meta field
<?php
//From: https://github.com/oyina/Note-Taker/blob/master/note.php
//Retreives Post Id from Meta Key
function get_post_id_by_meta_key_and_value($key, $value) {
global $wpdb;
$meta = $wpdb->get_results("SELECT * FROM `".$wpdb->postmeta."` WHERE meta_key='".$wpdb->escape($key)."'
AND meta_value='".$wpdb->escape($value)."'");
if (is_array($meta) && !empty($meta) && isset($meta[0])) {
$meta = $meta[0];
}
@tradesouthwest
tradesouthwest / wp-gettext-example.php
Created October 28, 2018 01:45
gettext example for wordpress to replace translated text
add_filter( 'gettext', 'misha_change_text_with_gettext', 20, 3 );
function misha_change_text_with_gettext( $translated_text, $text, $domain ) {
if ( is_admin()
&& isset($_GET['post'])
&& get_post_type( $_GET['post'] ) == 'shop_order'
&& $domain == 'woocommerce' ) {
if( $translated_text == 'Shipping' ) {
<?php
/**
* Get all blog ids of blogs in the current network that are:
* - not archived
* - not spam
* - not deleted
*
*
* @return array|false The blog ids, false if no matches.
*/
/**
* print custom post type category list
* @cpt name= hordes
* @taxonomy name= hordes-category
*/
if ( ! function_exists( 'theme_entry_footer_cat_list' ) ) :
function theme_entry_footer_cat_list() {
// Get custom taxonomy project_category for each specific CPT
if ( 'hordes' === get_post_type() ) {