Skip to content

Instantly share code, notes, and snippets.

View mathetos's full-sized avatar
💭
Working on @impress-org Stuff

Matt Cromwell mathetos

💭
Working on @impress-org Stuff
View GitHub Profile
@mathetos
mathetos / plugin.php
Created May 20, 2014 03:12
FooBox V2 or Free check and notice
<?php
/*
* This checks whether either version of FooBox --
* Free or Premium -- is activated. If not, it throws
* An admin notification, only for users who can
* activate plugins.
*/
function fooboxnotpresent_admin_notice() {
if ( class_exists('Foobox_Free') || class_exists('fooboxV2')) {
@mathetos
mathetos / gist:6c4d3dc77ee3591e0a74
Created July 22, 2014 04:45
Admin Enqueue Iris.js
<?php
function load_mc_iris() {
if (wp_script_is( 'iris', 'enqueued' )) {
return; // if it's already enqueued, don't enqueue it again.
} else { // since it's NOT enqueued, let's enqueue it
wp_enqueue_script(
'iris', //iris.js handle
admin_url( 'js/iris.min.js' ), //path to wordpress iris file
@mathetos
mathetos / imagelens-image-class.php
Last active August 29, 2015 14:05
Change image class if meta field available
<?php
add_filter('get_image_tag_class', 'add_imagelens_frames', 0, 4);
function add_imagelens_frames($classes, $id) {
$singlelens = get_post_meta( $id, '_enable_lens', true );
if ($singlelens === 'imagelens-single') {
return $classes . ' ' . $singlelens;
} else {
@mathetos
mathetos / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mathetos
mathetos / plugin-activation
Last active August 29, 2015 14:11
Plugin Redirect on Activation
function detect_plugin_activation( $plugin ) {
if( $plugin == 'path-to-my-plugin') {
wp_redirect("options-general.php?page=my-plugin-settings-page");
exit;
} else {}
}
add_action( 'activated_plugin', 'detect_plugin_activation', 10, 2 );
@mathetos
mathetos / give-centered-styles.css
Last active October 26, 2015 23:35
Give Center Form Styles
div[class*="give-form-wrap"] {
text-align: center;
}
.give-total-wrap,
#give-final-total-wrap {
display: inline-block;
margin: 0 auto;
}
@mathetos
mathetos / gist:8078647
Last active January 1, 2016 02:19
List WP Categories by First Letter
<?php
$args = array(
'orderby' => 'name',
'parent' => 0,
'order' => DESC
);
$categories = get_categories( $args );
$curr_letter = '';
foreach ( $categories as $category ) {
$this_letter = strtoupper(substr($category->name,0,1));
@mathetos
mathetos / gist:8078693
Created December 22, 2013 05:08
3 factor Featured Image Fallback in WordPress
/*
* This code allows your posts to have a fallback featured image based on your category.
* It requires manual upload of the featured images. In this case it assumed /category-images to have
* been created in the root WP install directory.
* It is based on this tutorial at WPBeginner:
* http://www.wpbeginner.com/wp-themes/set-fallback-featured-image-based-post-category-wordpress/
* The original tutorial assumed all categories have a featured image.
* This codes inserts a div (to be styled) when there is also no featured image for the category.
* Nathan Briggs was instrumental in implementation of the file_exists method.
*/
@mathetos
mathetos / smart-excerpts
Last active May 17, 2016 19:43
Smart Excerpts
<?php
/*
* This asks first for a Yoast SEO meta description,
* If that's not present, then it asks for the excerpt of the post,
* If that's not present, then it strips the content
* In this case, I have an excerpt length setting in the Customizer
* Both the excerpt and content stripping, also strip shortcodes
* @author Matt Cromwell <reachme@mattcromwell.com>
* @copyright Copyright (c) 2014, Matt Cromwell
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
@mathetos
mathetos / functions.php
Created June 28, 2016 17:58
Custom Autopopulate Dropdown for CalderaForms
add_filter( 'caldera_forms_autopopulate_options_post_value_field', 'givewp_customer_addon_purchases', 24, 2 );
function givewp_customer_addon_purchases()
{
$current_user = wp_get_current_user();
$purchases = edd_get_users_purchases($current_user->user_email, 100, false, 'any');
if ( $purchases ) {
foreach ($purchases as $purchase) {
$licenses = edd_software_licensing()->get_licenses_of_purchase( $purchase->ID );