• Heya,
    I need to overwrite this function, can someone tell me what I’m doing wrong because this isn’t working:

    // THIS FUNCTION OVERWRITES THE ONE THAT ORIGINATES IN WP-INCLUDES/LINK-TEMPLATE.PHP AT LINE 298 TO REMOVE THE FILENAME FROM THE END OF THE "Post URL" BUTTON
    function modified_get_attachment_link($id = false) {
    	global $post, $wp_rewrite;
    
    	$link = false;
    
    	if ( ! $id)
    		$id = (int) $post->ID;
    
    	$object = get_post($id);
    	if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {
    		$parent = get_post($object->post_parent);
    		if ( 'page' == $parent->post_type )
    			$parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front
    		else
    			$parentlink = get_permalink( $object->post_parent );
    
    		if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )
    			$name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker
    		else
    			$name = $object->post_name;
    
    		if ( strpos($parentlink, '?') === false )
    			$link = user_trailingslashit( trailingslashit($parentlink) );
    	}
    
    	if ( ! $link )
    		$link = home_url( "/?attachment_id=$id" );
    
    	return apply_filters('attachment_link', $link, $id);
    }
    
    add_filter('get_attachment_link', 'modified_get_attachment_link', 1, 2);

Viewing 4 replies - 1 through 4 (of 4 total)
  • surfgatinho

    (@surfgatinho)

    Hi,

    Did you ever work this out. I’ve just spent a day banging my head against the wall trying to overwrite exactly the same function. Trying to make gallery thumbs into page links.

    Would really appreciate it if you could help.

    Thanks

    I’ve been trying to overwrite this for two hours.

    remove_all_filters(‘the_attachment_link’, ‘wp_get_attachment_link’);
    remove_all_actions(‘the_attachment_link’, ‘wp_get_attachment_link’);
    remove_action(‘the_attachment_link’, ‘wp_get_attachment_link’);
    remove_action(‘wp_get_attachment_link’);

    I’ve tried EVERYTHING. Nothing works.

    So, if anyone answers to this, it will help both of us.

    – JC

    See, sorta similar.

    Should work, but doesn’t.

    //deactivate WordPress function
    remove_all_actions( 'wp_get_attachment_link' );
    //activate own function
    add_action('yetimade_wp_get_attachment_link');
    //the own renamed function
    function yetimade_wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false) {
    	$id = intval($id);
    	$_post = & get_post( $id );
    
    	if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
    		return __('Missing Attachment');
    
    	if ( $permalink )
    		$url = get_attachment_link($_post->ID);
    
    	$post_title = esc_attr($_post->post_title);
    
    	if ( $text ) {
    		$link_text = esc_attr($text);
    	} elseif ( ( is_int($size) && $size != 0 ) or ( is_string($size) && $size != 'none' ) or $size != false ) {
    		$link_text = wp_get_attachment_image($id, $size, $icon);
    	} else {
    		$link_text = '';
    	}
    
    	if( trim($link_text) == '' )
    		$link_text = $_post->post_title;
    
    	return apply_filters( 'wp_get_attachment_link', "$link_text", $id, $size, $permalink, $icon, $text );
    }

    You guys get anywhere with yours?

    Hey,

    I tried something like this for the media gallery and it works for me :

    add_filter('media_upload_gallery', 'fnc_dummy_redirect',0);
    function fnc_dummy_redirect()
    {
    	remove_all_filters( 'media_upload_gallery');
            my_overrided_media_upload_gallery_function();
    }

    Not a beautiful solution, but at least the core files remain intact.

    nnh

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do you overwrite a core function?’ is closed to new replies.