metaBox = $args;
$this->metaBox['args']['btn_txt'] = isset( $this->metaBox['args']['btn_txt'] ) ? $this->metaBox['args']['btn_txt'] : 'Upload Media';
if ( $this->metaBox['args']['type'] == 'media' ) {
$this->metaBox['args']['frame_title'] = isset( $this->metaBox['args']['frame_title'] ) ? $this->metaBox['args']['btn_txt'] : 'Select Media';
$this->metaBox['args']['multiple'] = isset( $this->metaBox['args']['multiple'] ) ? $this->metaBox['args']['multiple'] : false;
$this->metaBox['args']['preview'] = isset( $this->metaBox['args']['preview'] ) ? $this->metaBox['args']['preview'] : false;
if ( !isset( $this->metaBox['args']['display'] ) || !( $this->metaBox['args']['display'] == 'filename' || $this->metaBox['args']['display'] == 'id' ) ) {
$this->metaBox['args']['display'] = 'id';
}
$this->dataArr = $this->metaBox['args'];
unset( $this->dataArr['desc'] );
unset( $this->dataArr['type'] );
}
add_action( 'add_meta_boxes_' . $this->metaBox['postType'], array( $this, 'createMetaBox' ) );
add_action('save_post', array($this,'saveMetaBox'));
if ( $this->metaBox['args']['type'] == 'media' ) {
add_action( 'add_meta_boxes_' . $this->metaBox['postType'], array( $this, 'enqueueMediaScripts' ) );
}
}
public function enqueueMediaScripts() {
wp_enqueue_media();
wp_enqueue_script( 'bytephp-media-scripts', ARCADEREADY_PLUGIN_URL . '/admin/js/bytephp-media-scripts.js' );
$this->dataArr['postID'] = $this->metaBox['postID'];
wp_localize_script( 'bytephp-media-scripts', 'bytephp_mo_' . $this->metaBox['id'], $this->dataArr );
}
public function createMetaBox( $post )
{
$this->metaBox['postID'] = $post->ID;
add_meta_box(
$this->metaBox['id'],
__( $this->metaBox['title'], 'arcade-ready-tr' ),
array( $this, 'renderMetaBox' ),
$this->metaBox['postType'],
isset( $this->metaBox['context'] ) ? $this->metaBox['context'] : 'normal',
isset( $this->metaBox['priority'] ) ? $this->metaBox['priority'] : 'default',
$this->metaBox['args']
);
}
public function renderMetaBox( )
{
$postMeta = get_post_meta( $this->metaBox['postID'], $this->metaBox['id'], true );
if ( isset( $this->metaBox['args']['dataprocess'] ) && $this->metaBox['args']['dataprocess'] == 'base64' ) {
$postMeta = base64_decode( $postMeta );
}
switch( $this->metaBox['args']['type'] )
{
case 'textfield':
wp_nonce_field( array( $this, 'saveMetaBox' ), $this->metaBox['id'] . '_nonce' );
echo '' . $this->metaBox['args']['desc'] . '
';
break;
case 'textarea':
wp_nonce_field( array( $this, 'saveMetaBox' ), $this->metaBox['id'] . '_nonce' );
echo '' . $this->metaBox['args']['desc'] . '
';
break;
case 'checkbox':
wp_nonce_field( array( $this, 'saveMetaBox' ), $this->metaBox['id'] . '_nonce' );
echo '' . $this->metaBox['args']['desc'] . '
';
break;
case 'fileupload':
wp_nonce_field( array( $this, 'saveMetaBox' ), $this->metaBox['id'] . '_nonce' );
echo 'Current File:' . $postMeta . '' . $this->metaBox['args']['desc'] . '
';
break;
case 'media':
wp_nonce_field( array( $this, 'saveMetaBox' ), $this->metaBox['id'] . '_nonce' );
if ( isset( $this->metaBox['args']['preview'] ) && $this->metaBox['args']['preview'] == true ) {
$mediaList = '';
foreach ( explode( ',', $postMeta ) as $img )
{
$imageSrc = wp_get_attachment_image_src( $img, 'large' );
if ( $imageSrc !== false ) {
$mediaList .= '