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

Edit Lost Password Text

function change_lost_your_password ($text) { if ($text == ‘Lost your password?’){ $text = ‘Reset/Forgot Password?’; } return $text; } add_filter( ‘gettext’, ‘change_lost_your_password’ );Continue reading

WP GraphQL取得数変更

add_filter( ‘graphql_connection_max_query_amount’, function ( int $max_amount, $source, array $args, $context, $info ) { // Bail if the fieldName isn’t avail if ( empty( $info->fieldName ) ) { return $max_amount; } // Bail if we’re not dealing with our target fieldName…Continue reading

Allow SVG Files Upload

/** * Allow SVG uploads for administrator users. * * @param array $upload_mimes Allowed mime types. * * @return mixed */ add_filter( ‘upload_mimes’, function ( $upload_mimes ) { // By default, only administrator users are allowed to add SVGs. //…Continue reading

Move description to after product on category page

add_action(‘woocommerce_archive_description’, ‘custom_archive_description’, 2 ); function custom_archive_description(){ if( is_product_category() ) : remove_action(‘woocommerce_archive_description’, ‘woocommerce_taxonomy_archive_description’, 10 ); add_action( ‘woocommerce_after_main_content’, ‘woocommerce_taxonomy_archive_description’, 5 ); endif; }Continue reading