Skip to content

Instantly share code, notes, and snippets.

View mhull's full-sized avatar

Michael Hull mhull

View GitHub Profile
@mhull
mhull / .Autoload.php
Last active March 31, 2018 13:28
Demonstrates how to autoload classes in PHP, so that we don't have to explicitly require each file for each class used within our code
<?php
/**
* Uses the `spl_autoload_register` function to autoload classes so that we don't have to
* explicitly require each file for each class we use in our code
*/
<?php
/**
* The `Helping_Friendly_Post` class is an exercise in thinking about extending the `WP_Post` class
*
* @see https://github.com/mhull/helping-friendly-plugin/blob/master/lib/class-hphp-post.php
*/
/**
* To get a new extended post by ID
*/
@mhull
mhull / .WordPress-Using-hooks.php
Last active June 5, 2016 12:13
Code examples from my Asheville WordCamp 2016 talk entitled "Using Hooks (and creating your own)"
<?php
/**
* Attempting to register a post type within a plugin, without using a hook,
* results in a fatal error
*/
$args = array(
... etc ...
);
register_post_type( 'my_post_type', $args );
@mhull
mhull / Members_manage_roles_items.php
Last active May 25, 2016 23:24
Filter roles list in the Members plugin
<?php
/**
* Filter the roles table items on the Users > Roles screen
*
* @param array $roles List of role "slugs" being shown in the table
* @param string $role_view View type for current screen (e.g. all, mine, active, etc)
*
* @return array The filtered $roles array
*/
add_filter( 'members_manage_roles_items', 'my_manage_roles_items', 10, 2 );
@mhull
mhull / Draggable.html
Last active October 13, 2017 05:02
Draggable elements that have been styled to indicate draggability to users
<!-- CSS Stylesheet -->
<link rel='stylesheet' type='text/css' href='css/draggable.css' />
<!-- The things we are dragging -->
<div class='thing'><label>Thing 1</label></div>
<div class='thing'><label>Thing 2</label></div>
<div class='thing'><label>Thing 3</label></div>
<!-- jQuery and jQuery-UI -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>