WordPress.org

Ready to get started?Download WordPress

Forums

CMS Tree Page View
HTML in Titles (9 posts)

  1. Eric
    Member
    Posted 1 year ago #

    I use wp-Typography on my site and it makes a mess of CMS Tree Page View titles. The typography plugin inserts all sorts of spans into text with filters. Unfortunately, since CMS Tree Page View uses get_the_title() to grab the page titles, I end up with nearly illegible titles. I'm not sure why you think it is important that the titles be processed since you later do an esc_html() to make sure the results of that processing are not used. I would recommend just replacing the get_the_title with a grab of the post_title unprocessed. Here's how I fixed it for my use:

    $title = $onePage->post_title;

    ...instead of...

    $title = get_the_title($onePage->ID); // so hooks and stuff will do their work

    I hope this can make it into an update some day!

    http://wordpress.org/extend/plugins/cms-tree-page-view/

  2. Eric
    Member
    Posted 1 year ago #

    This is a very simple problem to fix, but a few revisions have now come and gone without any action. Is there a reason this will NOT be done? I note that other parts of the WordPress dashboard which display these titles do not use get_the_title and so do not suffer from this problem (see the regular title list, for example).

    Why must CMS Tree Page View be different?

    It would be a big help if this could be fixed in the actual plugin so that I didn't have to patch my copy after each upgrade. Thanks!

  3. Pär Thernström
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for reminding me about this.

    I want to keep using get_the_title() because other plugins depend on it (for example some translation plugins do output html comments otherwise).

    I have however made another fix to overcome this in CMS Tree Page View. Please try version 1.2.9 and let me know if it works better!

  4. Eric
    Member
    Posted 1 year ago #

    Nope, 1.2.9 does not fix the problem with wp-Typography.

    Here's what it looks like with get_the_title() http://imgur.com/Cr2B85o

    And here it is in the regular page list http://imgur.com/pGz8dnR

    The point is that the HTML output is not being properly rendered anyway, so get_the_title() is not helping other plugins anyway. If it were being rendered as HTML that would be fine, but it is being output as text.

    It is better to ignore the HTML than to output it as text, and it is more consistent with the rest of the WordPress dashboard, which does the same thing.

  5. Eric
    Member
    Posted 1 year ago #

    Just took a moment for a deeper look.

    It appears that the problem really is a few lines further along: $title = esc_html($title);

    If you compare this with the _draft_or_post_title() function in /wp-admin/includes/template.php (which is called to fill in regular title lists) you see the difference is that you escape HTML and WP does not.

    However, if I try to comment out your esc_html() then CMS Tree Page View hangs with an eternal "Loading..." indicator.

    Since you are escaping the HTML anyway, I'm not sure how using get_the_title() is helping plugins that ship HTML. But I also don't know why this plugin hangs when the HTML is not escaped.

    Also, note, if you do find out how to allow the HTML through, as WP does, then you should probably change the "<Untitled page>" to (no title) as used by WP so that the angle brackets don't make the text disappear. This would also be more like the rest of WP and avoid the issue that sometimes these are not "pages" but other content types.

  6. Eric
    Member
    Posted 1 year ago #

    Ah! Getting closer... you use esc_html() because you want to sanitize the string for inclusion in the JSON block later. But then, when you bring it out of JSON in the JavaScript for display, you do not reconstitute the HTML. There must be another way...

  7. Eric
    Member
    Posted 1 year ago #

    I think I have the fix you need, Pär...

    In your functions.php remove line 1255 (the esc_html() line).

    Make line 1325:

    "title": <?php echo json_encode($title) ?>,

    Make line 1355:

    "post_title": <?php echo json_encode($title) ?>

    Note the elimination of a set of quotes in 1325 and 1355 since json_encode() provides those quotes.

    Oh, and to keep the 'no title' case visible, replace line 1253 with:

    $title = __('(no title)', 'cms-tree-page-view');

    The plugin could probably be simplified by just constructing the whole array of values in PHP and then using json_encode() around the whole array to build the JSON. This might even fix other lurking problems. But for now, replacing esc_html() with json_encode() this way will do the trick!

  8. Pär Thernström
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks eceleste for digging into this problem a bit more.

    I made your suggested changes and they seem to work fine. QTranslate and other plugins that modify the title works since the get_the_title is still being used, and using json_encode seems to make it work with wp-Typography.

    Submitting new version now, please try it and let me know if it works!

  9. Eric
    Member
    Posted 1 year ago #

    Oops, Pär, I didn't catch this note till now. Thanks so much for implementing this fix! Yes, it is working just fine.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic