2017-06-04 56 views
0

我想修改在插件中調用的函數的參數。 插件Wordpress替換插件中的函數的參數

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 
    )); 

內的原代碼我試用的版本,我放在functions.php的在我的子主題

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);

我創建了我自己的templatefile.php,名爲mytemplatefile.php。我不知道將該文件存儲在插件外的位置。以及如何調用它來替換原來的插件。我想加載mytemplatefile.php來代替templatefile.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'); 
} 

任何建議的子文件夾模板?