densa
вот весь код. сайт работает, все добавляется, нужно только от появления ошибки избавиться
<?php
/*-----------------------------------------------------------------------------------
Add image upload metaboxes to Portfolio items
-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* Define Metabox Fields
/*-----------------------------------------------------------------------------------*/
$prefix = 'tz_';
$meta_box_portfolio = array(
'id' => 'tz-meta-box-portfolio',
'title' => __('Portfolio Options', 'theme1968'),
'page' => 'portfolio',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => __('Format', 'theme1968'),
'desc' => __('Choose post format that most fit your needs. ', 'theme1968'),
'id' => $prefix . 'portfolio_type',
"type" => "select",
'std' => 'Image',
'options' => array('Image', 'Slideshow', 'Grid Gallery', 'Video', 'Audio')
),
array(
'name' => __('Date', 'theme1968'),
'desc' => __('Input project end date. ', 'theme1968'),
'id' => $prefix . 'portfolio_date',
'type' => 'text',
'std' => ''
),
array(
'name' => __('Client', 'theme1968'),
'desc' => __('Input project owner name. ', 'theme1968'),
'id' => $prefix . 'portfolio_client',
'type' => 'text',
'std' => ''
),
array(
'name' => __('Info', 'theme1968'),
'desc' => __('Additional info for this portfolio item.', 'theme1968'),
'id' => $prefix . 'portfolio_info',
'type' => 'text',
'std' => ''
),
array(
'name' => __('URL', 'theme1968'),
'desc' => __('Input the project URL (external link)', 'theme1968'),
'id' => $prefix . 'portfolio_url',
'type' => 'text',
'std' => ''
)
)
);
$meta_box_portfolio_video = array(
'id' => 'tz-meta-box-portfolio-video',
'title' => __('Video Settings', 'theme1968'),
'page' => 'portfolio',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => __('Embedded Code', 'theme1968'),
'desc' => __('Use this field to embed video from various websites (YouTube, Vimeo etc).', 'theme1968'),
'id' => $prefix . 'portfolio_embed_code',
'type' => 'textarea',
'std' => ''
)
),
);
$meta_box_portfolio_audio = array(
'id' => 'tz-meta-box-portfolio-audio',
'title' => __('Audio Settings', 'theme1968'),
'page' => 'portfolio',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
"name" => __('MP3 File URL','theme1968'),
"desc" => __('The URL to the .mp3 audio file','theme1968'),
"id" => $prefix."audio_mp3",
"type" => "text",
'std' => ''
)
)
);
add_action('admin_menu', 'tz_add_box_portfolio');
/*-----------------------------------------------------------------------------------*/
/* Add metabox to edit page
/*-----------------------------------------------------------------------------------*/
function tz_add_box_portfolio() {
global $meta_box_portfolio, $meta_box_portfolio_image, $meta_box_portfolio_video, $meta_box_portfolio_audio;
add_meta_box($meta_box_portfolio['id'], $meta_box_portfolio['title'], 'tz_show_box_portfolio', $meta_box_portfolio['page'], $meta_box_portfolio['context'], $meta_box_portfolio['priority']);
add_meta_box($meta_box_portfolio_image['id'], $meta_box_portfolio_image['title'], 'tz_show_box_portfolio_image', $meta_box_portfolio_image['page'], $meta_box_portfolio_image['context'], $meta_box_portfolio_image['priority']);
add_meta_box($meta_box_portfolio_video['id'], $meta_box_portfolio_video['title'], 'tz_show_box_portfolio_video', $meta_box_portfolio_video['page'], $meta_box_portfolio_video['context'], $meta_box_portfolio_video['priority']);
add_meta_box($meta_box_portfolio_audio['id'], $meta_box_portfolio_audio['title'], 'tz_show_box_portfolio_audio', $meta_box_portfolio_audio['page'], $meta_box_portfolio_audio['context'], $meta_box_portfolio_audio['priority']);
}
/*-----------------------------------------------------------------------------------*/
/* Callback function to show fields in meta box
/*-----------------------------------------------------------------------------------*/
function tz_show_box_portfolio() {
global $meta_box_portfolio, $post;
echo '<p style="padding:10px 0 0 0;">'.__('Please choose desired Portfolio Format and fill additional fields. ', 'theme1968').'</p>';
// Use nonce for verification
echo '<input type="hidden" name="tz_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
echo '<table class="form-table">';
foreach ($meta_box_portfolio['fields'] as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field['id'], true);
switch ($field['type']) {
//If Text
case 'text':
echo '<tr style="border-top:1px solid #eeeeee;">',
'<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style=" display:block; color:#999; margin:5px 0 0 0; line-height: 18px;">'. $field['desc'].'</span></label></th>',
'<td>';
echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : stripslashes(htmlspecialchars(( $field['std']), ENT_QUOTES)), '" size="30" style="width:75%; margin-right: 20px; float:left;" />';
break;
//If Select
case 'select':
echo '<tr>',
'<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style=" display:block; color:#999; margin:5px 0 0 0; line-height: 18px;">'. $field['desc'].'</span></label></th>',
'<td>';
echo'<select id="' . $field['id'] . '" name="'.$field['id'].'">';
foreach ($field['options'] as $option) {
echo'<option';
if ($meta == $option ) {
echo ' selected="selected"';
}
echo'>'. $option .'</option>';
}
echo'</select>';
break;
}
}
echo '</table>';
}
function tz_show_box_portfolio_image() {
global $meta_box_portfolio_image, $post;
// Use nonce for verification
echo '<input type="hidden" name="tz_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
echo '<table class="form-table">';
foreach ($meta_box_portfolio_image['fields'] as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field['id'], true);
switch ($field['type']) {
//If Text
case 'text':
echo '<tr style="border-top:1px solid #eeeeee;">',
'<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style=" display:block; color:#999; margin:5px 0 0 0; line-height: 18px;">'. $field['desc'].'</span></label></th>',
'<td>';
echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : stripslashes(htmlspecialchars(( $field['std']), ENT_QUOTES)), '" size="30" style="width:75%; margin-right: 20px; float:left;" />';
break;
//If Select
case 'select':
echo '<tr>',
'<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style=" display:block; color:#999; margin:5px 0 0 0;">'. $field['desc'].'</span></label></th>',
'<td>';
echo'<select name="'.$field['id'].'">';
foreach ($field['options'] as $option) {
echo'<option';
if ($meta == $option ) {
echo ' selected="selected"';
}
echo'>'. $option .'</option>';
}
echo'</select>';
break;
}
}
echo '</table>';
}
function tz_show_box_portfolio_video() {
global $meta_box_portfolio_video, $post;
// Use nonce for verification
echo '<input type="hidden" name="tz_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
echo '<table class="form-table">';
foreach ($meta_box_portfolio_video['fields'] as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field['id'], true);
switch ($field['type']) {
//If Text
case 'text':
echo '<tr>',
'<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style="line-height:20px; display:block; color:#999; margin:5px 0 0 0;">'. $field['desc'].'</span></label></th>',
'<td>';
echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'],'" size="30" style="width:75%; margin-right: 20px; float:left;" />';
break;
//If textarea
case 'textarea':
echo '<tr>',
'<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style="line-height:18px; display:block; color:#999; margin:5px 0 0 0;">'. $field['desc'].'</span></label></th>',
'<td>';
echo '<textarea name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" rows="8" cols="5" style="width:100%; margin-right: 20px; float:left;">', $meta ? $meta : $field['std'], '</textarea>';
break;
}
}
echo '</table>';
}
function tz_show_box_portfolio_audio() {
global $meta_box_portfolio_audio, $post;
// Use nonce for verification
echo '<input type="hidden" name="tz_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';
echo '<table class="form-table">';
foreach ($meta_box_portfolio_audio['fields'] as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field['id'], true);
switch ($field['type']) {
//If Text
case 'text':
echo '<tr>',
'<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style="line-height:20px; display:block; color:#999; margin:5px 0 0 0;">'. $field['desc'].'</span></label></th>',
'<td>';
echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'],'" size="30" style="width:75%; margin-right: 20px; float:left;" />';
break;
//If textarea
case 'textarea':
echo '<tr style="border-top:1px solid #eeeeee;">',
'<th style="width:25%"><label for="', $field['id'], '"><strong>', $field['name'], '</strong><span style="line-height:18px; display:block; color:#999; margin:5px 0 0 0;">'. $field['desc'].'</span></label></th>',
'<td>';
echo '<textarea name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" rows="8" cols="5" style="width:100%; margin-right: 20px; float:left;">', $meta ? $meta : $field['std'], '</textarea>';
break;
}
}
echo '</table>';
}
add_action('save_post', 'tz_save_data_portfolio');
/*-----------------------------------------------------------------------------------*/
/* Save data when post is edited
/*-----------------------------------------------------------------------------------*/
function tz_save_data_portfolio($post_id) {
global $meta_box_portfolio, $meta_box_portfolio_video, $meta_box_portfolio_audio, $meta_box_portfolio_image;
// verify nonce
if (!wp_verify_nonce($_POST['tz_meta_box_nonce'], basename(__FILE__))) {
return $post_id;
}
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
// check permissions
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_portfolio['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'], stripslashes(htmlspecialchars($new)));
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
foreach ($meta_box_portfolio_image['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'], stripslashes(htmlspecialchars($new)));
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
foreach ($meta_box_portfolio_video['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'], stripslashes(htmlspecialchars($new)));
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
foreach ($meta_box_portfolio_audio['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'], stripslashes(htmlspecialchars($new)));
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
}