admin_url( 'admin-ajax.php' ), 'date_format' => ADB_Settings::$settings['date_format'] == 'd/m/Y' ? 'dd/mm/yy' : 'mm/dd/yy', 'nonce' => wp_create_nonce(ADB_Post_types::$nonce_title), ) ); wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_style('jquery-ui-style', plugins_url( "css/jquery-ui.css", ADB_PLUGIN )); } /////////////////////////////// /** * Register text field */ public static function cmb2_shortcode_key_name($field, $value, $object_id, $object_type, $field_type ){ $output = $field_type->input( array( 'name' => $field_type->_name(), 'id' => $field_type->_id(), 'value' => $value, ) ); echo $output; } /////////////////////////////// /** * Sanitize field */ public static function cmb2_sanitize_shortcode_key_name( $override_value, $value, $object_id, $field_args, $sanitizer_object ) { $value = sanitize_title($value); return $value; } /////////////////////////////////////// /** * Register extra fields. */ public static function metabox_adblock() { $prefix = ''; $cmb = new_cmb2_box( array( 'id' => 'metabox_adblock', 'title' => __( 'Shortcode options', ADB_TEXTDOMAIN ), 'object_types' => array( ADB_Post_types::$adblock_post_type, ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left // 'cmb_styles' => false, // false to disable the CMB stylesheet // 'closed' => true, // Keep the metabox closed by default ) ); $cmb->add_field( array( 'name' => __( 'Shortcode name param', ADB_TEXTDOMAIN ), 'id' => $prefix . 'shortcode_key_name', 'type' => 'shortcode_key_name', 'attributes' => array( 'required' => 'required', 'class' => 'medium-text', ), )); $cmb = new_cmb2_box( array( 'id' => 'metabox_adblock_auto', 'title' => __( 'Auto posting', ADB_TEXTDOMAIN ), 'object_types' => array( ADB_Post_types::$adblock_post_type, ), // Post type 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left // 'cmb_styles' => false, // false to disable the CMB stylesheet // 'closed' => true, // Keep the metabox closed by default ) ); $cmb->add_field( array( 'name' => __( 'Auto add to posts', ADB_TEXTDOMAIN ), 'id' => $prefix . 'add_to_posts', 'type' => 'radio_inline', 'options' => array( 0 => __( 'No', ADB_TEXTDOMAIN ), 1 => __( 'Yes', ADB_TEXTDOMAIN ), ), 'default' => 0 )); $cmb->add_field( array( 'name' => __( 'Insert location', ADB_TEXTDOMAIN ), 'id' => $prefix . 'add_location', 'type' => 'radio_inline', 'options' => array( 0 => __( 'Before content', ADB_TEXTDOMAIN ), 1 => __( 'After content', ADB_TEXTDOMAIN ), ), 'default' => 0 )); $cmb->add_field( array( 'name' => __( 'Post types', ADB_TEXTDOMAIN ), 'id' => $prefix . 'add_post_types', 'type' => 'multicheck', 'options' => self::get_post_types_options(), )); } ////////////////////////////// /** * Get post types option list. * * @return array */ public static function get_post_types_options() { $output = array(); $args = array( 'public' => true, ); $post_types = get_post_types( $args, 'objects'); foreach ( $post_types as $post_type ) { if ( !$post_type->_builtin || ($post_type->_builtin && ($post_type->name == 'post' || $post_type->name == 'page') )){ $output[ $post_type->name ] = $post_type->labels->singular_name; } } return $output; } ////////////////////////////// } ADB_CMB2_admin::init();