Skip to content

Instantly share code, notes, and snippets.

@gaupoit
Last active May 26, 2020 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaupoit/564cb89588f113de0701f22a5c28ee4f to your computer and use it in GitHub Desktop.
Save gaupoit/564cb89588f113de0701f22a5c28ee4f to your computer and use it in GitHub Desktop.
Form action URL
<?php
add_filter( 'ppwp_ppf_action_url', 'ppwp_get_custom_ppf_action_url', 999, 1 );
/**
* Replace the default URL to current page.
*
* @param string $default_url The default URL.
*
* @return mixed
*/
function ppwp_get_custom_ppf_action_url( $default_url ) {
$callback_value = rawurlencode( apply_filters( PPW_Constants::HOOK_CALLBACK_URL, get_permalink() ) );
// Get current page.
return add_query_arg(
array(
'action' => 'ppw_postpass',
PPW_Constants::CALL_BACK_URL_PARAM => $callback_value,
),
null
);
}
add_action( 'wp', 'ppwp_handle_ppf_form_submit', 5 );
/**
* Handle PPWP From Submit.
*/
function ppwp_handle_ppf_form_submit() {
// Check whether or not WordPress has already sent headers.
// Need to check it to prevent the error: Warning: cannot modify header information – headers already sent by ...
global $wp_did_header;
if ( ! $wp_did_header || ! isset( $_POST['post_password'] ) ) { // phpcs:ignore
return;
}
// Only allow URL with having action querystring is ppw_postpass.
if ( ! isset( $_GET['action'] ) || 'ppw_postpass' !== $_GET['action'] ) { // phpcs:ignore
return;
}
if ( ! class_exists( 'PPW_Password_Services' ) || ! array_key_exists( 'post_password', $_POST ) ) { // phpcs:ignore
return;
}
// Get post_id from referer url if Post data is not exist post_id.
$post_id = ppw_get_post_id_from_request();
if ( empty( $post_id ) ) {
return;
}
if ( ! isset( $_POST['post_password'] ) ) { // phpcs:ignore
return;
}
$password = wp_unslash( $_POST['post_password'] ); // phpcs:ignore
$free_services = new PPW_Password_Services();
$free_services->handle_after_enter_password_in_password_form( $post_id, $password );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment