PHP8.1にしたら管理画面でwarningが出たのを解消した方法
WP本体を最新にして、PHPも8.1にしたら管理画面でワーニングが出てしまいました。
原因はfundtions.phpのサイドメニューの非表示などに関する部分の記述が問題でした。
番号でしていしていたのが、新しいWPになったら番号も変わるからなのか、その辺らしかったです。
修正前
// クライアント用ダッシュボードウィジェット非表示 function example_remove_dashboard_widgets() { if (!current_user_can('level_10')) { //level10以下のユーザーの場合ウィジェットをunsetする global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); // 現在の状況 unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); // 最近のコメント unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); // 被リンク unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); // プラグイン unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); // クイック投稿 unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); // 最近の下書き unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); // WordPressブログ unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); // WordPressフォーラム } } add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets'); // 【管理画面】管理画面にもファビコンを表示 function admin_favicon() { echo '<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />'; } add_action('admin_head', 'admin_favicon'); //上部管理バー admin bar に新規リンク追加をつける function mytheme_admin_bar_render() { global $wp_admin_bar; $wp_admin_bar->add_menu( array( 'id' => 'oshirasebar', 'title' => 'お知らせ', 'href' => admin_url( 'edit.php') )); $wp_admin_bar->add_menu( array( 'parent' => 'oshirasebar', 'id' => 'newoshirasebarbar', 'title' => '新規お知らせの追加', 'href' => admin_url( 'post-new.php') )); $wp_admin_bar->add_menu( array( 'id' => 'sekoureibar', 'title' => '施工例&お客様の声', 'href' => admin_url( 'edit.php?post_type=sekourei') )); $wp_admin_bar->add_menu( array( 'parent' => 'sekoureibar', 'id' => 'newsekoureibar', 'title' => '新規 施工例&お客様の声の追加', 'href' => admin_url( 'post-new.php?post_type=sekourei') )); $wp_admin_bar->add_menu( array( 'id' => 'soudanbar', 'title' => 'エクステリアブログ', 'href' => admin_url( 'edit.php?post_type=blog') )); $wp_admin_bar->add_menu( array( 'parent' => 'soudanbar', 'id' => 'newsoudanbar', 'title' => '新規 エクステリアブログの追加', 'href' => admin_url( 'post-new.php?post_type=blog') )); $wp_admin_bar->add_menu( array( 'id' => 'faqbar', 'title' => 'よくある質問FAQ', 'href' => admin_url( 'edit.php?post_type=question') )); $wp_admin_bar->add_menu( array( 'parent' => 'faqbar', 'id' => 'newfaqbar', 'title' => '新規よくある質問FAQの追加', 'href' => admin_url( 'post-new.php?post_type=question') )); } add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' ); // 管理画面の項目名「投稿」を「お知らせに変更」 function change_post_menu_label() { global $menu; global $submenu; $menu[5][0] = 'お知らせ'; $submenu['edit.php'][5][0] = 'お知らせ一覧'; $submenu['edit.php'][10][0] = '新しいお知らせ'; $submenu['edit.php'][16][0] = 'タグ'; //echo ”; } function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = 'お知らせ'; $labels->singular_name = 'お知らせ'; $labels->add_new = _x('新規追加', 'お知らせ'); $labels->add_new_item = '新しいお知らせ'; $labels->edit_item = 'お知らせの編集'; $labels->new_item = '新しいお知らせ'; $labels->view_item = 'お知らせを表示'; $labels->search_items = 'お知らせ検索'; $labels->not_found = 'お知らせが見つかりませんでした'; $labels->not_found_in_trash = 'ゴミ箱のお知らせにも見つかりませんでした'; } add_action( 'init', 'change_post_object_label' ); add_action( 'admin_menu', 'change_post_menu_label' ); // 管理者以外の管理画面サイドバーメニュー非表示 function remove_menus () { if (!current_user_can('level_10')) { //level10以下のユーザーの場合メニューをunsetする remove_menu_page('wpcf7'); //Contact Form 7 コンタクトフォーム非表示 remove_menu_page('edit.php?post_type=mw-wp-form'); //mw-wp-form MW WP Form非表示 remove_menu_page('edit.php?post_type=slide'); //mw-wp-form MW WP Form非表示 global $menu; unset($menu[4]);//メニューの線1 unset($menu[10]);//メディア unset($menu[15]);//リンク unset($menu[20]);//ページ unset($menu[25]);//コメント unset($menu[59]);//メニューの線2 unset($menu[60]);//テーマ unset($menu[65]);//プラグイン unset($menu[70]);//プロフィール unset($menu[75]);//ツール unset($menu[80]);//設定 unset($menu[90]);//メニューの線3 } } add_action('admin_menu', 'remove_menus'); // バージョン更新を非表示にする //add_filter('pre_site_transient_update_core', '__return_zero'); // APIによるバージョンチェックの通信をさせない //remove_action('wp_version_check', 'wp_version_check'); //remove_action('admin_init', '_maybe_update_core'); //更新通知を管理者権限のみに表示 function update_nag_admin_only() { if ( ! current_user_can( 'administrator' ) ) { remove_action( 'admin_notices', 'update_nag', 3 ); } } add_action( 'admin_init', 'update_nag_admin_only' ); // フッターWordPressリンクを非表示に function custom_admin_footer() { echo '<a href="mailto:hp@hirocreate.com">お問い合わせ</a>'; } add_filter('admin_footer_text', 'custom_admin_footer'); // 管理バーの項目を非表示 function remove_admin_bar_menu( $wp_admin_bar ) { $wp_admin_bar->remove_menu( 'wp-logo' ); // WordPressシンボルマーク $wp_admin_bar->remove_menu('my-account'); // マイアカウント } add_action( 'admin_bar_menu', 'remove_admin_bar_menu', 70 ); // 管理バーから項目を削除する function mytheme_remove_item( $wp_admin_bar ) { $wp_admin_bar->remove_node('new-content');//新規(投稿などなどのデフォルト表示の部分を削除 $wp_admin_bar->remove_node('comments');// コメントを削除 $wp_admin_bar->remove_node('edit');// コメントを削除 } add_action( 'admin_bar_menu', 'mytheme_remove_item', 1000 ); // 管理バーのヘルプメニューを非表示にする function my_admin_head(){ echo '<style type="text/css">#contextual-help-link-wrap{display:none;}</style>'; } add_action('admin_head', 'my_admin_head'); // 管理バーにログアウトを追加 function add_new_item_in_admin_bar() { global $wp_admin_bar; $wp_admin_bar->add_menu(array( 'id' => 'new_item_in_admin_bar', 'title' => __('ログアウト'), 'href' => wp_logout_url() )); } add_action('wp_before_admin_bar_render', 'add_new_item_in_admin_bar'); // Contact Form 7の管理画面メニューを非表示にする function remove_admin_menus() { if (!current_user_can('level_10')) { remove_menu_page('wpcf7'); } } add_action('admin_menu', 'remove_admin_menus'); // 検索結果から除外したいページを指定 function search_filter($query) { if (!$query -> is_admin && $query -> is_search) { $query -> set('post__not_in', array(13)); } return $query; } add_filter('pre_get_posts', 'search_filter');
修正後
// 管理画面ウィジェット非表示(管理者以外) function example_remove_dashboard_widgets() { if (!current_user_can('administrator')) { global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } } add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets'); // 管理画面ファビコン function admin_favicon() { echo '<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />'; } add_action('admin_head', 'admin_favicon'); // 管理バーにカスタムメニュー追加 function mytheme_admin_bar_render() { global $wp_admin_bar; $menus = array( array( 'id' => 'oshirasebar', 'title' => 'お知らせ', 'href' => admin_url('edit.php'), 'children' => array( array( 'id' => 'newoshirasebarbar', 'title' => '新規お知らせの追加', 'href' => admin_url('post-new.php') ) ) ), array( 'id' => 'sekoureibar', 'title' => '施工例&お客様の声', 'href' => admin_url('edit.php?post_type=sekourei'), 'children' => array( array( 'id' => 'newsekoureibar', 'title' => '新規 施工例&お客様の声の追加', 'href' => admin_url('post-new.php?post_type=sekourei') ) ) ), array( 'id' => 'soudanbar', 'title' => 'エクステリアブログ', 'href' => admin_url('edit.php?post_type=blog'), 'children' => array( array( 'id' => 'newsoudanbar', 'title' => '新規 エクステリアブログの追加', 'href' => admin_url('post-new.php?post_type=blog') ) ) ), array( 'id' => 'faqbar', 'title' => 'よくある質問FAQ', 'href' => admin_url('edit.php?post_type=question'), 'children' => array( array( 'id' => 'newfaqbar', 'title' => '新規よくある質問FAQの追加', 'href' => admin_url('post-new.php?post_type=question') ) ) ) ); foreach ($menus as $menu) { $wp_admin_bar->add_menu(array( 'id' => $menu['id'], 'title' => $menu['title'], 'href' => $menu['href'] )); if (!empty($menu['children'])) { foreach ($menu['children'] as $child) { if ($wp_admin_bar->get_node($menu['id'])) { $child['parent'] = $menu['id']; $wp_admin_bar->add_menu($child); } } } } } add_action('wp_before_admin_bar_render', 'mytheme_admin_bar_render'); // 投稿を「お知らせ」に変更 function change_post_menu_label() { global $menu, $submenu; if (isset($menu[5][0])) $menu[5][0] = 'お知らせ'; if (isset($submenu['edit.php'][5][0])) $submenu['edit.php'][5][0] = 'お知らせ一覧'; if (isset($submenu['edit.php'][10][0])) $submenu['edit.php'][10][0] = '新しいお知らせ'; if (isset($submenu['edit.php'][16][0])) $submenu['edit.php'][16][0] = 'タグ'; } add_action('admin_menu', 'change_post_menu_label'); function change_post_object_label() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = 'お知らせ'; $labels->singular_name = 'お知らせ'; $labels->add_new = _x('新規追加', 'お知らせ'); $labels->add_new_item = '新しいお知らせ'; $labels->edit_item = 'お知らせの編集'; $labels->new_item = '新しいお知らせ'; $labels->view_item = 'お知らせを表示'; $labels->search_items = 'お知らせ検索'; $labels->not_found = 'お知らせが見つかりませんでした'; $labels->not_found_in_trash = 'ゴミ箱のお知らせにも見つかりませんでした'; } add_action('init', 'change_post_object_label'); // 管理者以外のサイドバー非表示 function remove_menus() { if (!current_user_can('administrator')) { remove_menu_page('wpcf7'); remove_menu_page('edit.php?post_type=mw-wp-form'); remove_menu_page('edit.php?post_type=slide'); remove_menu_page('upload.php'); remove_menu_page('link-manager.php'); remove_menu_page('edit.php?post_type=page'); remove_menu_page('edit-comments.php'); remove_menu_page('themes.php'); remove_menu_page('plugins.php'); remove_menu_page('profile.php'); remove_menu_page('tools.php'); remove_menu_page('options-general.php'); } } add_action('admin_menu', 'remove_menus'); // 更新通知を管理者のみ表示 function update_nag_admin_only() { if (!current_user_can('administrator')) { remove_action('admin_notices', 'update_nag', 3); } } add_action('admin_init', 'update_nag_admin_only'); // 管理画面フッター function custom_admin_footer() { echo '<a href="mailto:hp@hirocreate.com">お問い合わせ</a>'; } add_filter('admin_footer_text', 'custom_admin_footer'); // 管理バーの不要項目削除 function remove_admin_bar_menu($wp_admin_bar) { $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('my-account'); } add_action('admin_bar_menu', 'remove_admin_bar_menu', 70); function mytheme_remove_item($wp_admin_bar) { $wp_admin_bar->remove_node('new-content'); $wp_admin_bar->remove_node('comments'); $wp_admin_bar->remove_node('edit'); } add_action('admin_bar_menu', 'mytheme_remove_item', 1000); function my_admin_head() { echo '<style type="text/css">#contextual-help-link-wrap{display:none;}</style>'; } add_action('admin_head', 'my_admin_head'); // 管理バーにログアウト function add_new_item_in_admin_bar() { global $wp_admin_bar; $wp_admin_bar->add_menu(array( 'id' => 'new_item_in_admin_bar', 'title' => __('ログアウト'), 'href' => wp_logout_url() )); } add_action('wp_before_admin_bar_render', 'add_new_item_in_admin_bar'); // 検索結果から除外 function search_filter($query) { if (!$query->is_admin && $query->is_search) { $query->set('post__not_in', array(13)); } return $query; } add_filter('pre_get_posts', 'search_filter');
関連記事はこちら!
スポンサーリンク