Tribe__PUE__Checker::request_update()

Retrieve the latest update (if any) from the configured API endpoint.

Contents


Return

(Tribe__PUE__Utility) An instance of Tribe<strong>PUE</strong>Utility, or NULL when no updates are available.


Top ↑

Source

File: src/Tribe/PUE/Checker.php

		public function request_update() {
			// For the sake of simplicity, this function just calls request_info()
			// and transforms the result accordingly.
			$query_args = $this->get_validate_query();

			if ( ! empty( $_POST['key'] ) ) {
				$query_args['key'] = sanitize_text_field( $_POST['key'] );
			} elseif ( ! empty( $_POST[ $this->pue_install_key ] ) ) {
				$query_args['key'] = sanitize_text_field( $_POST[ $this->pue_install_key ] );
			}

			$this->plugin_info = $plugin_info = $this->license_key_status( $query_args );

			if ( null === $plugin_info ) {
				return null;
			}

			// admin display for if the update check reveals that there is a new version but the API key isn't valid.
			if ( isset( $plugin_info->api_invalid ) ) {
				$plugin_info = Tribe__PUE__Utility::from_plugin_info( $plugin_info );
				$plugin_info->license_error = $this->get_api_message( $plugin_info );
				return $plugin_info;
			}

			if ( ! empty( $plugin_info->new_install_key ) ) {
				$this->update_key( $plugin_info->new_install_key );
			}

			//need to correct the download url so it contains the custom user data (i.e. api and any other paramaters)
			$download_query = $this->get_download_query();

			if ( ! empty( $download_query ) ) {
				$plugin_info->download_url = esc_url_raw( add_query_arg( $download_query, $plugin_info->download_url ) );
			}

			// Add plugin dirname/file (this will be expected by WordPress when it builds the plugin list table)
			$plugin_info->plugin = $this->get_plugin_file();

			return Tribe__PUE__Utility::from_plugin_info( $plugin_info );
		}