Created
February 13, 2018 19:29
-
-
Save Ikonize/cadad7fb3f5ffeea10a198e6f881ad29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This function updates users that are using 2.x versions to | |
* the 3.x versions. | |
* | |
* 1. The four project meta labels were removed and replaced with | |
* a single field that allows creating arbitrary labels. | |
* If user's post contains the old labels and the new custom field | |
* "daisho_project_meta" is empty, move the labels to this new field. | |
* This is run on every front-end and back-end post opening. | |
*/ | |
function daisho_update_30() { | |
global $post; | |
if ( !is_object( $post ) ) { | |
return; | |
} | |
$updates = array( | |
'flow_post_description' => 'daisho_description', | |
'flow_post_layout' => 'daisho_layout', | |
'page_portfolio_loop_through' => 'browse_projects_in_selected_category', | |
); | |
if ( get_post_meta( $post->ID, 'flow_post_layout', true ) === 'no-sidebar' ) { | |
delete_post_meta( $post->ID, 'flow_post_layout' ); | |
} | |
foreach ( $updates as $key => $value ) { | |
if ( !empty( get_post_meta( $post->ID, $key, true ) ) && empty( get_post_meta( $post->ID, $value, true ) ) ) { | |
update_post_meta( $post->ID, $value, get_post_meta( $post->ID, $key, true ) ); | |
delete_post_meta( $post->ID, $key ); | |
} | |
} | |
$client = get_post_meta( $post->ID, 'portfolio_client', true ); | |
$date = get_post_meta( $post->ID, 'portfolio_date', true ); | |
$agency = get_post_meta( $post->ID, 'portfolio_agency', true ); | |
$ourrole = get_post_meta( $post->ID, 'portfolio_ourrole', true ); | |
$meta = ''; | |
$daisho_project_meta = get_post_meta( $post->ID, 'daisho_project_meta', true ); | |
$daisho_thumbnail_footer_text = get_post_meta( $post->ID, 'daisho_thumbnail_footer_text', true ); | |
if ( !empty( $date ) ) { | |
$meta .= '[daisho-project-label label="Date"]' . $date . '[/daisho-project-label]' . "\n"; | |
} | |
if ( !empty( $client ) ) { | |
$meta .= '[daisho-project-label label="Client"]' . $client . '[/daisho-project-label]' . "\n"; | |
} | |
if ( !empty( $agency ) ) { | |
$meta .= '[daisho-project-label label="Agency"]' . $agency . '[/daisho-project-label]' . "\n"; | |
} | |
if ( !empty( $ourrole ) ) { | |
$meta .= '[daisho-project-label label="Our role" placement="right"]' . $ourrole . '[/daisho-project-label]'; | |
} | |
if ( empty( $daisho_project_meta ) && !empty( $meta ) ) { | |
update_post_meta( $post->ID, 'daisho_project_meta', $meta ); | |
} | |
if ( empty( $daisho_thumbnail_footer_text ) && !empty( $client ) ) { | |
update_post_meta( $post->ID, 'daisho_thumbnail_footer_text', $client ); | |
} | |
return; | |
} | |
add_action( 'pre_get_posts', 'daisho_update_30' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment