Changeset 774084
- Timestamp:
- 09/17/2013 03:20:36 PM (12 years ago)
- Location:
- fifo-testimonials/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
testimonial.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fifo-testimonials/trunk/readme.txt
r760547 r774084 4 4 License: GPLv2 or later 5 5 Requires at least: 3.0 6 Tested up to: 3.6 6 Tested up to: 3.6.1 7 7 Stable tag: trunk 8 8 … … 60 60 == Changelog == 61 61 62 = V1.0.1 - 17.09.2013 = 63 * Fixed the metabox saving problem. 64 62 65 = V1.0.0 - 21.06.2013 = 63 66 * First Release -
fifo-testimonials/trunk/testimonial.php
r729921 r774084 4 4 Plugin URI: http://www.fifolab.com.bd/plugins/fifo-testimonials/ 5 5 Description: FIFO Testimonials is an easy to use Testimonial Manager that allows you to easily gather and display testimonials on your WordPress site via shortcode. 6 Version: 1.0. 06 Version: 1.0.1 7 7 Author: Monzurul Haque 8 8 Author URI: http://www.fifolab.com.bd/ … … 83 83 ?> 84 84 85 85 <div class="postbox"> 86 86 <form action="edit.php?post_type=testimonial&page=<?php echo $fifolab_slugs['settings']; ?>&save=1" method="post"> 87 <div class="postbox">87 88 88 <h3><label>Testimonial settings</label></h3> 89 89 … … 305 305 306 306 307 // Add the Testimonial Username Meta Boxes 308 309 add_action( 'add_meta_boxes', 'fifolab_add_testimonials_username_metaboxes' ); 310 311 312 function fifolab_add_testimonials_username_metaboxes() { 313 add_meta_box('fifolab_testimonial_username', 'Testimonial Item Username', 'fifolab_testimonial_username', 'testimonial', 'normal', 'default'); 314 } 315 316 317 // The Testimonial Metabox 318 319 function fifolab_testimonial_username() { 320 global $post; 321 322 // Noncename needed to verify where the data originated 323 echo '<input type="hidden" name="testimonialusernamemeta_noncename" id="testimonialusernamemeta_noncename" value="' . 324 wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; 325 326 // Get the location data if its already been entered 327 $testimonial_username = get_post_meta($post->ID, '_testimonial_username', true); 328 329 // Echo out the field 330 echo '<input type="text" name="_testimonial_username" value="' . $testimonial_username . '" class="widefat" />'; 331 332 } 333 334 335 // Save the Metabox Data 336 337 function fifolab_save_testimonial_username_meta($post_id, $post) { 338 339 340 341 // verify this came from the our screen and with proper authorization, 342 // because save_post can be triggered at other times 343 if ( !wp_verify_nonce( isset($_POST['testimonialusernamemeta_noncename']), basename(__FILE__) )) { 344 return $post_id; 345 } 346 347 // Is the user allowed to edit the post or page? 348 if ( !current_user_can( 'edit_post', $post->ID )) 349 return $post_id; 350 351 // OK, we're authenticated: we need to find and save the data 352 // We'll put it into an array to make it easier to loop though. 353 354 $testimonial_meta['_testimonial_username'] = $_POST['_testimonial_username']; 355 356 // Add values of $events_meta as custom fields 357 358 foreach ($testimonial_meta as $key => $value) { // Cycle through the $events_meta array! 359 if( $post->post_type == 'revision' ) return; // Don't store custom data twice 360 $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely) 361 if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value 362 update_post_meta($post->ID, $key, $value); 363 } else { // If the custom field doesn't have a value 364 add_post_meta($post->ID, $key, $value); 365 } 366 if(!$value) delete_post_meta($post->ID, $key); // Delete if blank 367 } 368 369 } 370 371 add_action('save_post', 'fifolab_save_testimonial_username_meta', 1, 2); // save the custom fields 372 373 374 375 // Add the Testimonial Company Name Meta Boxes 376 377 add_action( 'add_meta_boxes', 'fifolab_add_testimonials_companyname_metaboxes' ); 378 379 380 function fifolab_add_testimonials_companyname_metaboxes() { 381 add_meta_box('fifolab_testimonial_companyname', 'Testimonial Item Company Name', 'fifolab_testimonial_companyname', 'testimonial', 'normal', 'default'); 382 } 383 384 385 // The Testimonial Metabox 386 387 function fifolab_testimonial_companyname() { 388 global $post; 389 390 // Noncename needed to verify where the data originated 391 echo '<input type="hidden" name="testimonialcompanynamemeta_noncename" id="testimonialcompanynamemeta_noncename" value="' . 392 wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; 393 394 // Get the location data if its already been entered 395 $testimonial_companyname = get_post_meta($post->ID, '_testimonial_companyname', true); 396 397 // Echo out the field 398 echo '<input type="text" name="_testimonial_companyname" value="' . $testimonial_companyname . '" class="widefat" />'; 399 400 } 401 402 403 // Save the Metabox Data 404 405 function fifolab_save_testimonial_companyname_meta($post_id, $post) { 406 407 408 409 // verify this came from the our screen and with proper authorization, 410 // because save_post can be triggered at other times 411 if ( !wp_verify_nonce( isset($_POST['testimonialcompanynamemeta_noncename']), basename(__FILE__) )) { 412 return $post_id; 413 } 414 415 // Is the user allowed to edit the post or page? 416 if ( !current_user_can( 'edit_post', $post->ID )) 417 return $post_id; 418 419 // OK, we're authenticated: we need to find and save the data 420 // We'll put it into an array to make it easier to loop though. 421 422 $testimonial_meta['_testimonial_companyname'] = $_POST['_testimonial_companyname']; 423 424 // Add values of $events_meta as custom fields 425 426 foreach ($testimonial_meta as $key => $value) { // Cycle through the $events_meta array! 427 if( $post->post_type == 'revision' ) return; // Don't store custom data twice 428 $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely) 429 if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value 430 update_post_meta($post->ID, $key, $value); 431 } else { // If the custom field doesn't have a value 432 add_post_meta($post->ID, $key, $value); 433 } 434 if(!$value) delete_post_meta($post->ID, $key); // Delete if blank 435 } 436 437 } 438 439 add_action('save_post', 'fifolab_save_testimonial_companyname_meta', 1, 2); // save the custom fields 440 441 442 443 444 445 446 // Add the Testimonial URL Meta Boxes 447 448 add_action( 'add_meta_boxes', 'fifolab_add_testimonials_url_metaboxes' ); 449 450 451 function fifolab_add_testimonials_url_metaboxes() { 452 add_meta_box('fifolab_testimonial_url', 'Testimonial Item URL', 'fifolab_testimonial_url', 'testimonial', 'normal', 'default'); 453 } 454 455 456 // The Testimonial Metabox 457 458 function fifolab_testimonial_url() { 459 global $post; 460 461 // Noncename needed to verify where the data originated 462 echo '<input type="hidden" name="testimonialurlmeta_noncename" id="testimonialurlmeta_noncename" value="' . 463 wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; 464 465 // Get the location data if its already been entered 466 $testimonial_url = get_post_meta($post->ID, '_testimonial_url', true); 467 468 // Echo out the field 469 echo '<input type="text" name="_testimonial_url" value="' . $testimonial_url . '" class="widefat" />'; 470 471 } 472 473 474 // Save the Metabox Data 475 476 function fifolab_save_testimonial_url_meta($post_id, $post) { 477 478 479 480 // verify this came from the our screen and with proper authorization, 481 // because save_post can be triggered at other times 482 if ( !wp_verify_nonce( isset($_POST['testimonialurlmeta_noncename']), basename(__FILE__) )) { 483 return $post_id; 484 } 485 486 // Is the user allowed to edit the post or page? 487 if ( !current_user_can( 'edit_post', $post->ID )) 488 return $post_id; 489 490 // OK, we're authenticated: we need to find and save the data 491 // We'll put it into an array to make it easier to loop though. 492 493 $testimonial_meta['_testimonial_url'] = $_POST['_testimonial_url']; 494 495 // Add values of $events_meta as custom fields 496 497 foreach ($testimonial_meta as $key => $value) { // Cycle through the $events_meta array! 498 if( $post->post_type == 'revision' ) return; // Don't store custom data twice 499 $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely) 500 if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value 501 update_post_meta($post->ID, $key, $value); 502 } else { // If the custom field doesn't have a value 503 add_post_meta($post->ID, $key, $value); 504 } 505 if(!$value) delete_post_meta($post->ID, $key); // Delete if blank 506 } 507 508 } 509 510 add_action('save_post', 'fifolab_save_testimonial_url_meta', 1, 2); // save the custom fields 511 307 // Custom meta boxes 308 309 $prefix = 'fifolab_'; 310 311 $meta_box = array( 312 'id' => 'fifolab', 313 'title' => 'Clients Information', 314 'page' => 'testimonial', 315 'context' => 'normal', 316 'priority' => 'high', 317 'fields' => array( 318 319 array( 320 'name' => 'Client Name', 321 'desc' => '', 322 'id' => '_testimonial_username', 323 'type' => 'text', 324 'std' => '' 325 ), 326 327 array( 328 'name' => 'Client Gender', 329 'desc' => '', 330 'id' => '_gender_type', 331 'type' => 'radio', 332 'options' => array( 333 array('name' => 'Male', 'value' => 'male'), 334 array('name' => 'Female', 'value' => 'female') 335 ), 336 'std' => '' 337 ), 338 339 array( 340 'name' => 'Company Name', 341 'desc' => '', 342 'id' => '_testimonial_companyname', 343 'type' => 'text', 344 'std' => '' 345 ), 346 347 array( 348 'name' => 'Company URL', 349 'desc' => '', 350 'id' => '_testimonial_url', 351 'type' => 'text', 352 'std' => '' 353 ), 354 355 356 ), 357 358 ); 359 360 add_action('admin_menu', 'fifolab_add_box'); 361 362 // Add meta box 363 function fifolab_add_box() { 364 global $meta_box; 365 366 add_meta_box($meta_box['id'], $meta_box['title'], 'fifolab_show_box', $meta_box['page'], $meta_box['context'], $meta_box['priority']); 367 } 368 369 // Callback function to show fields in meta box 370 function fifolab_show_box() { 371 global $meta_box, $post; 372 373 // Use nonce for verification 374 echo '<input type="hidden" name="fifolab_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />'; 375 376 echo '<table>'; 377 378 foreach ($meta_box['fields'] as $field) { 379 // get current post meta data 380 $meta = get_post_meta($post->ID, $field['id'], true); 381 382 echo '<tr>', 383 '<th style="width:20%"><label for="', $field['id'], '">', $field['name'], '</label></th>', 384 '<td>'; 385 switch ($field['type']) { 386 case 'text': 387 echo '<input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width: 97%; height: 32px; margin-bottom: 10px;" />', 388 '<br />', $field['desc']; 389 break; 390 case 'textarea': 391 echo '<textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%">', $meta ? $meta : $field['std'], '</textarea>', 392 '<br />', $field['desc']; 393 394 break; 395 case 'select': 396 echo '<select name="', $field['id'], '" id="', $field['id'], '">'; 397 foreach ($field['options'] as $option) { 398 echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>'; 399 } 400 echo '</select>', 401 '<br />', $field['desc']; 402 break; 403 case 'radio': 404 foreach ($field['options'] as $option) { 405 echo '<input style="margin-bottom: 10px;" type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' /><span style="margin:0 15px 0 5px;">', $option['name'],'</span>'; 406 } 407 break; 408 case 'checkbox': 409 echo '<input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' />'; 410 break; 411 } 412 echo '<td>', 413 '</tr>'; 414 } 415 416 echo '</table>'; 417 } 418 419 add_action('save_post', 'fifolab_save_data'); 420 421 // Save data from meta box 422 function fifolab_save_data($post_id) { 423 global $meta_box; 424 425 // verify nonce 426 if (!wp_verify_nonce($_POST['fifolab_meta_box_nonce'], basename(__FILE__))) { 427 return $post_id; 428 } 429 430 // check autosave 431 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { 432 return $post_id; 433 } 434 435 // check permissions 436 if ('page' == $_POST['post_type']) { 437 if (!current_user_can('edit_page', $post_id)) { 438 return $post_id; 439 } 440 } elseif (!current_user_can('edit_post', $post_id)) { 441 return $post_id; 442 } 443 444 foreach ($meta_box['fields'] as $field) { 445 $old = get_post_meta($post_id, $field['id'], true); 446 $new = $_POST[$field['id']]; 447 448 if ($new && $new != $old) { 449 update_post_meta($post_id, $field['id'], $new); 450 } elseif ('' == $new && $old) { 451 delete_post_meta($post_id, $field['id'], $old); 452 } 453 } 454 } 512 455 513 456 514 457 add_action('init', 'fifolab_testimonial_post_type'); 515 458 add_filter('post_updated_messages', 'fifolab_testimonial_messages'); 516 517 518 function fifolab_add_testimonials_gender_metaboxes() {519 add_meta_box('fifolab_gender_type_metabox', __('Client Gender Type'), 'fifolab_gender_type_metabox', 'testimonial', 'side', 'low');520 }521 522 // Add meta box goes into our admin_init function523 //add_meta_box( 'fifolab_gender_type_metabox', __('Gender Type'), 'fifolab_gender_type_metabox', 'testimonial', 'normal', 'low');524 525 function fifolab_gender_type_metabox($post) {526 $gender_type = get_post_meta($post->ID, '_gender_type', TRUE);527 if (!$gender_type) $gender_type = 'male';528 ?>529 <input type="hidden" name="gender_type_noncename" id="gender_type_noncename" value="<?php echo wp_create_nonce( 'gender_type'.$post->ID );?>" />530 <input type="radio" name="_gender_type" value="male" <?php if ($gender_type == 'male') echo "checked=1";?>> Male<br/>531 <input type="radio" name="_gender_type" value="female" <?php if ($gender_type == 'female') echo "checked=1";?>> Female<br/>532 533 <?php534 }535 536 // Save the Metabox Data537 538 function fifolab_save_testimonial_gender_meta($post_id, $post) {539 540 541 542 // verify this came from the our screen and with proper authorization,543 // because save_post can be triggered at other times544 if ( !wp_verify_nonce( isset($_POST['gender_type_noncename']), basename(__FILE__) )) {545 return $post_id;546 }547 548 // Is the user allowed to edit the post or page?549 if ( !current_user_can( 'edit_post', $post->ID ))550 return $post_id;551 552 // OK, we're authenticated: we need to find and save the data553 // We'll put it into an array to make it easier to loop though.554 555 $gender_type['_gender_type'] = $_POST['_gender_type'];556 557 // Add values of $events_meta as custom fields558 559 foreach ($gender_type as $key => $value) { // Cycle through the $events_meta array!560 if( $post->post_type == 'revision' ) return; // Don't store custom data twice561 $value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)562 if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value563 update_post_meta($post->ID, $key, $value);564 } else { // If the custom field doesn't have a value565 add_post_meta($post->ID, $key, $value);566 }567 if(!$value) delete_post_meta($post->ID, $key); // Delete if blank568 }569 570 }571 572 add_action('save_post', 'fifolab_save_testimonial_gender_meta', 1, 2); // save the custom fields573 574 575 576 add_action( 'add_meta_boxes', 'fifolab_add_testimonials_gender_metaboxes' );577 459 578 460 … … 622 504 echo'</q><div class="arrow-down"></div><div class="fix">'; 623 505 $gender = get_post_meta($post->ID, "_gender_type", true); 506 if (!$gender) $gender = 'male'; 624 507 echo'<span class="company-name '; 625 508 if($gender == 'female') {echo "female";} else echo "male";
Note: See TracChangeset
for help on using the changeset viewer.