Get YouTube ID

function theme_get_video_id($url=”){ $url_parts = array(); $video_id = ”; if(!empty($url) && is_string($url)){ if(strpos($url,’youtube.be’) !== false){ $url_parts = explode(‘be/’,$url); }elseif(strpos($url,’?v=’) !== false){ $url_parts = explode(‘?v=’,$url); }elseif(strpos($url,’/v/’) !== false){ $url_parts = explode(‘/v/’,$url); }elseif(strpos($url,’/shorts/’) !== false){ $url_parts = explode(‘/shorts/’,$url); } if(isset($url_parts[0]) && isset($url_parts[1])){ if(strpos($url_parts[1],’?’)…Continue reading

Get YouTube API

function theme_youtube_api($media){ $ids = array(); foreach($media as $m){$ids[] = theme_get_video_id(get_field(‘video_url’,$m->ID));} $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,”https://www.googleapis.com/youtube/v3/videos?part=contentDetails,statistics&id=”.implode(‘,’,$ids).’&key=’.YOUTUBE_APIKEY); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_HEADER,0); $output = curl_exec($ch); curl_close($ch); $json = json_decode($output); $info = array(); foreach($json->items as $v){ $o = new stdClass(); $duration = str_replace(array(‘PT’,’H’,’M’,’S’),array(”,’:’,’:’,”),$v->contentDetails->duration); $duration_parts = explode(‘:’,$duration); $pad_parts…Continue reading

Disable Notifications

function disable_all_notifications() { wp_deregister_script(‘wp-notification-script’); } add_action(‘wp_enqueue_scripts’, ‘disable_all_notifications’, 999);Continue reading

Reusable Blocks accessible in backend

/** * Reusable Blocks accessible in backend * */ function be_reusable_blocks_admin_menu() { add_menu_page( ‘Reusable Blocks’, ‘Reusable Blocks’, ‘edit_posts’, ‘edit.php?post_type=wp_block’, ”, ‘dashicons-editor-table’, 22 ); } add_action( ‘admin_menu’, ‘be_reusable_blocks_admin_menu’ );Continue reading

Populate ACF Field with Post Types

function acf_load_post_types_populate_field( $field ) { // reset choices $field[‘choices’] = array(); // Get post types $args = array( ‘public’ => true, ); $post_types = get_post_types( $args, ‘objects’ ); unset( $post_types[‘attachment’] ); foreach ( $post_types as $post_type ) { $value =…Continue reading

Display the Last Updated Date (copy)

$u_time = get_the_time( ‘U’ ); $u_modified_time = get_the_modified_time( ‘U’ ); // Only display modified date if 24hrs have passed since the post was published. if ( $u_modified_time >= $u_time + 86400 ) { $updated_date = get_the_modified_time( ‘F jS, Y’ );…Continue reading