return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>pluggable - the file placed in the child theme is not included
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

pluggable - the file placed in the child theme is not included

programmeradmin1浏览0评论

I have modified the theme.php file located in the parent theme in the "Includes" folder, and I have placed it in the child theme also in the "Includes" folder, but my changes are not included. WordPress only reads the file placed in the parent theme folder. What is the reason for this? What should I do the modifications are included when the file is located in the child theme folder? Alternatively, how can I override a function from includes/theme.php in functions.php? I can’t override the function because there’s a redeclaration error.

Edit 7.05.2020

@JacobPeattie - Thanks a lot. I read it. I don't know if I understand it all right. My English isn't very good yet. I wrote so in functions.php:

if ( ! function_exists( 'bimber_capture_entry_featured_media' ) ) :
function bimber_capture_entry_featured_media_my_modifications( $args ) {

//function code with my modifications

}
endif;

It was successful added, but doesn’t work.

Maybe it’s usefull information:

  1. File theme.php is added in functions.php file in parentTheme/includes folder in this way: require_once BIMBER_INCLUDES_DIR . 'theme.php';

  2. Function is called by ‘echo’ in another function.

Here are php files:

  • .php.txt
  • .php.txt

I have modified the theme.php file located in the parent theme in the "Includes" folder, and I have placed it in the child theme also in the "Includes" folder, but my changes are not included. WordPress only reads the file placed in the parent theme folder. What is the reason for this? What should I do the modifications are included when the file is located in the child theme folder? Alternatively, how can I override a function from includes/theme.php in functions.php? I can’t override the function because there’s a redeclaration error.

Edit 7.05.2020

@JacobPeattie - Thanks a lot. I read it. I don't know if I understand it all right. My English isn't very good yet. I wrote so in functions.php:

if ( ! function_exists( 'bimber_capture_entry_featured_media' ) ) :
function bimber_capture_entry_featured_media_my_modifications( $args ) {

//function code with my modifications

}
endif;

It was successful added, but doesn’t work.

Maybe it’s usefull information:

  1. File theme.php is added in functions.php file in parentTheme/includes folder in this way: require_once BIMBER_INCLUDES_DIR . 'theme.php';

  2. Function is called by ‘echo’ in another function.

Here are php files:

  • http://srv19859.microhost.pl/phpfiles/functions.php.txt
  • http://srv19859.microhost.pl/phpfiles/theme.php.txt
Share Improve this question edited May 7, 2020 at 11:21 reti asked May 6, 2020 at 8:20 retireti 276 bronze badges 4
  • 2 No, child themes don't automatically substitute included files like that. You also can't undeclare a function to replace it - at least not without something like runkit, but I wouldn't go down that route. What behaviour are you trying to change? Are there any hooks provided in the theme that you can use? – Rup Commented May 6, 2020 at 8:31
  • 4 Does this answer your question? override parent theme configuration in child functions.php – Jacob Peattie Commented May 6, 2020 at 8:36
  • @Rup and Jacob Peattie. Thanks for your answers. I edited my question. – reti Commented May 7, 2020 at 11:24
  • 1 bimber_capture_entry_featured_media_my_modifications - you'd have to give it exactly the same function name. But unless the function is also pluggable in the parent theme this won't do any good. (I'd have expected the parent theme would be loaded first but I think I'm wrong and the child is loaded first.) – Rup Commented May 7, 2020 at 11:38
Add a comment  | 

1 Answer 1

Reset to default 2

You want to replace bimber_capture_entry_featured_media in your child theme. In the theme.php file you've given us you can see that this is only called in one place, from bimber_render_entry_featured_media, and the call is wrapped in a filter:

if ( apply_filters( 'bimber_render_entry_featured_media', true, $args ) ) {
    echo bimber_capture_entry_featured_media( $args );
}

where returning false from the filter will cancel the call to the default code. Assuming that's true, that nothing else calls this function without the filter guard, what you can do then instead is

  1. implement the bimber_render_entry_featured_media filter; choose a low priority if there's anything else that implements this, but I don't see anything in these files
  2. in the filter call your replacement bimber_capture_entry_featured_media_my_modifications and echo the result
  3. return false from the filter to cancel the call to the original unmodified code.

e.g. (untested)

function bimber_render_entry_featured_media_filter_my_modifications( $flag, $args ) {
    if ($flag) {
        echo bimber_capture_entry_featured_media_my_modifications( $args );
    }
    return false;
}
add_filter( 'bimber_render_entry_featured_media',
            'bimber_render_entry_featured_media_filter_my_modifications', 10, 2 );

However there are plenty of hooks in the original method too, so depending on what you're trying to do you might be able to use those to change the behaviour rather than completely overriding the method.

发布评论

评论列表(0)

  1. 暂无评论