Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metabox: Ícones de projetos #24

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/css/font-awesome.min.css

Large diffs are not rendered by default.

Binary file modified assets/fonts/FontAwesome.otf
Binary file not shown.
Binary file modified assets/fonts/fontawesome-webfont.eot
Binary file not shown.
169 changes: 152 additions & 17 deletions assets/fonts/fontawesome-webfont.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/fonts/fontawesome-webfont.ttf
Binary file not shown.
Binary file modified assets/fonts/fontawesome-webfont.woff
Binary file not shown.
Binary file added assets/fonts/fontawesome-webfont.woff2
Binary file not shown.
7 changes: 6 additions & 1 deletion content.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@

<div class="list-post-top">
<header class="entry-header">
<h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<h1 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?=project_icon(get_the_ID()); ?>
<?php the_title(); ?>
</a>
</h1>

<?php if ( 'post' == get_post_type() ) : ?>

Expand Down
68 changes: 65 additions & 3 deletions core/cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function womoz_projects_post_type() {
'label' => __( 'projetos', 'womoz' ),
'description' => __( 'Projetos do WoMoz', 'womoz' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', ),
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
Expand All @@ -63,7 +63,6 @@ function womoz_projects_post_type() {
'publicly_queryable' => true,
'capability_type' => 'post',
);

register_post_type( 'projetos', $args );
}
add_action( 'init', 'womoz_projects_post_type', 0 );
Expand Down Expand Up @@ -91,7 +90,7 @@ function womoz_group_post_type() {
'label' => __( 'integrantes', 'womoz' ),
'description' => __( 'Time do WoMoz', 'womoz' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', ),
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
Expand All @@ -110,3 +109,66 @@ function womoz_group_post_type() {
register_post_type( 'time', $args );
}
add_action( 'init', 'womoz_group_post_type', 0 );


/*========================================
= Add project icon =
========================================*/
function projeto_icone($object) {
wp_nonce_field(basename(__FILE__), "meta-box-nonce");
?>
<div>
<label for="icone"></label>
<select name="icone">
<?php
$icons = array(
"Nenhum" => null,
"Educação" => "fa-heart",
"Dev" => "fa-github-alt",
"Eventos" => "fa-camera-retro"
);
foreach($icons as $name => $icon) {
if($icon == get_post_meta($object->ID, "icone", true)) {
echo "<option selected value='$icon'>$name</option>";
}else{
echo "<option value='$icon'>$name</option>";
}
}
?>
</select>
</div>
<?php
}

function save_custom_meta_box($post_id, $post, $update) {
if (!isset($_POST["meta-box-nonce"]) || !wp_verify_nonce($_POST["meta-box-nonce"], basename(__FILE__)))
return $post_id;

if(!current_user_can("edit_post", $post_id))
return $post_id;

if(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)
return $post_id;

$slug = "projetos";
if($slug != $post->post_type)
return $post_id;

$meta_box_dropdown_value = "";

if(isset($_POST["icone"])) {
$meta_box_dropdown_value = $_POST["icone"];
}

update_post_meta($post_id, "icone", $meta_box_dropdown_value);
}

add_action("save_post", "save_custom_meta_box", 10, 3);

function add_custom_meta_box() {
add_meta_box("icone", "Ícone", "projeto_icone", "projetos", "side", "high", null);
}

add_action("add_meta_boxes", "add_custom_meta_box");

/*===== End of project icon ======*/
11 changes: 11 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,14 @@ function remove_class_function( $classes ) {
return $classes;
}
add_filter( 'body_class', 'remove_class_function' );

// Retorna ícones setados no projeto
// @parameter $id = get_the_ID()
// @return html
function project_icon($id) {
if (get_post_meta($id, 'icone', true)) {
$icon = get_post_meta($id, 'icone', true);
$icon = str_replace("fa-", "", $icon);
return "<i class='fa fa-$icon' style='margin-top: -.25rem;'></i>";
}
}