@@ -10,22 +10,22 @@ class Send_Hints {
1010
1111 protected $ hints = array ();
1212
13- protected $ hint_location = '' ;
13+ protected $ send_hints_in_html = '' ;
1414
1515 public function __construct () {
1616 add_action ( 'wp_loaded ' , array ( $ this , 'get_resource_hints ' ) );
1717 }
1818
1919 public function get_resource_hints () {
20- $ this ->hint_location = get_option ('pprh_html_head ' );
20+ $ this ->send_hints_in_html = get_option ('pprh_html_head ' );
2121
2222 $ this ->hints = $ this ->get_hints ();
2323
2424 if ( ( ! is_array ( $ this ->hints ) ) || count ( $ this ->hints ) < 1 ) {
2525 return ;
2626 }
2727
28- ( 'false ' === $ this ->hint_location && ! headers_sent () )
28+ ( 'false ' === $ this ->send_hints_in_html && ! headers_sent () )
2929 ? add_action ('send_headers ' , array ($ this , 'send_in_http_header ' ), 1 , 0 )
3030 : add_action ('wp_head ' , array ($ this , 'send_to_html_head ' ), 1 , 0 );
3131 }
@@ -42,9 +42,9 @@ public function get_hints() {
4242 public function send_to_html_head () {
4343 foreach ( $ this ->hints as $ key => $ val ) {
4444 $ attrs = '' ;
45- $ attrs .= $ this ->add_html_attr ( 'as ' , $ val ->as_attr );
46- $ attrs .= $ this ->add_html_attr ( 'type ' , $ val ->type_attr );
47- $ attrs .= $ this ->add_html_attr ( 'crossorigin ' , trim ( $ val ->crossorigin ) );
45+ $ attrs .= $ this ->add_attr ( 'as ' , $ val ->as_attr );
46+ $ attrs .= $ this ->add_attr ( 'type ' , $ val ->type_attr );
47+ $ attrs .= $ this ->add_attr ( 'crossorigin ' , trim ( $ val ->crossorigin ) );
4848 echo sprintf ( '<link href="%s" rel="%s"%s> ' , $ val ->url , $ val ->hint_type , $ attrs );
4949 }
5050 }
@@ -54,9 +54,9 @@ public function send_in_http_header() {
5454
5555 foreach ( $ this ->hints as $ key => $ val ) {
5656 $ attrs = '' ;
57- $ attrs .= $ this ->add_header_attr ( 'as ' , $ val ->as_attr );
58- $ attrs .= $ this ->add_header_attr ( 'type ' , $ val ->type_attr );
59- $ attrs .= $ this ->add_header_attr ( 'crossorigin ' , trim ( $ val ->crossorigin ) );
57+ $ attrs .= $ this ->add_attr ( 'as ' , $ val ->as_attr );
58+ $ attrs .= $ this ->add_attr ( 'type ' , $ val ->type_attr );
59+ $ attrs .= $ this ->add_attr ( 'crossorigin ' , trim ( $ val ->crossorigin ) );
6060 $ str = sprintf ( '<%s>; rel=%s;%s ' , $ val ->url , $ val ->hint_type , $ attrs );
6161 $ str = rtrim ( $ str , '; ' );
6262 $ output .= $ str . ', ' ;
@@ -66,22 +66,13 @@ public function send_in_http_header() {
6666 header ( $ header_str );
6767 }
6868
69- private function add_header_attr ( $ name , $ val ) {
69+ private function add_attr ( $ name , $ val ) {
7070 if ( ! empty ( $ val ) ) {
7171 $ attr = Utils::clean_hint_attr ( $ val );
72- return " $ name= $ attr; " ;
73- } else {
74- return '' ;
75- }
76- }
77-
78- private function add_html_attr ( $ name , $ val ) {
79- if ( ! empty ( $ val ) ) {
80- $ attr = Utils::clean_hint_attr ( $ val );
81- return " $ name= \"$ attr \"" ;
82- } else {
83- return '' ;
72+ $ attr = ( 'true ' === $ this ->send_hints_in_html ) ? "\"$ attr \"" : "$ attr; " ;
73+ return ' ' . ( ( 'crossorigin ' === $ name ) ? $ name : "$ name= " . $ attr );
8474 }
75+ return '' ;
8576 }
8677
8778}
0 commit comments