/libguides plugin concept Secret
Created
September 26, 2014 14:27
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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