Skip to content

Instantly share code, notes, and snippets.

Created September 26, 2014 14:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
class MySortingPluginClass{
//The $page_data variable is passed in through the hook system and contains page content data
public function sort_boxes( $page_data ){
usort( $page_data["boxes"], "sort_boxes_by_title");
return $page_data;
//This method is called by usort() above and sorts boxes by comparing the title string of two boxes
private function sort_boxes_by_title( $box_a, $box_b ){
strnatcmp( $box_a["title"], $box_b["title"] );
//Register the plugin with the on_page_load hook. "MySortingPluginClass" tells the hook system which class to initialize,
//"sort_boxes" is the method to call, and "on_page_load" is the name of the hook, which controls what data
//to pass into the function and what to expect back (in this case, an associative array of page data).
register_plugin( "MySortingPluginClass", "sort_boxes", "on_page_load" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment