>meta->title->helpers->prepare( $metaData->twitter_title ); } return $title ? $title : aioseo()->social->facebook->getTitle( $post ); } /** * Returns the Twitter description for the current page. * * @since 4.0.0 * * @param \WP_Post|integer $post The post object or ID (optional). * @return string The Twitter description. */ public function getDescription( $post = null ) { if ( is_home() && 'posts' === get_option( 'show_on_front' ) ) { $description = aioseo()->meta->description->helpers->prepare( aioseo()->options->social->twitter->homePage->description ); return $description ? $description : aioseo()->social->facebook->getDescription( $post ); } $post = aioseo()->helpers->getPost( $post ); $metaData = aioseo()->meta->metaData->getMetaData( $post ); if ( ! empty( $metaData->twitter_use_og ) ) { return aioseo()->social->facebook->getDescription( $post ); } $description = ''; if ( ! empty( $metaData->twitter_description ) ) { $description = aioseo()->meta->description->helpers->prepare( $metaData->twitter_description ); } return $description ? $description : aioseo()->social->facebook->getDescription( $post ); } /** * Prepare twitter username for public display. * * We do things like strip out the URL, etc and return just (at)username. * At the moment, we'll check for 1 of 3 things... (at)username, username, and https://twitter.com/username. * * @since 4.0.0 * * @param string $profile Twitter username. * @param boolean $includeAt Whether or not ot include the @ sign. * @return string Full Twitter username. */ public function prepareUsername( $profile, $includeAt = true ) { if ( ! $profile ) { return $profile; } $profile = (string) $profile; if ( preg_match( '/^(\@)?[A-Za-z0-9_]+$/', $profile ) ) { if ( '@' !== $profile[0] && $includeAt ) { $profile = '@' . $profile; } elseif ( '@' === $profile[0] && ! $includeAt ) { $profile = ltrim( $profile, '@' ); } } elseif ( strpos( $profile, 'twitter.com' ) ) { $profile = esc_url( $profile ); // extract the twitter username from the url. $parsedTwitterProfile = wp_parse_url( $profile ); $path = $parsedTwitterProfile['path']; $pathParts = explode( '/', $path ); $profile = $pathParts[1]; if ( $profile ) { if ( '@' !== $profile[0] && $includeAt ) { $profile = '@' . $profile; } elseif ( '@' === $profile[0] && ! $includeAt ) { $profile = ltrim( $profile, '@' ); } } } return $profile; } /** * Get additional twitter data. * * @since 4.0.0 * * @return array An array of additional twitter data. */ public function getAdditionalData() { if ( ! aioseo()->options->social->twitter->general->additionalData ) { return []; } $data = []; $post = aioseo()->helpers->getPost(); if ( ! is_a( $post, 'WP_Post' ) ) { return $data; } if ( $post->post_author ) { $data[] = [ 'label' => __( 'Written by', 'all-in-one-seo-pack' ), 'value' => get_the_author_meta( 'display_name', $post->post_author ) ]; } if ( ! empty( $post->post_content ) ) { $minutes = $this->getReadingTime( $post->post_content ); if ( ! empty( $minutes ) ) { $data[] = [ 'label' => __( 'Est. reading time', 'all-in-one-seo-pack' ), // Translators: 1 - The estimated reading time. 'value' => sprintf( _n( '%1$s minute', '%1$s minutes', $minutes, 'all-in-one-seo-pack' ), $minutes ) ]; } } return $data; } /** * Returns the estimated reading time for a string. * * @since 4.0.0 * * @param string $string The string to count. * @return integer The estimated reading time as an integer. */ private function getReadingTime( $string ) { $wpm = 200; $word = str_word_count( wp_strip_all_tags( $string ) ); return round( $word / $wpm ); } }