vate function get_woo_product_data() { global $post; $data = []; $product = \wc_get_product( $post ); $data[ __( 'Price', 'rank-math' ) ] = $this->get_product_price( $product ); $data[ __( 'Availability', 'rank-math' ) ] = $this->get_product_availability( $product ); return $data; } /** * Get Slack data for EDD download. * * @return array */ private function get_edd_product_data() { global $post; $data = []; $data[ __( 'Price', 'rank-math' ) ] = wp_strip_all_tags( \edd_price( $post->ID, false ) ); return $data; } /** * Get availability of product. * * @param object $product Product object. * * @return string */ private function get_product_availability( $product ) { $product_availability = $product->get_availability(); $availability_text = isset( $product_availability['availability'] ) ? $product_availability['availability'] : ''; if ( ! $availability_text ) { return __( 'In stock', 'rank-math' ); } return $availability_text; } /** * Get price of WooCommerce product. * Gets price range for variable products. * * @param object $product Product object. * * @return string */ private function get_product_price( $product ) { $price = wp_strip_all_tags( \wc_price( $product->get_price() ) ); if ( $product->is_type( 'variable' ) ) { $lowest = \wc_format_decimal( $product->get_variation_price( 'min', false ), \wc_get_price_decimals() ); $highest = \wc_format_decimal( $product->get_variation_price( 'max', false ), \wc_get_price_decimals() ); $price = wp_strip_all_tags( \wc_price( $lowest ) . ' - ' . \wc_price( $highest ) ); if ( $lowest === $highest ) { $price = wp_strip_all_tags( \wc_price( $lowest ) ); } } return $price; } /** * Get Slack data for post. * * @return array */ private function get_post_data() { global $post; $data = []; $data[ __( 'Written by', 'rank-math' ) ] = get_the_author(); $data[ __( 'Time to read', 'rank-math' ) ] = $this->calculate_time_to_read( $post ); return $data; } /** * Get Slack data for page. * * @return array */ private function get_page_data() { global $post; $data = []; $data[ __( 'Time to read', 'rank-math' ) ] = $this->calculate_time_to_read( $post ); return $data; } /** * Calculate the time to read for the post. * * @param object $post Post object. * * @return string */ private function calculate_time_to_read( $post ) { /** * Filter: 'rank_math/frontend/time_to_read_content' - Change the text to calculate the time to read. */ $content = $this->do_filter( 'frontend/time_to_read_content', wp_strip_all_tags( $post->post_content ) ); /** * Filter: 'rank_math/frontend/time_to_read_wpm' - Change the words per minute to calculate the time to read. */ $words_per_minute = absint( $this->do_filter( 'frontend/time_to_read_wpm', 200 ) ); $words = str_word_count( $content ); $minutes = floor( $words / $words_per_minute ); if ( $minutes > 0 ) { return sprintf( /* translators: %d: minutes */ _n( '%d minute', '%d minutes', $minutes, 'rank-math' ), $minutes ); } return __( 'Less than a minute', 'rank-math' ); } /** * Get Slack data for term. * * @return array */ private function get_term_data() { global $wp_query; $data = []; $term = $wp_query->get_queried_object(); if ( ! $term ) { return $data; } $label = __( 'Items', 'rank-math' ); $post_type_object = get_post_type_object( get_post_type() ); if ( is_object( $post_type_object ) && isset( $post_type_object->labels->name ) ) { $label = $post_type_object->labels->name; } $data[ $label ] = ( ! empty( $term->category_count ) ? $term->category_count : $term->count ); return $data; } /** * Get Slack data for author. * * @return array */ private function get_author_data() { global $wp_query; $data = []; $author = $wp_query->get_queried_object(); if ( ! $author ) { return $data; } $data[ __( 'Name', 'rank-math' ) ] = $author->display_name; $data[ __( 'Posts', 'rank-math' ) ] = count_user_posts( $author->ID ); return $data; } }