• Using slug (id=”slug”) bugs due to application of:
    $id = apply_filters( ‘wpml_object_id’, $page->ID, ‘text-blocks’ );
    (text-blocks.php:266)

    Polylang implementation of icl_object_id is registered to the hook wpml_object_id, and the implementation always returns null, because the post type of text-blocks is not registered as translated post type, and the function doesn’t return the original ID if no translation is found.

    Proposed fixes:
    1) Remove the application of the filter (why is it only applied to slug retrieval, and not retrieval by ID anyway?)
    2) Add a filter to control the application of the filter
    3) Pass true as third parameter (default for $return_original_if_missing is false atleast in Polylangs implementation)

    • This topic was modified 7 years, 2 months ago by aksl.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter aksl

    (@aksl)

    Workaround for the issue (translates slug to ID without applying the wpml_object_id filter):

    add_filter( 'text_blocks_show_text_block_id', 'fix_tb_wpml_bug' );
    
    function fix_tb_wpml_bug( $id )
    {
        if ( !is_numeric( $id ) ) {
            $page = get_page_by_path( $id, null, 'text-blocks' );
            if ( $page ) {
                $id = $page->ID;
            } else {
                $id = 0;
            }
        }
    
        return $id;
    }
    strarsis

    (@strarsis)

    +1 Just encountered the same issue and would love to see it fixed.

    Plugin Author Hal Gatewood

    (@halgatewood)

    If the filter by @aksl above works, I would leave it at that.

    This bug is a result of me trying to fix my plugin so it would work properly with one other plugin. Not a great idea on my part.

    @strarsis does the filter fix it for you also?

    @halgatewood: Why not add the filter to the plugin itself?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Retrieving via slug conflicts with Polylang’ is closed to new replies.