display-conditions
3 years ago
front
10 months ago
helpers
10 months ago
metas
3 years ago
multisite
3 years ago
palettes
3 years ago
provider
3 years ago
providers
10 months ago
templates
3 years ago
update
3 years ago
class-hustle-admin-page-abstract.php
10 months ago
class-hustle-black-friday-campaign.php
7 months ago
class-hustle-condition-factory.php
6 years ago
class-hustle-cross-sell.php
10 months ago
class-hustle-dashboard-admin.php
3 years ago
class-hustle-data.php
3 years ago
class-hustle-db.php
2 years ago
class-hustle-installer.php
4 years ago
class-hustle-meta.php
3 years ago
class-hustle-module-admin.php
10 months ago
class-hustle-module-collection.php
3 years ago
class-hustle-module-page-abstract.php
2 years ago
class-hustle-notifications.php
3 years ago
class-hustle-settings-admin.php
3 years ago
class-hustle-tutorials-page.php
4 years ago
class-hustle-wp-dashboard-page.php
3 years ago
hustle-deletion.php
3 years ago
hustle-embedded-admin.php
3 years ago
hustle-entries-admin.php
3 years ago
hustle-entry-model.php
3 years ago
hustle-general-data-protection.php
3 years ago
hustle-init.php
7 months ago
hustle-mail.php
3 years ago
hustle-migration.php
3 years ago
hustle-model.php
3 years ago
hustle-module-model.php
10 months ago
hustle-module-widget-legacy.php
3 years ago
hustle-module-widget.php
3 years ago
hustle-modules-common-admin-ajax.php
10 months ago
hustle-popup-admin.php
3 years ago
hustle-providers-admin.php
3 years ago
hustle-providers.php
3 years ago
hustle-settings-admin-ajax.php
3 years ago
hustle-settings-page.php
3 years ago
hustle-slidein-admin.php
3 years ago
hustle-sshare-admin.php
3 years ago
hustle-sshare-model.php
3 years ago
hustle-tracking-model.php
3 years ago
opt-in-geo.php
10 months ago
opt-in-utils.php
3 years ago
opt-in-wpmudev-api.php
3 years ago
opt-in-wpmudev-api.php
116 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Opt_In_WPMUDEV_API |
| 4 | * |
| 5 | * @package Hustle |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Class Opt_In_WPMUDEV_API |
| 10 | */ |
| 11 | class Opt_In_WPMUDEV_API { |
| 12 | const DOMAIN = 'https://wpmudev.com'; |
| 13 | const REDIRECT_URI = 'https://wpmudev.com/api/hustle/v1/provider'; |
| 14 | |
| 15 | /** |
| 16 | * Nonce option name |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | private $nonce_option_name = 'hustle_custom_nonce'; |
| 21 | |
| 22 | /** |
| 23 | * Helper function to generate unique none changeable nonce. |
| 24 | * |
| 25 | * @return string The unique nonce value. |
| 26 | */ |
| 27 | public function get_nonce_value() { |
| 28 | $nonce = get_option( $this->nonce_option_name ); |
| 29 | |
| 30 | if ( empty( $nonce ) ) { |
| 31 | /** |
| 32 | * Generate the nonce value only once to avoid error response |
| 33 | * when retrieving access token. |
| 34 | */ |
| 35 | $nonce = wp_generate_password( 40, false, false ); |
| 36 | |
| 37 | update_option( $this->nonce_option_name, $nonce ); |
| 38 | } |
| 39 | |
| 40 | return $nonce; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Helper function to validate nonce value. |
| 45 | * |
| 46 | * @param string $nonce Nonce. |
| 47 | * |
| 48 | * @return bool |
| 49 | */ |
| 50 | public function verify_nonce( $nonce ) { |
| 51 | return $nonce === $this->get_nonce_value(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get redirect URL |
| 56 | * |
| 57 | * @param string $provider Provider. |
| 58 | * @param string $action Action. |
| 59 | * @param array $params Params. |
| 60 | * @param bool $migration Migration. |
| 61 | * @return string |
| 62 | */ |
| 63 | public function redirect_uri( $provider, $action, $params = array(), $migration = 0 ) { |
| 64 | $params = wp_parse_args( |
| 65 | $params, |
| 66 | array( |
| 67 | 'action' => $action, |
| 68 | 'provider' => $provider, |
| 69 | 'wpnonce' => $this->get_nonce_value(), |
| 70 | 'migrate' => true === $migration ? 1 : 0, |
| 71 | 'redirect' => site_url( '/' ), |
| 72 | ) |
| 73 | ); |
| 74 | |
| 75 | return add_query_arg( $params, self::REDIRECT_URI ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Validates request callback from WPMU DEV |
| 80 | * |
| 81 | * @param string $provider Provider. |
| 82 | * @return bool |
| 83 | */ |
| 84 | public function validate_callback_request( $provider ) { |
| 85 | $wpnonce = filter_input( INPUT_GET, 'wpnonce', FILTER_SANITIZE_SPECIAL_CHARS ); |
| 86 | $domain = filter_input( INPUT_GET, 'domain', FILTER_VALIDATE_URL ); |
| 87 | $provider_input = filter_input( INPUT_GET, 'provider', FILTER_SANITIZE_SPECIAL_CHARS ); |
| 88 | |
| 89 | return ! empty( $wpnonce ) && $this->verify_nonce( $wpnonce ) |
| 90 | && self::DOMAIN === $domain && $provider === $provider_input; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Print error page on failed integration. |
| 95 | * |
| 96 | * @param string $message Message. |
| 97 | * @param string $retry_url Retry URL. |
| 98 | * @param string $cancel_url Cancel URL. |
| 99 | */ |
| 100 | public function api_die( $message, $retry_url = '', $cancel_url = '' ) { |
| 101 | $html = sprintf( '<p><img src="%s" /></p>', esc_url( Opt_In::$plugin_url . 'assets/img/hustle.png' ) ); |
| 102 | $html .= sprintf( '<p>%s</p>', esc_html( $message ) ); |
| 103 | |
| 104 | if ( ! empty( $retry_url ) ) { |
| 105 | $html .= sprintf( '<a href="%s" class="button button-large">%s</a>', esc_url( $retry_url ), esc_html__( 'Retry', 'hustle' ) ); } |
| 106 | |
| 107 | if ( ! empty( $cancel_url ) ) { |
| 108 | $html .= sprintf( ' <a href="%s" class="button button-large">%s</a>', esc_url( $cancel_url ), esc_html__( 'Cancel', 'hustle' ) ); } |
| 109 | |
| 110 | $html = sprintf( '<div style="text-align: center;">%s</div>', $html ); |
| 111 | |
| 112 | /* translators: Plugin name */ |
| 113 | wp_die( wp_kses_post( $html ), esc_html( sprintf( __( '%s failure notice.', 'hustle' ), Opt_In_Utils::get_plugin_name() ) ), 403 ); |
| 114 | } |
| 115 | } |
| 116 |