public function admin_register_meta_box_attributes() { $meta_box = new MetaBox('attributes', __('Attributes', 'wpk15')); $meta_box->add_field('price', __('Price', 'wpk15'), function () { $field = new Number(); $field->set_min(0.0); return $field; }); $meta_box->add_field('in-stock', __('In Stock', 'wpk15'), 'Checkbox'); $meta_box->add_post_type($this->_post_type_product); }
public static function get_product_variations($product_id = null) { if (null == $product_id) { $product_id = get_the_ID(); } $variations_photo = MetaBox::get($product_id, 'color-variations', 'photo'); $variations_color = MetaBox::get($product_id, 'color-variations', 'color'); $variations_title = MetaBox::get($product_id, 'color-variations', 'title'); $variations = []; foreach ($variations_photo as $key => $_) { $variations[] = ['photo' => wp_get_attachment_image($variations_photo[$key]), 'color' => $variations_color[$key], 'title' => $variations_title[$key]]; } return $variations; }
protected function _enqueue_javascript() { wp_enqueue_script('jquery-effects-highlight'); parent::_enqueue_javascript(); add_action('admin_print_footer_scripts', function () { echo "<script>\n\t\t\t\t\tjQuery(function (\$) {\n\t\t\t\t\t\t'use strict';\n\t\t\t\t\t\tvar get_editor_settings=function(id){\n\t\t\t\t\t\t var settings={};\n\t\t\t\t\t\t if(typeof tinymce != 'undefined'){\n\t\t\t\t\t\t var main_id=id.substring(0,(id.length-1))+'0';\n\t\t\t\t\t\t var main_editor=tinyMCE.get(main_id);\n\n\t\t\t\t\t\t if(main_editor){\n\t\t\t\t\t\t settings=main_editor.settings;\n\t\t\t\t\t\t settings.selector='#'+id;\n\t\t\t\t\t\t settings.id=id;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t return settings;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t return {};\n\t\t\t\t\t\t};\n\t\t\t\t\t\tvar reInitEditor = function (id) {\n\t\t\t\t\t\t if(typeof tinymce != 'undefined' && typeof id !== 'undefined'){\n\t\t\t\t\t\t var settings = get_editor_settings(id);\n\t\t\t\t\t\t\t tinymce.EditorManager.execCommand('mceRemoveEditor', true, id);\n tinyMCE.init(settings);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t\t\$(document).on('repeatable_row_added', function (e,el) {\n\t\t\t\t\t\t\treInitEditor(\$(el).find('.wp-editor-area').attr('id'));\n\t\t\t\t\t\t\tif(typeof wp.wpkit != 'undefined'){\n\t\t\t\t\t\t\t if(typeof wp.wpkit.datepicker != 'undefined'){\n wp.wpkit.datepicker.reinit();\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\tjQuery('#{$this->get_key()}').on('sortstop', function (event, ui) {\n\t\t\t\t\t\t\tui.item.find('.wp-editor-area').each(function () {\n\t\t\t\t\t\t\t\treInitEditor(\$(this).attr('id'));\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t</script>"; }); }
/** * Attach a meta box that will be used with this post type * * @param MetaBox $meta_box meta box object */ public function add_meta_box(MetaBox $meta_box) { $meta_box->add_post_type($this); }
protected function _enqueue_style() { ?> <style type="text/css"> .wpkit-query-results { border: 1px #dfdfdf solid; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; margin: 15px 1px 1px; background: #fff; overflow: auto; height: 200px; width: 99%; } .wpkit-query-results .query-notice, .wpkit-query-results li { clear: both; margin-bottom: 0; border-bottom: 1px solid #f1f1f1; color: #333; padding: 4px 6px; cursor: pointer; position: relative; } .wpkit-query-results ul { list-style: none; margin: 0; padding: 0; } .wpkit-query-results .waiting { display: none; padding: 10px 0; } .wpkit-query-results .waiting .spinner { margin: 0 auto; display: block; float: none; } .wpkit-query-results li:hover { background: #eaf2fa; color: #151515; } .wpkit-query-results .item-info { text-transform: uppercase; color: #666; font-size: 11px; position: absolute; right: 5px; top: 5px; } .wpkit-table .drag-handle { cursor: row-resize; vertical-align: top } .wpkit-table .item-info { text-transform: uppercase; } </style> <?php parent::_enqueue_style(); }
protected function _enqueue_javascript() { wp_enqueue_script('jquery-effects-highlight'); parent::_enqueue_javascript(); }