WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 6 weeks ago

#32143 new enhancement

wpLink function getAttrs() missing link-text

Reported by: xwolf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.2
Component: Editor Keywords:
Focuses: javascript Cc:

Description

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.
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/js/wplink.js?rev=32017

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 (5)

#1 in reply to: ↑ description @SergeyBiryukov
4 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
4 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
4 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
4 years ago

Hi!

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
3 years ago

+1 for this.

When using the link chooser outside of the WYSIWYG it would be preferable 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.

Last edited 3 years ago by hereswhatidid (previous) (diff)
Note: See TracTickets for help on using tickets.