Skip to content

Instantly share code, notes, and snippets.

@pixelbart
Created February 4, 2016 08:35
Show Gist options
  • Save pixelbart/57ae65766f68ff53c7d2 to your computer and use it in GitHub Desktop.
Save pixelbart/57ae65766f68ff53c7d2 to your computer and use it in GitHub Desktop.
Simple Doku Beispiel
<?php
/**
* Plugins controller
*
* @author Kevin pliester - info@leerzeile.com
* @version 1.0
* @date Februar 03, 2016
* @date updated Feb 04, 2016
*/
namespace Controllers;
use Core\View;
use Core\Controller;
use Helpers\CustomPostType;
use Helpers\CustomMetaBox;
new Plugins;
/**
* Plugins controller showing a construct and 3 methods for Custom Post Type,
* Custom Meta Box and Custom Shortcode
*
* @author Kevin pliester - info@leerzeile.com
* @version 1.0
* @date Februar 03, 2016
* @date updated Feb 03, 2016
*/
class Plugins extends Controller
{
// Stores the custom post type
protected $cpt;
// Stores the custom meta box
protected $cmb;
// Stores the unused prefix - lol
protected $prefix = 'plugins_';
// Stores the plugins name
public $plugins_name = 'Extensions';
// Stores the plugins path
public $plugins_path;
public function __construct()
{
parent::__construct();
/**
* Create the custom post type
*/
$this->cpt = new CustomPostType(array(
'post_type_name' => 'plugins',
'singular' => __('Plugin', 'extensions'),
'plural' => __('Plugins', 'extensions'),
'slug' => 'plugins'
));
/**
* Sets a custom menu icon
*/
$this->cpt->menu_icon("dashicons-portfolio");
/**
* Construct the meta box class
*/
$this->meta_box();
/**
* Add the shortcode
*/
add_shortcode( 'plugins', array( $this, 'shortcode' ) );
// Stores the plugins path
$this->plugins_path = plugins_url( $this->plugins_name, plugin_basename( dirname( EXT_PLUGIN_PATH ) ) );
}
/**
* Create the meta box with the CutomMetaBox class
*
* @author Kevin pliester - info@leerzeile.com
* @version 1.0
* @date Februar 03, 2016
* @date updated Feb 03, 2016
*/
public function meta_box()
{
$this->cmb = new CustomMetaBox( $this->meta_box_config() );
$this->cmb->addFile($this->prefix.'plugin_file', array(
'name' => __('Plugin File', 'extensions'),
'ext' => 'zip', 'mime_type' => 'application/zip'
));
$this->cmb->addText($this->prefix.'plugin_version',array(
'name' => __('Plugin Version', 'extensions')
));
$this->cmb->addText($this->prefix.'plugin_url',array(
'name'=> __('Plugin URL', 'extensions')
));
$this->cmb->addText($this->prefix.'plugin_author',array(
'name' => __('Author', 'extensions')
));
$this->cmb->addText($this->prefix.'plugin_author_url',array(
'name' => __('Author URL', 'extensions')
));
$this->cmb->Finish();
}
/**
* Create meta box config for the meta box method
*
* @author Kevin pliester - info@leerzeile.com
* @version 1.0
* @date Februar 03, 2016
* @date updated Feb 03, 2016
*/
public function meta_box_config()
{
$config = array(
'id' => 'plugin_meta_box_fields',
'title' => __('Plugin Fields', 'extensions'),
'pages' => array('plugins'),
'context' => 'normal',
'priority' => 'high',
'fields' => array(),
'local_images' => false,
'use_with_theme' => false
);
return $config;
}
/**
* Create shortcode to display the plugins in the frontend
*
* @author Kevin pliester - info@leerzeile.com
* @version 1.0
* @date Februar 03, 2016
* @date updated Feb 03, 2016
*/
public function shortcode( $atts, $content = null )
{
/**
* Shortcode functions
*/
$a = shortcode_atts( array(
'cover' => null,
'order' => 'ASC',
'orderby' => 'title',
'count' => -1,
), $atts );
/**
* Settings for the query
*/
$args = array(
'post_type' => 'plugins',
'post_status' => 'publish',
'orderby' => $a['orderby'],
'order' => $a['order'],
'posts_per_page' => $a['count'],
);
// Store the WP_Query in an array for the frontend
$temp = $data['plugins'];
$data['plugins'] = null;
$data['plugins'] = new \WP_Query();
$data['plugins']->query($args);
/**
* Render frontend view for plugins
*/
View::render('frontend/plugins', $data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment