diff --git a/admin/class-h5p-plugin-admin.php b/admin/class-h5p-plugin-admin.php
index e9086d9..c508cca 100644
--- a/admin/class-h5p-plugin-admin.php
+++ b/admin/class-h5p-plugin-admin.php
@@ -168,11 +168,37 @@ function add_settings_link($links) {
* @since 1.3.0
*/
public function embed() {
+ global $wpdb;
// Allow other sites to embed
header_remove('X-Frame-Options');
// Find content
- $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
+ $slug = filter_input(INPUT_GET, 'slug', FILTER_SANITIZE_ADD_SLASHES);
+
+ $id = NULL;
+
+ if (!empty($slug)) {
+ $q=$wpdb->prepare(
+ "SELECT id ".
+ "FROM {$wpdb->prefix}h5p_contents ".
+ "WHERE slug=%s",
+ $slug
+ );
+ $row=$wpdb->get_row($q,ARRAY_A);
+
+ if ($wpdb->last_error) {
+ return sprintf(__('Database error: %s.', $this->plugin_slug), $wpdb->last_error);
+ }
+
+ if (isset($row['id'])) {
+ $id = (int) $row['id'];
+ }
+ }
+
+ if ($id === NULL) {
+ $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
+ }
+
if ($id !== NULL) {
$plugin = H5P_Plugin::get_instance();
$content = $plugin->get_content($id);
diff --git a/public/class-h5p-plugin.php b/public/class-h5p-plugin.php
index 8cf283d..e568d79 100644
--- a/public/class-h5p-plugin.php
+++ b/public/class-h5p-plugin.php
@@ -936,6 +936,8 @@ public function get_content_settings($content) {
global $wpdb;
$core = $this->get_h5p_instance('core');
+ $insert_method = get_option('h5p_insert_method', 'id');
+
$safe_parameters = $core->filterParameters($content);
if (has_action('h5p_alter_filtered_parameters')) {
// Parse the JSON parameters
@@ -969,15 +971,17 @@ public function get_content_settings($content) {
: ''
);
+ $identifier = ($insert_method === 'slug' and !empty($content['slug'])) ? 'slug=' . $content['slug'] : 'id=' . $content['id'];
+
// Add JavaScript settings for this content
$settings = array(
'library' => H5PCore::libraryToString($content['library']),
'jsonContent' => $safe_parameters,
'fullScreen' => $content['library']['fullscreen'],
'exportUrl' => get_option('h5p_export', TRUE) ? $this->get_h5p_url() . '/exports/' . ($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p' : '',
- 'embedCode' => '',
+ 'embedCode' => '',
'resizeCode' => '',
- 'url' => admin_url('admin-ajax.php?action=h5p_embed&id=' . $content['id']),
+ 'url' => admin_url('admin-ajax.php?action=h5p_embed&' . $identifier),
'title' => $content['title'],
'displayOptions' => $core->getDisplayOptionsForView($content['disable'], $author_id),
'metadata' => $metadata,