Skip to content

Instantly share code, notes, and snippets.

@lucprincen
Last active December 18, 2015 23:29
Show Gist options
  • Select an option

  • Save lucprincen/5861817 to your computer and use it in GitHub Desktop.

Select an option

Save lucprincen/5861817 to your computer and use it in GitHub Desktop.
Preview of a simple Portfolio-plugin for Cuisine...
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* init the plugin:
*/
add_action( 'init', 'chef_portfolio_init', 10 );
function chef_portfolio_init(){
//check if Cuisine is running:
if( class_exists( 'Cuisine' ) ){
global $cuisine;
//add the taxonomy:
$cuisine->taxonomies->register(
'portfolio-categories', // name
'portfolio/category', // slug
'portfolio', // post-type
'Portfolio category', // singular name
'Portfolio categories' // plural name
);
//add the post_type:
$cuisine->posttypes->register(
'portfolio', // post_type
'Portfolio item', // singular name
'Portfolio items', // plural name
null, // slug (defaults to post_type )
array( 'title', 'editor', 'thumbnail' ) // capabilities, defaults to title, editor + thumbnail
);
//add the redirects:
$cuisine->plugins->register_template_redirect(
'portfolio', // slug
'post_type', // type (post_type or page)
'portfolio' // post_type to link to
);
// the redirect function defaults to {SLUG}.php and {SLUG}-single.php for template files.
}
}
/**
* add the meta_box:
*/
add_action( 'admin_init', 'chef_portfolio_admin_init');
function chef_portfolio_admin_init(){
//check if Cuisine is running:
if( class_exists( 'Cuisine' ) ){
//use the general Cuisine media-metabox
cuisine_media_init( 'portfolio', array( 'image', 'video' ) ); // post type, media-item types (image / video / text)
}
}
/**
* Get the portfolio media items:
*/
function chef_portfolio_get_media(){
return get_post_meta( cuisine_get_post_id(), 'portfolio_media', true );
}
/**
* Get the plugin URL:
*/
function chef_portfolio_plugin_url(){
$full_path = plugin_dir_url(__FILE__);
return substr( $full_path, 0 , -1 ); //strip the trailing slash
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment