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);
}
}
}
Chiar am nevoie de ajutor pentru ca acele erori sa nu mai apara asa ca multumesc anticipat celui care ma poate ajuta!