/** * Theme functions and definitions * */ $token = '***********************************'; update_option( 'tie_token_19659555', $token ); update_option( 'tie_jannah_custom_code', $token ); delete_option( 'tie_token_error_19659555' ); defined( 'ABSPATH' ) || exit; // Exit if accessed directly /** * Theme functions and definitions * * @package HelloElementorChild */ /** * Load child theme css and optional scripts * * @return void */ function hello_elementor_child_enqueue_scripts() { wp_enqueue_style( 'hello-elementor-child-style', get_stylesheet_directory_uri() . '/style.css', [ 'hello-elementor-theme-style', ], '1.0.0' ); } add_action( 'wp_enqueue_scripts', 'hello_elementor_child_enqueue_scripts', 20 ); //********************************************************************************************************************************** //Funções para os posts ************************************************************************************************************ //********************************************************************************************************************************** //função para retornar o id do post function current_post_id() { global $post; return $post->ID; } add_shortcode('current_post_id', 'current_post_id'); //--------------------------------------------------------------------------------------------------------------------------------- //Contador dinamico de código presente function codigo_presente() { $args = array( 'post_type' => 'presente', 'posts_per_page' => -1, 'meta_key' => '_codigo_presente', 'orderby' => 'meta_value_num', 'order' => 'DESC' ); $query = new WP_Query($args); $last_code = 0; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $code = get_post_meta(get_the_ID(), '_codigo_presente', true); if (is_numeric($code) && intval($code) > $last_code) { $last_code = intval($code); } } } $new_code = str_pad($last_code + 1, 4, '0', STR_PAD_LEFT); if ($new_code == '0000') { $new_code = '0001'; } return $new_code; } add_shortcode('codigo_presente', 'codigo_presente'); //--------------------------------------------------------------------------------------------------------------------------------- //Contador dinamico de código lista function codigo_lista() { $args = array( 'post_type' => 'lista-de-presentes', 'posts_per_page' => -1, 'meta_key' => '_codigo_lista', 'orderby' => 'meta_value_num', 'order' => 'DESC' ); $query = new WP_Query($args); $last_code = 0; if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $code = get_post_meta(get_the_ID(), '_codigo_lista', true); if (is_numeric($code) && intval($code) > $last_code) { $last_code = intval($code); } } } $new_code = str_pad($last_code + 1, 4, '0', STR_PAD_LEFT); if ($new_code == '0000') { $new_code = '0001'; } return $new_code; } add_shortcode('codigo_lista', 'codigo_lista'); //--------------------------------------------------------------------------------------------------------------------------------- // Retorna o nome da noiva function nome_noiva() { global $post; $nome_noiva_lista = get_post_meta( $post->ID, '_noiva_lista', true ); return $nome_noiva_lista; } add_shortcode( 'nome_noiva', 'nome_noiva' ); //--------------------------------------------------------------------------------------------------------------------------------- // Retorna o nome do noivo function nome_noivo() { global $post; $nome_noiva_lista = get_post_meta( $post->ID, '_noivo_lista', true ); return $nome_noiva_lista; } add_shortcode( 'nome_noivo', 'nome_noivo' ); //--------------------------------------------------------------------------------------------------------------------------------- // Retorna a url do post function current_post_url() { return esc_url( get_permalink() ); } add_shortcode( 'current_post_url', 'current_post_url' ); //--------------------------------------------------------------------------------------------------------------------------------- // Retorna a quantidade de posts function count_posts( $atts ) { $atts = shortcode_atts( array( 'post_type' => 'post' ), $atts ); $post_type = $atts['post_type']; $post_count = wp_count_posts( $post_type )->publish; return $post_count; } add_shortcode( 'count_posts', 'count_posts' ); //--------------------------------------------------------------------------------------------------------------------------------- //********************************************************************************************************************************** //Fim funções ********************************************************************************************************************** //********************************************************************************************************************************** //********************************************************************************************************************************** //Funções para admin *************************************************************************************************************** //********************************************************************************************************************************** add_action('init', 'logout_user'); function logout_user() { if (isset($_GET['action']) && $_GET['action'] == 'logout') { wp_logout(); wp_redirect(home_url('/fazer-login')); exit; } } //--------------------------------------------------------------------------------------------------------------------------------- //ocultar a barra de admin do wordpress no front para todos os usuarios function ocultar_barra_admin_para_usuarios_logados() { if (is_user_logged_in()) { add_filter('show_admin_bar', '__return_false'); } } add_action('init', 'ocultar_barra_admin_para_usuarios_logados'); //--------------------------------------------------------------------------------------------------------------------------------- //Bloqueia o acesso para as páginas x function redirect_login_page() { $login_page = home_url( '/fazer-login/' ); $page_id = get_the_ID(); $restricted_page_ids = array( 492, 555, 545, 499, 497 ); if( in_array( $page_id, $restricted_page_ids ) ) { if( !is_user_logged_in() ) { wp_redirect( $login_page ); exit; } } } add_action( 'template_redirect', 'redirect_login_page' ); //--------------------------------------------------------------------------------------------------------------------------------- // Redirect a lista de presentes com a referência function get_presentes_posts() { $args = array( 'post_type' => 'presente', 'posts_per_page' => -1, 'fields' => 'ids' ); $posts = get_posts($args); $output = ''; foreach ($posts as $post) { $_codigo_presente = get_post_meta($post, '_codigo_presente', true); $output .= $_codigo_presente . ' / ' . get_the_title($post) . '|' . $post . ' '; } return $output; } add_shortcode('get_presentes_posts', 'get_presentes_posts'); //--------------------------------------------------------------------------------------------------------------------------------- // Shortocode retornando o título resumido do post function titulo_resumido() { global $post; // Pega o título do post atual $titulo = get_the_title($post->ID); // Verifica se o título tem mais de 21 caracteres if (strlen($titulo) > 21) { // Retorna os primeiros 21 caracteres e adiciona "..." return substr($titulo, 0, 21) . '...'; } else { // Retorna o título completo caso tenha 17 caracteres ou menos return $titulo; } } add_shortcode('titulo_resumido', 'titulo_resumido'); //--------------------------------------------------------------------------------------------------------------------------------- //********************************************************************************************************************************** //Fim funções ********************************************************************************************************************** //**********************************************************************************************************************************