Skip to main content
deleted 645 characters in body
Source Link
cmsdeployed
  • 389
  • 3
  • 7
  • 19

I have updated by deleting some redundant options.

    // make the nopic.jpg update possible via child theme.
    if ( ! function_exists( 'TaskerDev_get_first_post_image_fnc' ) ) :// I 
 am using this to overwrite the parent action.
    
 function TaskerDev_get_first_post_image_fnc($pid, $w = /*************************************************************
100, $h = 100) //*{
    //* TaskerDev (c) sitemile.com - function
    //*
    **************************************************************/
    function TaskerDev_get_first_post_image($pid, $w = 100, $h = 100)
    {
        $img = TaskerDev_get_first_post_image_fnc($pid, $w, $h);//---------------------
        $img = apply_filters('TaskerDev_get_first_post_image_filter', $img, $pid, $w, $h);
   // build the exclude list
 return $img;
        
     }
  $exclude = /*************************************************************array();
    //*
    //* TaskerDev (c) sitemile.com - function
    //*
    **************************************************************/
    
     function TaskerDev_get_first_post_image_fnc($pid, $w = 100, $h$args = 100)array(
    {
        
     'order'   
        => 'ASC',
        //---------------------
        //'post_type' build the exclude list
  => 'attachment',
     $exclude = array();
        
  'post_parent'    => $pid,
  $args = array(
        'order'    'meta_key'       => 'ASC''another_reserved1',
        'post_type'      => 'attachment',
       'meta_value' 'post_parent'    => $pid'1',
        'meta_key'       => 'another_reserved1',
 'numberposts'    => -1,
  'meta_value'     => '1',
        'numberposts''post_status'    => -1null,
        'post_status'    => null,   );
        );
        $attachments = get_posts($args);
                if ($attachments) {
                        foreach ($attachments as $attachment) {
                        $url = $attachment->ID;
                        array_push($exclude, $url);
                    }
                }
                
                //-----------------
            
                $args = array(
                'order'          => 'ASC',
                'orderby'        => 'post_date',
                'post_type'      => 'attachment',
                'post_parent'    => $pid,
                'exclude'           => $exclude,
                'post_mime_type' => 'image',
                'post_status'    => null,
                'numberposts'    => 1,
                );
                $attachments = get_posts($args);
                if ($attachments) {
                    foreach ($attachments as $attachment) {
                {
                //$url = wp_get_attachment_url($attachment->ID);
                        return TaskerDev_wp_get_attachment_image($attachment->ID, 'thumb_image_thing'); 
   
                  }
                }
        else        #else   return get_bloginfo('template_url').'/images/nopic.jpg'; 
 // wanna replace with:            else    return get_stylesheet_directory_uri().'/images/Picture16.jpg';
            }
            /*************************************************************
            //*
    //        *   TaskerDev (c) sitemile.com - function
    //*
    **************************************************************    /
    endif;
    
     ///*************************************************************/end
        endif;
    // make the nopic.jpg update possible via child theme.
    if ( ! function_exists( 'TaskerDev_get_first_post_image_fnc' ) ) :// I am using this to overwrite the parent action.
    
     /*************************************************************
    //*
    //* TaskerDev (c) sitemile.com - function
    //*
    **************************************************************/
    function TaskerDev_get_first_post_image($pid, $w = 100, $h = 100)
    {
        $img = TaskerDev_get_first_post_image_fnc($pid, $w, $h);
        $img = apply_filters('TaskerDev_get_first_post_image_filter', $img, $pid, $w, $h);
        return $img;
        
     }
    /*************************************************************
    //*
    //* TaskerDev (c) sitemile.com - function
    //*
    **************************************************************/
    
     function TaskerDev_get_first_post_image_fnc($pid, $w = 100, $h = 100)
    {
        
        
         
        //---------------------
        // build the exclude list
        $exclude = array();
        
         $args = array(
        'order'          => 'ASC',
        'post_type'      => 'attachment',
        'post_parent'    => $pid,
        'meta_key'       => 'another_reserved1',
        'meta_value'     => '1',
        'numberposts'    => -1,
        'post_status'    => null,
        );
        $attachments = get_posts($args);
        if ($attachments) {
                foreach ($attachments as $attachment) {
            $url = $attachment->ID;
            array_push($exclude, $url);
        }
        }
        
        //-----------------
    
        $args = array(
        'order'          => 'ASC',
        'orderby'        => 'post_date',
        'post_type'      => 'attachment',
        'post_parent'    => $pid,
        'exclude'           => $exclude,
        'post_mime_type' => 'image',
        'post_status'    => null,
        'numberposts'    => 1,
        );
        $attachments = get_posts($args);
        if ($attachments) {
                foreach ($attachments as $attachment) 
                {
                //$url = wp_get_attachment_url($attachment->ID);
                return TaskerDev_wp_get_attachment_image($attachment->ID, 'thumb_image_thing');   
             }
        }
        else    return get_bloginfo('template_url').'/images/nopic.jpg'; // wanna replace with: return get_stylesheet_directory_uri().'/images/Picture16.jpg';
    }
    /*************************************************************
    //*
    //* TaskerDev (c) sitemile.com - function
    //*
    **************************************************************/
    endif;
    
     ////end

I have updated by deleting some redundant options.

    if ( ! function_exists( 'TaskerDev_get_first_post_image_fnc' ) ) : 
            function TaskerDev_get_first_post_image_fnc($pid, $w = 100, $h = 100) {
                            
                //---------------------
                // build the exclude list
                $exclude = array();
                
                $args = array(
                'order'          => 'ASC',
                'post_type'      => 'attachment',
                'post_parent'    => $pid,
                'meta_key'       => 'another_reserved1',
                'meta_value'     => '1',
                'numberposts'    => -1,
                'post_status'    => null,
                );
                $attachments = get_posts($args);
                if ($attachments) {
                        foreach ($attachments as $attachment) {
                        $url = $attachment->ID;
                        array_push($exclude, $url);
                    }
                }
                
                //-----------------
            
                $args = array(
                'order'          => 'ASC',
                'orderby'        => 'post_date',
                'post_type'      => 'attachment',
                'post_parent'    => $pid,
                'exclude'           => $exclude,
                'post_mime_type' => 'image',
                'post_status'    => null,
                'numberposts'    => 1,
                );
                $attachments = get_posts($args);
                if ($attachments) {
                    foreach ($attachments as $attachment) {
                        //$url = wp_get_attachment_url($attachment->ID);
                        return TaskerDev_wp_get_attachment_image($attachment->ID, 'thumb_image_thing'); 
                    }
                }
                #else   return get_bloginfo('template_url').'/images/nopic.jpg'; 
                else    return get_stylesheet_directory_uri().'/images/Picture16.jpg';
            }
            /*************************************************************
            //*
            *   TaskerDev (c) sitemile.com - function
            /
            *************************************************************/
        endif;
Source Link
cmsdeployed
  • 389
  • 3
  • 7
  • 19

How to replace a function using a child theme?

I have the following function where I would like to replace the image nopic.jpg

    // make the nopic.jpg update possible via child theme.
    if ( ! function_exists( 'TaskerDev_get_first_post_image_fnc' ) ) :// I am using this to overwrite the parent action.
    
    /*************************************************************
    //*
    //* TaskerDev (c) sitemile.com - function
    //*
    **************************************************************/
    function TaskerDev_get_first_post_image($pid, $w = 100, $h = 100)
    {
        $img = TaskerDev_get_first_post_image_fnc($pid, $w, $h);
        $img = apply_filters('TaskerDev_get_first_post_image_filter', $img, $pid, $w, $h);
        return $img;
        
    }
    /*************************************************************
    //*
    //* TaskerDev (c) sitemile.com - function
    //*
    **************************************************************/
    
    function TaskerDev_get_first_post_image_fnc($pid, $w = 100, $h = 100)
    {
        
        
        
        //---------------------
        // build the exclude list
        $exclude = array();
        
        $args = array(
        'order'          => 'ASC',
        'post_type'      => 'attachment',
        'post_parent'    => $pid,
        'meta_key'       => 'another_reserved1',
        'meta_value'     => '1',
        'numberposts'    => -1,
        'post_status'    => null,
        );
        $attachments = get_posts($args);
        if ($attachments) {
                foreach ($attachments as $attachment) {
            $url = $attachment->ID;
            array_push($exclude, $url);
        }
        }
        
        //-----------------
    
        $args = array(
        'order'          => 'ASC',
        'orderby'        => 'post_date',
        'post_type'      => 'attachment',
        'post_parent'    => $pid,
        'exclude'           => $exclude,
        'post_mime_type' => 'image',
        'post_status'    => null,
        'numberposts'    => 1,
        );
        $attachments = get_posts($args);
        if ($attachments) {
                foreach ($attachments as $attachment) 
                {
                //$url = wp_get_attachment_url($attachment->ID);
                return TaskerDev_wp_get_attachment_image($attachment->ID, 'thumb_image_thing');   
            }
        }
        else    return get_bloginfo('template_url').'/images/nopic.jpg'; // wanna replace with: return get_stylesheet_directory_uri().'/images/Picture16.jpg';
    }
    /*************************************************************
    //*
    //* TaskerDev (c) sitemile.com - function
    //*
    **************************************************************/
    endif;
    
    ////end

When done, everything works fine for about an hour and then I get the following error:

the function TaskerDev_get_first_post_image_fnc() cannot be called twice, it's been called in the parent already (just paragraphing what it says)

What is the most efficient way to update the image by been able to called it within the child theme. IS there a short hook or action maybe? Thanks.