• Resolved leanderbraunschweig

    (@leanderbraunschweig)


    Hi there,

    first of all: What a great plugin, many many thanks for creating and maintaining it!

    I encountered an issue where I could use some advice…

    I am trying to filter / process a string in order to add hyphenation but cannot get it to work. I double-checked already that a) no other filtering is happening which could remove the ­-tags and b) that the function calls are working fine and c) the user settings are correctly set.

    So essentially this is my demo code:

    if(class_exists('WP_Typography')) {
      $s = \WP_Typography::get_user_settings();
      $title_with_big_words = 'Bei Profis und Amateuren gleicherma?en beliebtes Leinenschl?ppchen mit geteilter Sohle';
      $hyphenated_title = \WP_Typography::process_title($title_with_big_words, $s);
      echo $hyphenated_title;
    }

    And this is what I am getting:

    Bei Profis und Amateuren gleicherma?en beliebtes Leinenschl?ppchen mit geteilter Sohle

    But I would expect to see:

    Bei Pro­fis und Ama­teu­ren glei­cher­ma­?en belieb­tes Lei­nen­schl?pp­chen mit geteil­ter Soh­le

    What could be the culprit here?

    I can var_dump the settings object just fine and wp-typogrophy definitely works because the content filtering is happening and I am seeing the ­-tags there just fine.

    Using WP 5.9 with the latest plugin version.

    Thanks for any help regarding further debugging this!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author pepe

    (@pputzer)

    Can you post the settings dump (JSON would be best)? You have probably disabled hyphenation for titles.

    Thread Starter leanderbraunschweig

    (@leanderbraunschweig)

    Hi @pputzer,

    you are right – title hyphenation was unchecked / disabled and thus the WP_Typography::process_title-function couldn’t work…

    But deviating from the code I have posted above I am actually using WP_Typography::process in order to hyphenate my string and that doesn’t work as well despite not falling under said setting. Obviously the title-setting overwrites any hyphenation-processing?

    Guess we would like to not have the titles be hyphenated and still programmatically process strings – how would that be possible?

    Thanks & regards!

    Plugin Author pepe

    (@pputzer)

    Please post your settings array and your updated WP_Typography::process line (including the exact HTML fragment). The interplay between settings and what is considered a title for hyphenation purposes is a bit complex.

    Thread Starter leanderbraunschweig

    (@leanderbraunschweig)

    Hi @pputzer,

    sure thing:

    Settings output

    See this gist

    Filter / code used

    // Add product sublines (via ACF)
    add_action('woocommerce_after_shop_loop_item_title', function() {
      $tagline = get_field('tagline');
    
      if(class_exists('WP_Typography')) {
        $s = \WP_Typography::get_user_settings();
        $tagline = \WP_Typography::process($tagline, $s);
      }
    
      echo '<p class="tagline">' . $tagline . '</p>';
    }, 9);

    Besides the action hook I also tested directly in the template, thus the usage of a filter / hook or not doesn’t make a difference with regards to the missing hyphenation here…

    I can also send you the link to our development environment where you can view the output directly if that is helpful.

    Thanks so much for looking into this!

    Plugin Author pepe

    (@pputzer)

    @leanderbraunschweig what does $tagline contain exactly?

    (BTW, when you don’t change the settings as defined in the plugin options, you can omit the parameter, no need to copy the object.)

    Thread Starter leanderbraunschweig

    (@leanderbraunschweig)

    Hi @pputzer,

    What does $tagline contain exactly?

    Just a regular string… It works fine when activating the “hyphenate titles” option. And I tried with said string “Bei Profis und Amateuren gleicherma?en beliebtes Leinenschl?ppchen mit geteilter Sohle” directly to go around any possible issues with input or filters and could reproduce the behaviour.

    Did you test on your end yet? Should be easily reproducible – at least that’s my guess.

    (BTW, when you don’t change the settings as defined in the plugin options, you can omit the parameter, no need to copy the object.)

    Makes sense ?? Thanks for pointing it out!

    Plugin Author pepe

    (@pputzer)

    Ah, I meant which string is contained in $tagline (including any markup).

    Thread Starter leanderbraunschweig

    (@leanderbraunschweig)

    @pputzer

    No markup, just a string like

    Wildleder-Tanzschuh, kleiner Absatz

    Plugin Author pepe

    (@pputzer)

    Weird then. I’ll have to look more closely at this.

    Plugin Author pepe

    (@pputzer)

    Hi @leanderbraunschweig, I overlooked something previously: In your snippet, you call ::process with the same parameters as ::process_title. However, it has a different signature (some additional boolean parameters in between $text and $settings). The first of these is the $is_title parameter. The settings object evaluates to true in a boolean context, so you are basically using process_title by accident.

    Thread Starter leanderbraunschweig

    (@leanderbraunschweig)

    Ah, gotcha – that makes sense then…

    I followed your documentation and there it doesn’t mention the $is_title parameter. I could / should have checked the source I guess ??

    Anyhow, thanks for getting back and I’ll adjust the code accordingly.

    Plugin Author pepe

    (@pputzer)

    Thanks, I’ve fixed this documentation bug. Looks like all the parameter sections were copy-pasta. I’ll have to look into autogenerating the API documentation again (was not easy to set up a nice theme last time, so I dropped it).

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Cannot process strings programmatically…?’ is closed to new replies.