Skip to content

Instantly share code, notes, and snippets.

View joelworsham's full-sized avatar

Joel Worsham joelworsham

View GitHub Profile
@joelworsham
joelworsham / gist:ca39eeacace703c368a4
Last active January 11, 2016 00:49
PHP Version Check
<?php
...
if ( version_compare( '5.3', phpversion(), '>' ) ) {
add_action( 'admin_notices', '_myplugin_php_notice' );
// Do what you need to stop your plugin from loading
}
/**
* Displays an admin error about needing to update the server's PHP version.
@joelworsham
joelworsham / dynamic-shortcode-scripts-pt1.php
Created January 30, 2015 16:43
Dynamic Shortcode Scripts
<?php
// Add our action
add_action( 'wp_enqueue_scripts', 'joelworsham_add_shortcode_styles' );
/**
* Dynamically calls scripts and styles based on the presence
* of shortcodes in the post content.
*/
function joelworsham_add_shortcode_styles() {
@joelworsham
joelworsham / extension-ideas.txt
Last active August 29, 2015 14:14
Render Extension Ideas
Extension:
Paypal
Shortcode Templates
Stylebox for TinyMCE
Custom shortcode creater (integrates directly into the modal, maybe)
Integration:
WooCommerce
Gravity Forms
Mini Loops
@joelworsham
joelworsham / add_to_logic.php
Last active August 29, 2015 14:13
Render: Add options to the Logic shortcode.
<?php
/**
* First, we need to actually add our new options to each selectbox.
*/
add_filter( 'render_att_pre_loop', function( $atts, $code ) {
// Make sure we only do this for the Logic shortcode
if ( $code == 'render_logic' ) {
// Here's an option for the first argument
@joelworsham
joelworsham / easy-register-post-type.php
Created January 2, 2015 16:57
Easy Register Post Type
<?php
/**
* Easy way to register a new post type!
*
* Example: easy_register_post_type( 'book', 'Book', 'Books', array( 'menu_icon' => 'dashicons-book' ) );
*
* @param string $name The name of the post type (not the label, must be lowercase and no spaces or dashes).
* @param string $label The label of the post type. This is public facing.
* @param string $label_plural The plural version of the label.
* @param array $_args An array of args to overwrite or add to the register_post_type() args.
@joelworsham
joelworsham / chosen-custom-input.js
Created November 25, 2014 16:22
Chosen Custom Input
// Apply Chosen
var $chosen = $('.chosen'),
container = '.container-class';
$chosen.chosen();
// Extend functionality to allow custom text input (if enabled on input)
if ($chosen.hasClass('allow-custom-input')) {
// When hiding the dropdown (submitting the field), use our custom input
@joelworsham
joelworsham / package.json
Created November 19, 2014 15:34
A basic package.json file for a WordPress plugin.
{
"name": "ProjectName",
"version": "1.0.0",
"description": "This plugin is incredible.",
"repository": {
"type": "git",
"url": "https://github.com/username/repository"
},
"author": "Thats you!",
"license": "GPLv2 or later",
@joelworsham
joelworsham / Gruntfile.js
Last active August 29, 2015 14:09
A basic Gruntfile for a WordPress plugin
'use strict';
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
// Define the package
pkg: grunt.file.readJSON('package.json'),
@joelworsham
joelworsham / SassMeister-input.scss
Created October 21, 2014 12:43
Generated by SassMeister.com.
// ----
// Sass (v3.4.6)
// Compass (v1.0.1)
// ----
@mixin icon($icon, $top, $left, $color, $atts: null) {
.icon-#{$icon} {
top: $top;
left: $left;