問題描述
我的 WordPress 網站上安裝了插件.
I have a Plugin installed on my WordPress site.
我想覆蓋插件中的一個功能.我是否在我的主題的 functions.php
中覆蓋它,如果是,我該怎么做?
I'd like to override a function within the Plugin. Do I override this in my theme's functions.php
and if so, how do I do this?
這是我插件中的原始函數:
Here's the original function in my plugin:
/**
* sensei_start_course_form function.
*
* @access public
* @param mixed $course_id
* @return void
*/
function sensei_start_course_form( $course_id ) {
$prerequisite_complete = sensei_check_prerequisite_course( $course_id );
if ( $prerequisite_complete ) {
?><form method="POST" action="<?php echo esc_url( get_permalink() ); ?>">
<input type="hidden" name="<?php echo esc_attr( 'woothemes_sensei_start_course_noonce' ); ?>" id="<?php echo esc_attr( 'woothemes_sensei_start_course_noonce' ); ?>" value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_start_course_noonce' ) ); ?>" />
<span><input name="course_start" type="submit" class="course-start" value="<?php echo apply_filters( 'sensei_start_course_text', __( 'Start taking this Course', 'woothemes-sensei' ) ); ?>"/></span>
</form><?php
} // End If Statement
} // End sensei_start_course_form()
推薦答案
你不能真正覆蓋"一個函數.如果定義了函數,則不能重新定義或更改它.您最好的選擇是創建插件的副本并直接更改功能.當然,每次插件更新時,您都必須重復此操作.
You can't really "override" a function. If a function is defined, you can't redefine or change it. Your best option is to create a copy of the plugin and change the function directly. Of course you will have to repeat this everytime the plugin is updated.
給插件一個不同的名字以在插件列表中區分它們.禁用原件,啟用您的副本.
Give the plugin a different name to distinguish them in the plugin listing. Disable the original, enable your copy.
這篇關于覆蓋 WordPress 中的插件功能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!