Suporte » Desenvolvendo com WordPress » Exibir valor do metabox fiel

  • Segue abaixo código da pagina do plugin, não estou conseguindo fazer que ele seja exibido nas paginas secretaria

    <?php
    /**
     * Generated by the WordPress Meta Box Generator at http://goo.gl/8nwllb
     */
    class inf_sec_Meta_Box {
    	private $screens = array(
    		'secretaria',
    	);
    	private $fields = array(
    		array(
    			'id' => 'cargo-do-responsvel-pelo-rgo',
    			'label' => 'Cargo do Responsável pelo Órgão',
    			'type' => 'select',
    			'options' => array(
    				'Secretário',
    				'Secretário Adjunto',
    				'Chefe de Gabinete',
    				'Chefe de Gabinete Adjunto',
    				'Controlador',
    				'Controlador Adjunto',
    				'Ouvidor',
    				'Ouvidor Adjunto',
    				'Procurador',
    				'Procurador Adjunto',
    				'',
    			),
    		),
    		array(
    			'id' => 'nome-do-secretario',
    			'label' => 'Nome do Secretario',
    			'type' => 'text',
    		),
    		array(
    			'id' => 'data-de-inicio',
    			'label' => 'Data de Inicio',
    			'type' => 'date',
    		),
    		array(
    			'id' => 'data-de-fim',
    			'label' => 'Data de Fim',
    			'type' => 'date',
    		),
    		array(
    			'id' => 'numero-da-portaria',
    			'label' => 'Numero da Portaria',
    			'type' => 'number',
    		),
    		array(
    			'id' => 'data-da-nomeao',
    			'label' => 'Data da Nomeação',
    			'type' => 'date',
    		),
    		array(
    			'id' => 'data-da-publicao',
    			'label' => 'Data da Publicação',
    			'type' => 'date',
    		),
    		array(
    			'id' => 'matricula',
    			'label' => 'Matricula',
    			'type' => 'number',
    		),
    		array(
    			'id' => 'arquivo-da-portaria',
    			'label' => 'Arquivo da Portaria',
    			'type' => 'media',
    		),
    		array(
    			'id' => 'foto-oficial',
    			'label' => 'Foto Oficial',
    			'type' => 'media',
    		),
    	);
    
    	/**
    	 * Class construct method. Adds actions to their respective WordPress hooks.
    	 */
    	public function __construct() {
    		add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
    		add_action( 'admin_footer', array( $this, 'admin_footer' ) );
    		add_action( 'save_post', array( $this, 'save_post' ) );
    	}
    
    	/**
    	 * Hooks into WordPress' add_meta_boxes function.
    	 * Goes through screens (post types) and adds the meta box.
    	 */
    	public function add_meta_boxes() {
    		foreach ( $this->screens as $screen ) {
    			add_meta_box(
    				'informaes-do-secretario',
    				__( 'Informações do Secretario', 'inf_sec' ),
    				array( $this, 'add_meta_box_callback' ),
    				$screen,
    				'advanced',
    				'default'
    			);
    		}
    	}
    
    	/**
    	 * Generates the HTML for the meta box
    	 * 
    	 * @param object $post WordPress post object
    	 */
    	public function add_meta_box_callback( $post ) {
    		wp_nonce_field( 'informaes_do_secretario_data', 'informaes_do_secretario_nonce' );
    		$this->generate_fields( $post );
    	}
    
    	/**
    	 * Hooks into WordPress' admin_footer function.
    	 * Adds scripts for media uploader.
    	 */
    	public function admin_footer() {
    		?><script>
    			// https://codestag.com/how-to-use-wordpress-3-5-media-uploader-in-theme-options/
    			jQuery(document).ready(function($){
    				if ( typeof wp.media !== 'undefined' ) {
    					var _custom_media = true,
    					_orig_send_attachment = wp.media.editor.send.attachment;
    					$('.rational-metabox-media').click(function(e) {
    						var send_attachment_bkp = wp.media.editor.send.attachment;
    						var button = $(this);
    						var id = button.attr('id').replace('_button', '');
    						_custom_media = true;
    							wp.media.editor.send.attachment = function(props, attachment){
    							if ( _custom_media ) {
    								$("#"+id).val(attachment.url);
    							} else {
    								return _orig_send_attachment.apply( this, [props, attachment] );
    							};
    						}
    						wp.media.editor.open(button);
    						return false;
    					});
    					$('.add_media').on('click', function(){
    						_custom_media = false;
    					});
    				}
    			});
    		</script><?php
    	}
    
    	/**
    	 * Generates the field's HTML for the meta box.
    	 */
    	public function generate_fields( $post ) {
    		$output = '';
    		foreach ( $this->fields as $field ) {
    			$label = '<label for="' . $field['id'] . '">' . $field['label'] . '</label>';
    			$db_value = get_post_meta( $post->ID, 'informaes_do_secretario_' . $field['id'], true );
    			switch ( $field['type'] ) {
    				case 'media':
    					$input = sprintf(
    						'<input class="regular-text" id="%s" name="%s" type="text" value="%s"> <input class="button rational-metabox-media" id="%s_button" name="%s_button" type="button" value="Upload" />',
    						$field['id'],
    						$field['id'],
    						$db_value,
    						$field['id'],
    						$field['id']
    					);
    					break;
    				case 'select':
    					$input = sprintf(
    						'<select id="%s" name="%s">',
    						$field['id'],
    						$field['id']
    					);
    					foreach ( $field['options'] as $key => $value ) {
    						$field_value = !is_numeric( $key ) ? $key : $value;
    						$input .= sprintf(
    							'<option %s value="%s">%s</option>',
    							$db_value === $field_value ? 'selected' : '',
    							$field_value,
    							$value
    						);
    					}
    					$input .= '</select>';
    					break;
    				default:
    					$input = sprintf(
    						'<input %s id="%s" name="%s" type="%s" value="%s">',
    						$field['type'] !== 'color' ? 'class="regular-text"' : '',
    						$field['id'],
    						$field['id'],
    						$field['type'],
    						$db_value
    					);
    			}
    			$output .= $this->row_format( $label, $input );
    		}
    		echo '<table class="form-table"><tbody>' . $output . '</tbody></table>';
    	}
    
    	/**
    	 * Generates the HTML for table rows.
    	 */
    	public function row_format( $label, $input ) {
    		return sprintf(
    			'<tr><th scope="row">%s</th><td>%s</td></tr>',
    			$label,
    			$input
    		);
    	}
    	/**
    	 * Hooks into WordPress' save_post function
    	 */
    	public function save_post( $post_id ) {
    		if ( ! isset( $_POST['informaes_do_secretario_nonce'] ) )
    			return $post_id;
    
    		$nonce = $_POST['informaes_do_secretario_nonce'];
    		if ( !wp_verify_nonce( $nonce, 'informaes_do_secretario_data' ) )
    			return $post_id;
    
    		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    			return $post_id;
    
    		foreach ( $this->fields as $field ) {
    			if ( isset( $_POST[ $field['id'] ] ) ) {
    				switch ( $field['type'] ) {
    					case 'email':
    						$_POST[ $field['id'] ] = sanitize_email( $_POST[ $field['id'] ] );
    						break;
    					case 'text':
    						$_POST[ $field['id'] ] = sanitize_text_field( $_POST[ $field['id'] ] );
    						break;
    				}
    				update_post_meta( $post_id, 'informaes_do_secretario_' . $field['id'], $_POST[ $field['id'] ] );
    			} else if ( $field['type'] === 'checkbox' ) {
    				update_post_meta( $post_id, 'informaes_do_secretario_' . $field['id'], '0' );
    			}
    		}
    	}
    }
    new inf_sec_Meta_Box;
    	?>
    • Este tópico foi modificado 5 anos, 3 meses atrás por Mário Valney. Motivo: Título
Visualizando 2 respostas - 1 até 2 (de um total de 2)
Visualizando 2 respostas - 1 até 2 (de um total de 2)
  • O tópico ‘Exibir valor do metabox fiel’ está fechado para novas respostas.