| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class LP_Nonce_Helper |
| 5 |
*/ |
| 6 |
class LP_Nonce_Helper { |
| 7 |
/** |
| 8 |
* Create nonce for course action. |
| 9 |
* Return nonce created with format 'learn-press-$action-$course_id-course-$user_id' |
| 10 |
* |
| 11 |
* @param string $action [retake, purchase, enroll] |
| 12 |
* @param int $course_id |
| 13 |
* @param int $user_id |
| 14 |
* |
| 15 |
* @since 3.0.0 |
| 16 |
* |
| 17 |
* @return string |
| 18 |
*/ |
| 19 |
public static function create_course( $action, $course_id = 0, $user_id = 0 ) { |
| 20 |
if ( ! $course_id ) { |
| 21 |
$course_id = get_the_ID(); |
| 22 |
} |
| 23 |
|
| 24 |
if ( ! $user_id ) { |
| 25 |
$user_id = get_current_user_id(); |
| 26 |
} |
| 27 |
|
| 28 |
return wp_create_nonce( sprintf( 'learn-press-%s-course-%s-%s', $action, $course_id, $user_id ) ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Verify nonce for course action. |
| 33 |
* |
| 34 |
* @param string $nonce |
| 35 |
* @param string $action |
| 36 |
* @param int $course_id |
| 37 |
* @param int $user_id |
| 38 |
* |
| 39 |
* @since 3.0.0 |
| 40 |
* |
| 41 |
* @return bool |
| 42 |
* @depecated 4.1.6.9 |
| 43 |
*/ |
| 44 |
/*public static function verify_course( $nonce, $action, $course_id = 0, $user_id = 0 ) { |
| 45 |
if ( ! $course_id ) { |
| 46 |
$course_id = get_the_ID(); |
| 47 |
} |
| 48 |
|
| 49 |
if ( ! $user_id ) { |
| 50 |
$user_id = get_current_user_id(); |
| 51 |
} |
| 52 |
|
| 53 |
return wp_verify_nonce( $nonce, sprintf( 'learn-press-%s-course-%s-%s', $action, $course_id, $user_id ) ); |
| 54 |
}*/ |
| 55 |
|
| 56 |
public static function quiz_action( $action, $quiz_id, $course_id, $ajax = false ) { |
| 57 |
?> |
| 58 |
<input type="hidden" name="quiz-id" value="<?php echo esc_attr( $quiz_id ); ?>"> |
| 59 |
<input type="hidden" name="course-id" value="<?php echo esc_attr( $course_id ); ?>"> |
| 60 |
<?php if ( $ajax ) { ?> |
| 61 |
<input type="hidden" name="lp-ajax" value="<?php echo esc_attr( $action ); ?>-quiz"> |
| 62 |
<?php } else { ?> |
| 63 |
<input type="hidden" name="lp-<?php echo esc_attr( $action ); ?>-quiz" value="<?php echo esc_attr( $quiz_id ); ?>"> |
| 64 |
<?php } ?> |
| 65 |
<input type="hidden" name="<?php echo esc_attr( $action ); ?>-quiz-nonce" value="<?php echo wp_create_nonce( sprintf( 'learn-press/quiz/%s/%s-%s-%s', $action, get_current_user_id(), $course_id, $quiz_id ) ); ?>"> |
| 66 |
<?php |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* @depecated 4.1.6.9 |
| 71 |
*/ |
| 72 |
/*public static function verify_quiz_action( $action, $nonce = '', $quiz_id = 0, $course_id = 0 ) { |
| 73 |
if ( ! $nonce ) { |
| 74 |
$nonce = LP_Request::get_post( $action . '-quiz-nonce' ); |
| 75 |
} |
| 76 |
|
| 77 |
if ( ! $quiz_id ) { |
| 78 |
global $lp_course_item; |
| 79 |
$quiz_id = $lp_course_item instanceof LP_Course_Item ? $lp_course_item->get_id() : 0; |
| 80 |
} |
| 81 |
|
| 82 |
if ( ! $course_id ) { |
| 83 |
$course_id = get_the_ID(); |
| 84 |
} |
| 85 |
|
| 86 |
return wp_verify_nonce( $nonce, sprintf( 'learn-press/quiz/%s/%s-%s-%s', $action, get_current_user_id(), $course_id, $quiz_id ) ); |
| 87 |
}*/ |
| 88 |
} |
| 89 |
|