| | 1317 | * Check whether a header video is set or not. |
| | 1318 | * |
| | 1319 | * @since 4.7.0 |
| | 1320 | * |
| | 1321 | * @see get_header_video() |
| | 1322 | * |
| | 1323 | * @return bool Whether a header video is set or not. |
| | 1324 | */ |
| | 1325 | function has_header_video() { |
| | 1326 | return (bool) get_header_video(); |
| | 1327 | } |
| | 1328 | |
| | 1329 | /* Retrieve header video for custom header. |
| | 1330 | * |
| | 1331 | * @since 4.7.0 |
| | 1332 | * |
| | 1333 | * @return string|false |
| | 1334 | */ |
| | 1335 | function get_header_video() { |
| | 1336 | $url = get_theme_mod( 'header_video' ); |
| | 1337 | |
| | 1338 | if ( 'remove-header' == $url ) |
| | 1339 | return false; |
| | 1340 | |
| | 1341 | if ( $url ) { |
| | 1342 | // We have an attachment ID, need the full URL |
| | 1343 | $url = wp_get_attachment_url( $url ); |
| | 1344 | } else { |
| | 1345 | // Fallback to the theme's default video |
| | 1346 | $url = get_theme_support( 'custom-header', 'default-video' ); |
| | 1347 | } |
| | 1348 | |
| | 1349 | return esc_url_raw( set_url_scheme( $url ) ); |
| | 1350 | } |
| | 1351 | |
| | 1352 | /** |
| | 1353 | * Create video tag markup for a custom header video. |
| | 1354 | * |
| | 1355 | * @since 4.7.0 |
| | 1356 | * |
| | 1357 | * @param array $attr Optional. Additional attributes for the image tag. Can be used |
| | 1358 | * to override the default attributes. Default empty. |
| | 1359 | * @return string HTML image element markup or empty string on failure. |
| | 1360 | */ |
| | 1361 | function get_header_video_tag( $attr = array() ) { |
| | 1362 | $header = get_custom_header(); |
| | 1363 | |
| | 1364 | if ( empty( $header->video_url ) ) { |
| | 1365 | return ''; |
| | 1366 | } |
| | 1367 | |
| | 1368 | $width = absint( $header->width ); |
| | 1369 | $height = absint( $header->height ); |
| | 1370 | |
| | 1371 | $attr = wp_parse_args( |
| | 1372 | $attr, |
| | 1373 | array( |
| | 1374 | 'src' => $header->video_url, |
| | 1375 | 'autoplay' => true, |
| | 1376 | 'loop' => true, |
| | 1377 | 'muted' => true, |
| | 1378 | ) |
| | 1379 | ); |
| | 1380 | |
| | 1381 | $attr = array_map( 'esc_attr', $attr ); |
| | 1382 | $html = '<video'; |
| | 1383 | |
| | 1384 | foreach ( $attr as $name => $value ) { |
| | 1385 | $html .= ' ' . $name . '="' . $value . '"'; |
| | 1386 | } |
| | 1387 | |
| | 1388 | $html .= '></video>'; |
| | 1389 | |
| | 1390 | /** |
| | 1391 | * Filters the markup of header videos. |
| | 1392 | * |
| | 1393 | * @since 4.7.0 |
| | 1394 | * |
| | 1395 | * @param string $html The HTML image tag markup being filtered. |
| | 1396 | * @param object $header The custom header object returned by 'get_custom_header()'. |
| | 1397 | * @param array $attr Array of the attributes for the image tag. |
| | 1398 | */ |
| | 1399 | return apply_filters( 'get_header_video_tag', $html, $header, $attr ); |
| | 1400 | } |
| | 1401 | |
| | 1402 | /** |
| | 1403 | * Display the video markup for a custom header video. |
| | 1404 | * |
| | 1405 | * @since 4.7.0 |
| | 1406 | * |
| | 1407 | * @param array $attr Optional. Attributes for the image markup. Default empty. |
| | 1408 | */ |
| | 1409 | function the_header_video_tag( $attr = array() ) { |
| | 1410 | echo get_header_video_tag( $attr ); |
| | 1411 | } |
| | 1412 | |
| | 1413 | /** |
| | 1414 | * Display header video URL. |
| | 1415 | * |
| | 1416 | * @since 4.7.0 |
| | 1417 | */ |
| | 1418 | function header_video() { |
| | 1419 | $video = get_header_video(); |
| | 1420 | if ( $video ) { |
| | 1421 | echo esc_url( $video ); |
| | 1422 | } |
| | 1423 | } |
| | 1424 | |
| | 1425 | /** |
| | 1426 | * Determines if a image or video tag should be returned. |
| | 1427 | * |
| | 1428 | * @since 4.7.0 |
| | 1429 | */ |
| | 1430 | function get_header_tag() { |
| | 1431 | $header = get_custom_header(); |
| | 1432 | |
| | 1433 | if ( $header->video_url ) { |
| | 1434 | return get_header_video_tag(); |
| | 1435 | } else if ( $header->url ) { |
| | 1436 | return get_header_image_tag(); |
| | 1437 | } |
| | 1438 | |
| | 1439 | return ''; |
| | 1440 | } |
| | 1441 | |
| | 1442 | /** |
| | 1807 | if ( defined( 'HEADER_VIDEO_WIDTH' ) ) |
| | 1808 | $args[0]['video-width'] = (int) HEADER_VIDEO_WIDTH; |
| | 1809 | elseif ( isset( $args[0]['video-width'] ) ) |
| | 1810 | define( 'HEADER_VIDEO_WIDTH', (int) $args[0]['video-width'] ); |
| | 1811 | |
| | 1812 | if ( defined( 'HEADER_VIDEO_HEIGHT' ) ) |
| | 1813 | $args[0]['video-height'] = (int) HEADER_VIDEO_HEIGHT; |
| | 1814 | elseif ( isset( $args[0]['video-height'] ) ) |
| | 1815 | define( 'HEADER_VIDEO_HEIGHT', (int) $args[0]['video-height'] ); |
| | 1816 | |
| | 1817 | if ( defined( 'HEADER_VIDEO' ) ) |
| | 1818 | $args[0]['default-video'] = HEADER_VIDEO; |
| | 1819 | elseif ( isset( $args[0]['default-video'] ) ) |
| | 1820 | define( 'HEADER_VIDEO', $args[0]['default-video'] ); |
| | 1821 | |