array( 'post_title' => 'Title', 'post_excerpt' => 'Excerpt', 'post_content' => 'Content', 'post_date' => 'Date', 'post_modified' => 'Last modified', 'permalink' => 'URL', 'post_id' => 'ID', 'featured_image' => 'Featured image', 'featured_image_alt' => 'Featured image alt', 'post_terms' => 'Terms', 'comments_count' => 'Comments count', 'reading_time' => 'Reading time', 'post_meta' => 'Custom field', ), 'author' => array( 'author_name' => 'Author name', 'author_bio' => 'Author bio', 'author_avatar' => 'Author avatar', 'author_url' => 'Author archive URL', ), 'site' => array( 'site_title' => 'Site title', 'site_tagline' => 'Tagline', 'site_url' => 'Home URL', 'site_logo' => 'Site logo', 'page_title' => 'Document title', 'current_date' => 'Current date', 'current_year' => 'Current year', ), 'archive' => array( 'archive_title' => 'Archive title', 'archive_desc' => 'Archive description', 'search_query' => 'Search query', ), 'user' => array( 'user_name' => 'Display name', 'user_first_name' => 'First name', 'user_email' => 'Email', ), 'other' => array( 'request_param' => 'URL parameter', 'shortcode' => 'Shortcode output', ), ); if ( function_exists( 'get_field' ) ) { $c['post']['acf'] = 'ACF field'; } if ( Options::has_woo() ) { $c['woocommerce'] = array( 'woo_price' => 'Price', 'woo_sku' => 'SKU', 'woo_stock' => 'Stock status', 'woo_rating' => 'Rating', 'woo_sale_badge' => 'Sale percentage', ); } return apply_filters( 'akram_dynamic_catalog', $c ); } public static function value( $tag, array $o ) { $id = get_the_ID(); switch ( $tag ) { case 'post_title': return $id ? get_the_title( $id ) : ''; case 'post_excerpt': return $id ? wp_trim_words( get_the_excerpt( $id ), (int) ( $o['words'] ?? 55 ) ) : ''; case 'post_content': return $id ? apply_filters( 'the_content', get_post_field( 'post_content', $id ) ) : ''; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- core or third-party hook. case 'post_date': return $id ? get_the_date( $o['format'] ?? '', $id ) : ''; case 'post_modified': return $id ? get_the_modified_date( $o['format'] ?? '', $id ) : ''; case 'permalink': return $id ? get_permalink( $id ) : home_url( add_query_arg( array() ) ); case 'post_id': return (string) $id; case 'featured_image': $url = $id ? get_the_post_thumbnail_url( $id, $o['size'] ?? 'large' ) : ''; return $url ?: ''; case 'featured_image_alt': $tid = $id ? get_post_thumbnail_id( $id ) : 0; return $tid ? get_post_meta( $tid, '_wp_attachment_image_alt', true ) : ''; case 'post_terms': $terms = $id ? get_the_terms( $id, sanitize_key( $o['tax'] ?? 'category' ) ) : array(); return is_array( $terms ) ? implode( (string) ( $o['sep'] ?? ', ' ), wp_list_pluck( $terms, 'name' ) ) : ''; case 'comments_count': return $id ? (string) get_comments_number( $id ) : '0'; case 'reading_time': $words = $id ? str_word_count( wp_strip_all_tags( get_post_field( 'post_content', $id ) ) ) : 0; /* translators: %d: minutes */ return sprintf( _n( '%d min read', '%d min read', max( 1, (int) ceil( $words / 220 ) ), 'akram' ), max( 1, (int) ceil( $words / 220 ) ) ); case 'post_meta': $v = $id && ! empty( $o['key'] ) && ! is_protected_meta( (string) $o['key'], 'post' ) ? get_post_meta( $id, sanitize_text_field( $o['key'] ), true ) : ''; return is_scalar( $v ) ? (string) $v : ''; case 'acf': if ( ! function_exists( 'get_field' ) || empty( $o['key'] ) ) { return ''; } $v = get_field( sanitize_text_field( $o['key'] ), $id ); if ( is_array( $v ) ) { return $v['url'] ?? ( $v['title'] ?? implode( ', ', array_filter( $v, 'is_scalar' ) ) ); } return (string) $v; case 'author_name': $a = (int) get_post_field( 'post_author', $id ); return $a ? get_the_author_meta( 'display_name', $a ) : ''; case 'author_bio': return get_the_author_meta( 'description', (int) get_post_field( 'post_author', $id ) ); case 'author_avatar': return get_avatar_url( (int) get_post_field( 'post_author', $id ), array( 'size' => (int) ( $o['size'] ?? 96 ) ) ); case 'author_url': return get_author_posts_url( (int) get_post_field( 'post_author', $id ) ); case 'site_title': return get_bloginfo( 'name' ); case 'site_tagline': return get_bloginfo( 'description' ); case 'site_url': return home_url( '/' ); case 'site_logo': $logo = (int) get_theme_mod( 'custom_logo' ); return $logo ? wp_get_attachment_image_url( $logo, 'full' ) : ''; case 'page_title': return wp_get_document_title(); case 'current_date': return wp_date( $o['format'] ?? get_option( 'date_format' ) ); case 'current_year': return wp_date( 'Y' ); case 'archive_title': return wp_strip_all_tags( get_the_archive_title() ); case 'archive_desc': return wp_strip_all_tags( get_the_archive_description() ); case 'search_query': return get_search_query(); case 'user_name': return is_user_logged_in() ? wp_get_current_user()->display_name : ''; case 'user_first_name': return is_user_logged_in() ? wp_get_current_user()->first_name : ''; case 'user_email': return is_user_logged_in() ? wp_get_current_user()->user_email : ''; case 'request_param': $k = sanitize_key( $o['key'] ?? '' ); return $k && isset( $_GET[ $k ] ) ? sanitize_text_field( wp_unslash( $_GET[ $k ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only request value; it changes nothing and is sanitised. case 'shortcode': return ! empty( $o['code'] ) ? do_shortcode( (string) $o['code'] ) : ''; case 'woo_price': case 'woo_sku': case 'woo_stock': case 'woo_rating': case 'woo_sale_badge': if ( ! function_exists( 'wc_get_product' ) ) { return ''; } $p = wc_get_product( $id ); if ( ! $p ) { return ''; } if ( 'woo_price' === $tag ) { return wp_strip_all_tags( wc_price( (float) $p->get_price() ) ); } if ( 'woo_sku' === $tag ) { return $p->get_sku(); } if ( 'woo_stock' === $tag ) { return $p->is_in_stock() ? __( 'In stock', 'akram' ) : __( 'Out of stock', 'akram' ); } if ( 'woo_rating' === $tag ) { return (string) $p->get_average_rating(); } $reg = (float) $p->get_regular_price(); $sale = (float) $p->get_sale_price(); return $p->is_on_sale() && $reg > 0 ? '-' . round( ( 1 - $sale / $reg ) * 100 ) . '%' : ''; } return (string) apply_filters( 'akram_dynamic_value', '', $tag, $o, $id ); } }