Zur Navigation

Es gibt vordefinierte Variablen, die als ['Array'] behandelt werden sollten

1 Lena567

Habe eine PHP-Datei auf PHP 8.1 getestet.

Folgendes wird angezeigt:

Fehler : Es gibt 1 vordefinierte Variablen, die als ['Array'] behandelt werden sollten:
$_REQUEST[ 'nchlb_media_' . ( $count - 1 )


Wie behebt man diesen Fehler?

Hier der komplette Code der PHP
<?php




/**
 * Add some image sizes
 */
function nchlb_add_sizes(){
	
	add_image_size( 'nch_lb_normal', 250, 250, false );
	add_image_size( 'nch_lb_square', 250, 250, true );

}
 
add_action( 'after_setup_theme', 'nchlb_add_sizes' );
 
/**
 * Catches the prefixed options from the shortcode returning them as array or string
 */
function nchlb_shortcode_atts( $atts, $exclude = array(), $format = 'string' ){
	
	$atts = ( array ) $atts;
	$data = array();
	
	$all = array(
		'animation' => '',
		'mode' => '', 
		'thumbs'  => '', 
		'thumbsize' => '', 
		'size' => '', 
		'margin' => '', 
		'backlight' => '', 
		'gridspace' => '', 
		'gridorder' => '',
		'grid' => '', 
		'play' => '', 
		'autoplay' => '', 
		'duration' => '', 
		'share' => '', 
		'social' => '', 
		'keyboard' => '', 
		'fullscreen' => '',
		'zoom' => '', 
		'info' => '', 
		'href' => '', 
		'rel' => '', 
		'title' => '', 
		'type' => '', 
		'src' => '', 
		'width' => '', 
		'height' => '', 
		'color' => '', 
		'effect' => '',
		'alt' => '',
		'twidth' => '',
		'theight' => '',
		'bgclose' => '',
		'captions' => '',
		'scheme' => '',
		'usecolor' => '',
		'notouch' => '',
		'nohashes' => ''
	);
	
	$base = array( 
		'href' => '', 
		'title' => '', 
		'rel' => '', 
		'src' => '',
		'id' => ''
	);	
	
	$types = array( 
		'image' => '',
		'youtube' => '',
		'vimeo' => '',
		'dailymotion' => '',
		'iframe' => '',
		'html' => '',
		'ajax' => ''
	);
	
	// shorthand types
	foreach( $atts as $type => $value )
		if( isset( $types[ $type ] ) ) $atts[ 'type' ] = $type;
		else if( is_numeric( $type ) && isset( $types[ $value ] ) ) $atts[ 'type' ] = $value;
	
	// exclude attributtes
	foreach( $exclude as $attr )
		if( isset( $atts[ $attr ] ) )
			unset( $atts[ $attr ] );			

	// drop invalid attributes
	foreach( $atts as $option => $value ){
		if( isset( $all[ $option ] ) ){			
			$data[ $option ] = esc_attr( $value );
		}
	}
	
	// filter the data
	$data = apply_filters( 'nchlb_shortcode_atts', $data, $format );
	
	if( $format == 'array' ) return $data;
	
	// generate the html attributes
	$html = ' ';
	
	foreach( $data as $option => $value )
		$html .= ( isset( $base[ $option ] ) ? '' : 'data-' ) . $option . '="' . $value . '" ';
	
	return $html;
	
}

/**
 * The [lightbox] shortcode
 */
function nchlb_shortcode( $atts, $content = NULL ){
	
	wp_enqueue_script( 'jquery' );
	wp_enqueue_script( 'hammerjs' );
	wp_enqueue_script( 'nch-lightbox' );
	
	$data = nchlb_shortcode_atts( $atts, array( 'src', 'alt', 'twidth', 'theight' ) );
	
	// allow media embed by id
	if( isset( $atts[ 'id' ] ) ){
		
		$id = intval( $atts[ 'id' ] );
		
		// get the image size
		$tsize = nchlb_check_imagesize( nch_get_option( 'nchlb_imagesize' ) );

		$src = wp_get_attachment_image_src( $id, 'large' );
		if( ! is_array( $src ) ) return '';
		
		if( ! isset( $atts[ 'href' ] ) )
			$data .= ' href="' . ( $atts[ 'href' ] = $src[ 0 ] ) . '" ';
		
		$src = wp_get_attachment_image_src( $id, $tsize );
		if( ! isset( $atts[ 'src' ] ) ) $atts[ 'src' ] = $src[ 0 ];

		unset( $atts[ 'id' ] );

	}
	
	// use an image 
	if( $content == NULL && isset( $atts[ 'src' ] ) ){

		$content = '<img src="' . esc_attr( $atts[ 'src' ] ) . '" alt="' . ( isset( $atts[ 'alt' ] ) ? esc_attr( $atts[ 'alt' ] ) : '' ) . '" style="';

		// set sizing for the thumbnail
		if( isset( $atts[ 'twidth' ] ) ) $content .= 'width:' . esc_attr( $atts[ 'twidth' ] ) . 'px;';
		if( isset( $atts[ 'theight' ] ) ) $content .= 'height:' . esc_attr( $atts[ 'theight' ] ) . 'px;';

		$content .= '">';
		
		unset( $atts[ 'src' ] );

	}

	return "<a class='nch-lightbox' $data >" . do_shortcode( $content ) . '</a>';
	
}

/**
 * Register it
 */
add_shortcode( 'lightbox', 'nchlb_shortcode' );



/**
 * Attachment link
 */
function nchlb_attachment_link( $id = 0, $size = 'nch_lb_normal', $attrs ){
	
	$id = intval( $id );
	$_post = $_post = get_post( $id );

	if ( empty( $_post ) || ( 'attachment' != $_post -> post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) return __( 'Missing Attachment', NCHTD );
	
	// get the title and make sure it's sanitized 
	$post_title = esc_attr( $_post -> post_title );
	
	// use appropriate thumbnails
	$size = nch_get_option( 'nchlb_imagesize' );
	
	// get the image tag
	$image = wp_get_attachment_image( $id, $size, false );
	
	return apply_filters( 'wp_get_attachment_link', "<a class='nch-lightbox' href='$url' $attrs title='$post_title'>$image</a>", $id, $size, false, false, false );
	
}



/**
 * Adds a proper gallery shortcode
 */
function nchlb_gallery_shortcode( $atts ){
	
	global $post;
	
	static $instance = 0;
	$instance ++;
	
	wp_enqueue_script( 'jquery' );
	wp_enqueue_script( 'hammerjs' );
	wp_enqueue_script( 'nch-lightbox' );
	
	// include that ids
	if ( ! empty( $atts[ 'ids' ] ) ) {		
		if ( empty( $atts[ 'orderby' ] ) ) $atts[ 'orderby' ] = 'post__in';	
		$atts[ 'include' ] = $atts[ 'ids' ];
	}

	// allow plugins/themes to override the default gallery template.
	$output = apply_filters( 'post_gallery', '', $atts );
		if ( $output != '' )
			return $output;

	// we're trusting author input, so let's at least make sure it looks like a valid orderby statement
	if ( isset( $atts[ 'orderby' ] ) ) {
		$atts[ 'orderby' ] = sanitize_sql_orderby( $atts[ 'orderby' ] );
		if ( ! $atts[ 'orderby' ] )
			unset( $atts[ 'orderby' ] );
    }
	
	// extract lightbox specific attributes
	$lb_data = nchlb_shortcode_atts( $atts, array( 'src', 'href', 'title', 'rel', 'color', 'effect', 'type', 'width', 'height' ) );
	
	// keep links to files
	if( is_array( $atts ) ){
		unset( $atts[ 'link' ] );
		unset( $atts[ 'size' ] );
	}
	
	// make those values available
	extract( shortcode_atts( array(
		
		'orderby' => 'menu_order',
		'order' => 'ASC',
		'columns' => 3,
		'id' => $post -> ID,
		'size' => 'medium',
		'itemtag' => 'dl',
		'icontag' => 'dt',
		'captiontag' => 'dd',
		'link' => 'file',
		'include' => '',
		'exclude' => ''
		
	), $atts, 'gallery' ) );
	
	$id = intval( $id );
	$size = nchlb_check_imagesize( nch_get_option( 'nchlb_imagesize' ) );
	
	if( $order == 'RAND' ) $orderby = 'none';
	
	// prepare common query attributes
	$query = array(
		
		'post_status' => 'inherit', 
		'post_type' => 'attachment', 
		'post_mime_type' => 'image', 
		'order' => $order, 
		'orderby' => $orderby
		
	);
	
	if( ! empty( $include ) ) {
		
		$attachments = array();
		$query[ 'include' ] = $include;
		$images = get_posts( $query );
		
		foreach( $images as $image ) $attachments[ $image -> ID ] = $image;

	} else {
		
		$query[ 'post_parent' ] = $id;		
		if( ! empty( $exclude ) ) $query[ 'exclude' ] = $exclude;
		
		$attachments = get_children( $query );
		
	}
	
	// return nothing
	if( empty( $attachments ) ) return '';
	
	// return feed formatted links
	if( is_feed() ){
	
		$output = '\n';
		foreach ( $attachments as $att_id => $attachment )
			$output .= wp_get_attachment_link( $att_id, $size, true ) . '\n';

		return $output;
		
	}
	
	// more sanitization
	$tags = wp_kses_allowed_html( 'post' );
	
	$itemtag = tag_escape( $itemtag );
	$captiontag = tag_escape( $captiontag );
	$icontag = tag_escape( $icontag );
	
	if ( ! isset( $tags[ $itemtag ] ) ) $itemtag = 'dl';
	if ( ! isset( $tags[ $captiontag ] ) ) $captiontag = 'dd';
	if ( ! isset( $tags[ $icontag ] ) ) $icontag = 'dt';
	
	// implementation specific
	$columns = intval( $columns );
	
	$selector = "nch-gallery-{$instance}";
	$lb_data .= ( isset( $atts[ 'grid' ] ) ) ? '' : ( ' data-grid="' . nch_get_option( 'nchlb_grid' ) . '" ' );
	$size_class = sanitize_html_class( $size );
	$output = apply_filters( 'gallery_style', "\n\t\t<div id='$selector' class='nch-gallery nch-galleryid-{$id} nch-gallery-columns-{$columns} nch-gallery-size-{$size_class}'>" );
	$first = true;
	
	$rel = ' rel="gallery' . $instance . rand( 1000, 9999 ) . '" ';
	
	foreach ( $attachments as $id => $attachment )		
		$output .= nchlb_attachment_link( $id, $size, ( $first ? ( ( $first = false ) ? 0 : $lb_data ) : '' ) . $rel );

	return $output . '</div>';

}

function nchlb_wrap_shortcode( $atts, $content = NULL ){
	
	return do_shortcode( $content );

}

function nchlb_remove_gallery(){
	
	// reset the shortcode
	if( nch_get_option( 'nchlb_gs' ) ){
		remove_shortcode( 'gallery' );
		add_shortcode( 'gallery', 'nchlb_gallery_shortcode' ); 
	}
	
	add_shortcode( 'nchlb_wrap', 'nchlb_wrap_shortcode' );
	add_shortcode( 'nchgallery', 'nchlb_gallery_shortcode' ); 

}

add_action( 'init', 'nchlb_remove_gallery' );





/**
 * Print out the necessary code for the shortcode editor to work
 */
function nchlb_shortcode_editor(){
	
	global $pagenow;
	global $typenow;
	global $nacho_framework;
	
	if( ! is_admin() || ( $pagenow != 'post.php' && $pagenow != 'post-new.php' ) || ! in_array( $typenow, apply_filters( 'nchlb_shortcode_post_types', array( 'post', 'page', 'portfolio' ) ) ) ) return ;

	$url = $nacho_framework[ 'baseurl' ];
	$effect = nchlb_get_effects();
	
	$select = array();
	foreach( $effect as $value => $name ) $select[] = "<option value='$value'>$name</option>";
	$select = implode( '', $select );
	
	?><script> ;(function($){ $(document).ready( function(){ $.fn.nchlbEditor.gallery = <?php nchlb_print_defaults(); ?> })})( jQuery ); </script><?php

	// print the settings menu
	?><div class='nchlb_sh_pane' style='padding:0;margin:0;display:none'>
	
		<ul class='nchlb_sh_gal'></ul>
		
		<ul class='nchlb_sh_tabmenu'>
			
			<li class='nchlb_sh_addmedia'><img src='<?php echo $url; ?>img/nchlb_mce_addmedia.png'><?php _e( 'Add Media', NCHTD ); ?></li>
			<li class='nchlb_sh_remmedia'><img src='<?php echo $url; ?>img/nchlb_mce_deletemedia.png'><?php _e( 'Remove', NCHTD ); ?></li>
			
			<li class='nchlb_sh_tab' data-nchtab='gallery'><?php _e( 'Gallery', NCHTD ); ?></li>
			<li class='nchlb_sh_tab nchlb_sh_tabsel' data-nchtab='edit'><?php _e( 'Edit', NCHTD ); ?></li>

		</ul>
		
		<table class='nchlb_sh_settings nchlb_sh_pane_edit'>
			
			<tr>
				<td><?php _e( 'Type', NCHTD ); ?></td>
				<td>
					<select class='nchlb_sh_f_type' data-control='type'>
						<option value='image' selected><?php _e( 'image', NCHTD ); ?></option>
						<option value='youtube'><?php _e( 'youtube', NCHTD ); ?></option>
						<option value='vimeo'><?php _e( 'vimeo', NCHTD ); ?></option>
						<option value='dailymotion'><?php _e( 'dailymotion', NCHTD ); ?></option>
						<option value='html'><?php _e( 'html', NCHTD ); ?></option>
						<option value='iframe'><?php _e( 'iframe', NCHTD ); ?></option>
					</selected>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Title', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_title nch_text nch_text_large' type='text' data-control='title' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'URL', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_url nch_text nch_text_large' type='text' data-control='href' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Effect', NCHTD ); ?></td>
				<td>
					<select class='nchlb_sh_f_effect' data-control='effect'>
						<option value='none' selected><?php _e( 'default', NCHTD ); ?></option>
						<?php echo $select; ?>
					</select>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Color', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_color' type='text' data-color='1' data-control='color' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Width', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_width nch_text nch_text_small' type='text' data-control='width' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Height', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_height nch_text nch_text_small' type='text' data-control='height' value=''>
				</td>
			</tr>	
			<tr>
				<td><?php _e( 'Content', NCHTD ); ?></td>
				<td>
					<ul>
						<li class='nch_slist_sel'><input type='radio' name='nchlb_sh_ctype' class='nchlb_sh_f_ctype' value='thumbnail' data-control='_ctype' checked><?php _e( 'Thumbnail', NCHTD ); ?></li>
						<li><input type='radio' class='nchlb_sh_f_ctype' name='nchlb_sh_ctype' value='html'><?php _e( 'Text', NCHTD ); ?></li>
					</ul>
				</td>
			</tr>
			<tr class='nchlb_sh_f_cno_thumbnail'>		
				<td colspan='2'>
					<div><?php _e( 'Text', NCHTD ); ?></div>
					<textarea class='nchlb_sh_f_text nch_textarea' data-control='_content'></textarea>
				</td>
			</tr>	
			<tr class='nchlb_sh_f_cno_html'>
				<td><?php _e( 'Thumbnail', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_src nch_text nch_text_large' type='text' data-control='src' value=''>
				</td>
			</tr>
			<tr class='nchlb_sh_f_cno_html'>
				<td><?php _e( 'Thumbnail size', NCHTD ); ?></td>
				<td>
					<span style='float:left;line-height:25px;padding:0 4px'>Width: </span><input class='nchlb_sh_f_twidth nch_text nch_text_small' type='text' data-control='twidth' value=''>
					<span style='float:left;line-height:25px;padding:0 4px'>Height: </span><input class='nchlb_sh_f_theight nch_text nch_text_small' type='text' data-control='theight' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Alt text', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_alt nch_text' type='text' data-control='alt' value=''>
				</td>
			</tr>
			
		</table>
		
		
		<table class='nchlb_sh_settings nchlb_sh_pane_gallery'>
			
			<tr>
				<td><?php _e( 'Group name', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_name nch_text' type='text' data-control='rel' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Skin', NCHTD ); ?></td>
				<td>
					<ul>
						<li class='nch_slist_sel'><input class='nchlb_sh_f_scheme' name='nchlb_sh_f_scheme' type='radio' data-control='scheme' value='dark' checked><?php _e( 'Dark', NCHTD ); ?></li>
						<li><input class='nchlb_sh_f_scheme' name='nchlb_sh_f_scheme' type='radio' value='light'><?php _e( 'Light', NCHTD ); ?></li>
					</ul>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Mode', NCHTD ); ?></td>
				<td>
					<ul>
						<li class='nch_slist_sel'><input class='nchlb_sh_f_mode' name='nchlb_sh_f_mode' type='radio' data-control='mode' value='linear' checked><?php _e( 'Linear', NCHTD ); ?></li>
						<li><input class='nchlb_sh_f_mode' name='nchlb_sh_f_mode' type='radio' value='continuous'><?php _e( 'Continuous', NCHTD ); ?></li>
					</ul>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Thumbnails', NCHTD ); ?></td>
				<td>
					<select class='nchlb_sh_f_thumbs' data-control='thumbs'>
						<option value='none' selected><?php _e( 'none', NCHTD ); ?></option>
						<option value='top'><?php _e( 'Top', NCHTD ); ?></option>
						<option value='right'><?php _e( 'Right', NCHTD ); ?></option>
						<option value='bottom'><?php _e( 'Bottom', NCHTD ); ?></option>
						<option value='left'><?php _e( 'Left', NCHTD ); ?></option>
					</select>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Thumbnails size', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_thumbsize nch_text nch_text_small' type='text' data-control='thumbsize' value='0'>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Show captions', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_captions' type='checkbox' data-control='captions'>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Backlight', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_backlight' type='text' data-control='backlight' data-color='1' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Default effect', NCHTD ); ?></td>
				<td>
					<select class='nchlb_sh_f_animation' data-control='animation'>
						<?php echo $select; ?>
					</select>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Background closing', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_bgclose' type='checkbox' data-control='bgclose'>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Video size', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_size nch_text' type='text' data-control='size' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Duration', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_duration nch_text nch_text_small' type='text' data-control='duration' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Margins', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_margin nch_text nch_range nch_control' type='range' min='0' max='100' data-control='margin' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Playable', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_play' type='checkbox' data-control='play' checked>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Autoplay', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_autoplay' type='checkbox' data-control='autoplay' checked>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Sharing', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_share' type='checkbox' data-control='share' checked>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Social', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_social nch_text' type='text' data-control='social' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Keyboard', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_keyboard' type='checkbox' data-control='keyboard' checked>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Fullscreen', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_fullscreen' type='checkbox' data-control='fullscreen' checked>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Zoom', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_zoom' type='checkbox' data-control='zoom' checked>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Grid', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_grid nch_text' type='text' data-control='grid' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Grid spacing', NCHTD ); ?></td>
				<td>
					<input class='nchlb_sh_f_gridspace nch_text nch_range nch_control' type='range' min='0' max='20' data-control='gridspace' value=''>
				</td>
			</tr>
			<tr>
				<td><?php _e( 'Info panel', NCHTD ); ?></td>
				<td>
					<select class='nchlb_sh_f_info' data-control='info'>
						<option class='nchlb_select_keep' value='none'>none</option>
					</select>
				</td>
			</tr>
		</table>	

	</div><?php
	
}

add_action( 'in_admin_footer', 'nchlb_shortcode_editor' );



function nchlb_admin_includes( $hook ){
	
	global $typenow;
	global $nacho_framework;
	
	// get upload directory
	$upload = wp_upload_dir();
	$path = $upload[ 'baseurl' ] . '/';
	
	// localize some texts and variables
	$lang = array(
	
		'title' => array(
			'add' => __( 'Add lightbox', NCHTD ), 
			'edit' => __( 'Edit lightbox', NCHTD )
		),
		
		'button' => array(
			'insert' => __( 'Insert', NCHTD ),
			'update' => __( 'Update', NCHTD ),
			'cancel' => __( 'Cancel', NCHTD ),
			'edit' =>   __( 'Edit', NCHTD ),
			'remove' => __( 'Delete', NCHTD )
		),
		
		'send' => wp_create_nonce( 'nchlb_sh_editor' ),
		'uploadpath' => $path,
		'imagesize' => nchlb_check_imagesize( nch_get_option( 'nchlb_imagesize' ) )
		
	);
	
	wp_enqueue_script( 'jquery-ui-core' );
	wp_enqueue_script( 'jquery-ui-sortable' );
	
	if( ( $hook == 'post.php' || $hook == 'post-new.php' ) && in_array( $typenow, apply_filters( 'nchlb_shortcode_post_types', array( 'post', 'page', 'portfolio' ) ) ) ){

		wp_enqueue_script( 'nchlb-shortcode-edit', $nacho_framework[ 'baseurl' ] . 'js/shortcodes/edit.nchlightbox.js', array(), '1.4', true );
	
		// include the translation inside the page
		wp_localize_script( 'nchlb-shortcode-edit', 'nchlb_edit_lang', $lang );	

		add_filter( 'mce_buttons', 'nchlb_mce_editor_button' );
		
	}
	
}
add_action( 'admin_enqueue_scripts', 'nchlb_admin_includes', 10, 1 );


// add the button key for address via JS
function nchlb_mce_editor_button( $buttons ) {

    array_push( $buttons, 'nchlb_sh_edit' );
    return $buttons;

}


function nchlb_send_backlight( $response, $attachment, $meta ) {
	
	global $nacho_lightbox;
	
	$upload = wp_upload_dir();
	$path = $upload[ 'baseurl' ] . '/';
	
	$field = $nacho_lightbox[ 'backlight_field' ];
	$value = nchlb_get_attachment_color( md5( str_replace( $path, '', $response[ 'url' ] ) ) );
	
	$response[ $field ] = $value;
	
	return $response;

}

add_filter( 'wp_prepare_attachment_for_js', 'nchlb_send_backlight', 100, 3 );







function nchlb_mce_style( $url ){
	
	if ( ! empty( $url ) ) $url .= ',';

    // Retrieves the plugin directory URL and adds editor stylesheet
    // Change the path here if using different directories
    $url .= trailingslashit( plugin_dir_url(__FILE__) ) . 'css/nacho-shortcode.css';

    return $url;
	
}
add_filter( 'mce_css', 'nchlb_mce_style' );







function nchlb_ajax_get_attachments(  ){

	// check against CSRF
	check_ajax_referer( 'nchlb_sh_editor', 'nchlb_nonce', true );

	$media = array();
	$response = array();
	$count = 0;

	while( array_key_exists( 'nchlb_media_' . ( $count++ ), $_REQUEST ) )
		$media[] = $_REQUEST[ 'nchlb_media_' . ( $count - 1 ) ];

	// get upload directory
	$upload = wp_upload_dir();
	$path = $upload[ 'baseurl' ] . '/';
	
	// associate the media
	foreach( $media as $i => $url ){
		if( strpos( $url, 'id:' ) === 0 ) $id = intval( str_replace( 'id:', '', $url ) );
		else $id = nchlb_get_attachment_id( md5( str_replace( $path, '', $url ) ) );
		$response[ $url ] = wp_prepare_attachment_for_js( $id );
	}
	
	echo json_encode( $response );

	die();
	
}

add_action( 'wp_ajax_nchlb_get_attachment', 'nchlb_ajax_get_attachments' );

/**
 * Load scripts conditionally into the footer
 */
function nchlb_conditional_scripts(){
	
	global $nacho_lightbox;
	
	// check if post has lightboxed media
	if( strlen( implode( ',', $nacho_lightbox[ 'images' ] ) ) <= 2 ) return '';

	wp_enqueue_script( 'jquery' );
	wp_enqueue_script( 'hammerjs' );
	wp_enqueue_script( 'nch-lightbox' );

}

add_action( 'wp_footer', 'nchlb_conditional_scripts' );



?>

11.02.2022 15:53

2 Jörg Kruse

Habe eine PHP-Datei auf PHP 8.1 getestet.

Womit hast du diese getestet? die Fehlermeldungen von PHP sind normalerweise englischsprachig, und damit kommt man mithilfe der Suchmaschinen leicht weiter.

11.02.2022 23:11

1 Forenmitglied fand diesen Beitrag gut

3 Lena567

Ich habe das ganze auf der folgenden Seite getestet
https://phpcodechecker.com/

Ich erhalte dabei folgende Fehlermeldungen

Error: There are 2 more closing parenthesis ')' found
This count is unaware if parenthesis are inside of a string
Error: There are 2 more closing curly braces '}' found
This count is unaware if curly braces are inside of a string
Error: There is 1 predefined variables that should be treated as an ['array']:
$_REQUEST[ 'nchlb_media_' . ( $count - 1 )


Suchmaschine habe ich auch bemüht, aber geholfen hat mir das aufgrund meines eingeschränkten Wissens nicht.
Wäre super, wenn du mir einen Tipp geben würdest.

14.02.2022 08:56

4 Jörg Kruse

Ich habe diesen Abschnitt mit dem in PHP 8.1 eingebauten Linter überprüft (`php -l test.php`):

<?php

$media = array();
$response = array();
$count = 0;

while( array_key_exists( 'nchlb_media_' . ( $count++ ), $_REQUEST ) )
	$media[] = $_REQUEST[ 'nchlb_media_' . ( $count - 1 ) ];

Es wurde kein Fehler bemängelt.

Der "PHP Code Checker" wirft den genannten Fehler auch für PHP 7.4 und 5.6 aus. Ich würde hier von einem false positive ausgehen. Möglicherweise ist der "PHP Code Checker" nicht in der Lage, einen konkatenierten Array-Key korrekt zu analysieren. Die Fehlermeldungen ergibt m.E. auch keinen Sinn. $_REQUEST wird hier ja als Array behandelt.

14.02.2022 12:12 | geändert: 14.02.2022 12:13

1 Forenmitglied fand diesen Beitrag gut

5 Lena567

Vielen vielen Dank Jörg!

Es überrascht mich jetzt schon, dass der Code in Ordnung ist und das Werkzeug, das ich verwendet habe, nicht richtig funktioniert.

Vielen Dank für deine Bemühungen!
Schönen Tag noch

15.02.2022 10:39

Beitrag schreiben (als Gast)

Die Antwort wird nach der Überprüfung durch einen Moderator freigeschaltet.





[BBCode-Hilfe]