• Resolved ripperdoc

    (@ripperdoc)


    Hi, I am trying my luck modifying a plugin that pulls in external pages and inserts them as posts. What I want to achieve is to insert image links in an identical way as when you use the media uploader and press “Insert into post”.

    After navigating through media.php in wp-admin/includes, I found a couple of function doing this (it is done in many places with different code it seems). Most of them use the function get_attachment_link() for the URL to link the image to. However, when I run it in my code, it does not output permalinks, although permalinks are activated and are outputted when I insert an image manually into a post.

    Does it have something do to with the code running before permalinks are initiated, or what is the context required for get_attachment_link() to work? (other permalink functions are also broken at that point in the running code).

Viewing 1 replies (of 1 total)
  • Thread Starter ripperdoc

    (@ripperdoc)

    Actually, found the issue: the plugin creates draft posts, and they are not given permalinks (although in the post editor, they are appearing with a permalink). Worth noting for others that if your plugin works with draft posts, permalink functions does not work.

    I circumvented it with a filter that temporarily pretends a post is not in draft in order for it to get a permalink.

Viewing 1 replies (of 1 total)

The topic ‘Permalinks not working in plugin code’ is closed to new replies.