Permalink
Browse files

fk-box-cast.php

* Added: In fk_save_post_cast(), $characters is set to an empty array if it's not an array already so array_diff etc. in fk_cast_edit() don't choke
fk-lib-cast.php
* Changed: Renemed $defaults to $old in fk_cast_edit()
  • Loading branch information...
1 parent 1b6b558 commit 2397e7360aa0b618925f4ab4cd9685ff1af459a0 @gabebw committed Jul 4, 2009
Showing with 10 additions and 6 deletions.
  1. +4 −0 fk-box-cast.php
  2. +6 −6 fk-lib-cast.php
View
4 fk-box-cast.php
@@ -70,6 +70,10 @@ function fk_box_cb_link_cast_to_character(){
function fk_save_post_cast($post_id){
check_admin_referer('fk_set_character_name', 'fk_set_character_name_nonce');
$characters = $_POST['fk_characters']; // array(32, 9, 10)
+ if( ! is_array($characters) ){
+ // Prevent array_diff etc. from choking in fk_cast_edit()
+ $characters = array();
+ }
if( fk_cast_exists($post_id) ){
fk_cast_edit($post_id, $characters);
} else {
View
12 fk-lib-cast.php
@@ -39,27 +39,27 @@ function fk_cast_add($cast_id, $characters=array()){
*/
function fk_cast_edit($cast_id, $characters){
global $wpdb, $fk_settings;
- $defaults = array(
+ $old = array(
'name' => get_the_title($cast_id),
'characters' => fk_cast_get_characters_for($cast_id)
);
$new = array(
'name' => $_POST['post_title'],
'characters' => $characters);
- $merged = wp_parse_args($new, $defaults);
+ $merged = wp_parse_args($new, $old);
foreach( $merged as $field => $value ){
- if( $defaults[$field] === $value ){
+ if( $old[$field] === $value ){
// Don't do anything if value hasn't changed.
continue;
}
switch($field){
case 'characters':
- // Delete characters that are only in $defaults
- $to_delete = array_diff($defaults['characters'], $value);
+ // Delete characters that are only in $old
+ $to_delete = array_diff($old['characters'], $value);
$to_delete = implode(',', $to_delete);
// Add characters that are only in $value
- $to_add = array_diff($value, $defaults['characters']);
+ $to_add = array_diff($value, $old['characters']);
$to_add = implode(',', $to_add);
// add
$wpdb->query($wpdb->prepare("UPDATE $fk_settings->cast2character_table SET cast_id = %d WHERE cast_id = $cast_id AND character_id IN %s",

0 comments on commit 2397e73

Please sign in to comment.