Skip to content

Enable the use of slug in the embed - #144

Open
tomekstach wants to merge 5 commits into
h5p:masterfrom
katalysteducation:add-slug-to-embed
Open

Enable the use of slug in the embed#144
tomekstach wants to merge 5 commits into
h5p:masterfrom
katalysteducation:add-slug-to-embed

Conversation

@tomekstach

Copy link
Copy Markdown

Insert method option might be used in the embed to get an item by slug or ID.

@bernhardkaindl

Copy link
Copy Markdown

@icc, can you review this or somebody else?

@otacke otacke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomekstach

Hi! I was made a community maintainer for H5P Group's repositories a few weeks ago, and I am still in the process trying to tackle all the open issues and pull requests.

I am terribly sorry that you have not received a reply before.

So, a late thank you in the name of H5P Group (I am not associated with them though). I'd have some small change requests, see comments. But your code absolutely does what it is supposed to, and it definitely makes sense to add it IMHO.

Comment thread admin/class-h5p-plugin-admin.php Outdated

if (!empty($slug)) {
$q=$wpdb->prepare(
"SELECT id ".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'fullScreen' => $content['library']['fullscreen'],
'exportUrl' => get_option('h5p_export', TRUE) ? $this->get_h5p_url() . '/exports/' . ($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p' : '',
'embedCode' => '<iframe src="' . admin_url('admin-ajax.php?action=h5p_embed&id=' . $content['id']) . '" width=":w" height=":h" frameborder="0" allowfullscreen="allowfullscreen" title="' . esc_attr($title) . '"></iframe>',
'embedCode' => '<iframe src="' . admin_url('admin-ajax.php?action=h5p_embed&' . $identifier) . '" width=":w" height=":h" frameborder="0" allowfullscreen="allowfullscreen" title="' . $title . '"></iframe>',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $title should still be passed through esc_attr to prevent broken HTML from being exploited (to mitigate XSS attacks).

$identifier should be passed through esc_attr as well. I know that the slug will have been processed before anyway, but anything that's user-provided should be sanitized. It's part of automated checks that Automattic runs against plugin code and they will complain about it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread admin/class-h5p-plugin-admin.php Outdated

// Find content
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
$slug = filter_input(INPUT_GET, 'slug', FILTER_SANITIZE_ADD_SLASHES);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is FILTER_SANITIZE_ADD_SLASHES the right choice here? The $slug is run through $wpdb->prepare later and will be escaped again, won't it? I think that could cause trouble with retrieval. FILTER_SANITIZE_STRING should suffice, right?

Hold the press ... I just checked https://www.php.net/manual/en/filter.constants.php#constant.filter-sanitize-string to be sure and noticed that it has been deprecated. Seems like

$slug = filter_input(INPUT_GET, 'slug', FILTER_DEFAULT, FILTER_FLAG_NO_ENCODE_QUOTES);

would be the way to go here?!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe in that way:

$slug = filter_input(INPUT_GET, 'slug', FILTER_VALIDATE_REGEXP, [
      'options' => ['regexp' => '/^[a-z0-9-]+$/i']
    ]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should even work better, yes! I am just nor entirely sure: Can WordPress slugs use underscores, too? If yes, then that would be missing, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are absolutely right. Done.

'embedCode' => '<iframe src="' . admin_url('admin-ajax.php?action=h5p_embed&' . $identifier) . '" width=":w" height=":h" frameborder="0" allowfullscreen="allowfullscreen" title="' . $title . '"></iframe>',
'resizeCode' => '<script src="' . plugins_url('h5p/h5p-php-library/js/h5p-resizer.js') . '" charset="UTF-8"></script>',
'url' => admin_url('admin-ajax.php?action=h5p_embed&id=' . $content['id']),
'url' => admin_url('admin-ajax.php?action=h5p_embed&' . $identifier),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think $identifier should also run through esc_attr(), see above.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@github-project-automation github-project-automation Bot moved this from Backlog to Waiting for Contributor in H5P Open Source Project Jul 28, 2026
@otacke

otacke commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@tomekstach Hope you're still around and interested?

@tomekstach

Copy link
Copy Markdown
Author

@otacke
Hi,
Yes, I am definitely interested. Unfortunately, my workload has been so heavy that I haven't had a chance yet to review your suggestions in the code. I will do my best to go through everything this week and implement the necessary changes.

Best regards,

@otacke

otacke commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@tomekstach Thanks for your reply! And there's no reason to hurry, really. This has been dormant for years now - sorry for that again.

I'm just following up to learn whether pull requests could be closed meanwhile, because the contributors lost interest. As someone with 100+ open pull requests myself, some dating back to the last decade, I could fully understand.

I'll keep the pull request in the "waiting for contributor" column for now then (H5P Open Source Project). Once you're done, this will go to "verified by community maintainer", and then the ball is in H5P Group's court eventually. They hopefully won't require years to empty that column ...

@otacke otacke added the feature New or improved product feature label Aug 7, 2026
@otacke

otacke commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

@tomekstach I don't want to push, just set a reminding "ping" after 4 weeks.

@tomekstach

Copy link
Copy Markdown
Author

@otacke please, review my changes.

@otacke

otacke commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Just that one comment about characters used in slugs ...

@otacke otacke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! I'll move the request to the status "verified by community maintainer" (see https://github.com/orgs/h5p/projects/6/views/7), meaning the pull request is to be picked up by H5P Group once it has been prioritized. Please note, however, that I don't know when they are going to handle this. My powers end here.

@otacke

otacke commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Info for H5P Group

This pull request implements the user story:

  • "As as admin/author, when I want to embed H5P content, I want to be able to use the content slug instead of the content id"

@otacke otacke moved this from Waiting for Contributor to Verified by Community Maintainer in H5P Open Source Project Aug 31, 2026
@tomekstach

Copy link
Copy Markdown
Author

@otacke Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New or improved product feature

Projects

Status: Verified by Community Maintainer

Development

Successfully merging this pull request may close these issues.

3 participants