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 .= '
  • '; } } echo ''; } // find filename for if ( $this->metaBox['args']['display'] == 'filename' ) { $filenames = array(); $attachments = explode( ',', $postMeta ); foreach ( $attachments as $attachment ) { $filenames[] = basename( get_attached_file( $attachment ) ); } $displayValue = implode( ',', $filenames ); } else { $displayValue = $postMeta; } echo '
    ' . $this->metaBox['args']['desc'] . '
    '; break; } } public function saveMetaBox( $post ) { if ( ! isset( $_POST[$this->metaBox['id'] . '_nonce'] ) ) { return; } if ( ! wp_verify_nonce( $_POST[$this->metaBox['id'] . '_nonce'], array( $this, 'saveMetaBox' ) ) ) { return; } if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) { if ( ! current_user_can( 'edit_page', $post ) ) { return; } } else { if ( ! current_user_can( 'edit_post', $post ) ) { return; } } if ( ! isset( $_POST[$this->metaBox['id']] ) ) { return; } if ( isset( $this->metaBox['args']['dataprocess'] ) && $this->metaBox['args']['dataprocess'] == 'base64' ) { $my_data = base64_encode( stripslashes( $_POST[ $this->metaBox['id'] ] ) ); } else { $my_data = sanitize_text_field( $_POST[$this->metaBox['id']] ); } $output = update_post_meta( $post, $this->metaBox['id'], $my_data ); } } $args = array( 'id' => 'ar_gameInst', 'title' => __( 'Game Instructions', 'arcade-ready-tr' ), 'postType' => 'ar_games', 'context' => 'normal', 'priority' => 'high', 'args' => array( 'desc' => __( 'Enter instructions on how to play the game.', 'arcade-ready-tr' ), 'type' => 'textarea', ) ); new ArcadeReady_MetaHandler( $args ); $args = array( 'id' => 'ar_gameCreator', 'title' => __( 'Game Creator', 'arcade-ready-tr' ), 'postType' => 'ar_games', 'context' => 'side', 'args' => array( 'desc' => __( 'Name of the game creator.', 'arcade-ready-tr' ), 'type' => 'textfield', ) ); new ArcadeReady_MetaHandler( $args ); $args = array( 'id' => 'ar_screenshots', 'title' => __( 'Screenshots', 'arcade-ready-tr' ), 'postType' => 'ar_games', 'args' => array( 'desc' => __( 'Select a list of screenshots', 'arcade-ready-tr' ), 'frame_title' => __( 'Select Game File', 'arcade-ready-tr' ), 'frameTypes' => 'image', 'multiple' => true, 'preview' => true, 'display' => 'id', 'btn_txt' => __( 'Select Screenshots', 'arcade-ready-tr' ), 'type' => 'media', ) ); new ArcadeReady_MetaHandler( $args ); $args = array( 'id' => 'ar_gameFile', 'title' => __( 'Game File', 'arcade-ready-tr' ), 'postType' => 'ar_games', 'args' => array( 'desc' => __( 'Gamefile to embed.', 'arcade-ready-tr' ), 'frame_title' => __( 'Select Game File', 'arcade-ready-tr' ), 'frameTypes' => 'games', 'multiple' => false, 'preview' => false, 'display' => 'filename', 'btn_txt' => __( 'Select Game File', 'arcade-ready-tr' ), 'type' => 'media', ) ); new ArcadeReady_MetaHandler( $args ); $args = array( 'id' => 'ar_gameEmbed', 'title' => __( 'Game Embed Code', 'arcade-ready-tr' ), 'postType' => 'ar_games', 'args' => array( 'dataprocess' => 'base64', 'desc' => __( 'Paste Game Embed Code (iframe, javascript, etc). NOTE: Takes precidence over Game File if both are present.', 'arcade-ready-tr' ), 'type' => 'textarea', ) ); new ArcadeReady_MetaHandler( $args ); $args = array( 'id' => 'ar_gameCreatorWebsite', 'title' => __( 'Game Creator Website', 'arcade-ready-tr' ), 'postType' => 'ar_games', 'context' => 'side', 'args' => array( 'desc' => __( 'Website of the game creator.', 'arcade-ready-tr' ), 'type' => 'textfield', ) ); new ArcadeReady_MetaHandler( $args ); ?>