Modify a function without directly editing it
<p>I am looking to modify a function inside a Wordpress plugin, where I am switching to the primary site in a multisite installation to load images. The plugin is regularly maintained, and therefore I do not want to modify the code so that I am able to easily update it.</p>

<p>Is there anyway to 'hook' into the function so that I can modify it this way? I have shown what I am trying to achieve below, where I have had to manually add <code>switch_to_blog(1)</code> and <code>restore_current_blog()</code>.</p>

<pre><code>function get_value($post_id, $field)
{
    $value = parent::get_value($post_id, $field);

    switch_to_blog(1);

    $attachments = get_posts(array(
        'post_type' =&gt; 'attachment',
        'post_status' =&gt; null,
        'post__in' =&gt; $value,
    ));

    $ordered_attachments = array();
    foreach( $attachments as $attachment)
    {
        $ordered_attachments[ $attachment-&gt;ID ] = array(
            'id' =&gt; $attachment-&gt;ID,
            'alt' =&gt; get_post_meta($attachment-&gt;ID, 
                        '_wp_attachment_image_alt', true),
            'title' =&gt; $attachment-&gt;post_title,
        );
    }

    restore_current_blog();

    return $ordered_attachments;
}
</code></pre>
