【发布时间】:2021-07-13 11:51:39
【问题描述】:
安装插件后,我的 WordPress 主题中出现此错误。我使用的是 Amy Movies 3.5.2 主题,插件是 Amy Movie Extends 3.5.4。我不知道这是否导致了问题。它在第 145 行显示错误
$permalinks = get_option('amy_movie_permalinks');
$cinema_slug = ($permalinks['cinema_slug']) ? $permalinks['cinema_slug'] : 'cinema'; //This Line
这是我的完整 PHP 代码:
<?php
if (!function_exists('amy_movie_create_postype_movie')) {
function amy_movie_create_postype_movie() {
$permalinks = get_option('amy_movie_permalinks');
$movie_slug = isset($permalinks['movie_slug']) ? $permalinks['movie_slug'] : 'movie';
$movie_args = array(
'labels' => array(
'name' => esc_html__('Movies', 'amy-movie-extend'),
'singular_name' => esc_html__('Movies', 'amy-movie-extend'),
'add_new_item' => esc_html__('Add Movie', 'amy-movie-extend'),
'add_new' => esc_html__('Add or Import Movie', 'amy-movie-extend'),
),
'public' => true,
'has_archive' => false,
'publicly_queryable' => true,
'exclude_from_search' => false,
'menu_icon' => 'dashicons-video-alt',
'supports' => array('title', 'editor', 'comments'),
'rewrite' => array(
'slug' => $movie_slug,
'with_front' => true,
'feeds' => true,
'pages' => true,
),
);
register_post_type('amy_movie', $movie_args);
}
add_action('init', 'amy_movie_create_postype_movie');
}
// Genre
if (!function_exists('amy_movie_create_taxonomy_genre')) {
function amy_movie_create_taxonomy_genre() {
$permalinks = get_option('amy_movie_permalinks');
$genre_slug = isset($permalinks['genre_slug']) ? $permalinks['genre_slug'] : 'genre';
register_taxonomy('amy_genre',array('amy_movie', 'amy_tvshow'), array(
'hierarchical' => true,
'labels' => array(
'name' => esc_html__('Genres', 'amy-movie-extend'),
'singular_name' => esc_html__('Genre', 'amy-movie-extend'),
'search_items' => esc_html__('Search Genre', 'amy-movie-extend'),
'all_items' => esc_html__('All Genres', 'amy-movie-extend'),
'parent_item' => esc_html__('Parent Genre', 'amy-movie-extend'),
'parent_item_colon' => esc_html__('Parent Genre:', 'amy-movie-extend'),
'edit_item' => esc_html__('Edit Genre', 'amy-movie-extend'),
'update_item' => esc_html__('Update Genre', 'amy-movie-extend'),
'add_new_item' => esc_html__('Add New Genre', 'amy-movie-extend'),
'new_item_name' => esc_html__('New Genre Name', 'amy-movie-extend'),
'menu_name' => esc_html__('Genres'),
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array(
'slug' => $genre_slug,
'with_front' => true,
'hierarchical' => true,
),
));
}
add_action('init', 'amy_movie_create_taxonomy_genre');
}
// Actor
if (!function_exists('amy_movie_create_taxonomy_actor')) {
function amy_movie_create_taxonomy_actor() {
$permalinks = get_option('amy_movie_permalinks');
$actor_slug = isset($permalinks['actor_slug']) ? $permalinks['actor_slug'] : 'actor';
register_taxonomy('amy_actor',array('amy_movie', 'amy_tvshow'), array(
'hierarchical' => false,
'labels' => array(
'name' => esc_html__('Actors', 'amy-movie-extend'),
'singular_name' => esc_html__('Actor', 'amy-movie-extend'),
'search_items' => esc_html__('Search Actor', 'amy-movie-extend'),
'all_items' => esc_html__('All Actors', 'amy-movie-extend'),
'edit_item' => esc_html__('Edit Actor', 'amy-movie-extend'),
'update_item' => esc_html__('Update Actor', 'amy-movie-extend'),
'add_new_item' => esc_html__('Add New Actor', 'amy-movie-extend'),
'new_item_name' => esc_html__('New Actor Name', 'amy-movie-extend'),
'menu_name' => esc_html__('Actors'),
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array(
'slug' => $actor_slug,
'with_front' => true,
'hierarchical' => true,
),
));
}
add_action('init', 'amy_movie_create_taxonomy_actor');
}
// Director
if (!function_exists('amy_movie_create_taxonomy_director')) {
function amy_movie_create_taxonomy_director() {
$permalinks = get_option('amy_movie_permalinks');
$director_slug = isset($permalinks['director_slug']) ? $permalinks['director_slug'] : 'director';
register_taxonomy('amy_director',array('amy_movie', 'amy_tvshow'), array(
'hierarchical' => false,
'labels' => array(
'name' => esc_html__('Directors', 'amy-movie-extend'),
'singular_name' => esc_html__('Director', 'amy-movie-extend'),
'search_items' => esc_html__('Search director', 'amy-movie-extend'),
'all_items' => esc_html__('All Directors', 'amy-movie-extend'),
'edit_item' => esc_html__('Edit Director', 'amy-movie-extend'),
'update_item' => esc_html__('Update Director', 'amy-movie-extend'),
'add_new_item' => esc_html__('Add New Director', 'amy-movie-extend'),
'new_item_name' => esc_html__('New Director Name', 'amy-movie-extend'),
'menu_name' => esc_html__('Directors'),
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array(
'slug' => $director_slug,
'with_front' => true,
'hierarchical' => true,
),
));
}
add_action('init', 'amy_movie_create_taxonomy_director');
}
// Cinema
if (!function_exists('amy_movie_create_posttype_cinema')) {
function amy_movie_create_posttype_cinema() {
if ((amy_get_option('enable_m_cinema', true) == false) || (amy_get_option('enable_m_cinema', true) == true && amy_get_option('is_single_cinema', false) == true)) {
return;
}
/***********This Line***********/
/***********This Line***********/
/***********This Line***********/
$permalinks = get_option('amy_movie_permalinks');
$cinema_slug = ($permalinks['cinema_slug']) ? $permalinks['cinema_slug'] : 'cinema'; //Line 145 ERROR HERE
/***********This Line***********/
/***********This Line***********/
/***********This Line***********/
register_post_type('amy_cinema',
array(
'labels' => array(
'name' => esc_html__('Cinemas', 'amy-movie-extend'),
'singular_name' => esc_html__('Cinemas', 'amy-movie-extend'),
),
'public' => true,
'has_archive' => true,
'menu-icon' => 'dashicons-building',
'supports' => array('title', 'editor', 'comments'),
'rewrite' => array(
'slug' => $cinema_slug,
'with_front' => true,
'hierarchical' => true,
),
)
);
}
add_action('init', 'amy_movie_create_posttype_cinema');
}
// Custom Fields
if (!function_exists('amy_movie_custom_fields_create_taxonomy')) {
function amy_movie_custom_fields_create_taxonomy() {
$custom_fields = amy_get_option('movie_custom_fields');
if (!empty($custom_fields)) {
foreach ($custom_fields as $field) {
if ($field['type'] == 'category' || $field['type'] == 'person') {
$name = (isset($field['name']) && $field['name'] != '') ? $field['name'] : '';
$singular_name = (isset($field['singular_name']) && $field['singular_name'] != '') ? sanitize_title($field['singular_name']) : sanitize_title($name);
register_taxonomy($singular_name,array('amy_movie', 'amy_tvshow'), array(
'hierarchical' => false,
'labels' => array(
'name' => $name,
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array(
'slug' => $singular_name,
'with_front' => true,
'hierarchical' => true,
),
));
}
}
}
}
add_action('init', 'amy_movie_custom_fields_create_taxonomy');
}
if (!function_exists('amy_movie_create_post_type_tvshow')) {
function amy_movie_create_post_type_tvshow() {
if (amy_get_option('enable_m_cinema', true) == true) {
return;
}
$permalinks = get_option('amy_movie_permalinks');
$tvshow_slug = isset($permalinks['tvshow_slug']) ? $permalinks['tvshow_slug'] : 'tvshow';
$args = array(
'labels' => array(
'name' => esc_html__('Tv Shows', 'amy-movie-helper'),
'singular_name' => esc_html__('Tv Show', 'amy-movie-helper'),
'search_items' => esc_html__('Search Tv Show', 'amy-movie-helper'),
'all_items' => esc_html__('All Tv Shows', 'amy-movie-helper'),
'edit_item' => esc_html__('Edit Tv Show', 'amy-movie-helper'),
'update_item' => esc_html__('Update Tv Show', 'amy-movie-helper'),
'add_new_item' => esc_html__('Add New Tv Show', 'amy-movie-helper'),
),
'public' => true,
'has_archive' => false,
'publicly_queryable' => true,
'exclude_from_search' => false,
'supports' => array('title', 'editor', 'comments'),
'rewrite' => array(
'slug' => $tvshow_slug,
'with_front' => true,
'feeds' => true,
'pages' => true
)
);
register_post_type('amy_tvshow', $args);
}
add_action('init', 'amy_movie_create_post_type_tvshow', 12);
}
// register chapper post type.
if (!function_exists('amy_movie_create_post_type_season')) {
function amy_movie_create_post_type_season() {
if (amy_get_option('enable_m_cinema', true) == true) {
return;
}
$permalinks = get_option('amy_movie_permalinks');
$season_slug = isset($permalinks['season_slug']) ? $permalinks['season_slug'] : 'season';
$args = array(
'labels' => array(
'name' => esc_html__('Seasons', 'amy-movie-helper'),
'singular_name' => esc_html__('Season', 'amy-movie-helper'),
'search_items' => esc_html__('Search Season', 'amy-movie-helper'),
'all_items' => esc_html__('All Seasons', 'amy-movie-helper'),
'edit_item' => esc_html__('Edit Season', 'amy-movie-helper'),
'update_item' => esc_html__('Update Season', 'amy-movie-helper'),
'add_new_item' => esc_html__('Add New Season', 'amy-movie-helper'),
),
'public' => true,
'has_archive' => false,
'publicly_queryable' => true,
'exclude_from_search' => false,
'supports' => array('title', 'editor'),
'rewrite' => array(
'slug' => $season_slug,
'with_front' => true,
'feeds' => true,
'pages' => true
)
);
register_post_type('amy_season', $args);
}
add_action('init', 'amy_movie_create_post_type_season', 12);
}
谁能告诉我如何解决这个错误?
【问题讨论】:
-
显然
$permalinks是假的,所以你无法从中获取值 -
您能说说如何解决这个问题吗?或者我现在应该用这条线做什么?这将是一个很大的帮助,我一整天都在努力解决这个问题
-
试试
$cinema_slug = $permalinks['cinema_slug'] ?? 'cinema';
标签: php wordpress wordpress-theming