Tagged: Debug mode, warning
- This topic has 14 replies, 2 voices, and was last updated 5 years, 7 months ago by
Jason.
-
AuthorPosts
-
-
June 14, 2016 at 5:16 am #6669
vayuMemberHi.
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? -
June 15, 2016 at 10:49 am #6678
JasonKeymasterHi @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?
-
June 15, 2016 at 10:55 am #6680
vayuMemberHere 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 -
June 15, 2016 at 11:14 am #6682
-
June 15, 2016 at 11:20 am #6683
vayuMemberYes 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.
-
June 15, 2016 at 11:21 am #6684
vayuMemberOh, the filetypes was not uploaded.I will try attach it in a .txt file.
-
June 15, 2016 at 11:22 am #6685
vayuMemberThat did not work either. Should I just paste it all here then?
-
June 15, 2016 at 11:34 am #6686
JasonKeymasterSorry, I don’t know the upload limits of this site. Hahah!
How about a gist, pastie, pastebin, etc.?
-
June 15, 2016 at 11:37 am #6687
vayuMemberOk no problem :-). I have used pastie: http://pastie.org/private/ornacmvb9lfuryv8qnddsg
-
June 15, 2016 at 12:10 pm #6688
JasonKeymasterGot it! The problem is that on some of the post types you’re setting
capability_typeas 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. -
June 16, 2016 at 3:36 am #6700
vayuMemberWell 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 -
June 16, 2016 at 7:40 am #6702
vayuMemberI just noticed that if use a string on
capability_typethe 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' -
June 16, 2016 at 10:55 am #6716
JasonKeymasterHey @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!
-
June 18, 2016 at 6:25 am #6741
vayuMemberI see, thanks a lot for your help on this Jason! 🙂
-
June 18, 2016 at 9:31 pm #6746
JasonKeymasterYou’re very welcome! 🙂
-
-
AuthorPosts
- You must be logged in to reply to this topic.