我正在寻找修改 Wordpress 插件中的一个函数,我在其中切换到多站点安装中的主站点以加载图像。该插件会定期维护,因此我不想修改代码以便能够轻松更新它。
无论如何要“挂钩”到函数中,以便我可以这样修改它?我在下面展示了我想要实现的目标,我必须手动添加switch_to_blog(1)
和restore_current_blog()
.
function get_value($post_id, $field)
{
$value = parent::get_value($post_id, $field);
switch_to_blog(1);
$attachments = get_posts(array(
'post_type' => 'attachment',
'post_status' => null,
'post__in' => $value,
));
$ordered_attachments = array();
foreach( $attachments as $attachment)
{
$ordered_attachments[ $attachment->ID ] = array(
'id' => $attachment->ID,
'alt' => get_post_meta($attachment->ID,
'_wp_attachment_image_alt', true),
'title' => $attachment->post_title,
);
}
restore_current_blog();
return $ordered_attachments;
}