Warning: Attempt to read property “ID” on null in D:\xampp\htdocs\yba\wp-content\themes\young-brand-child\functions.php on line 162

Question

My website working without error in PHP 7 when I change PHP 8 the website is giving this warning.

Warning: Attempt to read property “ID” on null in D:\xampp\htdocs\yba\wp-content\themes\young-brand-child\functions.php on line 162

<?php  
//include(STYLESHEETPATH  . '/lib/theme-meta-box.php');
require_once('lib/theme-meta-box.php');
require_once('lib/theme-options.php');
require_once('lib/custom-post.php');

// Menu register
register_nav_menus( array(
    'primary' => __( 'Primary Navigation', 'young-brand' ),
    'mobile-nav' => __( 'Mobile Navigation', 'young-brand' ),
    'footer' => __( 'Footer Navigation', 'young-brand' ),
) );

// Image
add_theme_support('post-thumbnails');
add_image_size ('share-holder', 140, 140, true);
add_image_size ('photo-gallery', 320, 240, true);
add_image_size ('lightbox-gallery', 850, 480, true);
add_image_size ('product-gall', 400, 600, true);
add_image_size ('testimonials', 95, 95, true);
add_image_size ('news-detail', 270, 220, true);
add_image_size ('news-update', 210, 160, true);

//Excerpt
function excerpt($limit) {
    $excerpt = explode(' ', get_the_excerpt(), $limit);
    if (count($excerpt)>=$limit) {
        array_pop($excerpt);
        $excerpt = implode(" ",$excerpt);
    } else {
        $excerpt = implode(" ",$excerpt);
    }
    $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
    return $excerpt;
}

 /* Function to change sender name */function wpb_sender_name( $original_email_from ) { return 'Young Brand Apparel';}add_filter( 'wp_mail_from_name', 'wpb_sender_name' );
 
/* Multi Featured Image
-----------------------------*/
if (class_exists('MultiPostThumbnails')) {
    new MultiPostThumbnails(array(
        'label' => 'Banner Image',
        'id' => 'feature-image-2',
        'post_type' => 'yb_products'
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Product Image1',
        'id' => 'product-image-1',
        'post_type' => 'yb_products'
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Product Hover Image',
        'id' => 'product-image-2',
        'post_type' => 'yb_products'
        )
    );
    new MultiPostThumbnails(array(
        'label' => 'Second Image',
        'id' => 'second-image-2',
        'post_type' => 'yb_testimonials'
        )
    );
}

