2017-06-04 10 views
0

プラグインで呼び出される関数の引数を変更しようとしています。 プラグイン内の元のコードWordpressはプラグイン内の関数内のargsを置き換えます

orplugin_load_template('templatefile.php', array(
     'post_type' => $post_type, 
     'userdata' => wp_get_current_user(), 
     'dashboard_query' => $dashboard_query, 
     'post_type_obj' => $post_type_obj, 
     'post' => $post, 
     'pagenum' => $pagenum 
    )); 

は、私は私の子供のテーマ

function my_orplugin_load_template('mytemplatefile.php', array(
     'post_type' => $post_type, 
     'userdata' => wp_get_current_user(), 
     'dashboard_query' => $dashboard_query, 
     'post_type_obj' => $post_type_obj, 
     'post' => $post, 
     'pagenum' => $pagenum 
    )); 

ADD_FILTER( 'orplugin_load_template'、 'my_orplugin_load_template'、10)でのfunctions.phpに配置されたバージョンを試しマイ;

mytemplatefile.phpという独自のtemplatefile.phpを作成しました。私はこのファイルをプラグインの外にどこに保存するかを知っていません。それを元のプラグインで置き換える方法。 templatefile.phpの代わりにmytemplatefile.phpをロードします。これを達成する方法は?

+1

あなたは 'orplugin_load_template'というフィルタを使い、 'orplugin_load_template'フィルタの仕組みがわからないようですが、私はこの質問に答えることができないのではないかと恐れています。私はあなたが使用しているプラ​​グインがフィルタを持っていないと思うし、 'add_filter'が何をしているのか誤解しているかもしれません。既存の関数をフィルタリングしません。このコードサンプルでは、​​関数 'my_orplugin_load_template'は何もしません。 –

+0

良い点。あなたは私に正しい方向を送った。私はWPがプラグインの標準機能を持っていることを知りました: <?php load_template($ _template_file、$ require_once)?> – user5526048

答えて

0

良い点。あなたは私に正しい方向を送った。私はWPがプラグインのための標準的な機能を持っていることを知りました:

<?php load_template($_template_file, $require_once) ?> 

[https://codex.wordpress.org/Function_Reference/load_template]]そして実際のプラグインは、template.phpファイルがある、サブフォルダテンプレートstored.Iは、任意の提案を、その後、私の適応template.phpファイルを使用するには、次のコードを試してみましたが、いくつかのエラーメッセージ

if ($overridden_template = locate_template('some-template.php')) { 
// locate_template() returns path to file 
// if either the child theme or the parent theme have overridden the template 
load_template($overridden_template); 
} else { 
    // If neither the child nor parent theme have overridden the template, 
// we load the template from the 'templates' sub-directory of the directory this file is in 
    load_template(dirname(__FILE__) . '/templates/some-template.php'); 
} 

を持っていますか?

関連する問題