Support » Plugin: WP YouTube Lyte » Why isn't the shortcode registered for admin pages?

  • Resolved Sutherland Boswell

    (@sutherlandboswell)


    Hi! I’m the developer of Video Thumbnails and I came to the realization that your shortcode is only being registered with WordPress on non-admin pages.

    This means that Video Thumbnails is unable to detect a [lyte] video when published in the dahboard because the shortcode isn’t getting parsed. Moving the shortcode and filter functions outside of the conditional statement at the end of wp-youtube-lyte.php seems to fix the problem, so I was hoping you could make this change.

    https://wordpress.org/plugins/wp-youtube-lyte/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Frank Goossens

    (@futtta)

    Hi Sutherland, nice to meet you!

    The goal of the conditional statement at the end is to only load required logic (i.e. options when in admin and filters/ shortcode/ actions when not in admin) to ensure the best possible performance, so if possible I’d like to avoid changing that unless absolutely needed.

    This particular problem can, however, easily be solved by adding this code to either a blog theme’s functions.php (best in a child theme off course or in a separate ad hoc plugin to avoid working in theme’s) or even in “Video Thumbnails” itself;

    if (is_admin() && function_exists("shortcode_lyte")) {
    	add_shortcode("lyte", "shortcode_lyte");
    }

    Did some tests with that, works like a charm 😉

    hope this helps,
    frank

    The add_shortcode() function adds very little overhead (you can see for yourself here), and the only aspect of the site you would theoretically save performance on is the admin section where visitors and search engines won’t be making any judgements on load times.

    Loading your options.php conditionally might have a tiny impact on performance (although I doubt it), so you might want to leave it in the if ( is_admin() ) statement but move the contents of the else section so they always get called.

    Keeping all these functions out of the admin section not only affects my plugin, but it will affect any admin-side tools trying to do analysis of a post’s content.

    Plugin Author Frank Goossens

    (@futtta)

    I understand your point and the add_shortcode-line might indeed be moved outside of the conditional statement at a future release (no ETA yet).

    But until that moment, if you want your user specifically or your plugin in general to be able fetch thumbnails for shortcode-initiated lyte’s, then the example code will work just fine 🙂

    greetings from Europe,
    frank

    I consider this a flaw in YouTube Lyte so I hope these changes are included in the future. I think the cost of breaking compatibility with other plugins far outweighs the potential benefit of saving a tiny fraction of a millisecond on admin pages.

    Plugin Author Frank Goossens

    (@futtta)

    That’s your right off course, but given there is an easy workaround (which your user labeled as being “awesome support”, you’re welcome 😉 ), the flaw seems pretty minor, no? Anyway, as I stated, I will look into this for a future release.

    frank

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Why isn't the shortcode registered for admin pages?’ is closed to new replies.