Salutare!
Am reusit sa fac sa functioneze un meta_box custom in wordpress dar am nevoie pe putin ajutor, pentru ca in modul wp_debug true, imi apar 3 erori, se pare toate din aceeasi cauza. De notat ca eroarea apare doar daca nimic nu este completat in custom field-urile respective.
De exemplu, daca acest <?php echo $instructions; ?> nu afiseaza nimic pentru ca nimic nu a fost completat in acel camp, atunci apare acea eroare. Daca acel camp este completat (cu text in cazul meu), eroarea nu mai apare.
Erorile suna asa:
Liniile respective sunt corespunzatoare urmatoarelor coduri:Cod:Notice: Undefined index: custom_meta_instructions in /.../single.php on line 11
Notice: Undefined index: custom_meta_gamefile in /.../single.php on line 13
Functia corespunzatoare acestora este urmatoarea:Cod:<?php
$custom_meta = get_post_custom($post->ID);
$instructions = $custom_meta['custom_meta_instructions'][0];
$difficulty = $custom_meta['custom_meta_difficulty'][0];
$gamefile = $custom_meta['custom_meta_gamefile'][0];
?>
Chiar am nevoie de ajutor pentru ca acele erori sa nu mai apara asa ca multumesc anticipat celui care ma poate ajuta!Cod:$prefix = 'custom_meta_';
$meta_box = array(
'fields' => array(
array(
'name' => 'Upload your swf game file:',
'desc' => 'Upload your swf game file using upload/insert media button, or paste your embed code. <br />*<small>Note that if you are using embed code, you should use the HTML tab instead of Visual. Anyway, sometimes you must play around with the dimension of the game, to display the proportional width and heigh.</small>',
'id' => $prefix . 'gamefile',
'type' => 'wysiwyg',
'std' => '',
'options' => array(
'textarea_rows' => 3,
),
),
array(
'name' => 'Game Instructions:',
'desc' => 'Instructions about how to play the game (key used to play, move, jump, etc.).',
'id' => $prefix . 'instructions',
'type' => 'wysiwyg',
'std' => '',
'options' => array(
'media_buttons' => false,
'textarea_rows' => 3,
),
),
array(
'name' => 'Game Difficulty:',
'id' => $prefix . 'difficulty',
'type' => 'select',
'options' => array('Very Easy', 'Easy', 'Medium', 'Hard', 'Very Hard' )
),
)
);
function my_game_meta_add_box() {
global $meta_box;
}
add_action('admin_menu', 'my_game_meta_add_box');
function display_gamecode() {
global $meta_box, $post;
echo '<input type="hidden" name="flash_game_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
echo '<table class="form-table">';
foreach ($meta_box['fields'] as $field) {
$meta = get_post_meta($post->ID, $field['id'], true);
echo '<tr>',
'<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>',
'<td>';
switch ($field['type']) {
case 'wysiwyg':
wp_editor( $meta ? $meta : $field['std'], $field['id'], isset( $field['options'] ) ? $field['options'] : array() );
echo '<p>', $field['desc'], '</p>';
break;
case 'select':
echo '<select name="', $field['id'], '" id="', $field['id'], '">';
foreach ($field['options'] as $option) {
echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>';
}
echo '</select>';
break;
}
echo '<td>',
'</tr>';
}
echo '</table>';
}
function my_game_meta_save_data($post_id) {
global $meta_box;
if( !isset( $_POST['flash_game_meta_box_nonce'] ) || !wp_verify_nonce($_POST['flash_game_meta_box_nonce'], basename(__FILE__))) {
return $post_id;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
foreach ($meta_box['fields'] as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
}

