array( 'name' => __( 'Projetos', 'gustavoo-portfolio-core' ), 'singular_name' => __( 'Projeto', 'gustavoo-portfolio-core' ), 'menu_name' => __( 'Portfólio', 'gustavoo-portfolio-core' ), 'name_admin_bar' => __( 'Projeto', 'gustavoo-portfolio-core' ), 'add_new' => __( 'Adicionar projeto', 'gustavoo-portfolio-core' ), 'add_new_item' => __( 'Adicionar novo projeto', 'gustavoo-portfolio-core' ), 'edit_item' => __( 'Editar projeto', 'gustavoo-portfolio-core' ), 'new_item' => __( 'Novo projeto', 'gustavoo-portfolio-core' ), 'view_item' => __( 'Ver projeto', 'gustavoo-portfolio-core' ), 'search_items' => __( 'Buscar projetos', 'gustavoo-portfolio-core' ), 'not_found' => __( 'Nenhum projeto encontrado.', 'gustavoo-portfolio-core' ), 'not_found_in_trash' => __( 'Nenhum projeto encontrado na lixeira.', 'gustavoo-portfolio-core' ), 'all_items' => __( 'Projetos', 'gustavoo-portfolio-core' ), 'featured_image' => __( 'Imagem do projeto', 'gustavoo-portfolio-core' ), 'set_featured_image' => __( 'Definir imagem do projeto', 'gustavoo-portfolio-core' ), 'remove_featured_image' => __( 'Remover imagem do projeto', 'gustavoo-portfolio-core' ), ), 'public' => false, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_admin_bar' => true, 'show_in_nav_menus' => false, 'show_in_rest' => true, 'menu_position' => 25, 'menu_icon' => 'dashicons-portfolio', 'capability_type' => 'post', 'map_meta_cap' => true, 'hierarchical' => false, 'has_archive' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'page-attributes', 'revisions', 'custom-fields' ), ) ); register_taxonomy( self::TAX_TYPE, self::POST_TYPE, array( 'labels' => array( 'name' => __( 'Tipos de projeto', 'gustavoo-portfolio-core' ), 'singular_name' => __( 'Tipo de projeto', 'gustavoo-portfolio-core' ), 'menu_name' => __( 'Tipos', 'gustavoo-portfolio-core' ), 'all_items' => __( 'Todos os tipos', 'gustavoo-portfolio-core' ), 'edit_item' => __( 'Editar tipo', 'gustavoo-portfolio-core' ), 'add_new_item' => __( 'Adicionar tipo', 'gustavoo-portfolio-core' ), 'search_items' => __( 'Buscar tipos', 'gustavoo-portfolio-core' ), ), 'public' => false, 'publicly_queryable' => false, 'show_ui' => true, 'show_admin_column' => false, 'show_in_rest' => true, 'hierarchical' => true, 'rewrite' => false, ) ); register_taxonomy( self::TAX_TECH, self::POST_TYPE, array( 'labels' => array( 'name' => __( 'Tecnologias', 'gustavoo-portfolio-core' ), 'singular_name' => __( 'Tecnologia', 'gustavoo-portfolio-core' ), 'menu_name' => __( 'Tecnologias', 'gustavoo-portfolio-core' ), 'all_items' => __( 'Todas as tecnologias', 'gustavoo-portfolio-core' ), 'edit_item' => __( 'Editar tecnologia', 'gustavoo-portfolio-core' ), 'add_new_item' => __( 'Adicionar tecnologia', 'gustavoo-portfolio-core' ), 'search_items' => __( 'Buscar tecnologias', 'gustavoo-portfolio-core' ), 'separate_items_with_commas' => __( 'Separe tecnologias com vírgulas', 'gustavoo-portfolio-core' ), ), 'public' => false, 'publicly_queryable' => false, 'show_ui' => true, 'show_admin_column' => false, 'show_in_rest' => true, 'hierarchical' => false, 'rewrite' => false, ) ); self::register_meta(); } /** * Register project metadata. * * @return void */ private static function register_meta() { $common = array( 'single' => true, 'show_in_rest' => true, 'auth_callback' => array( __CLASS__, 'authorize_meta' ), ); register_post_meta( self::POST_TYPE, self::META_URL, array_merge( $common, array( 'type' => 'string', 'sanitize_callback' => array( __CLASS__, 'sanitize_external_url' ), ) ) ); foreach ( array( self::META_CLIENT, self::META_LINK_LABEL ) as $meta_key ) { register_post_meta( self::POST_TYPE, $meta_key, array_merge( $common, array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', ) ) ); } register_post_meta( self::POST_TYPE, self::META_YEAR, array_merge( $common, array( 'type' => 'integer', 'sanitize_callback' => array( __CLASS__, 'sanitize_year' ), ) ) ); register_post_meta( self::POST_TYPE, self::META_FEATURED, array_merge( $common, array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', ) ) ); register_post_meta( self::POST_TYPE, self::META_ACCENT, array_merge( $common, array( 'type' => 'string', 'sanitize_callback' => 'sanitize_hex_color', ) ) ); } /** * Restrict meta updates to users who can edit the project. * * @param bool $allowed Current authorization result. * @param string $meta_key Meta key. * @param int $post_id Project ID. * @return bool */ public static function authorize_meta( $allowed, $meta_key, $post_id ) { unset( $allowed, $meta_key ); return current_user_can( 'edit_post', (int) $post_id ); } /** * Allow only valid external HTTP(S) URLs. * * @param mixed $value Raw URL. * @return string */ public static function sanitize_external_url( $value ) { $url = esc_url_raw( trim( (string) $value ), array( 'http', 'https' ) ); return $url && wp_http_validate_url( $url ) ? $url : ''; } /** * Validate a four-digit project year. * * @param mixed $value Raw year. * @return int */ public static function sanitize_year( $value ) { $year = absint( $value ); $max_year = (int) gmdate( 'Y' ) + 5; return $year >= 1900 && $year <= $max_year ? $year : 0; } /** * Register the project details metabox. * * @return void */ public static function add_meta_boxes() { add_meta_box( 'gso-project-details', __( 'Detalhes do projeto', 'gustavoo-portfolio-core' ), array( __CLASS__, 'render_meta_box' ), self::POST_TYPE, 'normal', 'high' ); } /** * Render project fields. * * @param WP_Post $post Current project. * @return void */ public static function render_meta_box( $post ) { $url = (string) get_post_meta( $post->ID, self::META_URL, true ); $client = (string) get_post_meta( $post->ID, self::META_CLIENT, true ); $year = absint( get_post_meta( $post->ID, self::META_YEAR, true ) ); $featured = (bool) get_post_meta( $post->ID, self::META_FEATURED, true ); $link_label = (string) get_post_meta( $post->ID, self::META_LINK_LABEL, true ); $accent = sanitize_hex_color( get_post_meta( $post->ID, self::META_ACCENT, true ) ); if ( ! $accent ) { $accent = '#7cf3da'; } wp_nonce_field( 'gso_save_project_details', 'gso_project_details_nonce' ); ?>