質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

2回答

3531閲覧

編集者権限でも管理バーに表示されるように権限を与えたい。

akkkkin

総合スコア83

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

1クリップ

投稿2017/07/08 10:41

編集2017/07/10 00:40

woocommerceでショッピングサイトを構築し、
初回のみ割引が適用できるwoo-first-discountというプラグインを入れました。

そして、
[ wp-admin-menu-manager](https : //codecanyon.net/item/wp-admin-menu-manager/9520160)という権限別に管理メニューを編集できるプラグインで
編集者権限でも管理メニューのサイドバーに表示されうように設定したんですが、
表示されません。ちなみにwoo-first-discountのプラグインはもともと
管理者権限でしか表示されていません。

となると、woo-first-discountのプラグイン自体の中身をカスタマイズして、
編集者権限でもwoo-first-discountが表示されるようにしたいのですが、
どこをいじればいいのでしょうか。以下にwoo-first-discountのプラグインの
phpファイルを添付しました。woo-first-discountは以下のファイルだけです。

<?php /** * Plugin Name: First Order Discount * Plugin URI: http://fmrfox.com/first-order-discount/ * Description: This plugin add some discount for authorized customer when they make first order * Version: 1.0.5 * Author: Andriyan Anton * Author URI: http://fmrfox.com * Text Domain: woo-first-discount * Domain Path: /lang * License: GPL2 */ // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit; } add_action( 'admin_menu', 'first_order_add_add_admin_menu' ); add_action( 'admin_init', 'first_order_add_settings_init' ); /* Include translations */ function first_order_add_load_textdomain() { load_plugin_textdomain( 'woo-first-discount', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); } add_action('plugins_loaded', 'first_order_add_load_textdomain'); /* Admin sttings page */ function first_order_add_add_admin_menu( ) { add_submenu_page( 'woocommerce', 'First Order Discount', 'First Order Discount', 'manage_options', 'woocomerce_first_order_discount', 'first_order_add_options_page' ); } function first_order_add_settings_init( ) { register_setting( 'pluginPage', 'first_order_add_settings' ); add_settings_section( 'first_order_add_pluginPage_section', __( 'Choose your setting', 'woo-first-discount' ), '', 'pluginPage' ); add_settings_field( 'first_order_choose', __( 'Choose discount type', 'woo-first-discount' ), 'first_order_choose_render', 'pluginPage', 'first_order_add_pluginPage_section' ); add_settings_field( 'first_order_add_value', __( 'Choose discount value', 'woo-first-discount' ), 'first_order_add_value_render', 'pluginPage', 'first_order_add_pluginPage_section' ); } function first_order_choose_render( ) { $options = get_option( 'first_order_add_settings' ); ?> <input id="off" type='radio' name='first_order_add_settings[first_order_choose]' <?php checked( $options['first_order_choose'], 'off' ); ?> value='off'> <label for="off"><?php echo __( 'Disable first order discount', 'woo-first-discount' ); ?></label> <br> <input id="fixed" type='radio' name='first_order_add_settings[first_order_choose]' <?php checked( $options['first_order_choose'], 'fixed' ); ?> value='fixed'> <label for="fixed"><?php echo __( 'Fixed discount', 'woo-first-discount' ); ?></label> <br> <input id="percent" type='radio' name='first_order_add_settings[first_order_choose]' <?php checked( $options['first_order_choose'], 'percent' ); ?> value='percent'> <label for="percent"><?php echo __( 'Percent discount', 'woo-first-discount' ); ?></label> <?php } function first_order_add_value_render( ) { $options = get_option( 'first_order_add_settings' ); ?> <input type='number' min="0" name='first_order_add_settings[first_order_add_value]' value='<?php echo $options['first_order_add_value']; ?>'> <?php } function first_order_add_options_page( ) { ?> <form action='options.php' method='post'> <h2><?php echo __( 'First Order Discount', 'woo-first-discount' ); ?></h2> <?php settings_fields( 'pluginPage' ); do_settings_sections( 'pluginPage' ); submit_button(); ?> </form> <?php } /* Discount */ function first_order_add_fee() { global $wpdb, $woocommerce; if ( is_user_logged_in() ) { $customer_id = get_current_user_id(); $orderNumCheck = wc_get_customer_order_count( $customer_id ); // count orders by current customer $options = get_option( 'first_order_add_settings' ); $discountType = $options['first_order_choose']; $discountValue = $options['first_order_add_value']; if ($orderNumCheck == 0 and $discountType != 'off') { // if first order by user $subtotal = WC()->cart->cart_contents_total; if ($discountType == 'fixed') { WC()->cart->add_fee( '初回割引', -$discountValue ); } else { $discount = $discountValue/100; WC()->cart->add_fee( '初回割引', -$subtotal*$discount ); } } } } add_action( 'woocommerce_cart_calculate_fees','first_order_add_fee' ); ?>

もし詳しい方がいらっしゃればご教示いただけますとありがたいです。

[追記]
User role editorというプラグインでも試してみましたが、
そもそも該当するプラグインの権限が表示されません。
イメージ説明
したがって権限の設定がUser role editorではできない状況です。

表示させたい項目は以下の画像の箇所です。
イメージ説明
First Order Discountの項目のパラメーター↓
?page=woocomerce_first_order_discount

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

wp-admin-menu-managerなるプラグインがどんなものか知りませんが、manage_optionsの権限を与えれば表示されるはずです。
User Role Editorでも同じような設定が可能ですが、編集者権限でWooCommerceを扱えるようにしてmanage_optionsの権限を与えると、お使いになりたいプラグインが編集者権限でも使えるようになります。
https://ja.wordpress.org/plugins/user-role-editor/

イメージ説明

投稿2017/07/08 11:38

編集2017/07/10 03:03
退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

akkkkin

2017/07/08 11:42

コメントありがとうございます。最初User Role Editorも入れてたんですけどもプラグインの権限自体表示されませんでした。
退会済みユーザー

退会済みユーザー

2017/07/09 00:31

では再度User Role Editorで出来ないか試してみてください。 出来ないのは設定の問題なので必ず出来ます。
akkkkin

2017/07/10 00:40

コメントありがとうございます。試しましたがプラグインの権限項目が表示されません。詳しくは上記に追記しました。
退会済みユーザー

退会済みユーザー

2017/07/10 03:03

ちゃんと読んでますか?だから先に書いた通り編集者権限に”manage_options”の権限を与えれば良いだけです。 ”manage_options”を探してチェックしてください。 画像を追加したのでよく確認してください。 もし”manage_options”が存在しないのなら別の部分に問題があるんでしょうが、その場合は分かりません。
akkkkin

2017/07/10 03:11

>”manage_options”を探してチェックしてください すでにチェックしています。
guest

0

実際に検証していないので間違っていたらすみません。

###①管理画面でのみ追加しているのを変更する案
以下の2行が、原因なのではないかと思われます。

add_action( 'admin_menu', 'first_order_add_add_admin_menu' );

add_action( 'admin_init', 'first_order_add_settings_init' );

それぞれ、admin_menu、admin_initというアクションの時に、
first_~が行われるという内容です。
admin_menu、admin_initは共に管理画面のアクションです。
そのため、管理者権限の場合にのみ行われます。

『First Order Discount』のサブメニューへの表示は、
admin_menuに紐づいているので、管理者権限で表示されています。

widgets_initか、initに変えたら管理者権限以外でも表示されるようになると思います。

###②編集者権限にプラグインへのアクセスを許可する案
以下を追加することで、権限を取得して、
編集者権限に対して、プラグインを許可する方法です。

php

1function add_theme_caps(){ 2 $role = get_role( 'editor' ); 3 $role->add_cap( 'activate_plugins' ); 4} 5add_action( 'admin_init', 'add_theme_caps' );

投稿2017/07/10 02:55

raindrop

総合スコア12

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問