Ready to get started?Download WordPress


Replace function (3 posts)

  1. 13rust
    Posted 3 years ago #

    Hi! I know English not very good, so I will write briefly.
    Can I change function in other module by my own function?
    For example, I need to replace 'si_captcha_comment_form_wp3' function in Si-captcha module. Can I do this?

  2. maxk
    Posted 3 years ago #

    Hi 13rust,
    Unless you rewrite the function in si-captcha.php, which is a bad idea, it is not possible to do this since si_captcha_comment_form_wp3() does not implement any filters.

    Good luck!

  3. Sergey Biryukov
    Trac Moderator
    Posted 3 years ago #

    You can “unhook” the plugin's function and replace it with your own:

    function my_captcha_comment_form() {
    	global $si_image_captcha;
    	// ...
    	remove_action('comment_form', array(&$si_image_captcha, 'si_captcha_comment_form'), 1);
    function replace_si_captcha_comment_form_wp3() {
    	global $si_image_captcha;
    	remove_action('comment_form_after_fields', array(&$si_image_captcha, 'si_captcha_comment_form_wp3'), 1);
    	remove_action('comment_form_logged_in_after', array(&$si_image_captcha, 'si_captcha_comment_form_wp3'), 1);
    	add_action('comment_form_after_fields', 'my_captcha_comment_form', 1);
    	add_action('comment_form_logged_in_after', 'my_captcha_comment_form', 1);
    add_action('init', 'replace_si_captcha_comment_form_wp3');

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.