Skip to content
This repository has been archived by the owner. It is now read-only.

Fix filter for saving Person post title/name #14

Merged
merged 1 commit into from
Jan 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions uc-people.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function uc_people_new_group_order_field(){
<label for="term_meta[group_order]">Order</label>
<input name="term_meta[group_order]" id="term_meta[group_order]" type="number" value="0">
<p class="description">Enter a value for this field or leave it blank</p>
</div>
</div>
<?php
}
add_action( 'group_add_form_fields', 'uc_people_new_group_order_field', 10, 2 );
Expand All @@ -102,7 +102,7 @@ function uc_people_edit_group_order_field( $term ){
<input type="number" name="term_meta[group_order]" id="term_meta[group_order]" value="<?php echo esc_attr( $order ) ? esc_attr( $order ) : 0; ?>">
<p class="description">Enter a value for this field or leave it blank</p>
</td>
</tr>
</tr>
<?php
}
add_action( 'group_edit_form_fields', 'uc_people_edit_group_order_field', 10, 2 );
Expand All @@ -120,43 +120,53 @@ function uc_people_save_group_custom_meta( $term_id ) {
// Save the option array.
update_option( "taxonomy_{$term_id}", $term_meta );
}
}
add_action( 'edited_group', 'uc_people_save_group_custom_meta', 10, 2 );
}
add_action( 'edited_group', 'uc_people_save_group_custom_meta', 10, 2 );
add_action( 'create_group', 'uc_people_save_group_custom_meta', 10, 2 );

add_filter('title_save_pre', 'save_title');
function save_title($my_post_title) {
if ($_POST['post_type'] == 'person') :
$new_title = $_POST['acf']['field_first_name'].' '.$_POST['acf']['field_last_name'];
$my_post_title = $new_title;
endif;
return $my_post_title;
if ($_POST['post_type'] == 'person') :
if( isset($_POST['acf']) ){ // Set when creating new post, not set when using quick edit
$new_title = $_POST['acf']['field_first_name'].' '.$_POST['acf']['field_last_name'];
} else {
$new_title = get_field( 'field_first_name', $_POST['ID'] ).' '.get_field( 'field_last_name', $_POST['ID'] );
}
$my_post_title = $new_title;
endif;
return $my_post_title;
}

add_filter('name_save_pre', 'save_name');
function save_name($my_post_name) {
if ($_POST['post_type'] == 'post_type_name') :
$new_name = strtolower($_POST['acf']['field_first_name'].' '.$_POST['acf']['field_last_name']);
$my_post_name = $new_name;
endif;
return $my_post_name;
if ($_POST['post_type'] == 'person') :
if( isset($_POST['acf']) ){
$new_name = strtolower($_POST['acf']['field_first_name'].' '.$_POST['acf']['field_last_name']);
} else {
$new_name = strtolower(get_field( 'field_first_name', $_POST['ID'] ).' '.get_field( 'field_last_name', $_POST['ID'] ));
$new_name = wp_unique_post_slug( $new_name, $_POST['ID'], $_POST['post_status'], 'person', $_POST['post_parent'] );
}
$my_post_name = $new_name;
endif;
return $my_post_name;
}

if(!function_exists('processCSV')){
function processCSV($file){
$data = array();

$fh = fopen($file, 'r');
if( $fh == false ){
return;
}
$header = fgetcsv($fh);

while( $line = fgetcsv($fh) ) {
$data[] = array_combine($header, $line);
}

fclose($fh);

return $data;
}
}
Expand All @@ -168,13 +178,13 @@ function importFile( $filename ){
if ( ! function_exists( 'wp_handle_upload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
}

$filePathInfo = pathinfo( $_FILES[$filename]['name'] );
if( $filePathInfo['extension'] !== 'csv' ){
echo '<div class="error notice is-dismissible below-h2" id="message"><p>Please upload a CSV file</p><button class="notice-dismiss" type="button"><span class="screen-reader-text">Dismiss this notice.</span></button></div>';
return;
}

$uploadedFile = wp_handle_upload( $_FILES[$filename], array( 'test_form' => false ) );

if( $uploadedFile && !isset($uploadedFile['error']) ){
Expand Down