┌────────────────────────────────┐ │ ░░░ ░░▓ ░▓▓ ███ ▓▓░ ▓░░ │ │ ~ M O O N ~ │ └────────────────────────────────┘
prd-web-01.centraldc.gr
LOCATION:
/var/www/html/adconect/wp-content/plugins/adconect-shortcodes
☗ ROOT
↻ REFRESH
✎ EDIT FILE
EDITING: adconect-shortcodes.php
<?php /* Plugin Name: Adconect Shortcodes Description: Shortcode and CPT to insert pages in other pages shortcode [related_clients] Version: 1.2 Author: Giannis Giannopoulos */ if ( ! defined( 'ABSPATH' ) ) exit; // [related_clients] function adconect_display_related_client_posts( $attributes = array() ) { $atts = shortcode_atts( array( 'title' => __('Σχετικά Άρθρα', 'adconect'), ), $attributes ); $client_terms = get_the_terms( get_the_ID(), 'clients_taxonomy' ); if ( $client_terms && ! is_wp_error( $client_terms ) ) { $related_posts_query = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 4, 'post__not_in' => array( get_the_ID() ), 'tax_query' => array( array( 'taxonomy' => 'clients_taxonomy', 'field' => 'term_id', 'terms' => wp_list_pluck( $client_terms, 'term_id' ), 'operator' => 'IN', ), ), ) ); if ( $related_posts_query->have_posts() ) : ?> <section class="related-posts"> <h3><?php echo esc_html( $atts['title'] ); ?></h3> <div class="related-posts-grid"> <?php while ( $related_posts_query->have_posts() ) : $related_posts_query->the_post(); ?> <article class="post-card"> <?php if ( has_post_thumbnail() ) : ?> <div class="post-thumbnail"> <a href="<?php the_permalink(); ?>"> <?php the_post_thumbnail( 'medium' ); ?> </a> </div> <?php endif; ?> <?php $categories = get_the_category(); if ( ! empty( $categories ) ) : $first_category = $categories[0]; ?> <span class="post-category"> <a href="<?php echo esc_url( get_category_link( $first_category->term_id ) ); ?>"> <?php echo esc_html( $first_category->name ); ?> </a> </span> <?php endif; ?> <h3 class="post-title"> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </h3> <time class="post-date" datetime="<?php echo esc_attr( get_the_date( 'c' ) ); ?>"> <?php echo esc_html( get_the_date() ); ?> </time> </article> <?php endwhile; ?> </div> </section> <?php endif; wp_reset_postdata(); } } function adconect_related_client_posts_shortcode( $atts ) { ob_start(); adconect_display_related_client_posts( $atts ); return ob_get_clean(); } add_shortcode( 'related_clients', 'adconect_related_client_posts_shortcode' ); // [custom_articles] function adconect_display_custom_articles_shortcode( $atts ) { $atts = shortcode_atts( array( 'count' => 5, 'category' => '', 'title' => 'Κεντρικά Άρθρα', 'class' => 'last_articles', 'type' => 'post', ), $atts, 'custom_articles' ); $count = intval( $atts['count'] ); $categories = array_map( 'trim', explode( ',', $atts['category'] ) ); $title = sanitize_text_field( $atts['title'] ); $class = sanitize_text_field( $atts['class'] ); $type = sanitize_text_field( $atts['type'] ); $args = array( 'post_type' => $type, 'posts_per_page' => $count, ); if ( ! empty( $atts['category'] ) ) { $args['tax_query'] = array( array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => $categories, ), ); } $query = new WP_Query( $args ); if ( $query->have_posts() ) { // ΔΙΟΡΘΩΣΗ: Ένωση markup αντί για overwrite $output = '<h3>' . esc_html( $title ) . '</h3>'; $output .= '<section class="more grd ' . esc_html( $class ) . '">'; while ( $query->have_posts() ) { $query->the_post(); $category = get_the_category(); $first_category = ! empty( $category ) ? esc_html( $category[0]->name ) : ''; $image = get_the_post_thumbnail( get_the_ID(), 'large' ); $post_title = get_the_title(); $excerpt = get_the_excerpt(); if ( empty( $excerpt ) ) { $content = wp_trim_words( strip_tags( get_the_content() ), 5 ); } else { $content = $excerpt; } $output .= '<div class="article-item">'; if ( $image ) { $output .= '<div class="featured-image">' . $image . '</div>'; } if ( $first_category ) { $output .= '<p class="category">' . $first_category . '</p>'; } $output .= '<h4><a href="' . esc_url( get_permalink() ) . '">' . esc_html( $post_title ) . '</a></h4>'; $output .= '<p class="excerpt">' . esc_html( $content ) . '</p>'; $output .= '</div>'; } wp_reset_postdata(); $output .= '</section>'; return $output; } else { return '<p>Δεν βρέθηκαν άρθρα.</p>'; } } add_shortcode( 'custom_articles', 'adconect_display_custom_articles_shortcode' ); // Homepage [show_homepage_jobs_block] function adconect_homepage_jobs_block( $atts ) { $atts = shortcode_atts( array( 'count' => 4, 'text' => '', ), $atts, 'show_homepage_jobs_block' ); $posts_per_page = absint( $atts['count'] ); $args = array( 'post_type' => 'page', 'posts_per_page' => $posts_per_page, 'tax_query' => array( array( 'taxonomy' => 'attributes_taxonomy', 'field' => 'slug', 'terms' => 'homepage_jobs', ), ), 'orderby' => 'date', 'order' => 'DESC', ); $homepage_jobs = new WP_Query( $args ); $output = '<div class="homepage_jobs_block grd">'; if ( $homepage_jobs->have_posts() ) : $i = 1; while ( $homepage_jobs->have_posts() ) : $homepage_jobs->the_post(); $output .= '<div><div class="title"><span>0' . $i . '.</span><a href="' . get_permalink() . '">' . get_the_title() . '</a></div>'; if (!empty($atts['text'])) { $output .= $atts['text']; } else { $output .= get_the_excerpt(); } $output .= '</div>'; $i++; endwhile; wp_reset_postdata(); endif; $output .= '</div>'; return $output; } add_shortcode( 'show_homepage_jobs_block', 'adconect_homepage_jobs_block' ); // [show_custom_homepage_block] function adconect_custom_homepage_block( $atts ) { $atts = shortcode_atts( array( 'type' => 'page', 'post_url' => '', 'taxonomy' => 'attributes_taxonomy', 'term' => 'featured', 'title' => 'Τελευταία άρθρα', 'text' => '', ), $atts, 'show_custom_homepage_block' ); $type = sanitize_key( $atts['type'] ); $postUrl = esc_url_raw( $atts['post_url'] ); $taxonomy = sanitize_key( $atts['taxonomy'] ); $term = sanitize_text_field( $atts['term'] ); $title = sanitize_text_field( $atts['title'] ); $text = sanitize_text_field( $atts['text'] ); $args = array( 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC', ); if ( ! empty( $postUrl ) ) { $post_id_by_url = url_to_postid( $postUrl ); if ( $post_id_by_url ) { $args['post_type'] = 'any'; $args['p'] = intval( $post_id_by_url ); } else { return ''; } } else { $args['post_type'] = $type; $args['tax_query'] = array( array( 'taxonomy' => $taxonomy, 'field' => 'slug', 'terms' => $term, ), ); } $custom_item = new WP_Query( $args ); $output = ''; if ( $custom_item->have_posts() ) : while ( $custom_item->have_posts() ) : $custom_item->the_post(); $output .= '<div class="custom_homepage_block">'; if ( ! empty( $title ) ) { $output .= '<h2>' . esc_html( $title ) . '</h2>'; } $output .= '<div class="item grd">'; $output .= '<div class="image">'; if ( has_post_thumbnail() ) { $output .= '<a href="' . get_permalink() . '">' . get_the_post_thumbnail( get_the_ID(), 'large' ) . '</a>'; } $output .= '</div>'; $output .= '<div class="content">'; $output .= '<h3 class="item-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>'; $output .= '<div class="excerpt">'; if (!empty($text)) { $output .= $text; } else { $output .= get_the_excerpt(); } $output .= '</div>'; $output .= '</div>'; $output .= '</div>'; $output .= '</div>'; endwhile; wp_reset_postdata(); endif; return $output; } add_shortcode( 'show_custom_homepage_block', 'adconect_custom_homepage_block' ); // [display_homepage_menu_as_jobs_block] function adconect_display_homepage_menu_as_jobs_block_shortcode() { $menu_name = 'homepage-menu'; $locations = get_nav_menu_locations(); if ( isset( $locations[ $menu_name ] ) ) { $menu_id = $locations[ $menu_name ]; $menu_items = wp_get_nav_menu_items( $menu_id ); if ( $menu_items && ! is_wp_error( $menu_items ) ) { $output = '<div class="homepage_jobs_block grd">'; $i = 1; foreach ( $menu_items as $item ) { $title = esc_html( $item->title ); $url = esc_url( $item->url ); $description = esc_html( $item->description ); $output .= '<div><div class="title"><span>0' . $i . '.</span><a href="' . $url . '">' . $title . '</a></div>'; $output .= '<div class="description">' . $description . '</div>'; $output .= '</div>'; $i++; } $output .= '</div>'; return $output; } else { return '<p>' . esc_html__( 'Το μενού "HomePage Menu" δεν βρέθηκε ή είναι κενό.', 'adconect' ) . '</p>'; } } else { return '<p>' . esc_html__( 'Δεν έχει οριστεί μενού στη θέση "HomePage Menu".', 'adconect' ) . '</p>'; } } add_shortcode( 'display_homepage_menu_as_jobs_block', 'adconect_display_homepage_menu_as_jobs_block_shortcode' ); // [insertPage id="1"] function adconect_register_widget_replacement_cpt() { register_post_type('custom_widget', [ 'label' => 'Custom Widgets', 'public' => false, 'show_ui' => true, 'supports' => ['title', 'editor', 'revisions'], 'show_in_rest' => true, 'capability_type' => 'page', ]); } add_action('init', 'adconect_register_widget_replacement_cpt'); function adconect_show_content_by_id_shortcode($atts) { $atts = shortcode_atts( array( 'id' => '', ), $atts, 'show_content_by_id' ); if (empty($atts['id'])) { return '<p class="content-id-error">Παρακαλώ δώστε ένα έγκυρο ID.</p>'; } $post = get_post($atts['id']); if (!$post) { return '<p class="content-id-error">Δεν βρέθηκε περιεχόμενο με αυτό το ID.</p>'; } return apply_filters('the_content', $post->post_content); } add_shortcode('insertPage', 'adconect_show_content_by_id_shortcode'); // [display_article_links] function adconect_display_repeater_links_shortcode() { $post_id = get_the_ID(); // Έλεγχος αν υπάρχει η συνάρτηση (για αποφυγή Fatal Error αν κλείσει το ACF/SCF) if ( ! function_exists('get_field') ) { return ''; } $rows = get_field('article_link', $post_id); if( $rows ) { $output = '<div class="links_in_article"><h4>Περιηγηθείτε στο διαδίκτυο:</h4> <ul class="article-links-list">'; foreach( $rows as $row ) { $url = isset( $row['url'] ) ? esc_url( $row['url'] ) : ''; $title = isset( $row['title_for_url'] ) && !empty($row['title_for_url']) ? esc_html( $row['title_for_url'] ) : $url; $output .= '<li><a href="' . $url . '" target="_blank" rel="noopener noreferrer">' . $title . '</a></li>'; } $output .= '</ul></div>'; } else { $output = ''; } return $output; } add_shortcode( 'display_article_links', 'adconect_display_repeater_links_shortcode' ); // [show_all_meta] function adconect_show_all_meta_shortcode() { global $post; if ( ! $post || ! isset( $post->ID ) ) { return '<!-- Δεν βρέθηκε post -->'; } $meta = get_post_meta( $post->ID ); if ( empty( $meta ) ) { return '<!-- Δεν υπάρχουν custom fields -->'; } $clean_meta = []; foreach ( $meta as $key => $values ) { $clean_meta[ $key ] = count( $values ) === 1 ? maybe_unserialize( $values[0] ) : array_map( 'maybe_unserialize', $values ); } $json = wp_json_encode( $clean_meta, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ); return '<pre class="post-meta-json" style="display:none;">' . html_entity_decode( $json ) . '</pre>'; } add_shortcode( 'show_all_meta', 'adconect_show_all_meta_shortcode' );
CANCEL
Name
Type
Size
Modified
Actions
↩ ..
DIR
—
—
📄 adconect-shortcodes.php
PHP
14.4 KB
2026-05-19 14:05
EDIT