Last active
July 4, 2016 19:22
-
-
Save pablo-sg-pacheco/743802ff697315fc0f937c2ce852cff9 to your computer and use it in GitHub Desktop.
CMB2 - Classe para criar uma galeria padrão, usando CMB2
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 | |
namespace OOPFunctions\MetaBoxes\Gallery; | |
if ( !class_exists('\OOPFunctions\MetaBoxes\Gallery\Gallery') ) { | |
/** | |
* Description of Gallery | |
* | |
* @author Pablo Pacheco <pablo.pacheco@origgami.com.br> | |
*/ | |
class Gallery { | |
private $id = 'gallerycmb'; | |
/** | |
* | |
* @var Metas | |
*/ | |
private $metas; | |
public function __construct() { | |
$this->setMetas(new Metas()); | |
add_action('cmb2_admin_init', array($this, 'addCmb')); | |
} | |
public function addCmb() { | |
/** | |
* Sample metabox to demonstrate each field type included | |
*/ | |
$cmb_demo = new_cmb2_box(array( | |
'id' => $this->getId(), | |
'title' => __('Galeria', 'cmb2'), | |
'object_types' => array('page',), // Post type | |
'show_on' => array('key' => 'page-template', 'value' => 'page-templates/santo-gostinho.php'), | |
)); | |
$cmb_demo->add_field(array( | |
//'name' => __('Test Text', 'cmb2'), | |
//'desc' => __('field description (optional)', 'cmb2'), | |
'id' => $this->getMetas()->fileList, | |
'type' => 'file_list', | |
'preview_size' => array(130, 130), // Default: array( 50, 50 ) | |
)); | |
} | |
function getId() { | |
return $this->id; | |
} | |
function getMetas() { | |
return $this->metas; | |
} | |
function setId( $id ) { | |
$this->id = $id; | |
} | |
function setMetas( Metas $metas ) { | |
$this->metas = $metas; | |
} | |
} | |
class Metas { | |
public $fileList = 'gal_filelist'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment