wp-shortcake / shortcake

Shortcake makes using WordPress shortcodes a piece of cake.
GNU General Public License v2.0
665 stars 143 forks source link

Unable to add Shortcode UI to new Custom Post Type #760

Closed gsalkin closed 6 years ago

gsalkin commented 6 years ago

Hoping this is a simple fix on 0.7.2.

I've recently created a new custom post type called longform to my site. A constant called SHORT_CODE_POST_TYPES has been created which is set to an array listing all my custom post types such that when registering new short codes I can do the following:

'label'            => 'foo',
'listItemImage'    => 'bar',
'post_type' => self::SHORT_CODE_POST_TYPES,
'etc' => 'etc'

When I add longform to that array, it does not appear to be working. Clicking the "Add Post Element" causes nothing to happen. Clicking the "Add Media" button brings up the normal media browser without the Post Element option on the sidebar.

Any idea what I'm doing wrong? Hope I'm just missing an obvious step or something.

goldenapples commented 6 years ago

Hope I'm not suggesting something stupid, but how are you defining that constant?

In most cases, constants in PHP (including class constants) are limited to scalar values, and the 'post_type' argument expects an array.

szepeviktor commented 6 years ago

but how are you defining that constant?

I haven't dared to ask this question.

BTW in php 7+ there is such a thing as array constant.

*It is almost correct, see https://stackoverflow.com/a/27413238

goldenapples commented 6 years ago

in php 7+ there is such a thing as array constant.

Oh cool, I had forgotten about that, guess I've spent so much time trying to preserve PHP5 compatability I had blocked out some cool newer features like that.

gsalkin commented 6 years ago

Hope I'm not suggesting something stupid, but how are you defining that constant?

Not a dumb question at all.

const SHORT_CODE_POST_TYPES = array( 'post', 'impact', 'events', 'longform', 'programs', 'seminars', 'series', 'page');

This constant has been working fine until I tried adding the longform slug. Now Shortcake doesn't work with that new post type.

goldenapples commented 6 years ago

That seems weird, and I can't think offhand of any reason that wouldn't work for you. What does get_post_type() return on the post.php screen for editing a post in that custom post type?

Here's the code which unsets shortcodes that don't match the current post's post type; I don't see any reason for it not working in your case.

gsalkin commented 6 years ago

get_post_type() returns longform like I expected.

Doesn't generate any PHP errors either.

Is the fact that the custom post type is registered through a plugin a possible culprit?

gsalkin commented 6 years ago

Whelp for no reason at all it appears to be working. From what I can tell it was an error in git not tracking my changes in the upstream.

Thanks for the help though!

goldenapples commented 6 years ago

Glad it works.

Also - no, you don't have to declare a post_type argument - if that's left blank, the shortcode will be available to all post types.