ID); // 1. Manual SEO title if (!empty($meta['title'])) { return ['value' => $meta['title'], 'source' => self::SOURCE_EXPLICIT]; } // 2. Post title (Auto) $title = get_the_title($post); $suffix = \ActiveTwist\SEO\Settings\Options::get('seo_title_suffix', get_bloginfo('name')); if (!empty($suffix)) { return ['value' => $title . ' - ' . $suffix, 'source' => self::SOURCE_AUTO]; } return ['value' => $title, 'source' => self::SOURCE_AUTO]; } public static function get_seo_description($post) { $result = self::get_seo_description_with_source($post); return $result['value']; } public static function get_seo_description_with_source($post) { $meta = self::get_post_meta($post->ID); // 1. Manual SEO description if (!empty($meta['description'])) { return ['value' => $meta['description'], 'source' => self::SOURCE_EXPLICIT]; } // 2. Post excerpt if (has_excerpt($post)) { return ['value' => get_the_excerpt($post), 'source' => self::SOURCE_AUTO]; } // 3. Global Default Description (Fallback) $default_desc = \ActiveTwist\SEO\Settings\Options::get('default_description'); if (!empty($default_desc)) { return ['value' => $default_desc, 'source' => self::SOURCE_INHERITED]; } // 4. Auto-generated summary (HTML stripped, ~25 words) $content = strip_shortcodes($post->post_content); $content = wp_strip_all_tags($content); $result = wp_trim_words($content, 25); if (!empty($result)) { return ['value' => $result, 'source' => self::SOURCE_AUTO]; } return ['value' => '', 'source' => self::SOURCE_MISSING]; } public static function get_canonical_url($post) { $result = self::get_canonical_url_with_source($post); return $result['value']; } public static function get_canonical_url_with_source($post) { $meta = self::get_post_meta($post->ID); // 1. Manual canonical override if (!empty($meta['canonical'])) { return ['value' => $meta['canonical'], 'source' => self::SOURCE_EXPLICIT]; } // 2. get_permalink() return ['value' => get_permalink($post), 'source' => self::SOURCE_AUTO]; } public static function get_robots($post) { $result = self::get_robots_with_source($post); return $result['value']; } public static function get_robots_with_source($post) { $meta = self::get_post_meta($post->ID); // 1. Manual robots if (!empty($meta['robots'])) { return ['value' => $meta['robots'], 'source' => self::SOURCE_EXPLICIT]; } // 2. Default return ['value' => 'index, follow', 'source' => self::SOURCE_AUTO]; } public static function get_og_title($post) { $result = self::get_og_title_with_source($post); return $result['value']; } public static function get_og_title_with_source($post) { $meta = self::get_post_meta($post->ID); if (!empty($meta['og_title'])) { return ['value' => $meta['og_title'], 'source' => self::SOURCE_EXPLICIT]; } // Inherit from SEO Title $seo_title = self::get_seo_title_with_source($post); return ['value' => $seo_title['value'], 'source' => self::SOURCE_INHERITED]; } public static function get_og_description($post) { $result = self::get_og_description_with_source($post); return $result['value']; } public static function get_og_description_with_source($post) { $meta = self::get_post_meta($post->ID); if (!empty($meta['og_description'])) { return ['value' => $meta['og_description'], 'source' => self::SOURCE_EXPLICIT]; } // Inherit from SEO Description $seo_desc = self::get_seo_description_with_source($post); return ['value' => $seo_desc['value'], 'source' => self::SOURCE_INHERITED]; } public static function get_og_image($post) { $result = self::get_og_image_with_source($post); return $result['value']; } public static function get_og_image_with_source($post) { $meta = self::get_post_meta($post->ID); // 1. Manual OG image if (!empty($meta['og_image'])) { return ['value' => $meta['og_image'], 'source' => self::SOURCE_EXPLICIT]; } // 2. Featured image if (has_post_thumbnail($post)) { return ['value' => get_the_post_thumbnail_url($post, 'full'), 'source' => self::SOURCE_AUTO]; } // 3. Global Default $default_image = \ActiveTwist\SEO\Settings\Options::get('default_og_image'); if (!empty($default_image)) { return ['value' => $default_image, 'source' => self::SOURCE_INHERITED]; } return ['value' => '', 'source' => self::SOURCE_MISSING]; } public static function get_twitter_title($post) { $result = self::get_twitter_title_with_source($post); return $result['value']; } public static function get_twitter_title_with_source($post) { $meta = self::get_post_meta($post->ID); if (!empty($meta['twitter_title'])) { return ['value' => $meta['twitter_title'], 'source' => self::SOURCE_EXPLICIT]; } // Inherit from OG Title $og_title = self::get_og_title_with_source($post); return ['value' => $og_title['value'], 'source' => self::SOURCE_INHERITED]; } public static function get_twitter_description($post) { $result = self::get_twitter_description_with_source($post); return $result['value']; } public static function get_twitter_description_with_source($post) { $meta = self::get_post_meta($post->ID); if (!empty($meta['twitter_description'])) { return ['value' => $meta['twitter_description'], 'source' => self::SOURCE_EXPLICIT]; } // Inherit from OG Description $og_desc = self::get_og_description_with_source($post); return ['value' => $og_desc['value'], 'source' => self::SOURCE_INHERITED]; } public static function get_twitter_image($post) { $result = self::get_twitter_image_with_source($post); return $result['value']; } public static function get_twitter_image_with_source($post) { $meta = self::get_post_meta($post->ID); if (!empty($meta['twitter_image'])) { return ['value' => $meta['twitter_image'], 'source' => self::SOURCE_EXPLICIT]; } // Inherit from OG Image $og_img = self::get_og_image_with_source($post); return ['value' => $og_img['value'], 'source' => self::SOURCE_INHERITED]; } }