Desenvolvi um plugin próprio para inserção de shortcodes no WordPress. Foi meu primeiro, para uso pessoal, esteve funcionando por anos.
Mas há algumas semanas, passou a causar erro 500 (POST wp-admin/admin-ajax.php 500) ao tentar fazer a inserção de imagens no editor de artigo. Consigo fazer o upload do arquivo, mas ao clicar em Adicionar mídia e escolher alguma, nada - e dá o erro no console:
Ativando o debug.log, tenho isso:
PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function give_linked_media(), 3 passed in /wp-includes/class-wp-hook.php on line 286 and at least 7 expected in wp-content/plugins/tt-shortcodes/tt-functions.php:205
Essa é a função da linha 205:
function give_linked_media( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
// only if user is sending video or image
if ( ( wp_attachment_is( 'video', $id ) ) || ( wp_attachment_is_image( $id ) ) ) {
// build datatype var
if ( 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 );