这里是新的,有点菜鸟。试图将字段添加到自定义帖子类型,并最终在所有网站页面上出现解析错误消息。我已经粘贴了错误消息和contractor-type.php 代码,谁能告诉我如何解决这个问题?我没有运气联系到托管服务提供商进行完全恢复。非常感谢任何和所有的建议。目前我没有 ftp 访问权限,我所能做的就是使用主机控制面板中的文件管理器尝试上传主题文件的备份副本,但无济于事。
解析错误:语法错误,意外的“数组”(T_ARRAY),在 /home/renovant/public_html/wp-content/themes/renovantage/self-development-plugin/contractor-type.php 中的第 212 行期待 ')'
<?php
function get_contractor_info($id)
{
if($id==0)return;
$p = get_post($id);
$infos = get_post_custom($id);
$return = array();
$return['id'] = $id;
$return['company'] = $p->post_title;
foreach($infos as $key => $vls)
{
$return[$key] = $vls[0];
}
return $return;
}
add_action( 'init', 'tr_contractor_type' );
function tr_contractor_type() {
$labels = array(
'name' => _x('Contractors', 'post type general name'),
'singular_name' => _x('Contractor', 'post type singular name'),
'add_new' => _x('Add New Contractor', 'article'),
'add_new_item' => __('Add New Contractor'),
'edit_item' => __('Edit Contractor'),
'new_item' => __('New Contractor'),
'view_item' => __('View Contractor'),
'search_items' => __('Search Contractor'),
'not_found' => __('No Contractors found'),
'not_found_in_trash' => __('No Contractors found in Trash'),
'parent_item_colon' => ''
);
$supports = array(
'title',
// 'editor',
//'author',
'thumbnail',
//'excerpt',
// 'comments',
// 'custom-fields',
// 'trackbacks',
'revisions'
);
$args = array(
'labels' => $labels,
'public' => true,
'capability_type' => 'post',
'supports' => $supports,
'rewrite' => array( 'slug' => 'contractor','with_front' => false ),
'taxonomies' => array('category')
);
register_post_type('contractor', $args);
}
add_action('admin_init','tr_admin_init_add_con');
function tr_admin_init_add_con()
{
global $wpdb;
if($_GET['act'] !='cc')return;
$results = $wpdb->get_results(
"SELECT * FROM ".'wpms1_contractor'." ");
foreach($results as $row)
{
$post_title = $row->company;
$post_content = '';
$post_status = 'publish';
$post_type = 'contractor';
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input', 'page_template');
//$post_id = wp_insert_post($postdata);
//$post = $wpdb->get_row("select ID from {$wpdb->posts} where post_title = '{$row->company}'");
if($post_id>0)
{
update_post_meta($post_id,'address',$row->company_address);
update_post_meta($post_id,'address2',$row->company_address2);
update_post_meta($post_id,'city',$row->company_city);
update_post_meta($post_id,'province',$row->company_province);
update_post_meta($post_id,'country',$row->company_country);
update_post_meta($post_id,'postal_code',$row->company_postal);
update_post_meta($post_id,'owner',$row->company_owner);
update_post_meta($post_id,'contact_name',$row->company_contact);
update_post_meta($post_id,'phone1',$row->company_phone);
update_post_meta($post_id,'phone2',$row->company_phone2);
update_post_meta($post_id,'fax',$row->company_fax);
update_post_meta($post_id,'website',$row->company_website);
update_post_meta($post_id,'email',$row->company_email);
update_post_meta($post_id,'email2',$row->company_email2);
update_post_meta($post_id,'overview',$row->company_overview);
update_post_meta($post_id,'motto',$row->company_motto);
update_post_meta($post_id,'services',$row->company_services);
update_post_meta($post_id,'postal_prefixes',$row->postal_prefix);
update_post_meta($post_id,'profile_column_1_title',$row->title1);
update_post_meta($post_id,'profile_column_1_description',$row->description1);
update_post_meta($post_id,'profile_column_2_title',$row->title2);
update_post_meta($post_id,'profile_column_2_description',$row->description2);
update_post_meta($post_id,'profile_column_3_title',$row->title3);
update_post_meta($post_id,'profile_column_3_description',$row->description3);
}
}
}
//hide button media
add_action('admin_menu','tr_admin_menu_landing_hidemedia',11);
function tr_admin_menu_landing_hidemedia()
{
$rs = wp_get_current_user();
foreach((array) $rs->roles as $role)
{
if($role == 'subscriber')
{
remove_menu_page('upload.php');
}
}
}
function tr_landing_is_admin()
{
$rs = wp_get_current_user();
foreach((array) $rs->roles as $role)
{
if($role == 'administrator')
{
return true;
}
}
return false;
}
$profile_metaboxs =array();
$Company_fields = array(
'address' => 'Address',
'address2' => 'Address2',
'city' => 'City',
'province' => 'Province',
'country' => 'Country',
'postal_code' =>'Postal Code',
'website' => 'Website',
'owner' => 'Owner',
'contact_name' => ' Contact Name',
'phone1' => 'Phone 1',
'phone2' => 'Phone 2',
'fax' => 'Fax',
'email' => 'Email',
'email2' => 'Email2',
);
$Company_fieldsb= array();
foreach($Company_fields as $k => $f)
{
$Company_fieldsb[] = array(
'id'=>$k,
'label'=>"{$f}:",
'name'=>$k,
'type'=>"text"
);
}
$profile_metaboxs[] = array(
'id'=>'profile-meta-box-1',
'title'=>'Company Information',
'page'=> 'contractor',
'context'=>'normal',
'priority'=>'high',
'fields'=>$Company_fieldsb
);
$profile_metaboxs[] = array(
'id'=>'profile-meta-box-2',
'title'=>'Profile Overview',
'page'=> 'contractor',
'context'=>'normal',
'priority'=>'high',
'fields'=>array(
array(
'id'=>'overview',
'label'=>"Overview:",
'type'=>"textarea",
'height' => '100px'
),
array(
'id'=>'motto',
'label'=>"Motto:",
'type'=>"textarea",
'height' => '100px'
),
array(
'id'=>'services',
'label'=>"Services:",
'type'=>"textarea",
'height' => '100px'
),
array(
'id'=>'postal_prefixes',
'label'=>"Postal Prefixes:",
'type'=>"textarea",
'height' => '100px',
'readonly' => (!tr_landing_is_admin())
)
// LINE 212 as per comment from OP
);
$profile_metaboxs[] = array(
'id'=>'profile-meta-box-3',
'title'=>'Profile Column 1',
'page'=> 'contractor',
'context'=>'normal',
'priority'=>'high',
'fields'=>array(
array(
'id'=>'profile_column_1_title',
'label'=>"Title:",
'type'=>"text",
),
array(
'id'=>'profile_column_1_image',
'label'=>"Image:",
'type'=>"img",
),
array(
'id'=>'profile_column_1_description',
'label'=>"Description:",
'type'=>"textarea",
'height' => '100px'
)
)
);
$profile_metaboxs[] = array(
'id'=>'profile-meta-box-4',
'title'=>'Profile Column 2',
'page'=> 'contractor',
'context'=>'normal',
'priority'=>'high',
'fields'=>array(
array(
'id'=>'profile_column_2_title',
'label'=>"Title:",
'type'=>"text",
),
array(
'id'=>'profile_column_2_image',
'label'=>"Image:",
'type'=>"img",
),
array(
'id'=>'profile_column_2_description',
'label'=>"Description:",
'type'=>"textarea",
'height' => '100px'
)
)
);
$profile_metaboxs[] = array(
'id'=>'profile-meta-box-5',
'title'=>'Profile Column 3',
'page'=> 'contractor',
'context'=>'normal',
'priority'=>'high',
'fields'=>array(
array(
'id'=>'profile_column_3_title',
'label'=>"Title:",
'type'=>"text",
),
array(
'id'=>'profile_column_3_image',
'label'=>"Image:",
'type'=>"img",
),
array(
'id'=>'profile_column_3_description',
'label'=>"Description:",
'type'=>"textarea",
'height' => '100px'
)
)
);
$profile_metaboxs[]=array(
'id'=>'page-meta-box-6',
'title'=>'Header Box',
'page'=> 'contractor',
'context'=>'normal',
'priority'=>'high',
'fields'=>array(
array(
'id'=>"header_title",
'label'=>"Title:",
'name'=>"header_title",
'type'=>"text"
),
array(
'id'=>"header_content",
'label'=>"Content:",
'name'=>"header_content",
'type'=>"text"
),
array(
'id'=>"header_link_text",
'label'=>"Text Link:",
'name'=>"header_link_text",
'type'=>"text"
),
array(
'id'=>"header_link_url",
'label'=>"Link:",
'name'=>"header_link_url",
'type'=>"text"
),
)
);
foreach ($profile_metaboxs as $meta_box) {
$my_box = new Ant_Meta_Box($meta_box);
}
add_filter('post_row_actions', 'tr_landing_row_actions');
function tr_landing_row_actions($actions){
global $post;
if($post->post_type == 'contractor')
{
$actions['referral'] = '<a href="'.get_bloginfo('url').'/referral/'.$post->post_name.'" >Referral</a>';
}
return $actions;
}