├── images └── ajax-loader.gif ├── readme.txt ├── wordpress-creation-kit.css ├── wordpress-creation-kit.js └── wordpress-creation-kit.php /images/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/madalinungureanu/wordpress-creation-kit-api/18a89535b9e76476ac3bf03d4a1d1305c647df76/images/ajax-loader.gif -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | Usage Example 1 2 | 3 | 'text', 'title' => 'Title', 'description' => 'Description for this input' ), 7 | array( 'type' => 'textarea', 'title' => 'Description' ), 8 | array( 'type' => 'upload', 'title' => 'Image', 'description' => 'Upload a image' ), 9 | array( 'type' => 'select', 'title' => 'Select This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ), 10 | 11 | array( 'type' => 'checkbox', 'title' => 'Check This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ), 12 | 13 | array( 'type' => 'radio', 'title' => 'Radio This', 'options' => array( 'Radio 1', 'Radio 2', 'Radio 3' ) ), 14 | ); 15 | 16 | $args = array( 17 | 'metabox_id' => 'rm_slider_content', 18 | 'metabox_title' => 'Slideshow Class', 19 | 'post_type' => 'slideshows', 20 | 'meta_name' => 'rmscontent', 21 | 'meta_array' => $fint 22 | ); 23 | 24 | new Wordpress_Creation_Kit( $args ); 25 | 26 | ?> 27 | 28 | For Frontend use like this: 29 | 30 | ID, 'rmscontent', true ); ?> 31 | 32 | 33 | 34 | 35 | Default Parameters 36 | 37 | '', 39 | 'metabox_title' => 'Meta Box', 40 | 'post_type' => 'post', 41 | 'meta_name' => '', 42 | 'meta_array' => array(), 43 | 'page_template' => '', 44 | 'post_id' => '', 45 | 'single' => false, 46 | 'wpml_compatibility' => false, 47 | 'sortable' => true, 48 | 'context' => 'post_meta' 49 | ) 50 | ?> 51 | 52 | Parameters 53 | 54 | $metabox_id 55 | (string) (required) HTML 'id' attribute of the edit screen section 56 | 57 | Default: None 58 | 59 | $metabox_title 60 | (string) (required) Title of the edit screen section, visible to user 61 | 62 | Default: 'Meta Box' 63 | 64 | $post_type 65 | (string) (required) The type of Write screen on which to show the edit screen section ('post', 'page', 'link', or 'custom_post_type' where custom_post_type is the custom post type slug) 66 | 67 | Default: 'post' 68 | 69 | $meta_name 70 | (string) (required) The name of the meta key used to query for data 71 | 72 | Default: None 73 | 74 | $meta_array 75 | (array) (required) The array of fields used to create the form. See example above. Must be array( array() ). Type and Title are required. 76 | 77 | Default: None 78 | 79 | $page_template 80 | (string) (optional) The name of the page template on wich you want the meta box to appear. If this is set than $post_type can be omitted. 81 | 82 | Default: None 83 | 84 | $post_id 85 | (string) (optional) The id of the post you want the meta box to appear. If this is set than $post_type can be omitted. 86 | 87 | Default: None 88 | 89 | $single 90 | (boolean) (optional) Set this to true if you don't want a repeater box and you will be able to enter just one value. 91 | 92 | Default: false 93 | 94 | $wpml_compatibility 95 | (boolean) (optional) Set this to true if you want to enable wpml compatibility 96 | 97 | $sortable 98 | (boolean) (optional) Wheater or not the fields in a repeater box are sortable. 99 | 100 | Default: true 101 | 102 | $context 103 | (string) (optional) WCK API can add data as meta or as option depending on the context. Using 'post_meta' will add data as post meta and using 'option' will add data as option 104 | 105 | Default: 'post_meta' 106 | 107 | Parameters for meta_array 108 | 109 | 'title' (string) Title of the field. 110 | 'type' (string) The field type. Possible values: 'text', 'textarea', 'select', 'checkbox', 'radio', 'upload'. 111 | 'description' (string) The description of the field. 112 | 'required' (boolean) true if the field is required. 113 | 'default' (string) If you want the string to have a default value enter it here. For Checkboxes if there are multiple 114 | values separete them with a ",". 115 | 'default-option' (boolean) true if you want Select to have a default option. 116 | 'options' (array) Options for field types "select", "checkbox" and "radio". 117 | 118 | 119 | How to add into a plugin: 120 | 121 | 1. Copy the foldder "wordpress-creation-kit-api" into the plugin dir 122 | 2. Change the class name "Wordpress_Creation_Kit" if multiple plugins use wordpress-creation-kit-api on the same site. 123 | 3. Include "wordpress-creation-kit.php" into the plugin file 124 | 125 | /* include Custom Fields Creator API */ 126 | require_once('wordpress-creation-kit/wordpress-creation-kit.php'); 127 | 128 | 4. Use the API as in Exampe 1, in your plugin file or functions or whatever fits the situation. 129 | 130 | 131 | WPML Compatibility 132 | 133 | When wpml_compatibility is true on a meta box, besides saving the contents of the box in one serialized custom field, we create automatically a custom field for every field in every entry. We do this because WPML can't handle serialized custom fields and also we will get good control on what actions we want to perform (don't translate, copy, translate ) on each of the fields. 134 | 135 | After the fields are translated with Icanlcalize and we have the translated post in our system, we can go on the translated post and press the "Syncronize WCK Translation" button which will create the serialized array from the individual custom fields. -------------------------------------------------------------------------------- /wordpress-creation-kit.css: -------------------------------------------------------------------------------- 1 | .mb-list-entry-fields li{ 2 | margin-bottom:15px; 3 | clear:both; 4 | overflow:hidden; 5 | } 6 | 7 | .mb-right-column{ 8 | overflow:hidden; 9 | } 10 | 11 | .field-label{ 12 | width:190px; 13 | float:left; 14 | min-height:30px; 15 | font-weight:bold; 16 | padding-right:10px; 17 | } 18 | 19 | .field-label.error{ 20 | color:#ff0000; 21 | } 22 | 23 | .field-label .required{ 24 | color:#ff0000; 25 | padding:0 2px; 26 | } 27 | 28 | .mb-right-column label{ 29 | padding:0 6px 0 3px; 30 | } 31 | 32 | #mb-ajax-loading{ 33 | position:absolute; 34 | top:0; 35 | left:0; 36 | width:100%; 37 | height:100%; 38 | background:url(images/ajax-loader.gif) center center no-repeat; z-index:999; 39 | } 40 | 41 | .mb-table-container pre{ 42 | display:inline-block; 43 | vertical-align:top; 44 | margin:0; 45 | white-space: -moz-pre-wrap; 46 | white-space: -pre-wrap; 47 | white-space: -o-pre-wrap; 48 | white-space: pre-wrap; 49 | word-wrap: break-word; 50 | } 51 | 52 | .wck-edit, .wck-delete, .wck-number{ 53 | width:50px; 54 | text-align:center !important; 55 | } 56 | 57 | td.wck-number{ 58 | cursor:move; 59 | } 60 | 61 | .not-sortable td.wck-number{ 62 | cursor:auto; 63 | } 64 | 65 | .wck-edit .button-secondary{ 66 | padding:3px 15px; 67 | } 68 | 69 | .mbdelete{ 70 | color:#BC0B0B; 71 | } 72 | 73 | .mbdelete:hover{ 74 | color:#FF0000; 75 | } 76 | 77 | .mb-list-entry-fields{ 78 | list-style:none; 79 | } 80 | 81 | .mb-table-container tr:nth-child(2n+1) { 82 | background-color:#FCFCFC; 83 | } 84 | 85 | .mb-table-container tr:last-child td { 86 | border-bottom: 0 none; 87 | } 88 | 89 | .mb-table-container tr td { 90 | background: none repeat scroll 0 0 transparent; 91 | border-bottom: 1px solid #EDEDED; 92 | border-right: 1px solid #EDEDED; 93 | padding: 8px; 94 | position: relative; 95 | } 96 | 97 | .mb-table-container tr td:last-child { 98 | border-right: 0 none; 99 | } 100 | 101 | .mb-table-container thead > tr > th { 102 | border-right: 1px solid #E1E1E1; 103 | } 104 | 105 | .mb-table-container tr > th:last-child { 106 | border-right: 0 none; 107 | } 108 | 109 | .mb-textarea{ 110 | width:60%; 111 | max-width:600px; 112 | height:130px; 113 | } 114 | .mb-text-input{ 115 | width:40%; 116 | max-width:400px; 117 | } 118 | 119 | .mb-select{ 120 | min-width:150px; 121 | } 122 | 123 | /* Settings page. */ 124 | .side .form-table th { 125 | width: 20%; 126 | font-weight: bold; 127 | text-align: left; 128 | padding-left: 0; 129 | } 130 | 131 | .wck-post-body{ 132 | clear: left; 133 | float: left; 134 | margin-right: -2000px; 135 | width: 100%; 136 | } 137 | 138 | .metabox-holder .column-1 { 139 | margin-right:300px; 140 | } 141 | .metabox-holder .column-2 { 142 | float: right; 143 | width: 280px; 144 | clear:right; 145 | position:relative; 146 | } 147 | .metabox-holder .column-3 { 148 | clear: both; 149 | margin-right:300px; 150 | } -------------------------------------------------------------------------------- /wordpress-creation-kit.js: -------------------------------------------------------------------------------- 1 | /* Add width to elements at startup */ 2 | jQuery(function(){ 3 | jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); 4 | 5 | 6 | 7 | }); 8 | 9 | /* add reccord to the meta */ 10 | function addMeta(value, id, nonce){ 11 | jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('
'); 12 | /*object to hold the values */ 13 | var values = {}; 14 | 15 | jQuery('#'+value+' .mb-field').each(function(){ 16 | 17 | var key = jQuery(this).attr('name'); 18 | 19 | if(jQuery(this).attr('type') == 'checkbox' || jQuery(this).attr('type') == 'radio' ) { 20 | 21 | if( typeof values[key.toString()] === "undefined" ) 22 | values[key.toString()] = ''; 23 | 24 | if(jQuery(this).is(':checked')){ 25 | if( values[key.toString()] == '' ) 26 | values[key.toString()] += jQuery(this).val().toString(); 27 | else 28 | values[key.toString()] += ', ' + jQuery(this).val().toString(); 29 | } 30 | } 31 | 32 | else 33 | values[key.toString()] = jQuery(this).val().toString(); 34 | }); 35 | 36 | 37 | jQuery.post( ajaxurl , { action:"wck_add_meta"+value, meta:value, id:id, values:values, _ajax_nonce:nonce}, function(response) { 38 | 39 | jQuery( '#'+value+' .field-label').removeClass('error'); 40 | 41 | if( response.error ){ 42 | jQuery('#'+value).parent().css('opacity','1'); 43 | jQuery('#mb-ajax-loading').remove(); 44 | 45 | for( var i in response.errorfields ){ 46 | jQuery( '#'+value+' .field-label[for="' + response.errorfields[i] + '"]' ).addClass('error'); 47 | } 48 | 49 | alert( response.error ); 50 | } 51 | else{ 52 | /* refresh the list */ 53 | jQuery.post( ajaxurl , { action:"wck_refresh_list"+value, meta:value, id:id}, function(response) { 54 | 55 | jQuery('#container_'+value).replaceWith(response); 56 | 57 | jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); 58 | 59 | if( !jQuery( '#'+value ).hasClass('single') ) 60 | mb_sortable_elements(); 61 | 62 | jQuery('#'+value+' .mb-field').each(function(){ 63 | if(jQuery(this).attr('type') == 'checkbox' || jQuery(this).attr('type') == 'radio' ) 64 | jQuery(this).removeAttr( 'checked' ); 65 | else 66 | jQuery(this).val(''); 67 | }); 68 | jQuery('#'+value).parent().css('opacity','1'); 69 | 70 | /* Remove form if is single */ 71 | if( jQuery( '#'+value ).hasClass('single') ) 72 | jQuery( '#'+value ).remove(); 73 | 74 | jQuery('#mb-ajax-loading').remove(); 75 | }); 76 | } 77 | }); 78 | } 79 | 80 | /* remove reccord from the meta */ 81 | function removeMeta(value, id, element_id, nonce){ 82 | 83 | var response = confirm( "Delete this item ?" ); 84 | 85 | if( response == true ){ 86 | 87 | jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append(''); 88 | jQuery.post( ajaxurl , { action:"wck_remove_meta"+value, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) { 89 | 90 | /* If single add the form */ 91 | if( jQuery( '#container_'+value ).hasClass('single') ){ 92 | jQuery.post( ajaxurl , { action:"wck_add_form"+value, meta:value, id:id }, function(response) { 93 | jQuery( '#container_'+value ).before( response ); 94 | jQuery( '#'+value ).addClass('single'); 95 | }); 96 | } 97 | 98 | /* refresh the list */ 99 | jQuery.post( ajaxurl , { action:"wck_refresh_list"+value, meta:value, id:id}, function(response) { 100 | jQuery('#container_'+value).replaceWith(response); 101 | 102 | jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); 103 | 104 | mb_sortable_elements(); 105 | jQuery('#'+value).parent().css('opacity','1'); 106 | jQuery('#mb-ajax-loading').remove(); 107 | }); 108 | 109 | }); 110 | } 111 | } 112 | 113 | /* swap two reccords */ 114 | /*function swapMetaMb(value, id, element_id, swap_with){ 115 | jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append(''); 116 | jQuery.post( ajaxurl , { action:"swap_meta_mb", meta:value, id:id, element_id:element_id, swap_with:swap_with}, function(response) { 117 | 118 | jQuery.post( ajaxurl , { action:"refresh_list", meta:value, id:id}, function(response) { 119 | jQuery('#container_'+value).replaceWith(response); jQuery('#'+value).parent().css('opacity','1'); jQuery('#mb-ajax-loading').remove(); 120 | }); 121 | 122 | }); 123 | } 124 | */ 125 | 126 | /* reorder elements through drag and drop */ 127 | function mb_sortable_elements() { 128 | jQuery( ".mb-table-container tbody" ).not( jQuery( ".mb-table-container.single tbody, .mb-table-container.not-sortable tbody" ) ).sortable({ 129 | update: function(event, ui){ 130 | 131 | var value = jQuery(this).parent().prev().attr('id'); 132 | var id = jQuery(this).parent().attr('post'); 133 | 134 | var result = jQuery(this).sortable('toArray'); 135 | 136 | var values = {}; 137 | for(var i in result) 138 | { 139 | values[i] = result[i].replace('element_',''); 140 | } 141 | 142 | jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append(''); 143 | 144 | jQuery.post( ajaxurl , { action:"wck_reorder_meta"+value, meta:value, id:id, values:values}, function(response) { 145 | jQuery.post( ajaxurl , { action:"wck_refresh_list"+value, meta:value, id:id}, function(response) { 146 | jQuery('#container_'+value).replaceWith(response); 147 | 148 | jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); 149 | 150 | mb_sortable_elements(); 151 | jQuery('#'+value).parent().css('opacity','1'); 152 | jQuery('#mb-ajax-loading').remove(); 153 | }); 154 | 155 | }); 156 | } 157 | }); 158 | jQuery( "#sortable" ).disableSelection(); 159 | 160 | 161 | jQuery('.mb-table-container ul').mousedown( function(e){ 162 | e.stopPropagation(); 163 | }); 164 | } 165 | jQuery(mb_sortable_elements); 166 | 167 | 168 | 169 | /* show the update form */ 170 | function showUpdateFormMeta(value, id, element_id, nonce){ 171 | if( jQuery( '#update_container_' + value + '_' + element_id ).length == 0 ){ 172 | jQuery('#container_'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append(''); 173 | 174 | jQuery( '#container_' + value + " tbody" ).sortable("disable"); 175 | 176 | jQuery.post( ajaxurl , { action:"wck_show_update"+value, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) { 177 | //jQuery('#container_'+value+' #element_'+element_id).append(response); 178 | jQuery(response).insertAfter('#container_'+value+' #element_'+element_id); 179 | jQuery('#container_'+value).parent().css('opacity','1'); 180 | jQuery('#mb-ajax-loading').remove(); 181 | wckGoToByScroll('update_container_' + value + '_' + element_id); 182 | }); 183 | } 184 | } 185 | 186 | /* remove the update form */ 187 | function removeUpdateForm( id ){ 188 | jQuery( '#'+id ).remove(); 189 | } 190 | 191 | /* update reccord */ 192 | function updateMeta(value, id, element_id, nonce){ 193 | jQuery('#container_'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append(''); 194 | var values = {}; 195 | jQuery('#update_container_'+value+'_'+element_id+' .mb-field').each(function(){ 196 | var key = jQuery(this).attr('name'); 197 | 198 | if(jQuery(this).attr('type') == 'checkbox' || jQuery(this).attr('type') == 'radio' ) { 199 | 200 | if( typeof values[key.toString()] === "undefined" ) 201 | values[key.toString()] = ''; 202 | 203 | if(jQuery(this).is(':checked')){ 204 | if( values[key.toString()] == '' ) 205 | values[key.toString()] += jQuery(this).val().toString(); 206 | else 207 | values[key.toString()] += ', ' + jQuery(this).val().toString(); 208 | } 209 | } 210 | 211 | else 212 | values[key.toString()] = jQuery(this).val().toString(); 213 | 214 | }); 215 | 216 | jQuery.post( ajaxurl , { action:"wck_update_meta"+value, meta:value, id:id, element_id:element_id, values:values, _ajax_nonce:nonce}, function(response) { 217 | 218 | jQuery( '#update_container_'+value+'_'+element_id + ' .field-label').removeClass('error'); 219 | 220 | if( response.error ){ 221 | jQuery('#container_'+value).parent().css('opacity','1'); 222 | jQuery('#mb-ajax-loading').remove(); 223 | 224 | for( var i in response.errorfields ){ 225 | jQuery( '#update_container_'+value+'_'+element_id + ' .field-label[for="' + response.errorfields[i] + '"]' ).addClass('error'); 226 | } 227 | 228 | alert( response.error ); 229 | } 230 | else{ 231 | jQuery('#update_container_'+value+'_'+element_id).remove(); 232 | /* refresh the list */ 233 | jQuery.post( ajaxurl , { action:"wck_refresh_entry"+value, meta:value, id:id, element_id:element_id}, function(response) { 234 | jQuery('#container_'+value+' #element_'+element_id).replaceWith(response); 235 | 236 | jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); 237 | 238 | jQuery( '#container_' + value + " tbody" ).sortable("enable"); 239 | 240 | jQuery('#container_'+value).parent().css('opacity','1'); 241 | jQuery('#mb-ajax-loading').remove(); 242 | }); 243 | } 244 | }); 245 | } 246 | 247 | /* function syncs the translation */ 248 | function wckSyncTranslation(id){ 249 | jQuery.post( ajaxurl , { action:"wck_sync_translation", id:id}, function(response) { 250 | if( response == 'syncsuccess' ) 251 | window.location.reload(); 252 | }); 253 | } 254 | 255 | function wckGoToByScroll(id){ 256 | jQuery('html,body').animate({scrollTop: jQuery("#"+id).offset().top - 28},'slow'); 257 | } -------------------------------------------------------------------------------- /wordpress-creation-kit.php: -------------------------------------------------------------------------------- 1 | 'text', 'title' => 'Title', 'description' => 'Description for this input' ), 23 | array( 'type' => 'textarea', 'title' => 'Description' ), 24 | array( 'type' => 'upload', 'title' => 'Image', 'description' => 'Upload a image' ), 25 | array( 'type' => 'select', 'title' => 'Select This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ), 26 | array( 'type' => 'checkbox', 'title' => 'Check This', 'options' => array( 'Option 1', 'Option 2', 'Option 3' ) ), 27 | array( 'type' => 'radio', 'title' => 'Radio This', 'options' => array( 'Radio 1', 'Radio 2', 'Radio 3' ) ), 28 | ); 29 | 30 | $args = array( 31 | 'metabox_id' => 'rm_slider_content', 32 | 'metabox_title' => 'Slideshow Class', 33 | 'post_type' => 'slideshows', 34 | 'meta_name' => 'rmscontent', 35 | 'meta_array' => $fint 36 | ); 37 | 38 | new Wordpress_Creation_Kit( $args ); 39 | 40 | 41 | On the frontend: 42 | 43 | $meta = get_post_meta( $post->ID, 'rmscontent', true ); 44 | 45 | */ 46 | 47 | class WCK_CFC_Wordpress_Creation_Kit{ 48 | 49 | private $defaults = array( 50 | 'metabox_id' => '', 51 | 'metabox_title' => 'Meta Box', 52 | 'post_type' => 'post', 53 | 'meta_name' => '', 54 | 'meta_array' => array(), 55 | 'page_template' => '', 56 | 'post_id' => '', 57 | 'single' => false, 58 | 'wpml_compatibility' => false, 59 | 'sortable' => true, 60 | 'context' => 'post_meta' 61 | ); 62 | private $args; 63 | 64 | 65 | /* Constructor method for the class. */ 66 | function __construct( $args ) { 67 | 68 | /* Global that will hold all the arguments for all the custom boxes */ 69 | global $wck_objects; 70 | 71 | /* Merge the input arguments and the defaults. */ 72 | $this->args = wp_parse_args( $args, $this->defaults ); 73 | 74 | /* Add the settings for this box to the global object */ 75 | $wck_objects[$this->args['metabox_id']] = $this->args; 76 | 77 | /*print scripts*/ 78 | add_action('admin_enqueue_scripts', array( &$this, 'wck_print_scripts' )); 79 | 80 | // Set up the AJAX hooks 81 | add_action("wp_ajax_wck_add_meta".$this->args['meta_name'], array( &$this, 'wck_add_meta') ); 82 | add_action("wp_ajax_wck_update_meta".$this->args['meta_name'], array( &$this, 'wck_update_meta') ); 83 | add_action("wp_ajax_wck_show_update".$this->args['meta_name'], array( &$this, 'wck_show_update_form') ); 84 | add_action("wp_ajax_wck_refresh_list".$this->args['meta_name'], array( &$this, 'wck_refresh_list') ); 85 | add_action("wp_ajax_wck_refresh_entry".$this->args['meta_name'], array( &$this, 'wck_refresh_entry') ); 86 | add_action("wp_ajax_wck_add_form".$this->args['meta_name'], array( &$this, 'wck_add_form') ); 87 | add_action("wp_ajax_wck_remove_meta".$this->args['meta_name'], array( &$this, 'wck_remove_meta') ); 88 | //add_action("wp_ajax_swap_meta_mb", array( & $this, 'mb_swap_meta') ); 89 | add_action("wp_ajax_wck_reorder_meta".$this->args['meta_name'], array( &$this, 'wck_reorder_meta') ); 90 | 91 | /* modify Insert into post button */ 92 | add_action('admin_head-media-upload-popup', array( &$this, 'wck_media_upload_popup_head') ); 93 | 94 | /* custom functionality for upload video */ 95 | add_filter('media_send_to_editor', array( &$this, 'wck_media_send_to_editor' ), 15, 2 ); 96 | 97 | add_action('add_meta_boxes', array( &$this, 'wck_add_metabox') ); 98 | 99 | /* hook to add a side metabox with the Syncronize translation button */ 100 | add_action('add_meta_boxes', array( &$this, 'wck_add_sync_translation_metabox' ) ); 101 | 102 | /* ajax hook the syncronization function */ 103 | add_action("wp_ajax_wck_sync_translation", array( &$this, 'wck_sync_translation_ajax' ) ); 104 | 105 | } 106 | 107 | 108 | //add metabox using wordpress api 109 | 110 | function wck_add_metabox() { 111 | 112 | global $wck_pages_hooknames; 113 | 114 | if( $this->args['context'] == 'post_meta' ){ 115 | if( $this->args['post_id'] == '' && $this->args['page_template'] == '' ) 116 | add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), $this->args['post_type'], 'normal', 'low', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) ); 117 | else{ 118 | $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; 119 | 120 | if( $this->args['post_id'] != '' && $this->args['page_template'] != '' ){ 121 | $template_file = get_post_meta($post_id,'_wp_page_template',TRUE); 122 | if( $this->args['post_id'] == $post_id && $template_file == $this->args['page_template'] ) 123 | add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), 'page', 'normal', 'low', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array'] ) ); 124 | } 125 | else{ 126 | 127 | if( $this->args['post_id'] != '' ){ 128 | if( $this->args['post_id'] == $post_id ){ 129 | $post_type = get_post_type( $post_id ); 130 | add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), $post_type, 'normal', 'low', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array'] ) ); 131 | } 132 | } 133 | 134 | if( $this->args['page_template'] != '' ){ 135 | $template_file = get_post_meta($post_id,'_wp_page_template',TRUE); 136 | if ( $template_file == $this->args['page_template'] ) 137 | add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), 'page', 'normal', 'low', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) ); 138 | } 139 | 140 | } 141 | 142 | } 143 | } 144 | else if( $this->args['context'] == 'option' ){ 145 | add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'wck_content' ), $wck_pages_hooknames[$this->args['post_type']], 'normal', 'low', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) ); 146 | } 147 | } 148 | 149 | function wck_content($post, $metabox){ 150 | //output the add form 151 | if( $this->args['single'] ){ 152 | 153 | if( $this->args['context'] == 'post_meta' ) 154 | $meta_val = get_post_meta( $post->ID, $metabox['args']['meta_name'], true ); 155 | else if ( $this->args['context'] == 'option' ) 156 | $meta_val = get_option( $metabox['args']['meta_name'] ); 157 | 158 | if( empty( $meta_val ) ) 159 | self::create_add_form($metabox['args']['meta_array'], $metabox['args']['meta_name'], $post); 160 | } 161 | else 162 | self::create_add_form($metabox['args']['meta_array'], $metabox['args']['meta_name'], $post); 163 | //output the entries 164 | echo self::wck_output_meta_content($metabox['args']['meta_name'], $post->ID, $metabox['args']['meta_array']); 165 | } 166 | 167 | /** 168 | * The function used to create a form element 169 | * 170 | * @since 1.0.0 171 | * 172 | * @param string $meta Meta name. 173 | * @param array $details Contains the details for the field. 174 | * @param string $value Contains input value; 175 | * @param string $context Context where the function is used. Depending on it some actions are preformed.; 176 | * @return string $element input element html string. 177 | */ 178 | 179 | function wck_output_form_field( $meta, $details, $value = '', $context = '' ){ 180 | $element = ''; 181 | 182 | if( $context == 'edit_form' ){ 183 | $edit_class = '.mb-table-container '; 184 | $var_prefix = 'edit'; 185 | } 186 | else{ 187 | if( !empty( $details['default'] ) ) 188 | $value = $details['default']; 189 | } 190 | 191 | 192 | $element .= ''; 196 | 197 | $element .= ''. $details['description'].'
'; 261 | } 262 | 263 | $element .= '# | Content | Edit | Delete |
---|
'.htmlspecialchars( $results[$element_id][sanitize_title_with_dashes( remove_accents( $details['title'] ) )] ) . ''; 424 | 425 | $list = apply_filters( "wck_before_listed_{$meta}_element_{$j}", $list, $element_id, $value ); 426 | 427 | $list .= '