• Resolved clams4shoes

    (@clams4shoes)


    When saving a recipe with the post type set to public, and the WPML plugin enabled, the REST API returns a HTTP status code of 500.

    Error log (with paths shortened)

    Stack trace:
    #0 /web/app/plugins/wpml-multilingual-cms/sitepress.class.php(1493): Rareloop\Lumberjack\Bootstrappers\RegisterExceptionHandler->handleError(2, 'Undefined array...', '/shared/httpd/t...', 1493)
    #1 /web/wp/wp-includes/class-wp-hook.php(324): SitePress->set_element_language_details_action(Array)
    #2 /web/wp/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
    #3 /web/wp/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
    #4 /web/app/plugins/wp-recipe-maker/includes/public/class-wprm-compatibility.php(534): do_action('wpml_set_elemen...', Array)
    #5 /web/app/plugins/wp-recipe-maker/includes/public/class-wprm-recipe-saver.php(235): WPRM_Compatibility::set_language_for(17510, 'en')
    #6 /web/app/plugins/wp-recipe-maker/includes/public/api/class-wprm-api-recipe.php(98): WPRM_Recipe_Saver::update_recipe(17510, Array, true)
    #7 /web/wp/wp-includes/class-wp-hook.php(324): WPRM_Api_Recipe::api_insert_update_recipe(Object(WP_Post), Object(WP_REST_Request), true)
    #8 /web/wp/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
    #9 /web/wp/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
    #10 /web/wp/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(708): do_action('rest_insert_wpr...', Object(WP_Post), Object(WP_REST_Request), true)
    #11 /web/wp/wp-includes/rest-api/class-wp-rest-server.php(1230): WP_REST_Posts_Controller->create_item(Object(WP_REST_Request))
    #12 /web/wp/wp-includes/rest-api/class-wp-rest-server.php(1063): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wp/v2/wprm_rec...', Array, NULL)
    #13 /web/wp/wp-includes/rest-api/class-wp-rest-server.php(439): WP_REST_Server->dispatch(Object(WP_REST_Request))
    #14 /web/wp/wp-includes/rest-api.php(428): WP_REST_Server->serve_request('/wp/v2/wprm_rec...')
    #15 /web/wp/wp-includes/class-wp-hook.php(324): rest_api_loaded(Object(WP))
    #16 /web/wp/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
    #17 /web/wp/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
    #18 /web/wp/wp-includes/class-wp.php(418): do_action_ref_array('parse_request', Array)
    #19 /web/wp/wp-includes/class-wp.php(813): WP->parse_request('')
    #20 /web/wp/wp-includes/functions.php(1336): WP->main('')
    #21 /web/wp/wp-blog-header.php(16): wp()
    #22 /web/index.php(6): require('/shared/httpd/t...')
    #23 {main}

    It looks like on line 534 of class-wprm-compatibility.php you’re calling the wpml_set_element_language_details action and failing to set the trid(translation group id) in the second argument array — which is required.

    https://wpml.org/wpml-hook/wpml_set_element_language_details/

    if ( $multilingual ) {
    // WPML.
    if ( 'wpml' === $multilingual['plugin'] ) {
    do_action( 'wpml_set_element_language_details', array(
    'element_id' => $recipe_id,
    'element_type' => 'post_' . WPRM_POST_TYPE,
    'language_code' => $language ? $language : null,
    ) );
    }
    }

    Should probably look something like

    if ( $multilingual ) {
    // WPML.
    if ( 'wpml' === $multilingual['plugin'] ) {
    $post_type = 'post_' . WPRM_POST_TYPE;
    $translation_group_id = apply_filters( 'wpml_element_trid', NULL, $recipe_id, $post_type );

    do_action( 'wpml_set_element_language_details', array(
    'element_id' => $recipe_id,
    'trid' => $translation_group_id ?: false,
    'element_type' => $post_type,
    'language_code' => $language ? $language : null,
    ) );
    }
    }

    This seems to fix the issue. Though there might be some side effects I’m not aware of.

    Also a bit of a tangent, but the short form the short form ternary operator has been available since PHP 5.3. So it’s probably safe to write $language ? $language : null as $language ?: null.

    Any help you could offer would be greatly appreciated.

    Thanks,

    Andrew

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Brecht

    (@brechtvds)

    Hi Andrew,

    Thanks a lot for letting me know and even giving me the solution. It does just seem to be that “trid” argument missing, which your change solves. I’ll include this in the next update!

    I personally find the shortform less readable, which is why I stick to what I’m used to. But fair point!

    Thanks,
    Brecht

    Thread Starter clams4shoes

    (@clams4shoes)

    Hi Brecht,

    Thanks, I appreciate all the help and quick response! Look forward to the update.

    No worries, didn’t mean to nitpick. It is definitely easier to read, just thought the short form was a little cleaner and more DRY.

    Sorry to add another question, but is there any way to associate different language recipes with each other through the dashboard, so that they’re all in the same translation group? That way when someone switches languages on a recipe page the associated translated recipe is loaded.

    Thanks,

    Andrew

    Plugin Author Brecht

    (@brechtvds)

    There is not at the moment, I’m afraid.

    I generally recommend adding recipes as part of a regular post (or custom post type), as that gives you a lot more compatibility with other plugins, like WPML for example.

    Plugin Author Brecht

    (@brechtvds)

    Hi again,

    I wanted to let you know we just released WP Recipe Maker 9.6.0 which includes this fix.

    You can learn more about the update here: https://bootstrapped.ventures/wp-recipe-maker-9-6-0/

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.