Last active
January 8, 2017 17:01
-
-
Save graylaurenm/fbd38eddb5fbf879535c5efb9ed17f59 to your computer and use it in GitHub Desktop.
MPP to WPRM "Servings" Fix
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 | |
$recipes = WPRM_Recipe_Manager::get_recipes(); | |
foreach ( $recipes as $recipe_id => $options ) { | |
$recipe = WPRM_Recipe_Manager::get_recipe( $recipe_id ); | |
if ( ! $recipe->servings() ) { | |
$import_source = get_post_meta( $recipe_id, 'wprm_import_source', true ); | |
if ( 'mealplannerpro' === $import_source || 'mealplannerpro-checked' === $import_source ) { | |
$import_backup = get_post_meta( $recipe_id, 'wprm_import_backup', true ); | |
$mpp_recipe_id = $import_backup['mpp_recipe_id']; | |
global $wpdb; | |
$mpp_recipe = $wpdb->get_row( 'SELECT * FROM ' . $wpdb->prefix . 'mpprecipe_recipes WHERE recipe_id=' . $mpp_recipe_id ); | |
// Get servings from mpp servings. | |
$match = preg_match( '/^\s*\d+/', $mpp_recipe->serving_size, $servings_array ); | |
if ( 1 === $match ) { | |
$servings = str_replace( ' ','', $servings_array[0] ); | |
} else { | |
$servings = ''; | |
} | |
$servings_unit = preg_replace( '/^\s*\d+\s*/', '', $mpp_recipe->serving_size ); | |
// Update WPRM recipe. | |
update_post_meta( $recipe_id, 'wprm_servings', $servings ); | |
update_post_meta( $recipe_id, 'wprm_servings_unit', $servings_unit ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment