'.esc_html(get_the_title($id)).'
'.esc_html(get_the_excerpt($id)).'
View specs & compatibility['name'=>'Products','singular_name'=>'Product'],
'public'=>true,'show_ui'=>true,'show_in_rest'=>true,
'menu_icon'=>'dashicons-battery',
'supports'=>['title','editor','excerpt','thumbnail','custom-fields'],
'rewrite'=>['slug'=>'products','with_front'=>false],
'has_archive'=>'products'
]);
register_taxonomy(self::BRAND, self::TYPE, [
'labels'=>['name'=>'Brands','singular_name'=>'Brand'],
'public'=>true,'show_ui'=>true,'show_in_rest'=>true,
'rewrite'=>['slug'=>'brands','with_front'=>false],
'hierarchical'=>false
]);
register_taxonomy(self::PTYPE, self::TYPE, [
'labels'=>['name'=>'Product Types','singular_name'=>'Product Type'],
'public'=>true,'show_ui'=>true,'show_in_rest'=>true,
'rewrite'=>['slug'=>'product-types','with_front'=>false],
'hierarchical'=>true
]);
$fields = [
'model','sku','status','official_url','amazon_url','affiliate_url','image_url',
'capacity_wh','continuous_w','surge_w','battery_chemistry','solar_input_w',
'weight_lb','compatibility','not_compatible','required_cables','evidence_status',
'source_urls','best_for','index_status','replacement_for','replaced_by'
];
foreach ($fields as $f) {
register_post_meta(self::TYPE, 'bbb_'.$f, [
'type'=>'string','single'=>true,'show_in_rest'=>true,
'sanitize_callback'=>'sanitize_textarea_field',
'auth_callback'=>function(){ return current_user_can('edit_posts'); }
]);
}
}
public static function rest_fields() {}
private static function meta($id,$key){ return trim((string)get_post_meta($id,'bbb_'.$key,true)); }
private static function list_items($v){
return array_values(array_filter(array_map('trim', preg_split('/[\n|]+/', (string)$v))));
}
public static function seo_title($title) {
if (!is_singular(self::TYPE)) return $title;
$id=get_queried_object_id();
$brand = wp_get_post_terms($id,self::BRAND,['fields'=>'names']);
$brand = $brand ? $brand[0] : '';
return trim(get_the_title($id) . ($brand && stripos(get_the_title($id),$brand)===false ? ' by '.$brand : '') . ' | Specs, Compatibility & Accessories');
}
public static function seo_description($desc) {
if (!is_singular(self::TYPE)) return $desc;
$id=get_queried_object_id();
$best=self::meta($id,'best_for');
$cap=self::meta($id,'capacity_wh'); $out=self::meta($id,'continuous_w');
$bits=[];
if($cap) $bits[]=$cap.'Wh capacity';
if($out) $bits[]=$out.'W output';
if($best) $bits[]='best for '.$best;
$bits[]='compatibility, cables, accessories and buying options';
return 'See '.get_the_title($id).': '.implode(', ',$bits).'.';
}
public static function robots($robots) {
if (!is_singular(self::TYPE)) return $robots;
$v=self::meta(get_queried_object_id(),'index_status');
if ($v==='noindex') return ['noindex'=>'noindex','follow'=>'follow'];
return $robots;
}
public static function render_content($content) {
if (!is_singular(self::TYPE) || !in_the_loop() || !is_main_query()) return $content;
$id=get_the_ID();
$m=[];
foreach(['model','sku','status','official_url','amazon_url','affiliate_url','image_url','capacity_wh','continuous_w','surge_w','battery_chemistry','solar_input_w','weight_lb','compatibility','not_compatible','required_cables','evidence_status','best_for','replacement_for','replaced_by'] as $k) $m[$k]=self::meta($id,$k);
$brand = wp_get_post_terms($id,self::BRAND,['fields'=>'names']); $brand=$brand?$brand[0]:'';
$types = wp_get_post_terms($id,self::PTYPE,['fields'=>'names']); $type=$types?$types[0]:'';
$cta = $m['affiliate_url'] ?: $m['amazon_url'];
ob_start(); ?>
Verified specifications, compatibility, required cables, related accessories and buying options.'.esc_html($label).'
Product overview
Find exact models, compatible expansion batteries, solar panels, chargers, replacement batteries, kits, cables and accessories. matching records.
'.esc_html(get_the_excerpt($id)).'
View specs & compatibility