PHP code example of automattic / jetpack-help-center

1. Go to this page and download the library: Download automattic/jetpack-help-center library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

automattic / jetpack-help-center example snippets


use Automattic\Jetpack\Help_Center\Help_Center;

add_action( 'init', array( Help_Center::class, 'init' ), 10, 0 );

add_filter(
	'jetpack_help_center_should_load_logged_out',
	static function ( $should_load ) {
		return is_front_page() || $should_load;
	}
);

use Automattic\Jetpack\Help_Center\Wpcom_Request_Client;

final class My_Help_Center_Request_Client implements Wpcom_Request_Client {
	public function is_user_connected() {
		return my_wpcom_access_token() !== null;
	}

	public function request(
		$path,
		$version = '2',
		$args = array(),
		$body = null,
		$base_api_path = 'wpcom'
	) {
		if ( is_user_logged_in() ) {
			return my_authenticated_wpcom_request( $path, $version, $args, $body, $base_api_path );
		}

		return my_anonymous_wpcom_request( $path, $version, $args, $body, $base_api_path );
	}
}

add_filter(
	'jetpack_help_center_wpcom_request_client',
	static function () {
		return new My_Help_Center_Request_Client();
	}
);
bash
pnpm jetpack test php packages/help-center