Make WordPress Core

Opened 9 years ago

Last modified 4 years ago

#32143 new enhancement

wpLink function getAttrs() missing link-text

Reported by: xwolf's profile xwolf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.2
Component: Editor Keywords: reporter-feedback
Focuses: javascript Cc:


After last update to 4.2 wpLink() was renewed and the title-input was replaced.
Instead of title, you can now insert/change the link text.

But in function getAttrs() the val of link-text was forgotten.

Therfor I proporse to add this line in getAttrs():

linktext: $.trim( inputs.text.val() ),

Also it would be nice to populate the link-text field with the document title of a chosed intern element, like it was made with the old title-field before.

Change History (6)

#1 in reply to: ↑ description @SergeyBiryukov
9 years ago

  • Component changed from General to Editor

Hi @xwolf, welcome to Trac!

That line already exists in htmlUpdate() and mceUpdate() functions. Link text is not really an attribute like href or target, why should it be in getAttrs()?

#2 @xwolf
9 years ago

In some plugins wpLink is also used to add contextual links beneath the editor (mostly in a seperate metabox). Therfor htmlUpdate() or mceUpdate() wont help, cause they are only for use within the textarea of the editor.
The content of the wp-link-text is not a HTML attribute and so getAttrs() might be the wrong position to return it, but to add a single line of code there wouldnt hurt anyone :)

#3 @thesarahkemp
9 years ago

The title here is also used for the ACF Link Picker field type. Currently I can't add "Related links" to my site because the title doesn't fill in because it is no longer present in the getAttrs() function. I don't mind it not being there and am happy to adjust my code to get it from somewhere else... is there somewhere else I can get it? I can't figure out a way to access the 'inputs' variable that is used throughout wplink to access the Title value.

I realize you can never count on reusing a piece of the core in a plugin, but it seems confusing and unnecesssary to rewrite wplink just to use it in practically the same way a little further down the page.

Just my use-case and upvote.

#4 @dingo_bastard
8 years ago


I agree with xwolf and thesarahkemp. Removing the title from the getAttrs() basically makes it impossible to get the title outside the editor (metaboxes for instance).

If you could add a function that will just return the title that would be great :)

#5 @hereswhatidid
8 years ago

+1 for this.

When using the link chooser outside of the WYSIWYG it would be much nicer to not have to sniff around the DOM to find the link text input field and it's value. Having it be part of the returned value from getAttrs() method would be much nicer.

Version 0, edited 8 years ago by hereswhatidid (next)

#6 @noisysocks
4 years ago

  • Keywords reporter-feedback added

Agree with @SergeyBiryukov that the text isn't a link attribute and therefore doesn't belong in getAttrs().

Would adding a new function e.g. getText() help?

Is this functionality still desirable in light of the block editor and its link components?

Note: See TracTickets for help on using tickets.