Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't save meta box field on camel case CPT #1109

Closed
bke-daniel opened this issue Apr 25, 2017 · 2 comments
Closed

Can't save meta box field on camel case CPT #1109

bke-daniel opened this issue Apr 25, 2017 · 2 comments

Comments

@bke-daniel
Copy link

Hey everyone,

first of all, great work you did with the Plugin! Even though I found some possible bug / enhancement. Consider this:

class Test
{

    /**
     * @const string
     */
    const WP_POST_TYPE = 'CamelCase';

    /**
     * Test constructor.
     */
    public function __construct()
    {
        add_action('init', [$this, 'registerCustomPostType']);
    }

    /**
     * Method registers custom post types
     */
    public function registerCustomPostType()
    {
        register_post_type(
            self::WP_POST_TYPE,
            [
                'label'  => 'CamelCases',
                'public' => TRUE,
            ]
        );
    }
}

$Test = new Test();


add_filter('rwmb_meta_boxes', 'registerMetaBoxCamelCase');

/**
 * Method registers a meta box
 *
 * @param $meta_boxes
 *
 * @return array
 */
function registerMetaBoxCamelCase($meta_boxes)
{
    $meta_boxes[] = [
        'id'         => 'camel-case-id',
        'title'      => __('Weitere Informationen'),
        'post_types' => [Test::WP_POST_TYPE],
        'context'  => 'side',
        'priority' => 'high',
        'fields'   => [
            [
                'name'        => __('Camel Case name'),
                'id'          => 'camel-case-id-input',
                'type'        => 'text',
                // Default value (optional)
                'std'         => __(''),
                // CLONES: Add to make the field cloneable (i.e. have multiple value)
                'clone'       => FALSE,
                // Placeholder
                'placeholder' => __(''),
                // Input size
                'size'        => 20,],

        ],
    ];

    return $meta_boxes;
}

Under these circumstances it is not possible to save the input field, but it is still displayed. If you enable 'custom-fields' on the WP CPT (Custom Post Type) and change the value manually it'll work like a charm.
The problem itself lies within the camel case CPT ID, WordPress itself sanitizes the post type name before registering it.
Surely, I can sanitize the name on my own and therefor it's not directly a bug. Would love to hear your thoughts about it being a bug or maybe an enhancement.

Cheers,
Daniel

P.S.: Sorry for the title, but with it I'll try to make sure that someone's going to find help if he's trying to fix this in his project.

@rilwis
Copy link
Member

rilwis commented May 4, 2017

Hi @bke-daniel,

Interesting thing! I've never experienced with this one, cause I always "think" the post type slug should be something_like_this.

The problem is Meta Box uses save_post_{$post_type} hook, which is sanitized by WP. I've just added a little enhancement to cover this issue :)

@rilwis rilwis closed this as completed May 4, 2017
@bke-daniel
Copy link
Author

Very cool, @rilwis! Thank you very much! :) 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants