wordpress - How to override a not plugable parent theme function from a non function.php file? -


i want reduce number of image files parent theme produces. after little research found need override function php file (not function.php) of parent theme, impossible because this function not pluggable (not wrapped in if (!function_exists()) condition). now, wrapped parent function in if (!function_exists()) condition , overridden in child theme function.php file.

in described situation, possible override parent function not changing parent theme? ask here because not have reaction developer.

i tried remove parent theme function next code in child theme , in plugin, didn't helped:

function remove_fastnews_actions() {     remove_action('after_setup_theme','kopa_front_after_setup_theme'); } add_action('after_setup_theme','remove_fastnews_actions'); //add_action('wp_loaded','remove_fastnews_actions'); 

this function need override (it bigger, keeped here need change):

add_action('after_setup_theme', 'kopa_front_after_setup_theme');  function kopa_front_after_setup_theme() {     $sizes = array(         'flexslider-image-size'   => array(500, 500, true, __('flexslider post image (kopatheme)', kopa_get_domain())),         'article-list-image-size' => array(300, 277, true, __('article list post image (kopatheme)', kopa_get_domain())),         'article-list-sm-image-size' => array(120, 120, true, __('article list small post image (kopatheme)', kopa_get_domain())),         'article-carousel-image-size' => array(354, 354, true, __('article carousel post image (kopatheme)', kopa_get_domain())),         'entry-list-image-size' => array(227, 182, true, __('entry list thumbnail image (kopatheme)', kopa_get_domain())),         'blog-image-size' => array(680, 419, true, __('blog image size (kopatheme)', kopa_get_domain())),     );      apply_filters('kopa_get_image_sizes', $sizes);      foreach ($sizes $slug => $details) {         add_image_size($slug, $details[0], $details[1], $details[2]);     } } 

the same parent function made pluggable:

if( !function_exists('kopa_front_after_setup_theme') ) {  add_action('after_setup_theme', 'kopa_front_after_setup_theme');  function kopa_front_after_setup_theme() {     $sizes = array(         'flexslider-image-size'   => array(500, 500, true, __('flexslider post image (kopatheme)', kopa_get_domain())),         'article-list-image-size' => array(300, 277, true, __('article list post image (kopatheme)', kopa_get_domain())),         'article-list-sm-image-size' => array(120, 120, true, __('article list small post image (kopatheme)', kopa_get_domain())),         'article-carousel-image-size' => array(354, 354, true, __('article carousel post image (kopatheme)', kopa_get_domain())),         'entry-list-image-size' => array(227, 182, true, __('entry list thumbnail image (kopatheme)', kopa_get_domain())),         'blog-image-size' => array(680, 419, true, __('blog image size (kopatheme)', kopa_get_domain())),     );      apply_filters('kopa_get_image_sizes', $sizes);      foreach ($sizes $slug => $details) {         add_image_size($slug, $details[0], $details[1], $details[2]);     } }  } 

and child theme function override parent function:

add_action('after_setup_theme', 'kopa_front_after_setup_theme');  function kopa_front_after_setup_theme() {     $sizes = array(         'flexslider-image-size'   => array(0, 0, true, __('flexslider post image (kopatheme)', kopa_get_domain())),         'article-list-image-size' => array(0, 0, true, __('article list post image (kopatheme)', kopa_get_domain())),         'article-list-sm-image-size' => array(120, 120, true, __('article list small post image (kopatheme)', kopa_get_domain())),         'article-carousel-image-size' => array(0, 0, true, __('article carousel post image (kopatheme)', kopa_get_domain())),         'entry-list-image-size' => array(0, 0, true, __('entry list thumbnail image (kopatheme)', kopa_get_domain())),         'blog-image-size' => array(0, 0, true, __('blog image size (kopatheme)', kopa_get_domain())),     );      apply_filters('kopa_get_image_sizes', $sizes);      foreach ($sizes $slug => $details) {         add_image_size($slug, $details[0], $details[1], $details[2]);     } } 

since original function has filter in function, why not take advantage of that? in functions.php, (untested code):

add_filter('kopa_get_image_sizes', 'override_kopa_images');  function override_kopa_images($sizes) {     $new_sizes = array(         'flexslider-image-size'   => array(0, 0, true, __('flexslider post image (kopatheme)', kopa_get_domain())),         'article-list-image-size' => array(0, 0, true, __('article list post image (kopatheme)', kopa_get_domain())),         'article-list-sm-image-size' => array(120, 120, true, __('article list small post image (kopatheme)', kopa_get_domain())),         'article-carousel-image-size' => array(0, 0, true, __('article carousel post image (kopatheme)', kopa_get_domain())),         'entry-list-image-size' => array(0, 0, true, __('entry list thumbnail image (kopatheme)', kopa_get_domain())),         'blog-image-size' => array(0, 0, true, __('blog image size (kopatheme)', kopa_get_domain())),     );     return $new_sizes; } 

alternatively, use input variable $sizes change individual entries, eg

add_filter('kopa_get_image_sizes', 'override_kopa_images');  function override_kopa_images($sizes) {     $sizes['flexslider-image-size'] = array(0, 0, true, __('flexslider post image (kopatheme)', kopa_get_domain()));     return $sizes; } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -