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

a more generic solution #1

Open
lophas opened this issue Sep 29, 2018 · 2 comments
Open

a more generic solution #1

lophas opened this issue Sep 29, 2018 · 2 comments
Labels

Comments

@lophas
Copy link

lophas commented Sep 29, 2018

class cmb2_fix {
    const TYPES = ['term', 'user'];

    static private $_instance;function instance() {if(!isset(self::$_instance)) self::$_instance =  new self();return self::$_instance;}

    function __construct() {

        add_filter('cmb2_override_meta_value', function($data, $object_id, $a, $instance) {
            if(!in_array($a['type'], self::TYPES) || !$a['repeat']) return $data;
            $data = get_metadata( $a['type'], $a['id'], $a['field_id'], false );
            return $data;
        }, 10, 4);

        add_filter( 'cmb2_override_meta_save', function($override, $a, Array $args, $instance ) {
            if(!in_array($a['type'], self::TYPES) || !$a['repeat']) return $override;
            $id = delete_metadata($a['type'], $a['id'], $a['field_id']);
            if(!empty($a['value'])) foreach($a['value'] as $value) $id = add_metadata( $a['type'], $a['id'], $a['field_id'], $value, false );
            return $id ? $id : false;
        }, 10, 4);

    } //__construct
} //cmb2_fix
cmb2_fix::instance();
@lucatume
Copy link
Owner

lucatume commented Oct 1, 2018

Hi,

could you clarify your intention here? Is this a PR? A suggestion? A problem?

@lucatume lucatume closed this as completed Oct 1, 2018
@lucatume lucatume reopened this Oct 1, 2018
@lucatume
Copy link
Owner

lucatume commented Oct 1, 2018

Closed by mistake.

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

No branches or pull requests

2 participants