php - WordPress hook / filter to process link inside a post -


is there hook / filter process link being added wordpress post ?

my aim pre-process link inserted in post using following button , shorten using third party api bit.ly

i want both internal / external links.

tinymce add link button

one solution think of add button editor prefer hook / filter job, way more clean , convert custom plugin website (there allowing wordpress up-gradable).

i went through wordpress docs , skimmed through following hooks / filters of no use me

  1. https://developer.wordpress.org/reference/hooks/add_link/

  2. https://developer.wordpress.org/reference/hooks/post_link/

  3. and of ones listed here https://developer.wordpress.org/?s=link

update 1: far know, external urls inserted post content tinymce editor link plugin, php nothing.

in wordpress, there're 2 plugins located @ wp-includes/js/wplink.js , wp-includes/js/tinymce/plugins/wplink/plugin.js. note if you're not in script_debug mode, have .min suffix.

  1. wp-includes/js/wplink.js handles dialog:

wplink dialog box 1

to filter urls inserted via dialog box, must override wplink.getattrs method. example, add so39115564 string every urls:

jquery(document).ready(function($) {   wplink.getattrs = function() {     wplink.correcturl();     return {       href: $.trim( $("#wp-link-url").val() + "so39115564" ),       target: $("#wp-link-target").prop("checked") ? "_blank" : ""     };   } }); 

you should take @ wp-includes/js/wplink.js more info. it's long explain in detail here.

and let above script mylink.js, here how should enqueue it:

add_filter('admin_enqueue_scripts', function() {   // { maybe conditions valid screen here. }    wp_enqueue_script('mylink', 'link/to/the/mylink.js', ['link'], '1.0', true); }, 0, 0); 
  1. wp-includes/js/tinymce/plugins/wplink/plugin.js handles dialog:

wplink dialog 2

this time, have override seturl method of tinymce.ui.wplinkpreview. but, it's almost impossible, unless deregister script , register modified version. manage script unpredictable changes wordpress.

now, choose wisely! shorten external urls before pasting them posts or mess wordpress tinymce plugins or use dialog box of wp-includes/js/wplink.js plugin.


yes! wordpress inserts inline links via wp_link_ajax action executed wp_ajax_wp_link_ajax() function.

as can see in source code of function, $results retrieved _wp_editors::wp_link_query. check out method, meet wp_link_query filter. filter accept 2 arguments: $results , $query. $results need filter.

for example, need append so39115564 queried link:

add_filter('wp_link_query', function(array $results, array $query) {   $results[0]['permalink'] = $results[0]['permalink'] . 'so39115564';    return $results; }, php_int_max, 2); 

now, should know how it. make sure take @ _wp_editors::wp_link_query filter $results more efficient.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -