Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a Plugin installed on my WordPress site.

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()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
669 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can do it by using add_filter() function.
See wordpress stackexchange: Override plugin with functions.php

Just add the below code in theme's functions.php file.

add_filter('sensei_start_course_form','MyCustomfilter',$priority = 10, $args = 1);

function MyCustomfilter($course_id) { 
// Do your logics here
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...