• PHP 8.1 warnings, :

    [12-May-2024 07:11:56 UTC] PHP Warning: Attempt to read property “ID” on null in /home//public_html/wp-content/plugins/swifty-bar/public/class-sb-bar-public.php on line 87
    [12-May-2024 07:11:56 UTC] PHP Warning: Attempt to read property “ID” on null in /home//public_html/wp-content/plugins/swifty-bar/public/class-sb-bar-public.php on line 87

Viewing 1 replies (of 1 total)
  • Thread Starter djixas

    (@djixas)

    ChatGTP suggested this fix, maybe you can implement it

    public function enqueue_scripts() {
    // Call scripts only if swifty is enabled and for chosen post types.
    $options = (get_option('sb_bar_options') ? get_option('sb_bar_options') : false);
    //Post Type
    $posttype = array();
    if(isset($options["post-type"]) && $options["post-type"] != '') {
    $posttype = $options["post-type"];
    }

    if($options == false || (!isset($options["disable-bar"]) && is_singular() && in_array(get_post_type(), $posttype))) {
        global $post;
        if (!is_null($post)) {
            wp_enqueue_script( $this->sb_bar, plugin_dir_url( __FILE__ ) . 'assets/js/sb-bar-public.js', array( 'jquery' ), $this->version, false );
            wp_localize_script($this->sb_bar, 'admin_urls', 
                array( 
                'admin_ajax' => admin_url( 'admin-ajax.php'),
                'post_id' => $post->ID,
                'postNonce' => wp_create_nonce( 'myajax-post-nonce' )
                )
            );
        } else {
            // Handle the case when $post is null
            // Maybe log an error or do something else
        }
    }

    }

    • This reply was modified 10 months, 2 weeks ago by djixas.
Viewing 1 replies (of 1 total)
  • The topic ‘Attempt to read property “ID” on null in’ is closed to new replies.