1

警告:array_keys()は、パラメーター1が配列であると想定しています。文字列は/home/hennacur/public_html/shop/wp-content/themes/montezuma/includes/image_meta.phpの34行目にあります。

警告:40行目の/home/hennacur/public_html/shop/wp-content/themes/montezuma/includes/image_meta.phpのforeach()に無効な引数が指定されています

                                                 function bfa_image_size() {
$meta = wp_get_attachment_metadata();
echo $meta['width']. '×' . $meta['height'];
    }


    function bfa_image_meta( $args = '' ) {

$defaults = array(
    'keys' => '',
    'before' => '', 
    'after' => '',
    'item_before' => '', 
    'item_after' => '',
    'item_sep' => ' · ',
    'key_before' => '',
    'key_after' => ': ',
    'value_before' => '',
    'value_after' => '',
    'display_empty' => FALSE    
);

$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );

$meta = wp_get_attachment_metadata();

$string_array = array();

       // All keys, alphabetically sorted, as provided by wp_get_attachment_metadata()
if( $keys == '' ) {
    $array_keys = array_keys( $meta['image_meta'] );  ---***line34***       
// Only keys specificed in parameter:
} else {
    $array_keys = array_map( 'trim', explode( ',', $keys ) );
}

foreach( $array_keys as $key ) { --***line 40***

    $value = $meta['image_meta'][$key];

    if( $display_empty === TRUE || ( $value != '' && $value != '0' ) ) {

        if( $key == 'created_timestamp' )
            // Transform timestamp into readable date, based on default WP date/time settings:
            $value = date( get_option('date_format') . ' - ' . get_option('time_format'), $value );

        // Prettify key
        $key = ucwords( str_replace( '_', ' ', $key ) );
        $key = $key == 'Iso' ? 'ISO' : $key;


        $key = str_replace( 
            array(
                'Aperture',
                'Credit',
                'Camera',
                'Caption',
                'Created Timestamp',
                'Copyright',
                'Focal Length',
                'ISO',
                'Shutter Speed',
                'Title'
            ),
            array(
                __( 'Aperture', 'montezuma' ),
                __( 'Credit', 'montezuma' ),
                __( 'Camera', 'montezuma' ),
                __( 'Caption', 'montezuma' ),
                __( 'Timestamp', 'montezuma' ),
                __( 'Copyright', 'montezuma' ),
                __( 'Focal Length', 'montezuma' ),
                __( 'ISO', 'montezuma' ),
                __( 'Shutter Speed', 'montezuma' ),
                __( 'Title', 'montezuma' )
            ),      
            $key
        );

私は上記のコードを持っています。表示されている警告の原因は何でしょうか?

4

2 に答える 2

1

次の場合は、これを試してください ($array_keys の型が文字列またはそれ以外であるため、この警告が表示されます)。

 if(is_array($array_keys) && !empty($array_keys)) { // foreach stetment here }
于 2012-11-25T17:37:50.530 に答える
0

警告はそれをすべて説明しています。

array_keys() expects parameter 1 to be array, string givenarray_keys()配列の代わりに文字列が渡されたことを示しています。

したがって、$meta['image_meta']おそらく配列ではありません。

その結果、$array_keys配列として設定されていないため、適用しようとすると次の警告が表示されますforeach

于 2012-11-25T17:38:44.807 に答える