2017-02-02 2 views
1

custom divi moduleを作成してのに変換しました。 Diviテーマがアクティブになっている場合にのみアクティブプラグインにしたいと思っています。 このようにコードを書くと毎回通知が表示されます。add_actionが管理通知のための別の関数で動作していません

function my_admin_notice(){ 
    echo '<div class="updated"> 
     <p>test Admin notice.</p> 
    </div>'; 
} 
add_action('admin_notices', 'my_admin_notice'); 

しかし、私は

function angelleye_setup_For_paypal_divi_install() 
    {  
     if (function_exists('et_setup_theme')) { 
      // Divi is the current theme or the active theme's parent. 
      // trigger our function that registers PayPal for Divi plugin.  
      angelleye_setup_for_paypal_divi();   
     } 
     else{ 
      // code when theme is not activated. 
      add_action('admin_notices', 'my_admin_notice'); 
     }    
    } 
    register_activation_hook(__FILE__, 'angelleye_setup_For_paypal_divi_install'); 

function my_admin_notice(){ 
     echo '<div class="updated"> 
      <p>test Admin notice.</p> 
     </div>'; 
    } 

ベースの条件でコードを書くとき、私は今、私はangelleye_setup_For_paypal_divi_install 機能ではなく、関数内で呼び出していますadd_actionここhttps://wptheming.com/2011/08/admin-notices-in-wordpress/

を管理者通知を表示するためのコードをコピーadd_actionが機能していません。

+0

のための活性化関数の後に、私はあなた 'add_action'が動作しているが、その' add_actionのfunction'内に問題があると思います。このコードを追加します。関数内でロジックを実装する前に 'echo Hello World;'を試してください。あなたがhello worldを見れば、add_actionは動作していますが、実装しているロジックに問題があります –

+0

@FahadSohail今すぐ自分のコードをチェックしてください。 –

+0

@FahadSohail私はエコーしか書いていませんし、関数を呼び出すこともありません:( –

答えて

2

てみhttps://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices

に述べたように、あなたが2つの管理者通知{class}の要件と{message}が欠落していることです。ここから状態を取り除いてください。

/** 
* The code that runs during plugin activation. 
    * 
    */ 
function angelleye_setup_For_paypal_divi_install() 
{ 

angelleye_setup_for_paypal_divi(); 

} 
     register_activation_hook(__FILE__,'angelleye_setup_For_paypal_divi_install'); 

表示管理者通知

/* Display a notice that can be dismissed */ 
function my_custom_notice() { 
?> 
<div class="update-nag notice"> 
    <p><?php _e('Please install Divi theme to use PayPal Divi Module!', 'angelleye_paypal_divi'); ?></p> 
</div> 
<?php 
} 
$theme = wp_get_theme(); 
if($theme != 'Divi') { 
add_action('admin_notices', 'my_custom_notice'); 
} 
+0

ありがとうございます。 –

0

あなたのコードの問題は、あなたが間違った場所に条件を追加している

function angelleye_setup_For_paypal_divi_install() 
{  
    if (function_exists('et_setup_theme')) { 
     // Divi is the current theme or the active theme's parent. 
     // trigger our function that registers PayPal for Divi plugin.  
     angelleye_setup_for_paypal_divi();   
    } 
    else{ 
     // code when theme is not activated. 
     add_action('admin_notices', 'sample_admin_notice__success'); 
    }    
} 
register_activation_hook(__FILE__, 'angelleye_setup_For_paypal_divi_install'); 

function sample_admin_notice__success() { 
    ?> 
    <div class="notice notice-success is-dismissible"> 
     <p><?php _e('Done!', 'sample-text-domain'); ?></p> 
    </div> 
    <?php 
} 
+0

あなたのコードをコピーしてあなたと同じコードに変更しましたが、まだadd_actionは呼び出していません。 so die()は実行されませんが、if else条件にechoを置くと致命的なエラーでそのエコーが表示されます –

+0

http://pastebin.com/sDvmLEBWここに私のフルコード –

+0

umm .. 。。 'angelleye_setup_For_paypal_divi_install'機能の上に' sample_admin_notice__success'関数を宣言 –

関連する問題