Skip to content

Instantly share code, notes, and snippets.

@sybrew
Last active August 21, 2019 05:23
Show Gist options
  • Save sybrew/59130560fcbeb98f7580dc11c54ba174 to your computer and use it in GitHub Desktop.
Save sybrew/59130560fcbeb98f7580dc11c54ba174 to your computer and use it in GitHub Desktop.
Adjust and add SEO Bar item tests for The SEO Framework.
<?php
// Example!
/**
* Add or adjust SEO Bar items here.
*
* @since 4.0.0
* @param string $interpreter The interpreter class name.
*/
add_action( 'the_seo_framework_seo_bar', function( $interpreter ) {
/**
* This is a collector method. However, it's best to use
* `register_seo_bar_item()` and `edit_seo_bar_item()` instead.
*/
$items = $interpreter::collect_seo_bar_items();
// Don't do anything if there's a blocking redirect.
if ( ! empty( $items['redirect']['meta']['blocking'] ) ) return;
// Add a custom item:
$interpreter::register_seo_bar_item(
'something',
[
'symbol' => 'S',
'title' => \__( 'Some assessment', 'my-text-domain' ),
'status' => $interpreter::STATE_BAD,
'reason' => \__( 'Something bad happened.', 'my-text-domain' ),
'assess' => [
'something' => \__( 'Something is not right.', 'my-text-domain' ),
'else' => \__( 'Something else is not right either.', 'my-text-domain' ),
],
]
);
// Edit known items. Warning: Advanced magic! Know your PHP.
// NB: If the item isn't registered, this won't produce errors, but all changes will be voided.
$index_item = &$interpreter::edit_seo_bar_item( 'indexing' );
$index_item['status'] = $interpreter::STATE_UNKNOWN;
$index_item['reason'] = \__( 'Robots.txt blocks all crawlers.', 'my-text-domain' );
$index_item['assess'] = []; // clear all assessments... be considerate!
$index_item['assess']['plugin'] = \__( 'This is a developer site. Plugin "MyNoRobots - Robots.txt Robot Blocker" is activated.', 'my-text-domain' );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment