PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / lp-webhooks.php

lp-webhooks.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7, at inc/lp-webhooks.php

95 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Common functions to process the webhooks
4 *
5 * @author ThimPress
6 * @package LearnPress/Functions
7 * @version 1.0
8 */
9
10 defined( 'ABSPATH' ) || exit();
11
12 /**
13 * Register a webhook
14 *
15 * @param $key
16 * @param $param
17 */
18 function learn_press_register_web_hook( $key, $param ) {
19 if ( ! $key ) {
20 return;
21 }
22 if ( empty( $GLOBALS['learn_press']['web_hooks'] ) ) {
23 $GLOBALS['learn_press']['web_hooks'] = array();
24 }
25 $GLOBALS['learn_press']['web_hooks'][ $key ] = $param;
26 do_action( 'learn_press_register_web_hook', $key, $param );
27 }
28
29 /**
30 * Return all registered webhooks
31 *
32 * @return mixed|void
33 */
34 function learn_press_get_web_hooks() {
35 $web_hooks = empty( $GLOBALS['learn_press']['web_hooks'] ) ? array() : (array) $GLOBALS['learn_press']['web_hooks'];
36 return apply_filters( 'learn_press_web_hooks', $web_hooks );
37 }
38
39 /**
40 * Return a registered webhook by it's name
41 *
42 * @param $key
43 *
44 * @return mixed|void
45 */
46 function learn_press_get_web_hook( $key ) {
47 $web_hooks = learn_press_get_web_hooks();
48 $web_hook = empty( $web_hooks[ $key ] ) ? false : $web_hooks[ $key ];
49
50 return apply_filters( 'learn_press_web_hook', $web_hook, $key );
51 }
52
53 /**
54 * Process all registered webhooks
55 */
56 function learn_press_process_web_hooks() {
57 $web_hooks = learn_press_get_web_hooks();
58 $web_hooks_processed = array();
59
60 foreach ( $web_hooks as $key => $param ) {
61 if ( ! empty( $_REQUEST[ $param ] ) ) {
62 // $web_hooks_processed = true;
63 $request_scheme = is_ssl() ? 'https://' : 'http://';
64 $requested_web_hook_url = untrailingslashit( $request_scheme . esc_url_raw( $_SERVER['HTTP_HOST'] ) ) . esc_url_raw( $_SERVER['REQUEST_URI'] );
65 $parsed_requested_web_hook_url = parse_url( $requested_web_hook_url );
66 $required_web_hook_url = add_query_arg( $param, '1', trailingslashit( get_home_url() /* SITE_URL */ ) );
67 $parsed_required_web_hook_url = parse_url( $required_web_hook_url );
68 $web_hook_diff = array_diff_assoc( $parsed_requested_web_hook_url, $parsed_required_web_hook_url );
69
70 if ( empty( $web_hook_diff ) ) {
71 do_action( 'learn_press_web_hook_' . $param, $_REQUEST );
72 } else {
73
74 }
75 $web_hooks_processed[ $param ] = LP_Helper::sanitize_params_submitted( $_REQUEST );
76 break;
77 }
78 }
79 if ( $web_hooks_processed ) {
80 do_action( 'learn_press_web_hooks_processed' );
81 ob_start();
82 foreach ( $web_hooks_processed as $k => $v ) {
83 echo "\n===============================================================\n<br />";
84 printf( __( 'LearnPress webhook %s process completed', 'learnpress' ), $k );
85 echo "\n<pre>";
86 print_r( $v );
87 echo "</pre>\n===============================================================\n";
88 }
89 $output = ob_get_clean();
90 wp_die( $output, __( 'LearnPress webhook process Complete', 'learnpress' ), array( 'response' => 200 ) );
91 }
92 }
93
94 add_action( 'wp_loaded', 'learn_press_process_web_hooks', 999 );
95