Skip to content

Extending SEO Auto Linker

Christopher Davis edited this page Sep 3, 2012 · 2 revisions

SEO Auto Linker comes packed with quite a few filters, making extending the plugin quite a bit easier. The purpose of this page is to explain the design of SEO Auto Linker as well as give you some "how to" examples.

The Plugin's Design

SEO Auto Linker uses a custom post type to store all of the link data and provide a nice UI for editing links. The post type's name is seoal_container, it's not public and not accessible from the front end unless you create a custom WP_Query or use get posts.

The post type key is stored in a class constant of SEO_Auto_Linker_Base named POST_TYPE. Rather than using a string to identify the post type in your own code, it might be better to use the class constant:

<?php
$links = get_posts(array(
    'post_type'     => SEO_Auto_Linker_Base::POST_TYPE,
    // ...
));

As you might suspect, the links being a post type means that nearly everything in the admin UI for them is a customizable.

You can add meta boxes to associate additional data with links or even remove the default SEO Auto Linker meta boxes. You could add (or remove) columns from the links list table.

Doing these sorts of things are well documented elsewhere.

Extending SEO_Auto_Linker_Base

Every class defined in this plugin uses SEO_Auto_Linker_Base as its parent class. You can do so to.

First off, there's a safe action that you hook into to load any classes that extend SEO_Auto_Linker_Base:

<?php
add_action('seoal_loaded', 'myplugin_load');
function myplugin_load()
{
    require '/path/to/file/container/seo-auto-linker/subclass.php'
}

Your subclass will have access to quite a few handy methods. You can read the source for more info, but here's a crash course:

<?php
class MyPluginClass extends SEO_Auto_Linker_Base
{
    function example()
    {
        // The post type
        self::POST_TYPE
        // The option name, useful for additin addition fields to the
        // settings page
        self::SETTING
        // The meta key prefix (or namespace, if you prefer) for this plugin
        self::PREFIX
        // Get a meta key, add the prefix to it
        self::get_key('url'); // return seoal_url
        // Get a meta value -- mostly useful in the admin area. No need to
        // prefix the key, the method will take care of it.
        self::get_meta('key', 'default_value');
        // Echo out a meta key, escaping it first
        self::meta('url', 'attr'); // echos the meta value for `seoal_url` running it through `esc_attr` first
        // Echo out a meta key, running it through `esc_attr` first
        self::key('url'); // echo `seoal_url`
    }
}
Clone this wiki locally