Support » Plugin: Dynamic Featured Image » Trying to get property of non-object in dynamic-featured-image.php on line 210

  • Resolved Vlad Stratulat

    (@vladstratulat)


    I’m using Toolset Types plugin version 1.9.1 alongside with Dynamic Featured Image version 3.5.2. When I create a new post type or edit existing one (posts for example /wp-admin/admin.php?page=wpcf-edit-type&wpcf-post-type=post), I get the following error:
    Notice: Trying to get property of non-object in ../dynamic-featured-image.php on line 210

    In the code, in initialize_featured_box() method (line 204), I’ve added if statement if $post is an object and it resolved the issue.

    public function initialize_featured_box() {
        global $post;
    
        //make metabox title dynamic
        $this->_metabox_title = apply_filters( 'dfi_set_metabox_title', __( "Featured Image" ) );
    
        if (is_object($post)) {
          $featuredData  = get_post_meta( $post->ID, 'dfiFeatured', true );
          $totalFeatured = count( $featuredData );
    
          $defaultFilter     = array( 'attachment', 'revision', 'nav_menu_item' );
          $this->_userFilter = apply_filters( 'dfi_post_type_user_filter', $this->_userFilter );
          $filter            = array_merge( $defaultFilter, $this->_userFilter );
    
          $postTypes = get_post_types();
          $postTypes = array_diff( $postTypes, $filter );
    
          $postTypes = apply_filters( 'dfi_post_types', $postTypes );
    
          if ( ! empty( $featuredData ) && $totalFeatured >= 1 ) {
            $i = 2;
            foreach ( $featuredData as $featured ) {
              self::_dfi_add_meta_box( $postTypes, $featured, $i );
              $i ++;
            }
          } else {
            self::_dfi_add_meta_box( $postTypes );
          }
        }
    
      } // END initialize_featured_box()

    I don’t know how the plugin works in depth, but I believe it make sense to have a look.

    https://wordpress.org/plugins/dynamic-featured-image/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Hi Vlad,

    Thank you for report. I don’t know how the Toolset Types plugin works or do but the $post always needs to be object at this point of execution. The toolset plugin might be messing the post object. If you can send PR we can see if it breaks anything. I can merge the request it doesn’t break other things.

    Regards,
    Ankit

    Thread Starter Vlad Stratulat

    (@vladstratulat)

    I believe that Toolset Types invoke a method or something that causes initialize_featured_box() method to run, but there’s no global $post available in Toolset Types. That’s why I believe that validation if $post is an existing object will help.

    How can I commit my changes?
    I cloned the repo and tried to push to dev, but I get permission denied.

    Plugin Author Ankit Pokhrel

    (@ankitpokhrel)

    Basically you need to fork the project, make changes, commit and send a pull request. Please refer this tutorial on how to send pull request in github.

    Thread Starter Vlad Stratulat

    (@vladstratulat)

    Thanks Ankit!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Trying to get property of non-object in dynamic-featured-image.php on line 210’ is closed to new replies.