Skip to content

Commit b391c3e

Browse files
authored
Merge pull request #162 from manualdousuario/202502
Uma nova versão, afinal!
2 parents 0eebc68 + 1f45f8d commit b391c3e

File tree

9 files changed

+304
-329
lines changed

9 files changed

+304
-329
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.sass-cache
3-
*.zip
3+
*.zip
4+
assets/.DS_Store

assets/.DS_Store

6 KB
Binary file not shown.

assets/fogo.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

orbita.php

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Plugin Name: Órbita
1212
* Plugin URI: https://gnun.es
1313
* 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
1515
* Author: Gabriel Nunes
1616
* Author URI: https://gnun.es
1717
* License: GPL v3
@@ -41,44 +41,53 @@
4141
* Define plugin version constant
4242
*/
4343

44-
define( 'ORBITA_VERSION', '1.15.3.2' );
44+
define( 'ORBITA_VERSION', '1.16' );
4545
define( 'ORBITA_IMAGE_MAX_SIZE', '10' ); // MB
4646

4747
/**
48-
* Enqueue style file
48+
* Enqueue assets
4949
*/
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();
5252

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+
}
6956

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+
}
8089
}
81-
add_action( 'wp_enqueue_scripts', 'orbita_enqueue_scripts' );
90+
add_action( 'wp_enqueue_scripts', 'orbita_enqueue_assets' );
8291

8392
/**
8493
* Setup post type
@@ -256,9 +265,7 @@ function orbita_get_vote_html( $post_id ) {
256265
$title = 'Você já votou!';
257266
}
258267

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>';
262269

263270
return $html;
264271
}
@@ -930,6 +937,10 @@ function orbita_form_post() {
930937

931938
$default_category = get_term_by( 'slug', 'link', 'orbita_category' );
932939

940+
if (!$default_category) {
941+
$default_category = (object) ['term_id' => 0];
942+
}
943+
933944
if ( ! isset( $_POST['orbita_post_content'] ) ) {
934945
$orbita_post_content = '';
935946
} else {

0 commit comments

Comments
 (0)