|
11 | 11 | * Plugin Name: Órbita |
12 | 12 | * Plugin URI: https://gnun.es |
13 | 13 | * Description: Órbita é o plugin para criar um sistema Hacker News-like para o Manual do Usuário |
14 | | - * Version: 1.15.3 |
| 14 | + * Version: 1.16 |
15 | 15 | * Author: Gabriel Nunes |
16 | 16 | * Author URI: https://gnun.es |
17 | 17 | * License: GPL v3 |
|
41 | 41 | * Define plugin version constant |
42 | 42 | */ |
43 | 43 |
|
44 | | -define( 'ORBITA_VERSION', '1.15.3.2' ); |
| 44 | +define( 'ORBITA_VERSION', '1.16' ); |
45 | 45 | define( 'ORBITA_IMAGE_MAX_SIZE', '10' ); // MB |
46 | 46 |
|
47 | 47 | /** |
48 | | - * Enqueue style file |
| 48 | + * Enqueue assets |
49 | 49 | */ |
50 | | -function orbita_enqueue_styles() { |
51 | | - wp_register_style( 'orbita', plugins_url( '/public/main.css', __FILE__ ), array(), ORBITA_VERSION, 'all' ); |
| 50 | +function orbita_enqueue_assets() { |
| 51 | + $post = get_post(); |
52 | 52 |
|
53 | | - wp_enqueue_style( 'orbita' ); |
54 | | - wp_enqueue_script( 'orbita' ); |
55 | | -} |
56 | | - |
57 | | -add_action( 'wp_enqueue_scripts', 'orbita_enqueue_styles' ); |
58 | | - |
59 | | -function orbita_preload_style ($preload_resources) { |
60 | | - $preload_resources[] = array( |
61 | | - 'href' => plugins_url() . '/orbita/public/main.css?ver=' . ORBITA_VERSION, |
62 | | - 'as' => 'style', |
63 | | - 'type' => 'text/css', |
64 | | - 'media' => 'all', |
65 | | - ); |
66 | | - return $preload_resources; |
67 | | -} |
68 | | -add_filter('wp_preload_resources', 'orbita_preload_style'); |
| 53 | + if ( ! $post || ! isset( $post->post_content ) ) { |
| 54 | + return; |
| 55 | + } |
69 | 56 |
|
70 | | -/** |
71 | | - * Enqueue script file |
72 | | - */ |
73 | | -function orbita_enqueue_scripts() { |
74 | | - wp_register_script( 'orbita', plugins_url( '/public/main.min.js', __FILE__ ), array(), ORBITA_VERSION, array( 'strategy' => 'async' ) ); |
75 | | - $orbita_inline_script = "var orbitaApi = { |
76 | | - restURL: '" . rest_url() . "', |
77 | | - restNonce: '" . wp_create_nonce( 'wp_rest' ) . "' |
78 | | - };"; |
79 | | - wp_add_inline_script( 'orbita', $orbita_inline_script ); |
| 57 | + $shortcodes = array( 'orbita-header', 'orbita-posts', 'orbita-my-posts', 'orbita-my-comments', 'orbita-form' ); |
| 58 | + |
| 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 | + } |
| 88 | + } |
80 | 89 | } |
81 | | -add_action( 'wp_enqueue_scripts', 'orbita_enqueue_scripts' ); |
| 90 | +add_action( 'wp_enqueue_scripts', 'orbita_enqueue_assets' ); |
82 | 91 |
|
83 | 92 | /** |
84 | 93 | * Setup post type |
@@ -256,9 +265,7 @@ function orbita_get_vote_html( $post_id ) { |
256 | 265 | $title = 'Você já votou!'; |
257 | 266 | } |
258 | 267 |
|
259 | | - $html = '<button title="' . $title . '" class="orbita-vote-button ' . $additional_class . '" data-post-id="' . $post_id . '">'; |
260 | | - $html .= ' <img loading="lazy" src="' . plugin_dir_url(__FILE__) . 'assets/fogo.svg" alt="Votar" width="17" height="17" />'; |
261 | | - $html .= '</button>'; |
| 268 | + $html = '<button title="' . $title . '" class="orbita-vote-button ' . $additional_class . '" data-post-id="' . $post_id . '">▲</button>'; |
262 | 269 |
|
263 | 270 | return $html; |
264 | 271 | } |
@@ -930,6 +937,10 @@ function orbita_form_post() { |
930 | 937 |
|
931 | 938 | $default_category = get_term_by( 'slug', 'link', 'orbita_category' ); |
932 | 939 |
|
| 940 | + if (!$default_category) { |
| 941 | + $default_category = (object) ['term_id' => 0]; |
| 942 | + } |
| 943 | + |
933 | 944 | if ( ! isset( $_POST['orbita_post_content'] ) ) { |
934 | 945 | $orbita_post_content = ''; |
935 | 946 | } else { |
|
0 commit comments