Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add response to post save filter #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ function h5pxapi_get_auth_settings() {
$settings=array(
"endpoint_url"=>get_option("h5pxapi_endpoint_url"),
"username"=>get_option("h5pxapi_username"),
"password"=>get_option("h5pxapi_password")
"password"=>get_option("h5pxapi_password"),
"alerts" => get_option("h5pxapi_alerts"),
);
}

return $settings;
}
}
4 changes: 2 additions & 2 deletions process-xapi-statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
&& !$statementObject["context"]["extensions"])
unset($statementObject["context"]["extensions"]);

if (has_filter("h5p-xapi-pre-save")) {
if ( has_filter("h5p-xapi-pre-save")) {
$statementObject=apply_filters("h5p-xapi-pre-save",$statementObject);

if (!$statementObject) {
Expand Down Expand Up @@ -95,7 +95,7 @@
exit;
}

$h5pxapi_response_message = apply_filters("h5p-xapi-post-save",$statementObject);
$h5pxapi_response_message = apply_filters("h5p-xapi-post-save",$statementObject,$decoded);

$response=array(
"ok"=>1,
Expand Down
8 changes: 8 additions & 0 deletions src/template/settings.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ class="regular-text"/>
class="regular-text"/>
</td>
</tr>
<tr valign="top">
<th scope="row">Alerts On <small>(un-checking will make debug statements happen to console instead of alert)</small></th>
<td>
<input type="checkbox" name="h5pxapi_alerts"
<?php echo (get_option("h5pxapi_alerts") == "on" )? 'checked="checked"' : ''; ?> />

</td>
</tr>
</table>

<?php submit_button(); ?>
Expand Down
9 changes: 6 additions & 3 deletions wp-h5p-xapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ jQuery(function($) {
*/
function showError(message, code) {
console.error("Unable to save xAPI statement");

alert("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code);
if( xapi_settings.alerts == true ){
alert("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code);
} else {
console.log("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code);
}
}

/**
Expand Down Expand Up @@ -124,4 +127,4 @@ jQuery(function($) {
$("body").append("<div id='wp-h5p-xapi-spinner'>Saving...</div>");
$("#wp-h5p-xapi-spinner").hide();
});
});
});
14 changes: 9 additions & 5 deletions wp-h5p-xapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/**
* Enqueue scripts and stylesheets.
*/

function h5pxapi_enqueue_scripts()
{
wp_register_script("wp-h5p-xapi", plugins_url() . "/wp-h5p-xapi/wp-h5p-xapi.js", array("jquery"));
Expand Down Expand Up @@ -45,6 +46,7 @@ function h5pxapi_enqueue_scripts()
}

wp_localize_script('wp-h5p-xapi', 'xapi_settings', $xapi_js_settings);

}

/**
Expand All @@ -68,11 +70,13 @@ function h5pxapi_admin_menu()
/**
* Admin init.
*/
function h5pxapi_admin_init()
{
register_setting("h5pxapi", "h5pxapi_endpoint_url");
register_setting("h5pxapi", "h5pxapi_username");
register_setting("h5pxapi", "h5pxapi_password");

function h5pxapi_admin_init() {
register_setting("h5pxapi","h5pxapi_endpoint_url");
register_setting("h5pxapi","h5pxapi_username");
register_setting("h5pxapi","h5pxapi_password");
register_setting("h5pxapi", "h5pxapi_alerts");

}

/**
Expand Down