[wp-trac] [WordPress Trac] #40044: A little strange logic in get_header_video_url() function

WordPress Trac noreply at wordpress.org
Mon Mar 6 12:41:35 UTC 2017


#40044: A little strange logic in get_header_video_url() function
-------------------------+-----------------------------
 Reporter:  Tkama        |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Permalinks   |    Version:  4.7.2
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Lets see func code here:
 https://developer.wordpress.org/reference/functions/get_header_video_url/

 {{{
 function get_header_video_url() {
     $id = absint( get_theme_mod( 'header_video' ) );
     $url = esc_url( get_theme_mod( 'external_header_video' ) );

     if ( ! $id && ! $url ) {
         return false;
     }

     if ( $id ) {
         // Get the file URL from the attachment ID.
         $url = wp_get_attachment_url( $id );
     }

     return esc_url_raw( set_url_scheme( $url ) );
 }
 }}}

 {{{
 // at the bigining
 $url = esc_url( get_theme_mod( 'external_header_video' ) );

 // at the end
 return esc_url_raw( set_url_scheme( $url ) );
 }}}

 May be better to do esc only just before return (variant 1). Or if we dont
 need it for wp_get_attachment_url() do esc_url_raw() only for it (variant
 2)...

 And also it seems better to improve all logic, in order it become more
 clear an faster in some cases...

 variant 1:

 {{{
 function get_header_video_url() {
     $id = get_theme_mod( 'header_video' ); // absint( $id ) - no need

     if ( $id ) {
         // Get the file URL from the attachment ID.
         $url = wp_get_attachment_url( $id );
     }
     else {
         $url = get_theme_mod( 'external_header_video' );
     }

     if ( ! $url ) {
         return false;
     }

     return esc_url( $url );
 }
 }}}

 variant 2:

 {{{
 function get_header_video_url() {
     $id = get_theme_mod( 'header_video' ); // absint( $id ) - no need

     if ( $id ) {
         // Get the file URL from the attachment ID.
         $url = esc_url_raw( wp_get_attachment_url( $id ) );
     }
     else {
         $url = esc_url( get_theme_mod( 'external_header_video' ) );
     }

     if ( ! $url ) {
         return false;
     }

     return $url;
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40044>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list