Robots Meta Decision
Determines index/follow directives based on route, filters, search terms, and content quality.
Function signature
ogDecideRobotsMeta(page_data = array(), policy = array())
Categories
- Database Integrity
Parameters
page_dataRoute, filter, search, and content-quality data used for robots policy decisions.policyCaller-approved indexing policy controls.Return value
Public-safe status string returned by the function for controller branching or logging.
- success
- message
- data
Compatibility
Existing function name, slug, path, and call order preserved; advertised metadata corrected to the actual source behavior.
Minimum PHP version: 7.4
Security notes
Use caller-owned allowlists and context-specific escaping; validate file paths, routes, email tokens, cart totals, discount rules, and tax-region rules before production use.
Code
<?php
/*
* Copyright (c) 2026 Jeffery L. Paris <jparis@phpog.com>.
* Free for personal and internal use. Paid project use requires visible credit
* to Jeffery L. Paris. Corporate use requires a paid license fee unless a
* separate written license states otherwise.
*/
/**
* Determines index/follow directives based on route, filters, search terms, and content quality.
*
* Primary use case: Thin pages, internal search, duplicate filters.
* Typical inputs: route data, content count, policy.
* Typical output: robots directive.
*
* Implementation note: Use conservative noindex on weak search/filter pages if needed.
*
* @param array $page_data Route and content quality data.
* @param array $policy Robots policy options.
* @return array Robots meta decision.
*/
function ogDecideRobotsMeta($page_data = array(), $policy = array()) {
$result = array(
'success' => false,
'message' => '',
'data' => array()
);
if (!is_array($page_data)) {
$result['message'] = 'Page data must be an array.';
return $result;
}
if (!is_array($policy)) {
$policy = array();
}
$index = true;
$follow = true;
$reasons = array();
$content_count = 0;
if (isset($page_data['content_count'])) {
$content_count = (int)$page_data['content_count'];
}
$route_type = '';
if (!empty($page_data['route_type'])) {
$route_type = trim((string)$page_data['route_type']);
}
if ($route_type == 'search') {
$index = false;
$reasons[] = 'Internal search route.';
}
if ($content_count <= 0) {
$index = false;
$reasons[] = 'No indexable content count.';
}
if (!empty($page_data['has_duplicate_filters'])) {
$index = false;
$reasons[] = 'Duplicate filter combination.';
}
if (isset($policy['force_noindex']) && $policy['force_noindex'] === true) {
$index = false;
$reasons[] = 'Policy forced noindex.';
}
if (isset($policy['nofollow']) && $policy['nofollow'] === true) {
$follow = false;
$reasons[] = 'Policy requested nofollow.';
}
if ($index) {
$index_directive = 'index';
} else {
$index_directive = 'noindex';
}
if ($follow) {
$follow_directive = 'follow';
} else {
$follow_directive = 'nofollow';
}
$directive = $index_directive . ', ' . $follow_directive;
$result['success'] = true;
$result['message'] = 'Robots directive decided.';
$result['data'] = array(
'directive' => $directive,
'index' => $index,
'follow' => $follow,
'reasons' => $reasons
);
return $result;
}