// Load our main stylesheet.
function spero_scripts_child() {
    // Jquery
    //wp_enqueue_script('jquery');
    wp_deregister_script( 'jquery' );
    wp_enqueue_script( 'jquery-min', get_stylesheet_directory_uri() . '/js/jquery-1.7.2.min.js', true, '1.0', false );
    
    wp_enqueue_script( 'easing-js', get_stylesheet_directory_uri() . '/js/jquery.easing.min.js', true, '1.0', false );
    wp_enqueue_script( 'custom-js', get_stylesheet_directory_uri() . '/js/jquery-ui-1.8.18.custom.min.js', true, '1.0', false );
    wp_enqueue_script( 'hashchange-js', get_stylesheet_directory_uri() . '/js/jquery.ba-hashchange.min.js', true, '1.0', false );
    wp_enqueue_script( 'mousewheel-js', get_stylesheet_directory_uri() . '/js/jquery.mousewheel.js', true, '1.0', true );
    
    wp_enqueue_script( 'Scrollbar', get_stylesheet_directory_uri() . '/js/jquery.mCustomScrollbar.js', true, '1.0', false );
    
    wp_enqueue_script( 'cufon-js', get_stylesheet_directory_uri() . '/js/cufon-yui.js', true, '1.0', false );
    wp_enqueue_script( 'Aller_400-js', get_stylesheet_directory_uri() . '/js/Aller_400-Aller_700.font.js', true, '1.0', false );
    wp_enqueue_script( 'cufon-colors-js', get_stylesheet_directory_uri() . '/js/cufon-colors.js', true, '1.0', false );
    wp_enqueue_script( 'image-loaded-js', get_stylesheet_directory_uri() . '/js/jquery.image-loaded.js', true, '1.0', false );
    wp_enqueue_script( 'skitter-js', get_stylesheet_directory_uri() . '/js/jquery.skitter.js', true, '1.0', false );
    wp_enqueue_script( 'smoothDiv-js', get_stylesheet_directory_uri() . '/js/jquery.smoothDivScroll-1.2.js', true, '1.0', false );
    wp_enqueue_script( 'supersized-js', get_stylesheet_directory_uri() . '/js/supersized.3.2.7.js', true, '1.0', false );
    wp_enqueue_script( 'load-content-js', get_stylesheet_directory_uri() . '/js/load-content.js', true, '1.0', false );
    
    wp_enqueue_script( 'transform-js', get_stylesheet_directory_uri() . '/js/jquery.transform-0.9.3.min_.js', true, '1.0', true );
    wp_enqueue_script( 'RotateImageMenu-js', get_stylesheet_directory_uri() . '/js/jquery.RotateImageMenu.js', true, '1.0', true );
    wp_enqueue_script( 'easyzoom-js', get_stylesheet_directory_uri() . '/js/easyzoom.js', true, '1.0', false );
    wp_enqueue_script( 'Selectric-js', get_stylesheet_directory_uri() . '/js/jquery.selectric.min.js', true, '1.0', false );
    
    //if(is_page('home')) {}
    wp_enqueue_script( 'jquery-sldr-js', get_stylesheet_directory_uri() . '/js/jquery.sidr.min.js', true, '1.0', true );
    wp_enqueue_script( 'fancybox-js', get_stylesheet_directory_uri() . '/js/jquery.fancybox.js', true, '1.0', true );
    wp_enqueue_script( 'bxslider-js', get_stylesheet_directory_uri() . '/js/jquery.bxslider.min.js', true, '1.0', true );
    wp_enqueue_script( 'main-js', get_stylesheet_directory_uri() . '/js/main.js', true, '1.0', true );
    wp_enqueue_script( 'script-js', get_stylesheet_directory_uri() . '/js/script.js', true, '1.0', false );
    wp_enqueue_script( 'supersized-js', get_stylesheet_directory_uri() . '/js/supersized.3.2.7.js', true, '1.0', false );
    
    //CSS files
    wp_dequeue_style( 'original-enqueue-stylesheet-handle' );
    wp_deregister_style( 'original-register-stylesheet-handle' );
    
    wp_enqueue_style( 'Scrollbar-css', get_stylesheet_directory_uri() . '/css/jquery.mCustomScrollbar.css', array());
    wp_enqueue_style( 'Sliders-css', get_stylesheet_directory_uri() . '/css/sliders.css', array());
    wp_enqueue_style( 'Supersized-css', get_stylesheet_directory_uri() . '/css/supersized.css', array());
    wp_enqueue_style( 'Skitter-css', get_stylesheet_directory_uri() . '/css/skitter.styles.css', array());
    wp_enqueue_style( 'bxslider-css', get_stylesheet_directory_uri() . '/css/jquery.bxslider.css', array());
    wp_enqueue_style( 'fancybox-css', get_stylesheet_directory_uri() . '/css/jquery.fancybox.css', array());
    wp_enqueue_style( 'smooth-css', get_stylesheet_directory_uri() . '/css/smoothDivScroll.css', array());
    wp_enqueue_style( 'rotating-css', get_stylesheet_directory_uri() . '/css/rotating-style.css', array());
    wp_enqueue_style( 'easyzoom-css', get_stylesheet_directory_uri() . '/css/easyzoom.css', array());
    wp_enqueue_style( 'selectric-css', get_stylesheet_directory_uri() . '/css/selectric.css', array());
    wp_enqueue_style( 'jquery.sidr-css', get_stylesheet_directory_uri() . '/css/jquery.sidr.dark.css', array());
    wp_enqueue_style( 'style-css', get_stylesheet_directory_uri() . '/style.css', array());
    wp_enqueue_style( 'responsive-css', get_stylesheet_directory_uri() . '/css/responsive.css', array());
    
}
    add_action( 'wp_enqueue_scripts', 'spero_scripts_child' );


//Walker finction
class description_walker extends Walker_Nav_Menu {
    function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
        $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
        $class_names = $value="";

        $classes = empty( $item->classes ) ? array() : (array) $item->classes;
        $classes[] = 'menu-item-' . $item->ID;

        $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
        $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';

        $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args );
        $id = $id ? ' id="' . esc_attr( $id ) . '"' : '';

        $output .= $indent . '<li' . $id . $value . $class_names .'>';

        $atts = array();
        $atts['title']  = ! empty( $item->attr_title ) ? $item->attr_title : '';
        $atts['target'] = ! empty( $item->target )     ? $item->target     : '';
        $atts['rel']    = ! empty( $item->xfn )        ? $item->xfn        : '';
        $atts['href']   = ! empty( $item->url )        ? $item->url        : '';
        $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );

        $attributes="";
        foreach ( $atts as $attr => $value ) {
        if ( ! empty( $value ) ) {
         $value = ('href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
            $attributes .= ' ' . $attr . '="' . $value . '"';
            //$attributes .= ' ' . $attr . '="javascript:void(0)"';
            }
        }

        $item_output = $args->before;
        $pg_name = apply_filters( 'the_title', $item->title, $item->ID );
        $page_id = get_page_by_title( $pg_name );
        $item_output .= '<a'. $attributes .' id="'.$page_id->ID.'">';
        
        /** This filter is documented in wp-includes/post-template.php */
        $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
        $item_output .= '</a>';
        $item_output .= $args->after;

        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    }
}

//Contact From custom mail
// Mail---> [careers position]
wpcf7_add_shortcode('careers', 'position', true);
function position(){
    global $post;
    //$args = array( 'post_type' => 'contactus' );
    $args = array('post_type' => 'yb_careers', 'posts_per_page'=>-1 );
    $myposts = get_posts( $args );
    $output .= "<select name="position">";
    //<option value="Select">Select</option>";
    foreach ( $myposts as $post ) : setup_postdata($post);
        $title = get_the_title();
        $slug = $post->post_name;
        $output .= "<option value="$title"> $title </option>";
    endforeach;
    //$output .= "<option value="Test" select="selected">test select</option>";
    $output .= "</select>";
    return $output;
}

?>

0
Rup 5 months 2022-07-07T04:29:31-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse