Skip to content

Commit 8d9346c

Browse files
Merge pull request #32 from LearningLabUFC/develop
Shortcode de instrutores
2 parents cb67171 + b589f56 commit 8d9346c

4 files changed

Lines changed: 63 additions & 6 deletions

File tree

.gitignore

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
1+
# macOS
12
.DS_Store
2-
.vscode/
3+
4+
# IDEs
5+
.vscode/
6+
.idea/
7+
8+
# Dependencies
9+
/vendor/
10+
11+
# Node
12+
node_modules/
13+
npm-debug.log*
14+
yarn-error.log*
15+
16+
# Build files
17+
dist/
18+
build/
19+
20+
# Logs
21+
*.log
22+
23+
# Env files
24+
.env
25+
.env.*
26+
27+
# OS / misc
28+
Thumbs.db

inc/custom-post-types.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ function registrar_cpt_membros()
2424
'labels' => $labels,
2525
'public' => true,
2626
'has_archive' => true,
27-
'show_in_rest' => false,
28-
'supports' => array('title', 'editor', 'thumbnail'),
27+
'show_in_rest' => true,
28+
'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
2929
'menu_position' => 20,
3030
'menu_icon' => 'dashicons-groups',
3131
);

inc/shortcodes.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,41 @@ function membros_shortcode($atts)
6565
function instrutor_shortcode($atts, $content = null)
6666
{
6767
$atts = shortcode_atts(array(
68-
'nome' => 'Nome do Instrutor',
68+
'slug' => '',
69+
'nome' => '',
6970
'imagem' => '',
7071
'descricao' => ''
7172
), $atts, 'instrutor');
7273

73-
if (!filter_var($atts['imagem'], FILTER_VALIDATE_URL)) {
74+
if (!empty($atts['slug'])) {
75+
$args = array(
76+
'name' => $atts['slug'],
77+
'post_type' => 'membro',
78+
'post_status' => 'publish',
79+
'numberposts' => 1,
80+
);
81+
$membros = get_posts($args);
82+
83+
if ($membros) {
84+
$membro = $membros[0];
85+
if (empty($atts['nome'])) {
86+
$atts['nome'] = get_the_title($membro->ID);
87+
}
88+
if (empty($atts['imagem'])) {
89+
$atts['imagem'] = get_the_post_thumbnail_url($membro->ID, 'full');
90+
}
91+
if (empty($atts['descricao'])) {
92+
$atts['descricao'] = get_the_excerpt($membro->ID);
93+
}
94+
}
95+
}
96+
97+
// Valores padrão se ainda estiverem vazios
98+
if (empty($atts['nome'])) {
99+
$atts['nome'] = 'Nome do Instrutor';
100+
}
101+
102+
if (!empty($atts['imagem']) && !filter_var($atts['imagem'], FILTER_VALIDATE_URL)) {
74103
$img = get_page_by_title($atts['imagem'], OBJECT, 'attachment');
75104
if ($img) {
76105
$atts['imagem'] = wp_get_attachment_url($img->ID);

inc/taxonomies.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function registrar_taxonomia_tipo_de_membro()
2222
'hierarchical' => true,
2323
'labels' => $labels,
2424
'show_ui' => true,
25+
'show_in_rest' => true,
2526
'show_admin_column' => true,
2627
'query_var' => true,
2728
'rewrite' => array('slug' => 'tipo-de-membro'),
@@ -54,6 +55,7 @@ function registrar_taxonomia_status_curso()
5455
'hierarchical' => true,
5556
'labels' => $labels,
5657
'show_ui' => true,
58+
'show_in_rest' => true,
5759
'show_admin_column' => true,
5860
'query_var' => true,
5961
'rewrite' => array('slug' => 'status-do-curso'),
@@ -119,4 +121,4 @@ function registrar_taxonomia_ano_artigo()
119121
);
120122
register_taxonomy('ano_artigo', array('artigo'), $args);
121123
}
122-
add_action('init', 'registrar_taxonomia_ano_artigo');
124+
add_action('init', 'registrar_taxonomia_ano_artigo');

0 commit comments

Comments
 (0)