Viewing 6 reply threads
  • Author
    Posts
    • #7280
      thomas
      Participant

      Hi,

      i have an error when i want to add new custom post. I use themosis framework to declare my new post type :

      PostType::make('mission', 'Missions', 'Mission')->set([
          'public'        => true,
          'menu_position' => 25,
          'supports'      => ['title'],
          'rewrite'       => ['slug' => 'mission'],
          'capability_type' => 'post',
          'query_var'     => true,
      ]);

      But when i access to : /cms/wp-admin/post-new.php?post_type=mission
      got this error :

      Message:
      Trying to get property of non-object
      Location:
      /path_to_webroot/htdocs/cms/wp-admin/includes/template.php on line 699

      Problem comes from this line :
      <?php touch_time(($action == 'edit'), ($pagenow != 'post-new.php'), 4); ?>
      (/htdocs/content/plugins/piklist/parts/meta-boxes/submitdiv.php l.218)

      so when i add post ($pagenow != 'post-new.php')=0,
      but the wordpress function touch_time() get get_comment()->comment_date for $post_date value

      function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
      /* ... */
      $post_date = ($for_post) ? $post->post_date : get_comment()->comment_date;
      

      whereas get_comment don’t return an object in my case !! why ?

      (/htdocs/cms/wp-admin/includes/template.php l.699)

      How can i fix this ?

      Thank you,
      Thomas

    • #7284
      vavakco
      Member

      i have same error 🙁

    • #7285
      thomas
      Participant

      yeah i saw @vavakco ! i really thing that piklist must add a fix for this.
      since WP 4.4 touch_time use get_comment()… and give this error

      i don’t understand why piklist needs this condition ($pagenow != 'post-new.php') in touch_time() function calling

      we’ll see what support can say us !

    • #7340
      thomas
      Participant

      Need answer please !

    • #7406
      guicara
      Participant

      Hello,

      I have also this problem with Themosis Framework and Piklist when creating a new post (only for Custom Post Type).

      Stack trace:

      #0 ...\content\mu-plugins\themosis-framework\bootstrap\start.php(175): Themosis\Error\Error::native(8, 'Trying to get p...', 'C:\\xampp\\htdocs...', 699)
      #1 ...\cms\wp-admin\includes\template.php(699): THFWK_Themosis->{closure}(8, 'Trying to get p...', 'C:\\xampp\\htdocs...', 699, Array)
      #2 ...\content\plugins\piklist\parts\meta-boxes\submitdiv.php(218): touch_time(false, false, 4)
      #3 ...\content\plugins\piklist\includes\class-piklist.php(507): include('C:\\xampp\\htdocs...')
      #4 ...\content\plugins\piklist\includes\class-piklist-meta.php(313): Piklist::render('C:\\xampp\\htdocs...', Array)
      #5 [internal function]: Piklist_Meta::meta_box(Object(WP_Post), Array)
      #6 ...\cms\wp-admin\includes\template.php(1045): call_user_func(Array, Object(WP_Post), Array)
      #7 ...\cms\wp-admin\edit-form-advanced.php(686): do_meta_boxes('cm-actors', 'side', Object(WP_Post))
      #8 ...\cms\wp-admin\post-new.php(85): include('C:\\xampp\\htdocs...')
      #9 {main}

      To resolve the issue, change the line 218 of htdocs/content/plugins/piklist/parts/meta-boxes/submitdiv.php:
      <?php touch_time(($action == 'edit'), ($pagenow != 'post-new.php'), 4); ?>

      With:
      <?php touch_time(($action == 'edit'), ($pagenow == 'post-new.php'), 4); ?>

      I’m pretty sure it is a bug with Piklist, because if the second parameters of the touch_time() method is false, WordPress will try to apply the date for a comment. However the get_comment() method returns null. That’s why Themosis throw the error “Trying to get property of non-object”.

      /**
       * Print out HTML form date elements for editing post or comment publish date.
       *
       * @since 0.71
       * @since 4.4.0 Converted to use get_comment() instead of the global <code>$comment</code>.
       *
       * @global WP_Locale  $wp_locale
       *
       * @param int|bool $edit      Accepts 1|true for editing the date, 0|false for adding the date.
       * @param int|bool $for_post  Accepts 1|true for applying the date to a post, 0|false for a comment.
       * @param int      $tab_index The tabindex attribute to add. Default 0.
       * @param int|bool $multi     Optional. Whether the additional fields and buttons should be added.
       *                            Default 0|false.
       */
      function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
      	...
      	$post = get_post();
      	...
      	$post_date = ($for_post) ? $post->post_date : get_comment()->comment_date;
      	...
      }

      Can you please confirm and correct this issue?

      Thanks,

      Guillaume

    • #7451
      mindmantra
      Participant

      Had same problem. Investigated a lot and came to conclusion to replacing the $pagenow comparison with ‘1’ would work without any issue.

      So <?php touch_time(($action == 'edit'), ($pagenow != 'post-new.php'), 4); ?>
      would become
      <?php touch_time(($action == 'edit'), 1, 4); ?>

      reason to put $pagenow check (only on post-new.php?) is beyond my understanding.

      @steve or @kevin may put some light into this!

    • #7473
      Steve
      Keymaster

      Can you try changing Line 218 in piklist/parts/meta-boxes/submitdiv.php to:


      touch_time( ( $action === 'edit' ), 1 );

      Let us know if that works.

      • #7583
        Tonny Keuken
        Member

        Hi Steve,

        I have tried this out, and it will work.

        touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 );

        It works for every post whatever it’s type as long $for_post value will be 1 or true.

        @line 699 in wp_root/wp-admin/includes/template.php this value will be checked with:

        $post_date = ($for_post) ? $post->post_date : get_comment()->comment_date;

        if the item to check is not a “comment” then the notice (error) will be thrown because a post is not a comment
        and get_comment()->comment_date does not exist

        Self I choose to change line 218 in piklist/parts/meta-boxes/submitdiv.php with the following:

        touch_time(($action == ‘edit’), false === isset( get_comment()->comment_date ), 4);

        I hope this info helps

        Kind regards,
        Tonny

Viewing 6 reply threads
  • You must be logged in to reply to this topic.