@@ -55,50 +55,36 @@ function orbita_enqueue_assets() {
5555 }
5656
5757 $ shortcodes = array ( 'orbita-header ' , 'orbita-posts ' , 'orbita-my-posts ' , 'orbita-my-comments ' , 'orbita-form ' );
58- $ cache_key = 'orbita_shortcode_check_ ' . $ post ->ID ;
59-
60- // Tenta obter o resultado do cache
61- $ has_shortcode = wp_cache_get ( $ cache_key );
62-
63- if ( $ has_shortcode === false ) {
64- // Se não estiver no cache, verifica os shortcodes
65- $ has_shortcode = false ;
66- foreach ( $ shortcodes as $ shortcode ) {
67- if ( has_shortcode ( $ post ->post_content , $ shortcode ) || is_singular ( 'orbita_post ' ) ) {
68- $ has_shortcode = true ;
69- break ;
70- }
71- }
7258
73- // Armazena o resultado no cache
74- wp_cache_set ( $ cache_key , $ has_shortcode );
75- }
76-
77- if ( $ has_shortcode ) {
78- // style
79- wp_register_style ( ' orbita ' , plugins_url ( ' /public/main.min.css ' , __FILE__ ), array (), ORBITA_VERSION , ' all ' );
80- wp_enqueue_style ( ' orbita ' );
81-
82- // preload style
83- add_filter ( ' wp_preload_resources ' , function ( $ preload_resources ) {
84- $ preload_resources [] = array (
85- ' href ' => plugins_url () . ' /orbita/public/main.min.css?ver= ' . ORBITA_VERSION ,
86- ' as ' => ' style ' ,
87- ' type ' => ' text/css ' ,
88- ' media ' => ' all ' ,
89- );
90- return $ preload_resources ;
91- } );
92-
93- // script
94- wp_register_script ( ' orbita ' , plugins_url ( ' /public/main.min.js ' , __FILE__ ), array (), ORBITA_VERSION , array ( ' strategy ' => ' async ' ) );
95- wp_enqueue_script ( ' orbita ' );
96-
97- $ orbita_inline_script = " var orbitaApi = {
98- restURL: ' " . rest_url () . " ',
99- restNonce: ' " . wp_create_nonce ( ' wp_rest ' ) . " '
100- }; " ;
101- wp_add_inline_script ( ' orbita ' , $ orbita_inline_script );
59+ foreach ( $ shortcodes as $ shortcode ) {
60+ if ( has_shortcode ( $ post -> post_content , $ shortcode ) || is_singular ( ' orbita_post ' ) ) {
61+ // style
62+ wp_register_style ( ' orbita ' , plugins_url ( ' /public/main.min.css ' , __FILE__ ), array (), ORBITA_VERSION , ' all ' );
63+ wp_enqueue_style ( ' orbita ' );
64+
65+ // preload style
66+ add_filter ( ' wp_preload_resources ' , function ( $ preload_resources ) {
67+ $ preload_resources [] = array (
68+ ' href ' => plugins_url () . ' /orbita/public/main.min.css?ver= ' . ORBITA_VERSION ,
69+ ' as ' => ' style ' ,
70+ ' type ' => ' text/css ' ,
71+ ' media ' => ' all ' ,
72+ );
73+ return $ preload_resources ;
74+ });
75+
76+ // script
77+ wp_register_script ( ' orbita ' , plugins_url ( ' /public/main.min.js ' , __FILE__ ), array (), ORBITA_VERSION , array ( ' strategy ' => ' async ' ) );
78+ wp_enqueue_script ( ' orbita ' );
79+
80+ $ orbita_inline_script = " var orbitaApi = {
81+ restURL: ' " . rest_url () . " ',
82+ restNonce: ' " . wp_create_nonce ( ' wp_rest ' ) . " '
83+ }; " ;
84+ wp_add_inline_script ( ' orbita ' , $ orbita_inline_script );
85+
86+ break ;
87+ }
10288 }
10389}
10490add_action ( 'wp_enqueue_scripts ' , 'orbita_enqueue_assets ' );
0 commit comments