From: Steve Sutton Date: Wed, 14 Jan 2015 16:27:39 +0000 (-0500) Subject: Refractor the glm-blocks plugin X-Git-Tag: v1.1.1^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=727d5aedb48652b318d3699ae485fe4549543611;p=WP-Plugins%2Fglm-blocks.git Refractor the glm-blocks plugin You can now call the fetch_all_glm_blocks function to fetch all the glm blocks from the CPT. Use the returned array to output the blocks in whatever format you like. Backward compatible with Preston Feathers original plugin in use. --- diff --git a/controllers/front.php b/controllers/front.php index ce18541..0d7de0b 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -10,6 +10,12 @@ defined('ABSPATH') or die(); class glm_blocks_front { + /** + * pluginDirName + * + * @var mixed + * @access public + */ public $pluginDirName; /** @@ -20,9 +26,27 @@ class glm_blocks_front $this->pluginDirName = $path; } + /** + * Display the blocks + * + * Used in Preston feather it uses a default template to output the fetchAllBlocks + */ public function showBlocks() { $block = new glm_models_block($this->pluginDirName); $block->displayBlocks(); } + + /** + * Fetches the blocks into an array + * + * Now you can control how the block is output + * + * @return array + */ + public function fetchAllBlocks() + { + $block = new glm_models_block($this->pluginDirName); + return $block->fetchAllBlocks(); + } } diff --git a/glm-blocks.php b/glm-blocks.php index 35871ea..dabdc69 100644 --- a/glm-blocks.php +++ b/glm-blocks.php @@ -43,3 +43,13 @@ if (!function_exists('glm_blocks_show')) { $frontController->showBlocks(); } } + +if (!function_exists('fetch_all_glm_blocks')) { + function fetch_all_glm_blocks() + { + $frontController = new glm_blocks_front( + plugin_dir_path(__FILE__) + ); + return $frontController->fetchAllBlocks(); + } +} diff --git a/models/block.php b/models/block.php index c0baf44..144cbc0 100644 --- a/models/block.php +++ b/models/block.php @@ -1,10 +1,32 @@ + * @license PHP Version 5.5 {@link http://www.php.net/license/3_0.txt} + */ class glm_models_block { + /** + * pluginDirName + * + * @var mixed + * @access public + */ public $pluginDirName; + /** + * __construct + * + * @param mixed $path + * @access public + * @return void + */ public function __construct($path) { $this->pluginDirName = $path; @@ -17,6 +39,13 @@ class glm_models_block add_action('pre_get_posts', array($this, 'sortQuery')); } + /** + * sortQuery + * + * @param mixed $query + * @access public + * @return void + */ public function sortQuery($query) { if (is_admin() && !isset($_REQUEST['orderby'])) { @@ -68,6 +97,12 @@ class glm_models_block register_post_type(GLM_BLOCK_POST_TYPE, $args); } + /** + * addMetaBoxes + * + * @access public + * @return void + */ public function addMetaBoxes() { add_meta_box( @@ -79,6 +114,13 @@ class glm_models_block ); } + /** + * metaBoxCallBack + * + * @param mixed $post + * @access public + * @return void + */ public function metaBoxCallBack($post) { $glm_block_url = ($post) @@ -93,6 +135,13 @@ class glm_models_block include $this->pluginDirName . 'views/admin/metaBoxes.php'; } + /** + * saveMetaBox + * + * @param mixed $post_id + * @access public + * @return void + */ public function saveMetaBox($post_id) { global $post; @@ -118,7 +167,13 @@ class glm_models_block update_post_meta($post->ID, 'glm_block_page', $_POST['glm_block_page']); } - public function displayBlocks() + /** + * fetchAllBlocks + * + * @access public + * @return void + */ + public function fetchAllBlocks() { global $wpdb, $wp; $args = array( @@ -129,7 +184,7 @@ class glm_models_block $blocks = get_posts($args); foreach ($blocks as $block) { $block->externalUrl = false; - $custom = get_post_custom($block->ID); + $custom = get_post_custom($block->ID); if ($custom['glm_block_url'][0] == 'page') { $block->url = get_permalink($custom['glm_block_page'][0]); } @@ -141,6 +196,23 @@ class glm_models_block $block->externalUrl = true; } } + $block->thumbnail = get_the_post_thumbnail( + $block->ID, GLM_BLOCK_POST_TYPE, array('class' => 'aligncenter') + ); + } + return $blocks; + } + + /** + * displayBlocks + * + * @access public + * @return void + */ + public function displayBlocks() + { + $blocks = $this->fetchAllBlocks(); + foreach ($blocks as $block) { $block->thumbnail = get_the_post_thumbnail( $block->ID, array(298, 228), array('class' => 'aligncenter') ); @@ -148,12 +220,26 @@ class glm_models_block include $this->pluginDirName . 'views/front/showBlocks.php'; } + /** + * addOrderColumn + * + * @param mixed $header_text_columns + * @access public + * @return void + */ function addOrderColumn($header_text_columns) { $header_text_columns['menu_order'] = "Order"; return $header_text_columns; } + /** + * showOrderColumn + * + * @param mixed $name + * @access public + * @return void + */ function showOrderColumn($name) { global $post; @@ -166,6 +252,14 @@ class glm_models_block break; } } + + /** + * orderSortable + * + * @param mixed $columns + * @access public + * @return void + */ function orderSortable($columns) { $columns['menu_order'] = 'menu_order';