/** * This is a helper function that returns the post's or page's description. * * Important: MUST return sanitized data, unless this plugin has sanitized the data before storing to db. * */ function amt_get_content_description($post, $auto = true) { // By default, if a custom description has not been entered by the user in the // metabox, a description is autogenerated. To stop this automatic generation // of a description and return only the description that has been entered manually, // set $auto to false via the following filter. $auto = apply_filters('amt_generate_description_if_no_manual_data', $auto); $content_description = ''; if (is_singular() || amt_is_static_front_page() || amt_is_static_home()) { // TODO: check if this check is needed at all! $desc_fld_content = amt_get_post_meta_description($post->ID); if (!empty($desc_fld_content)) { // If there is a custom field, use it $content_description = $desc_fld_content; } else { // Else, use the post's excerpt. Valid for Pages too. if ($auto) { // The generated excerpt should already be sanitized. $content_description = amt_get_the_excerpt($post); } } } return $content_description; }
/** * This is a helper function that returns the post's or page's description. * * Important: MUST return sanitized data, unless this plugin has sanitized the data before storing to db. * */ function amt_get_content_description($post, $auto = true) { // Non persistent object cache $amtcache_key = amt_get_amtcache_key('amt_cache_get_content_description', $post); $content_description = wp_cache_get($amtcache_key, $group = 'add-meta-tags'); if ($content_description !== false) { return $content_description; } // By default, if a custom description has not been entered by the user in the // metabox, a description is autogenerated. To stop this automatic generation // of a description and return only the description that has been entered manually, // set $auto to false via the following filter. $auto = apply_filters('amt_generate_description_if_no_manual_data', $auto); $content_description = ''; if (is_singular() || amt_is_static_front_page() || amt_is_static_home()) { // TODO: check if this check is needed at all! $desc_fld_content = amt_get_post_meta_description($post->ID); if (!empty($desc_fld_content)) { // If there is a custom field, use it $content_description = $desc_fld_content; } else { // Else, use the post's excerpt. Valid for Pages too. if ($auto) { // The generated excerpt should already be sanitized. $content_description = amt_get_the_excerpt($post); } } } // Non persistent object cache // Cache even empty wp_cache_add($amtcache_key, $content_description, $group = 'add-meta-tags'); // Allow filtering of the final description // NOTE: qtranslate-X needs to pass through __() at this point. $content_description = apply_filters('amt_get_content_description', $content_description, $post); return $content_description; }