I developed a plugin for inserting shortcodes in WordPress. It was my first one, for personal use, it has been running for years.
But a few weeks ago, it started to cause error 500 (POST wp-admin / admin-ajax.php 500) when trying to insert images into the article editor. I can upload the file, but when I click Add media and choose some, nothing - and gives the error in the console:
Activatingdebug.log,Ihavethis:
PHPFatalerror:UncaughtArgumentCountError:Toofewargumentsto functiongive_linked_media(),3passedin /wp-includes/class-wp-hook.phponline286andatleast7expectedin wp-content/plugins/tt-shortcodes/tt-functions.php:205
Thisisthefunctionofline205:
functiongive_linked_media($html,$id,$caption,$title,$align,$url,$size,$alt=''){//onlyifuserissendingvideoorimageif((wp_attachment_is('video',$id))||(wp_attachment_is_image($id))){//builddatatypevarif(wp_attachment_is('video',$id)){$datatype='data-lightview-type="iframe" ';
} else if ( wp_attachment_is_image( $id ) ) {
$datatype = ' data-lightview-type="image" ';
} else { }
// setting lightview params
if ( empty( get_post_meta( $id, "pop_title", true ) ) ) {
$poptitle = '';
} else {
$poptitle = ' data-lightview-title="' . get_post_meta( $id, "pop_title", true ) . '"';
}
if ( empty( get_post_meta( $id, "pop_caption", true ) ) ) {
$popcaption = '';
} else {
$popcaption = ' data-lightview-caption="' . get_post_meta( $id, "pop_caption", true ) . '"';
}
if ( empty( get_post_meta( $id, "pop_group", true ) ) ) {
$popgroup = '';
} else {
$popgroup = ' data-lightview-group="' . get_post_meta( $id, "pop_group", true ) . '"';
}
// if user decided to don't use, don't replace original html
$tha_meta = get_post_meta( $id, 'lightbox_on', true );
// regex bad, DOM good
// http://stackoverflow.com/a/3820783/2234159
$dom = new DOMDocument;
$dom->loadHTML( $html );
// get the link rel
foreach ( $dom->getElementsByTagName( 'a' ) as $node ) {
$therel = $node->getAttribute( 'rel' );
// get the attachment val, if exists
$therel = explode( ' ', $therel, 2 );
$therel = $therel[ 0 ];
}
if ( $tha_meta == '1' ) { // is checkbox was set
if ( $therel == 'attachment' ) { // if yes, no candy for you
$html2 = $html;
} else { // no attachment? Oh yeah
$html2 = preg_replace( '/(<a.*?)>/', '$1 class="lightview"' . $poptitle . $popcaption . $popgroup . $datatype . 'fufu="' . $therel . '">', $html );
}
} else { // no checkbox? No candy
$html2 = $html;
}
} else {
$html2 = $html;
}
return $html2;
}
add_filter( 'media_send_to_editor', 'give_linked_media', 10, 8 );