Viewing 14 reply threads
  • Author
    Posts
    • #6669
      vayu
      Member

      Hi.
      I have Piklist installed on my Multisite Network and when I turn debug mode on in wp-config.php I get this Warning:
      Notice: Undefined offset: 1 in /wp-includes/post.php line 1336
      If I deactivate Piklist, the warning goes away.
      I am using WordPress v. 4.5.2 and Piklist v. 0.9.9.8
      I have no idea of what the cause of this warning could be. Maybe you guys have?

    • #6678
      Jason
      Keymaster

      Hi @vayu!

      Most times in these situations it’s something using Piklist that’s misconfigured that’s causing the issue. Using the piklist function incorrectly, on accident, for example, can raise an error that looks like it’s Piklist having an issue.

      In any case, could you please provide a stack trace to try and isolate the culprit line of code?

    • #6680
      vayu
      Member

      Here is the stack trace that is printed to the page.

      ( ! ) Notice: Undefined offset: 1 in /Users/vayu/Sites/example.dev/wp-includes/post.php on line 1336
      Call Stack
      #	Time	Memory	Function	Location
      1	0.0093	509688	{main}( )	../index.php:0
      2	0.0094	512472	require( '/Users/vayu/Sites/example.dev/wp-blog-header.php' )	../index.php:17
      3	0.0099	529376	require_once( '/Users/vayu/Sites/example.dev/wp-load.php' )	../wp-blog-header.php:13
      4	0.0101	546832	require_once( '/Users/vayu/Sites/example.dev/wp-config.php' )	../wp-load.php:37
      5	0.0114	648528	require_once( '/Users/vayu/Sites/example.dev/wp-settings.php' )	../wp-config.php:112
      6	1.5505	45825904	do_action( )	../wp-settings.php:393
      7	2.7630	48002344	call_user_func_array:{/Users/vayu/Sites/example.dev/wp-includes/plugin.php:525} ( )	../plugin.php:525
      8	2.7630	48002424	Piklist_CPT::init( )	../plugin.php:525
      9	2.7702	48041304	Piklist_CPT::register_post_types( )	../class-piklist-cpt.php:107
      10	2.7738	48082680	register_post_type( )	../class-piklist-cpt.php:167
      11	2.7738	48090680	get_post_type_capabilities( )	../post.php:1096
    • #6682
      Jason
      Keymaster

      Hi @vayu!

      Thanks! That helps!

      Are you registering any custom post types via the piklist_post_types hook? If so could you show me the code for that? Either you’ve found a bug or there’s a simple misconfiguration.

    • #6683
      vayu
      Member

      Yes I am. There are 444 lines of code that does this, so it seems a bit drastic to paste all that code here. I will just attach the file instead, hope that is ok.

    • #6684
      vayu
      Member

      Oh, the filetypes was not uploaded.I will try attach it in a .txt file.

    • #6685
      vayu
      Member

      That did not work either. Should I just paste it all here then?

    • #6686
      Jason
      Keymaster

      Sorry, I don’t know the upload limits of this site. Hahah!

      How about a gist, pastie, pastebin, etc.?

    • #6687
      vayu
      Member

      Ok no problem :-). I have used pastie: http://pastie.org/private/ornacmvb9lfuryv8qnddsg

    • #6688
      Jason
      Keymaster

      Got it! The problem is that on some of the post types you’re setting capability_type as an array. As is standard with register_post_type, it either has to be a string or an array with pre-defined indexes. From the looks of it, if you just change, for example, array('invoice') to simply 'invoice', that should fix the issue. But that depends on what you’re trying to do.

    • #6700
      vayu
      Member

      Well spotted Jason! That fixed it. 🙂 But I still don’t understand why it throws a warning? In the docs it says that it’s optional to use either string or array.
      https://codex.wordpress.org/Function_Reference/register_post_type

    • #6702
      vayu
      Member

      I just noticed that if use a string on capability_type the Menu item in the admin disappears for all users that are not superadmins and they do not have rights to access the custom post type page in the admin. So there must be some difference in the way WordPress registers the capability_type if it’s a string or if it’s an array.
      So this works but throws a warning:
      'capability_type' => array('invoice')
      This does not work and throws no warning:
      'capability_type' => 'invoice'

    • #6716
      Jason
      Keymaster

      Hey @vayu!

      It’s because you’re passing an incorrectly structured array. 🙂

      Please take a look on the register_post_type docs under the capability_type section. You’ll see there that it’s expecting the array to be your post type name in singular and plural form (e.g. array('product', 'products')).

      My favorite place to look is in the WordPress code itself: https://github.com/WordPress/WordPress/blob/4.5-branch/wp-includes/post.php#L1331

      Hope this helps!

    • #6741
      vayu
      Member

      I see, thanks a lot for your help on this Jason! 🙂

    • #6746
      Jason
      Keymaster

      You’re very welcome! 🙂

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