Instantly share code, notes, and snippets.
Last active
November 6, 2015 04:54
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
-
Save ytsuyuzaki/ae2c1ea3d588f689f82f to your computer and use it in GitHub Desktop.
wordpress 会員登録した人が投稿できるサイトの細かい設定。投稿者権限が記事やメディアやコメントの閲覧が自分のみになるとか
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @package 投稿者権限の調整 | |
| * @version 1.0 | |
| */ | |
| /* | |
| Plugin Name: author can | |
| Plugin URI: http://soramugi.net | |
| Description: 投稿者の権限を変更します | |
| Author: soramugi | |
| Version: 1.0 | |
| Author URI: http://soramugi.net | |
| */ | |
| // wp会員制サイト設定 | |
| // http://www.wakatta-blog.com/wordpress-makes-menber-page.html | |
| function remove_extra_meta_boxes() { | |
| if (!current_user_can('level_10')) { | |
| //remove_meta_box( 'categorydiv','post','side'); /* 投稿のカテゴリーフィールド */ | |
| //remove_meta_box( 'postcustom' , 'post' , 'normal' ); /* 投稿のカスタムフィールド */ | |
| //remove_meta_box( 'postcustom' , 'page' , 'normal' ); /* 固定ページのカスタムフィールド */ | |
| //remove_meta_box( 'postexcerpt' , 'post' , 'normal' ); /* 投稿の抜粋 */ | |
| //remove_meta_box( 'postexcerpt' , 'page' , 'normal' ); /* 固定ページの抜粋 */ | |
| //remove_meta_box( 'commentsdiv' , 'post' , 'normal' ); /* 投稿のコメント */ | |
| //remove_meta_box( 'commentsdiv' , 'page' , 'normal' ); /* 固定ページのコメント */ | |
| //remove_meta_box( 'tagsdiv-post_tag' , 'post' , 'side' ); /* 投稿のタグ */ | |
| //remove_meta_box( 'tagsdiv-post_tag' , 'page' , 'side' ); /* 固定ページのタグ */ | |
| //remove_meta_box( 'trackbacksdiv' , 'post' , 'normal' ); /* 投稿のトラックバック */ | |
| //remove_meta_box( 'trackbacksdiv' , 'page' , 'normal' ); /* 固定ページのトラックバック */ | |
| //remove_meta_box( 'commentstatusdiv' , 'post' , 'normal' ); /* 投稿のディスカッション */ | |
| //remove_meta_box( 'commentstatusdiv' , 'page' , 'normal' ); /* ページのディスカッション */ | |
| //remove_meta_box( 'slugdiv','post','normal'); /* 投稿のスラッグ */ | |
| //remove_meta_box( 'slugdiv','page','normal'); /* 固定ページのスラッグ */ | |
| //remove_meta_box( 'authordiv','post','normal' ); /* 投稿の作成者 */ | |
| //remove_meta_box( 'authordiv','page','normal' ); /* 固定ページの作成者 */ | |
| //remove_meta_box( 'revisionsdiv','post','normal' ); /* 投稿のリビジョン */ | |
| //remove_meta_box( 'revisionsdiv','page','normal' ); /* 固定ページのリビジョン */ | |
| //remove_meta_box( 'pageparentdiv','page','side'); /* 固定ページのページ属性 */ | |
| // simplicity | |
| remove_meta_box( 'comment_setting_in_page','post','side'); | |
| remove_meta_box( 'ad_setting_in_page','post','side'); | |
| remove_meta_box( 'page_setting_in_page','post','side'); | |
| remove_meta_box( 'seo_setting_in_page','post','side'); | |
| } | |
| } | |
| // 管理バーの項目を非表示 | |
| function remove_admin_bar_menu( $wp_admin_bar ) { | |
| if (!current_user_can('level_10')) { | |
| $wp_admin_bar->remove_node('wp-logo'); //WordPressロゴ | |
| //$wp_admin_bar->remove_node('site-name'); //サイト名 | |
| $wp_admin_bar->remove_node('updates'); //アップデート通知 | |
| //$wp_admin_bar->remove_node('comments'); //コメント | |
| //$wp_admin_bar->remove_node('new-content');//新規追加 | |
| //$wp_admin_bar->remove_node('new-media'); // メディア | |
| $wp_admin_bar->remove_node('new-link'); // リンク | |
| //$wp_admin_bar->remove_node('new-page'); // 個別ページ | |
| // $wp_admin_bar->remove_node('new-user'); // ユーザー | |
| //$wp_admin_bar->remove_node('view'); //投稿を表示 | |
| //$wp_admin_bar->remove_node('my-account'); // 右のプロフィール欄全体 | |
| //$wp_admin_bar->remove_node('edit-profile'); // プロフィール編集 | |
| //$wp_admin_bar->remove_node('user-info'); // ユーザー | |
| //$wp_admin_bar->remove_node('logout'); //ログアウト | |
| } | |
| } | |
| function remove_menu() { | |
| if (!current_user_can('level_10')) { | |
| //remove_menu_page('index.php'); // ダッシュボード | |
| //remove_menu_page('edit.php'); // 投稿 | |
| //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('users.php'); // ユーザー | |
| //remove_menu_page('tools.php'); // ツール | |
| //remove_menu_page('options-general.php'); // 設定 | |
| remove_menu_page('wpcf7'); //Contact Form 7 | |
| } | |
| } | |
| function remove_dashboard_widgets() { | |
| if (!current_user_can('level_10')) { | |
| 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フォーラム | |
| } | |
| } | |
| /* | |
| * メディアの抽出条件にログインユーザーの絞り込み条件を追加する | |
| */ | |
| function display_only_self_uploaded_medias( $wp_query ) { | |
| if(!current_user_can('level_10')){ | |
| if ( is_admin() && ( $wp_query->is_main_query() || ( defined( 'DOING_QUERY_ATTACHMENT' ) && DOING_QUERY_ATTACHMENT ) ) && $wp_query->get( 'post_type' ) == 'attachment' ) { | |
| $wp_query->set( 'author', get_current_user_id() ); | |
| } | |
| } | |
| } | |
| function define_doing_query_attachment_const() { | |
| if(!current_user_can('level_10')){ | |
| if ( ! defined( 'DOING_QUERY_ATTACHMENT' ) ) { | |
| define( 'DOING_QUERY_ATTACHMENT', true ); | |
| } | |
| } | |
| } | |
| //他の人の投稿を見れないようにする | |
| function exclude_other_posts( $wp_query ) { | |
| if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) { | |
| $post_type = get_post_type_object( $_REQUEST['post_type'] ); | |
| $cap_type = $post_type->cap->edit_other_posts; | |
| } else { | |
| $cap_type = 'edit_others_posts'; | |
| } | |
| if ( is_admin() && $wp_query->is_main_query() && ! $wp_query->get( 'author' ) && ! current_user_can( $cap_type ) ) { | |
| $wp_query->set( 'author', get_current_user_id() ); | |
| } | |
| } | |
| //投稿リストから「すべて」などを消す | |
| function custom_columns($columns) { | |
| if (!current_user_can('level_10')) { | |
| echo '<style type="text/css">li.all,li.publish,li.pending {display:none;}</style>'; | |
| } | |
| return $columns; | |
| } | |
| //入力画面 現在の状況のWordPress表示を消す | |
| function my_admin_print_styles(){ | |
| if (!current_user_can('level_10')) { | |
| echo '<style type="text/css">.versions p,#wp-version-message,#footer-upgrade{display:none;}</style>'; | |
| } | |
| } | |
| // フッターWordPressリンクを非表示に | |
| function custom_admin_footer() { | |
| echo ''; | |
| } | |
| // 自分のコメントだけ表示 | |
| function my_pre_get_comments( $query ) { | |
| if ( is_admin() && ! current_user_can( 'administrator' )) { | |
| $query->query_vars['user_id'] = get_current_user_id(); | |
| } | |
| } | |
| // コメントの編集権限剥奪 | |
| function my_user_has_cap( $allcaps, $caps, $args ) { | |
| if ( 'edit_comment' == $args[0] && get_current_user_id() == $args[1] ) { | |
| foreach ( $caps as $cap ) { | |
| //$allcaps[$cap] = true; | |
| unset( $allcaps[$cap] ); | |
| } | |
| } | |
| return $allcaps; | |
| } | |
| add_action('admin_menu', 'remove_menu'); | |
| add_action('pre_get_comments', 'my_pre_get_comments' ); | |
| add_filter('user_has_cap', 'my_user_has_cap', 10, 3 ); | |
| add_action('admin_bar_menu', 'remove_admin_bar_menu', 1000 ); | |
| add_action('wp_dashboard_setup', 'remove_dashboard_widgets'); | |
| add_action('pre_get_posts', 'display_only_self_uploaded_medias' ); | |
| add_action('wp_ajax_query-attachments', 'define_doing_query_attachment_const', 0 ); | |
| add_action('admin_bar_menu', 'remove_admin_bar_menu', 70 ); | |
| add_action('admin_init', 'remove_extra_meta_boxes' ); | |
| add_action('pre_get_posts', 'exclude_other_posts' ); | |
| add_action('admin_print_styles', 'my_admin_print_styles', 21); | |
| add_filter('admin_footer_text', 'custom_admin_footer'); | |
| add_filter('manage_posts_columns', 'custom_columns' ); | |
| remove_action('wp_version_check', 'wp_version_check'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment