Ankündigung

Einklappen
Keine Ankündigung bisher.

Was bedeutet: Warning: Invalid argument supplied for foreach()

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Was bedeutet: Warning: Invalid argument supplied for foreach()

    Hi, ich betreue die WP-Seite meiner Freundin.
    Wegen der Abmahnwelle habe ich die Tage alle Fonts rausgenommen, die von Google geladen werden.
    Nun erhalte ich auf der Webseite https://annatheil.de die Fehlermeldung (Warnung):

    Warning: Invalid argument supplied for foreach() in /var/www/web43/html/wordpress/wp-content/themes/fusion/inc/customize/customize-style.php on line 170

    Diese Zeile sieht so aus:

    foreach ($font_arr as $key => $font) {

    Was kann ich tun?
    Gibt es ein try catch in PHP?

    Herzliche Grüße!

    PHP-Code:
    <?php
    /**
     * Import customize style
     *
     * @return Css inline at header.
     *
     * @package     Zoo Theme
     * @version     1.0.0
     * @author      Zootemplate
     * [USER="23286"]Link[/USER]        https://www.zootemplate.com/
     * @copyright   Copyright (c) 2020 ZooTemplate

     */

    // Render css customize
    add_action('wp_enqueue_scripts''zoo_enqueue_render'1000);
    // Enqueue scripts for theme.
    function zoo_enqueue_render()
    {
        
    //Load font
        
    $zoo_fonts = array();
        
    $zoo_local_font = array();
        
    $zoo_google_font = array();
        if(
    get_theme_mod('zoo_use_font','google') != 'custom') {
            if (
    get_theme_mod('zoo_typo_base''') == '' || get_theme_mod('zoo_typo_base')['font'] == '') {
                
    $zoo_fonts[] = array('font-family' => 'Roboto Mono''variant' => '400');
            }
            if (
    get_theme_mod('zoo_typo_base''') == '' || get_theme_mod('zoo_typo_base')['font'] == '') {
                
    $zoo_fonts[] = array('font-family' => 'Roboto Mono''variant' => '500');
            }
            if (
    get_theme_mod('zoo_typo_base''') == '' || get_theme_mod('zoo_typo_base')['font'] == '') {
                
    $zoo_fonts[] = array('font-family' => 'Roboto Mono''variant' => '600');
            }
            if (
    get_theme_mod('zoo_typo_heading''') == '' || get_theme_mod('zoo_typo_heading')['font'] == '') {
                
    $zoo_fonts[] = array('font-family' => 'Oswald''variant' => '400');
            }
            if (
    get_theme_mod('zoo_typo_heading''') == '' || get_theme_mod('zoo_typo_heading')['font'] == '') {
                
    $zoo_fonts[] = array('font-family' => 'Oswald''variant' => '500');
            }
            if (
    get_theme_mod('zoo_typo_heading''') == '' || get_theme_mod('zoo_typo_heading')['font'] == '') {
                
    $zoo_fonts[] = array('font-family' => 'Oswald''variant' => '600');
            }
            if (
    get_theme_mod('zoo_typo_woo''') == '' || get_theme_mod('zoo_typo_woo')['font'] == '') {
                
    $zoo_fonts[] = array('font-family' => 'Oswald''variant' => '400');
            }
            foreach (
    $zoo_fonts as $font) {
                if (
    $font) {
                    if (
    in_array('futura-pt'$font)) {
                        
    $zoo_local_font[] = 'futura-pt';
                    } else {
                        
    $zoo_google_font[] = $font;
                    }
                }
            }
            if (!empty(
    array_filter($zoo_google_font))) {
                
    $zoo_google_font zoo_import_google_fonts($zoo_google_font);
                
    wp_enqueue_style('zoo-font'$zoo_google_fontfalse'');
            }
        }
        
    // Load custom style
        
    wp_add_inline_style('zoo-styles'zoo_customize_style($zoo_local_font));
        if (
    get_theme_mod('zoo_custom_js') != '') {
            
    wp_add_inline_script('zoo-scripts'zoo_customize_js());
        }
    }

    if (!
    function_exists('zoo_customize_js')) {
        function 
    zoo_customize_js()
        {
            
    $zoo_script '';
            if (
    get_theme_mod('zoo_custom_js') != '') {
                
    $zoo_script get_theme_mod('zoo_custom_js');
            }
            return 
    $zoo_script;
        }
    }
    if (!
    function_exists('zoo_customize_style')) {
        function 
    zoo_customize_style($zoo_local_font = array())
        {
            
    /* ----------------------------------------------------------
                                        Responsive control
                                Control Breakpoint of header Layout
                                Don't remove this section
            ---------------------------------------------------------- */
            
    $css '';
            
    $theme_settings get_option(ZOO_SETTINGS_KEY, []);
            
    $mobile_breakpoint = !empty($theme_settings['mobile_breakpoint_width']) ? strval(intval($theme_settings['mobile_breakpoint_width'])) : '992';
            
    $css .= '@media(min-width: ' $mobile_breakpoint 'px) {
              .wrap-site-header-mobile {
                display: none;
              }
              .show-on-mobile {
                display: none;
              }
            }

            @media(max-width: ' 
    $mobile_breakpoint 'px) {
              .wrap-site-header-desktop {
                display: none;
              }
              .show-on-desktop {
                display: none;
              }
            }'
    ;
            
    $css .= '@media(min-width:1500px){.container{max-width:' zoo_site_width() . ';width:100%}}';
            
    $css .= '@media(min-width:768px){.container{max-width:' zoo_site_width() . ';width:100%;}}';
            
    /* ----------------------------------------------------------
                                End Responsive control
                        Control Breakpoint of header Layout
                        Don't remove this section
            ---------------------------------------------------------- */
            /* ----------------------------------------------------------
                                        Typography
                                All typography must add here
            ---------------------------------------------------------- */
            
    if (!empty($zoo_local_font)) {
                if (
    in_array('futura-pt'$zoo_local_font)) {
                    
    $css .= '@font-face {
                        font-family: \'futura-pt\';
                        src: url(\'' 
    ZOO_THEME_URI.'assets/fonts/futurapt/futurapt-light.woff\') format(\'woff\');
                        font-weight: 300;
                        font-style: normal;
                        font-display: auto;
                    }@font-face {
                        font-family: \'futura-pt\';
                        src: url(\'' 
    ZOO_THEME_URI.'assets/fonts/futurapt/futurapt-light-italic.woff\') format(\'woff\');
                        font-weight: 300;
                        font-style: italic;
                        font-display: auto;
                    }

                    @font-face {
                        font-family: \'futura-pt\';
                        src: url(\'' 
    ZOO_THEME_URI.'assets/fonts/futurapt/futurapt-book.woff\') format(\'woff\');
                        font-weight: 400;
                        font-style: normal;
                        font-display: auto;
                    }@font-face {
                        font-family: \'futura-pt\';
                        src: url(\'' 
    ZOO_THEME_URI.'assets/fonts/futurapt/futurapt-book-italic.woff\') format(\'woff\');
                        font-weight: 400;
                        font-style: italic;
                        font-display: auto;
                    }

                    @font-face {
                        font-family: \'futura-pt\';
                        src: url(\'' 
    ZOO_THEME_URI.'assets/fonts/futurapt/futurapt-medium.woff\') format(\'woff\');
                        font-weight: 500;
                        font-style: normal;
                        font-display: auto;
                    }@font-face {
                        font-family: \'futura-pt\';
                        src: url(\'' 
    ZOO_THEME_URI.'assets/fonts/futurapt/futurapt-medium-italic.woff\') format(\'woff\');
                        font-weight: 500;
                        font-style: italic;
                        font-display: auto;
                    }
                    '
    ;
                }
            }
            if(
    get_theme_mod('zoo_use_font','google') == 'custom'){

                
    /* ----------------------------------------------------------
                                      Load Font Custom by User
               ---------------------------------------------------------- */

                
    $font_name get_theme_mod('zoo_typo_new_font_family');
                
    $font_arr get_theme_mod('zoo_font_items');
                foreach (
    $font_arr as $key => $font) {
                    
    $css .= '@font-face {';
                    
    $css .= 'font-family: '.$font_name.';';
                    
    $css .= 'font-weight: '.$font['weight'].';';
                    
    $css .= 'font-style:  '.$font['style'].';';

                    
    $css .= 'src:';
                    
    $arr  = array();
                    if ( 
    $font['woff2'] ) {
                        
    $arr[] = 'url(' esc_url$font['woff2'] ) . ") format('woff2')";
                    }
                    if ( 
    $font['woff'] ) {
                        
    $arr[] = 'url(' esc_url$font['woff'] ) . ") format('woff')";
                    }
                    if ( 
    $font['ttf'] ) {
                        
    $arr[] = 'url(' esc_url$font['ttf'] ) . ") format('truetype')";
                    }
                    if ( 
    $font['svg'] ) {
                        
    $arr[] = 'url(' esc_url$font['svg'] ) . '#' esc_attrstrtolowerstr_replace' ''_'$font_name ) ) ) . ") format('svg')";
                    }
                    
    $css .= join', '$arr );
                    
    $css .= ';';
                    
    $css .= '}';
                }
                
    //display font
                
    $css .= 'body{';
                
    $css .= 'font-family: "'.$font_name.'", sans-serif;;';
                
    $css .= 'font-weight: normal;';
                
    $css .= 'font-style:  normal;';
                
    $css .= '}';
            }else {
                
    /* ----------------------------------------------------------
                                       Load Font Default or Google
                ---------------------------------------------------------- */
                
    $body_font get_theme_mod('zoo_typo_base''');
                if (isset(
    $body_font['font-size'])) {
                    
    $css .= "html{";
                    
    $css .= "font-size:" $body_font['font-size'];
                    
    $css .= "}";
                }

                
    /*Typography generate Css*/
                
    if ($body_font == '' || $body_font['font'] == '') {
                    
    $css .= "html{";
                    
    $css .= "font-size: 14px;";
                    
    $css .= "}";
                    
    $css .= zoo_generate_css_font('body', array('font-family' => 'Roboto Mono''variant' => '400'));
                }
                if (
    get_theme_mod('zoo_typo_heading''') == '' || get_theme_mod('zoo_typo_heading')['font'] == '') {
                    
    $css .= zoo_generate_css_font('h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6', array('font-family' => 'Oswald''variant' => '500'));
                }
                if (
    get_theme_mod('zoo_typo_woo''') == '' || get_theme_mod('zoo_typo_woo')['font'] == '') {
                    
    $css .= zoo_generate_css_font('.product-loop-title,  .product_title', array('font-family' => 'Oswald''variant' => '400'));
                }
            }
            
    /*Preset Color*/
            
    if (zoo_theme_preset() != '') {
                
    //put all css class follow accent color to $accent_class
                
    $accent_class '.accent-class';
                
    $css .= $accent_class '{color:' zoo_theme_preset() . '}';
            }
            if (
    class_exists('WooCommerce')) {
                
    $gutter zoo_product_gutter();
                
    $css .= '.products .product{padding-left:' $gutter 'px;padding-right:' $gutter 'px}';
                
    $css .= 'ul.products, .woocommerce ul.products{margin-left:-' $gutter 'px !important;margin-right:-' $gutter 'px !important;width:calc(100% + ' . ($gutter 2) . 'px)}';
            }
            if (
    get_theme_mod('zoo_custom_css') != '') {
                
    $css .= get_theme_mod('zoo_custom_css');
            }
            return 
    $css;
        }
    }

  • #2
    $font_arr ist kein Array.

    Was kann ich tun?
    Sicherstellen, das es ein array ist.

    Gibt es ein try catch in PHP?
    Ja.
    Über 90% aller Gewaltverbrechen passieren innerhalb von 24 Stunden nach dem Konsum von Brot.

    Kommentar


    • #3
      ohne jetzt motzen zu wollen - aber beides hätte man auch bei (bpw.) google gefunden.,
      zudem stllst du hier eine fareg zu:
      a) einem fremden softweareprodukt
      b) einem comerziellen product
      c) einem supporteten und wohl auch meintaintem product

      Kommentar


      • #4
        Vielen herzlichen Dank lstegelitz!
        Hab einfach ein
        PHP-Code:
        if (is_array($font_arr)) 
        eingebaut. Jetzt tut's.

        @tomBuilder Du kannst auch einfach auf's motzen verzichten. Damit ist ja niemanden geholfen.

        Herzliche Grüße!

        Kommentar

        Lädt...
        X