diff --git a/readme.txt b/readme.txt index b4947f9..f43f694 100644 --- a/readme.txt +++ b/readme.txt @@ -21,7 +21,7 @@ Usage Example 1 'meta_array' => $fint ); - new Custom_Fields_Creator( $args ); + new Wordpress_Creation_Kit( $args ); ?> @@ -92,7 +92,7 @@ wpml_compatibility How to add into a plugin: 1. Copy the foldder "custom-fields-creator" into the plugin dir -2. Change the class name "Custom_Fields_Creator" if multiple plugins use custom-fields-creator on the same site. +2. Change the class name "Wordpress_Creation_Kit" if multiple plugins use custom-fields-creator on the same site. 3. Include "custom-fields-creator.php" into the plugin file /* include Custom Fields Creator API */ @@ -105,4 +105,4 @@ WPML Compatibility 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. -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 CFC Translation" button which will create the serialized array from the individual custom fields. \ No newline at end of file +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. \ No newline at end of file diff --git a/custom-fields-creator.css b/wordpress-creation-kit.css similarity index 100% rename from custom-fields-creator.css rename to wordpress-creation-kit.css diff --git a/custom-fields-creator.js b/wordpress-creation-kit.js similarity index 90% rename from custom-fields-creator.js rename to wordpress-creation-kit.js index c6552fa..e4cc372 100644 --- a/custom-fields-creator.js +++ b/wordpress-creation-kit.js @@ -30,10 +30,10 @@ function addMeta(value, id, nonce){ values[key.toString()] = jQuery(this).val().toString(); }); - jQuery.post( ajaxurl , { action:"cfc_add_meta"+value, meta:value, id:id, values:values, _ajax_nonce:nonce}, function(response) { + jQuery.post( ajaxurl , { action:"wck_add_meta"+value, meta:value, id:id, values:values, _ajax_nonce:nonce}, function(response) { //alert(response); /* refresh the list */ - jQuery.post( ajaxurl , { action:"cfc_refresh_list"+value, meta:value, id:id}, function(response) { + jQuery.post( ajaxurl , { action:"wck_refresh_list"+value, meta:value, id:id}, function(response) { jQuery('#container_'+value).replaceWith(response); @@ -67,18 +67,18 @@ function removeMeta(value, id, element_id, nonce){ if( response == true ){ jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('
'); - jQuery.post( ajaxurl , { action:"cfc_remove_meta"+value, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) { + jQuery.post( ajaxurl , { action:"wck_remove_meta"+value, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) { /* If single add the form */ if( jQuery( '#container_'+value ).hasClass('single') ){ - jQuery.post( ajaxurl , { action:"cfc_add_form"+value, meta:value, id:id }, function(response) { + jQuery.post( ajaxurl , { action:"wck_add_form"+value, meta:value, id:id }, function(response) { jQuery( '#container_'+value ).before( response ); jQuery( '#'+value ).addClass('single'); }); } /* refresh the list */ - jQuery.post( ajaxurl , { action:"cfc_refresh_list"+value, meta:value, id:id}, function(response) { + jQuery.post( ajaxurl , { action:"wck_refresh_list"+value, meta:value, id:id}, function(response) { jQuery('#container_'+value).replaceWith(response); jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); @@ -123,8 +123,8 @@ function mb_sortable_elements() { jQuery('#'+value).parent().css({'opacity':'0.4', 'position':'relative'}).append('
'); - jQuery.post( ajaxurl , { action:"cfc_reorder_meta"+value, meta:value, id:id, values:values}, function(response) { - jQuery.post( ajaxurl , { action:"cfc_refresh_list"+value, meta:value, id:id}, function(response) { + jQuery.post( ajaxurl , { action:"wck_reorder_meta"+value, meta:value, id:id, values:values}, function(response) { + jQuery.post( ajaxurl , { action:"wck_refresh_list"+value, meta:value, id:id}, function(response) { jQuery('#container_'+value).replaceWith(response); jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); @@ -149,7 +149,7 @@ function showUpdateFormMeta(value, id, element_id, nonce){ jQuery( '#container_' + value + " tbody" ).sortable("disable"); - jQuery.post( ajaxurl , { action:"cfc_show_update"+value, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) { + jQuery.post( ajaxurl , { action:"wck_show_update"+value, meta:value, id:id, element_id:element_id, _ajax_nonce:nonce}, function(response) { //jQuery('#container_'+value+' #element_'+element_id).append(response); jQuery(response).insertAfter('#container_'+value+' #element_'+element_id); jQuery('#'+value).parent().css('opacity','1'); @@ -182,10 +182,10 @@ function updateMeta(value, id, element_id, nonce){ }); - jQuery.post( ajaxurl , { action:"cfc_update_meta"+value, meta:value, id:id, element_id:element_id, values:values, _ajax_nonce:nonce}, function(response) { + jQuery.post( ajaxurl , { action:"wck_update_meta"+value, meta:value, id:id, element_id:element_id, values:values, _ajax_nonce:nonce}, function(response) { jQuery('#update_container_'+value+'_'+element_id).remove(); /* refresh the list */ - jQuery.post( ajaxurl , { action:"cfc_refresh_list"+value, meta:value, id:id}, function(response) { + jQuery.post( ajaxurl , { action:"wck_refresh_list"+value, meta:value, id:id}, function(response) { jQuery('#container_'+value).replaceWith(response); jQuery('.mb-table-container tbody td').css('width', function(){ return jQuery(this).width() }); @@ -199,8 +199,8 @@ function updateMeta(value, id, element_id, nonce){ } /* function syncs the translation */ -function cfcSyncTranslation(id){ - jQuery.post( ajaxurl , { action:"cfc_sync_translation", id:id}, function(response) { +function wckSyncTranslation(id){ + jQuery.post( ajaxurl , { action:"wck_sync_translation", id:id}, function(response) { if( response == 'syncsuccess' ) window.location.reload(); }); diff --git a/custom-fields-creator.php b/wordpress-creation-kit.php similarity index 69% rename from custom-fields-creator.php rename to wordpress-creation-kit.php index 8f28e21..0fc52f6 100644 --- a/custom-fields-creator.php +++ b/wordpress-creation-kit.php @@ -35,7 +35,7 @@ 'meta_array' => $fint ); -new Custom_Fields_Creator( $args ); +new Wordpress_Creation_Kit( $args ); On the frontend: @@ -44,7 +44,7 @@ */ -class Custom_Fields_Creator{ +class Wordpress_Creation_Kit{ private $defaults = array( 'metabox_id' => '', @@ -61,65 +61,77 @@ class Custom_Fields_Creator{ /* Constructor method for the class. */ - function __construct( $args ) { + function __construct( $args ) { + + /* Global that will hold all the arguments for all the custom boxes */ + global $wck_objects; /* Merge the input arguments and the defaults. */ $this->args = wp_parse_args( $args, $this->defaults ); + /* Add the settings for this box to the global object */ + $wck_objects[$this->args['metabox_id']] = $this->args; + /*print scripts*/ - add_action('admin_enqueue_scripts', array( &$this, 'cfc_print_scripts' )); + add_action('admin_enqueue_scripts', array( &$this, 'wck_print_scripts' )); /*print styles */ - add_action('admin_print_styles', array( &$this, 'cfc_print_css' )); + add_action('admin_print_styles', array( &$this, 'wck_print_css' )); // Set up the AJAX hooks - add_action("wp_ajax_cfc_add_meta".$this->args['meta_name'], array( &$this, 'cfc_add_meta') ); - add_action("wp_ajax_cfc_update_meta".$this->args['meta_name'], array( &$this, 'cfc_update_meta') ); - add_action("wp_ajax_cfc_show_update".$this->args['meta_name'], array( &$this, 'cfc_show_update_form') ); - add_action("wp_ajax_cfc_refresh_list".$this->args['meta_name'], array( &$this, 'cfc_refresh_list') ); - add_action("wp_ajax_cfc_add_form".$this->args['meta_name'], array( &$this, 'cfc_add_form') ); - add_action("wp_ajax_cfc_remove_meta".$this->args['meta_name'], array( &$this, 'cfc_remove_meta') ); + add_action("wp_ajax_wck_add_meta".$this->args['meta_name'], array( &$this, 'wck_add_meta') ); + add_action("wp_ajax_wck_update_meta".$this->args['meta_name'], array( &$this, 'wck_update_meta') ); + add_action("wp_ajax_wck_show_update".$this->args['meta_name'], array( &$this, 'wck_show_update_form') ); + add_action("wp_ajax_wck_refresh_list".$this->args['meta_name'], array( &$this, 'wck_refresh_list') ); + add_action("wp_ajax_wck_add_form".$this->args['meta_name'], array( &$this, 'wck_add_form') ); + add_action("wp_ajax_wck_remove_meta".$this->args['meta_name'], array( &$this, 'wck_remove_meta') ); //add_action("wp_ajax_swap_meta_mb", array( & $this, 'mb_swap_meta') ); - add_action("wp_ajax_cfc_reorder_meta".$this->args['meta_name'], array( &$this, 'cfc_reorder_meta') ); + add_action("wp_ajax_wck_reorder_meta".$this->args['meta_name'], array( &$this, 'wck_reorder_meta') ); /* modify Insert into post button */ - add_action('admin_head-media-upload-popup', array( &$this, 'cfc_media_upload_popup_head') ); + add_action('admin_head-media-upload-popup', array( &$this, 'wck_media_upload_popup_head') ); /* custom functionality for upload video */ - add_filter('media_send_to_editor', array( &$this, 'cfc_media_send_to_editor' ), 15, 2 ); + add_filter('media_send_to_editor', array( &$this, 'wck_media_send_to_editor' ), 15, 2 ); - add_action('add_meta_boxes', array( &$this, 'cfc_add_metabox') ); + add_action('add_meta_boxes', array( &$this, 'wck_add_metabox') ); + + /* hook to add a side metabox with the Syncronize translation button */ + add_action('add_meta_boxes', array( &$this, 'wck_add_sync_translation_metabox' ) ); + + /* ajax hook the syncronization function */ + add_action("wp_ajax_wck_sync_translation", array( &$this, 'wck_sync_translation_ajax' ) ); } //add metabox using wordpress api - function cfc_add_metabox() { + function wck_add_metabox() { if( $this->args['post_id'] == '' && $this->args['page_template'] == '' ) - add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'cfc_content' ), $this->args['post_type'], 'normal', 'low', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) ); + 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']) ); else{ $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; if( $this->args['post_id'] != '' && $this->args['page_template'] != '' ){ $template_file = get_post_meta($post_id,'_wp_page_template',TRUE); if( $this->args['post_id'] == $post_id && $template_file == $this->args['page_template'] ) - add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'cfc_content' ), 'page', 'normal', 'low', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array'] ) ); + 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'] ) ); } else{ if( $this->args['post_id'] != '' ){ if( $this->args['post_id'] == $post_id ){ $post_type = get_post_type( $post_id ); - add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'cfc_content' ), $post_type, 'normal', 'low', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array'] ) ); + 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'] ) ); } } if( $this->args['page_template'] != '' ){ $template_file = get_post_meta($post_id,'_wp_page_template',TRUE); if ( $template_file == $this->args['page_template'] ) - add_meta_box($this->args['metabox_id'], $this->args['metabox_title'], array( &$this, 'cfc_content' ), 'page', 'normal', 'low', array( 'meta_name' => $this->args['meta_name'], 'meta_array' => $this->args['meta_array']) ); + 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']) ); } } @@ -128,7 +140,7 @@ function cfc_add_metabox() { } - function cfc_content($post, $metabox){ + function wck_content($post, $metabox){ //output the add form if( $this->args['single'] ){ $meta_val = get_post_meta( $post->ID, $metabox['args']['meta_name'], true ); @@ -138,7 +150,7 @@ function cfc_content($post, $metabox){ else self::create_add_form($metabox['args']['meta_array'], $metabox['args']['meta_name'], $post); //output the entries - echo self::cfc_output_meta_content($metabox['args']['meta_name'], $post->ID, $metabox['args']['meta_array']); + echo self::wck_output_meta_content($metabox['args']['meta_name'], $post->ID, $metabox['args']['meta_array']); } /** @@ -153,7 +165,7 @@ function cfc_content($post, $metabox){ * @return string $element input element html string. */ - function cfc_output_form_field( $meta, $details, $value = '', $context = '' ){ + function wck_output_form_field( $meta, $details, $value = '', $context = '' ){ $element = ''; if( $context == 'edit_form' ){ @@ -245,7 +257,7 @@ function cfc_output_form_field( $meta, $details, $value = '', $context = '' ){ * @param object $post Post object */ function create_add_form($fields, $meta, $post){ - $nonce = wp_create_nonce( 'cfc-add-meta' ); + $nonce = wp_create_nonce( 'wck-add-meta' ); ?>
args['single'] ) echo 'class="single"' ?>>