Skip to content

Instantly share code, notes, and snippets.

@graylaurenm
Last active January 8, 2017 17:01
Show Gist options
  • Save graylaurenm/fbd38eddb5fbf879535c5efb9ed17f59 to your computer and use it in GitHub Desktop.
Save graylaurenm/fbd38eddb5fbf879535c5efb9ed17f59 to your computer and use it in GitHub Desktop.
MPP to WPRM "Servings" Fix
<?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