Skip to content

Commit

Permalink
Add zi-media auth script.
Browse files Browse the repository at this point in the history
  • Loading branch information
wallat committed Apr 15, 2020
1 parent 2858844 commit fe5bb8b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions classes/class-p4ct-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ protected function hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
// add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_public_assets' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_public_assets' ] );
add_filter( 'script_loader_tag', [ $this, 'add_async_tag' ], 10, 3);
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_tw_assets' ] );
add_action( 'after_setup_theme', [ $this, 'add_oembed_filter' ] );
// add_action( 'save_post', [ $this, 'p4_auto_generate_excerpt' ], 10, 2 );
add_action( 'save_post', [ $this, 'gpea_auto_set_tag' ], 10, 2 );
Expand Down Expand Up @@ -332,6 +334,31 @@ public function enqueue_public_assets( $hook ) {
wp_enqueue_script( 'search-script' );
}

/**
* Enqueu scripts which only used for Taiwan
* @param string $hook Hook.
*/
public function enqueue_tw_assets ( $hook) {
wp_enqueue_script( 'zi-media', "//a.breaktime.com.tw/js/au.js?spj=NlEyMDUzMjBIS0tBSTFWTjkyNlM4Ng==",[], false, false );
}

/**
* Use async to load script in order not to block the main thread.
*
* @see https://developer.wordpress.org/reference/hooks/script_loader_tag/
* @param string $tag The <script> tag for the enqueued script.
* @param string $handle The script's registered handle.
* @param string $src The script's source URL.
*/
public function add_async_tag($tag, $handle, $src) {
$scriptNamesToBeAsyc = ['zi-media'];

if( !in_array($handle, $scriptNamesToBeAsyc)) {
return $tag; //We return the entire <script> tag as is without modifications.
}
return "<script type='text/javascript' async defer src='".$src."'></script>";
}

/**
* Registers taxonomies.
*/
Expand Down

0 comments on commit fe5bb8b

Please sign in to comment.