Contents
GeoDirectoryとは
GeoDirectoryとはLocal Business Review(口コミ)サイトを構築するためのプラグインである。
初期設定
インストール
“GeoDirectory”で検索すると”Business Directory Plugin | GeoDirectory”として見つかるので、そちらをインストール、有効化する
WordPressの設定
ダッシュボードのカスタマイズ
口コミサイトを提供する際は、ビジネスオーナーにWordpress管理ダッシュボードを公開することになる。
デフォルトのままでは使用しづらい点が多いので、カスタマイズする。
編集画面へのリダイレクト
ビジネスオーナーがログインした際は管理ダッシュボードのトップページではなく、編集ページにリダイレクトする。
新規作成時は新規作成ページに、1つの投稿作成後はその投稿へリダイレクトする。
※1ユーザーで1投稿しかできない前提である
add_action('admin_init', 'restrict_admin_with_redirect'); function restrict_admin_with_redirect() { if(current_user_can('author') && !defined('DOING_AJAX') && !(preg_match('/^\/wp-admin\/post\.php?.*/',$_SERVER["REQUEST_URI"]) || preg_match('/^\/wp-admin\/post-new\.php?.*/',$_SERVER["REQUEST_URI"]))) { $postlist = get_posts(array( 'post_type' => 'gd_place', 'author' => wp_get_current_user()->ID, )); if(is_null($postlist[0]->ID)) { wp_redirect('/wp-admin/post-new.php?post_type=gd_place'); } else { wp_redirect('/wp-admin/post.php?post='.$postlist[0]->ID.'&action=edit'); } exit(); } }
メニューバーの削除
ビジネスオーナーには自身のサイトの編集のみ行えるようにしたい。
その場合、上記の「編集画面へのリダイレクト」を実装することで、メニューの一切は不要となる。
add_action('admin_menu', 'remove_menus'); function remove_menus() { if(current_user_can('author')) { remove_menu_page('index.php'); remove_menu_page('upload.php'); remove_menu_page('edit-comments.php'); remove_menu_page('edit.php'); remove_menu_page('edit.php?post_type=gd_place'); remove_menu_page('profile.php'); remove_menu_page('tools.php'); global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); } } add_action('admin_head', 'custom_admin_style'); function custom_admin_style() { if(current_user_can('author')) { #wpadminbar,#adminmenumain,#wpfooter,#adv-settings,#wp-heading-inline,#screen-meta-links,.page-title-action,#edit-slug-buttons,.sd-lable-shortcode-inserter { display:none; } #post-body { margin-right: 0px; } #wpcontent, #wpfooter { margin-left: 0px; } #minor-publishing, #misc-publishing-actions, #major-publishing-actions { display:none; } </style><?php } }
投稿ページを強制的に1カラムにする
add_filter('get_user_option_screen_layout_gd_place', 'post_layout_force'); function post_layout_force() { if(current_user_can('author')) { return 1; } }
投稿ページのコメント操作を制限する
add_filter('comment_row_actions', 'filter_comment_operation', 10, 1); function filter_comment_operation($array) { if(current_user_can('author')) { return [ 'Reply' => $array['reply'], ]; } else { return $array; } }
不要なメタボックスを消去する
add_action('admin_menu','remove_metaboxes'); function remove_metaboxes() { if(current_user_can('author')) { remove_meta_box('postcustom','gd_place','normal'); // カスタムフィールド remove_meta_box('postexcerpt','gd_place','normal'); // 抜粋 remove_meta_box('commentstatusdiv','gd_place','normal'); // ディスカッション remove_meta_box('slugdiv','gd_place','normal'); // スラッグ } }
公開メタボックスの機能の制限
add_action('admin_init', 'custom_admin_script'); function custom_admin_script() { if(!current_user_can('author') || defined('DOING_AJAX')) return; if(!wp_script_is('jquery', 'done')) { wp_enqueue_script('jquery'); } $script = ' jQuery(function($) { const Submitpost = $("#submitpost"); $("#publish").appendTo(Submitpost); $("#post-preview").appendTo(Submitpost); });'; wp_add_inline_script('jquery-migrate', $script, 'after'); } add_action('admin_menu', 'move_submit_metabox'); function move_submit_metabox() { remove_meta_box('submitdiv', 'gd_place', 'normal' ); add_meta_box('submitdiv ', __('Publish' ), 'post_submit_meta_box', 'gd_place', 'normal', 'low' ); }