Site Perspectives

The Treeline plugin has some useful hooks for developers to use to further enhance its functionality.

siteperspectives_subheader_left

TYPE ⇢ Action

This action fires inside the left side of the white subheader bar, after the page title, on every Site Perspectives admin tab. Use it to add buttons or notices. The active tab slug is passed so you can limit output to one tab (for example site-perspectives-settings for the Settings tab).

Example Usage

PHP
/**
 * Add a link next to the title on the Settings tab only.
 *
 * @param string $active_page The slug of the active tab.
 */
add_action( 'siteperspectives_subheader_left', function( $active_page ) {
    if ( $active_page !== 'site-perspectives-settings' ) {
        return;
    }

    echo '<a class="siteperspectives-button" href="' . esc_url( admin_url( 'tools.php' ) ) . '">' . esc_html__( 'Tools', 'your-text-domain' ) . '</a>';
} );

siteperspectives_subheader_right

TYPE ⇢ Action

This action fires inside the right side of the subheader bar, on every Site Perspectives admin tab. The plugin uses it for the Frontend toolbar and the version, How-To Guide and Support Forum links. Use the priority to place your output before (lower than 10) or after (higher than 10) the plugin’s own items.

Example Usage

PHP
/**
 * Add a button to the right side of every tab.
 *
 * @param string $active_page The slug of the active tab.
 */
add_action( 'siteperspectives_subheader_right', function( $active_page ) {
    echo '<a class="siteperspectives-button" href="' . esc_url( home_url( '/' ) ) . '" target="_blank" rel="noopener">' . esc_html__( 'View Site', 'your-text-domain' ) . '</a>';
}, 20 );

TYPE ⇢ Filter

This filter allows developers to change the logo URL shown in the plugin header when no custom logo has been set in Settings. A logo chosen in Settings still takes priority.

Example Usage

PHP
/**
 * Replace the default header logo.
 *
 * @param string $url The default logo URL.
 *
 * @return string Modified logo URL.
 */
add_filter( 'siteperspectives_default_logo', function( $url ) {
    return get_stylesheet_directory_uri() . '/images/perspectives-logo.png';
} );

siteperspectives_theme_colors

TYPE ⇢ Filter

This filter allows developers to override the colors of the plugin’s admin header and buttons. It returns an empty array by default, so the plugin’s own colors are used. If Admin Help Docs is active, the built-in integration uses this filter to match its color scheme. Any key you leave out keeps its default.

Accepted keys: header-bg, header-font, header-tab, header-tab-link, accent, button, button-font, button-hover.

Example Usage

PHP
/**
 * Match the plugin header to a brand color scheme.
 *
 * @param array $colors Color overrides, keyed by name.
 *
 * @return array Modified colors.
 */
add_filter( 'siteperspectives_theme_colors', function( $colors ) {
    $colors[ 'header-bg' ]   = '#1d2327';
    $colors[ 'header-font' ] = '#ffffff';
    $colors[ 'button' ]      = '#2271b1';
    $colors[ 'button-font' ] = '#ffffff';
    $colors[ 'button-hover' ] = '#135e96';

    return $colors;
} );

siteperspectives_color_themes

TYPE ⇢ Filter

This filter allows developers to add, remove or change the color themes offered on the Shortcode tab. Each theme has a label and a colors array containing card_bg, border, title, font, link, link_hover and accent. The frontend theme (“Same as Frontend Tab”) is added after this filter’s input is built, so it appears first in the list.

Example Usage

PHP
/**
 * Add a custom theme and remove a built-in one.
 *
 * @param array $themes Themes, keyed by slug.
 *
 * @return array Modified themes.
 */
add_filter( 'siteperspectives_color_themes', function( $themes ) {
    // Remove a built-in theme
    unset( $themes[ 'mono' ] );

    // Add a custom theme
    $themes[ 'brand' ] = [
        'label'  => __( 'Brand', 'your-text-domain' ),
        'colors' => [
            'card_bg'    => '#FFFFFF',
            'border'     => '#D9E2EC',
            'title'      => '#102A43',
            'font'       => '#486581',
            'link'       => '#0B69A3',
            'link_hover' => '#102A43',
            'accent'     => '#0B69A3',
        ],
    ];

    return $themes;
} );

siteperspectives_dashicons

TYPE ⇢ Filter

This filter allows developers to modify the list of Dashicons that can be chosen in the icon picker. Values are icon slugs without the dashicons- prefix. Duplicates are removed and the list is sorted automatically.

Example Usage

PHP
/**
 * Remove brand icons from the picker and add a newer icon.
 *
 * @param array $dashicons Icon slugs, without the dashicons- prefix.
 *
 * @return array Modified icon slugs.
 */
add_filter( 'siteperspectives_dashicons', function( $dashicons ) {
    // Remove social brand icons
    $remove = [ 'facebook', 'facebook-alt', 'twitter', 'linkedin', 'pinterest' ];
    $dashicons = array_diff( $dashicons, $remove );

    // Add an icon from a newer WordPress version
    $dashicons[] = 'database';

    return $dashicons;
} );

siteperspectives_default_menu_id

TYPE ⇢ Filter

This filter allows developers to choose which navigation menu seeds the Frontend tree the first time it is built. By default the plugin looks for a menu assigned to a location named primary, main, header or menu-1, then falls back to the first assigned menu. Return 0 to start with an empty tree.

Example Usage

PHP
/**
 * Seed the Frontend tree from a specific menu.
 *
 * @param int $menu_id The detected menu ID.
 *
 * @return int Modified menu ID.
 */
add_filter( 'siteperspectives_default_menu_id', function( $menu_id ) {
    // Use a menu by name
    $menu = wp_get_nav_menu_object( 'Footer Menu' );

    if ( $menu ) {
        return (int) $menu->term_id;
    }

    // Otherwise keep the detected menu
    return $menu_id;
} );

siteperspectives_utility_post_types

TYPE ⇢ Filter

This filter allows developers to change which post types get the Utility Page feature (the Quick Edit checkbox, the bulk actions and the Utility and Non-Utility list views). It defaults to page. Post types that do not exist are removed automatically.

Example Usage

PHP
/**
 * Enable utility page flags on pages and a custom post type.
 *
 * @param array $post_types The post types that get the feature.
 *
 * @return array Modified post types.
 */
add_filter( 'siteperspectives_utility_post_types', function( $post_types ) {
    // Add a custom post type
    $post_types[] = 'landing_page';

    // Or replace the list entirely
    // $post_types = [ 'landing_page' ];

    return $post_types;
} );

siteperspectives_utility_suggestions

TYPE ⇢ Filter

This filter allows developers to modify the suggested utility pages offered when adding items to the Frontend tree: Login, Register, Lost Password, Privacy Policy, Posts Page and Search Results. Each suggestion is a tree node array keyed by a unique slug. You can remove suggestions or add your own.

Example Usage

PHP
/**
 * Remove one suggestion and add a custom link.
 *
 * @param array $suggestions Suggested nodes, keyed by slug.
 *
 * @return array Modified suggestions.
 */
add_filter( 'siteperspectives_utility_suggestions', function( $suggestions ) {
    // Remove a suggestion
    unset( $suggestions[ 'search' ] );

    // Add a custom link suggestion
    $suggestions[ 'my_account' ] = [
        'id'          => 'my_account',
        'type'        => 'custom',
        'post_id'     => 0,
        'title'       => __( 'My Account', 'your-text-domain' ),
        'url'         => home_url( '/my-account/' ),
        'icon'        => '',
        'color'       => '',
        'hidden'      => false,
        'hide_public' => false,
        'children'    => [],
    ];

    return $suggestions;
} );

siteperspectives_meta_value

TYPE ⇢ Filter

This filter allows developers to change a custom meta value before it is shown as data in the Frontend tree or the sitemap shortcode. Use it to format dates, translate stored IDs into names or hide values. The result is stripped of tags and shortened to 120 characters after the filter runs. Arrays and objects are converted to JSON.

Example Usage

PHP
/**
 * Format a date meta value and hide another on the public sitemap.
 *
 * @param mixed  $value   The raw meta value.
 * @param string $key     The meta key.
 * @param int    $post_id The post ID.
 * @param bool   $public  True when rendering the public shortcode, false in the admin.
 *
 * @return mixed Modified value.
 */
add_filter( 'siteperspectives_meta_value', function( $value, $key, $post_id, $public ) {
    // Format a date
    if ( $key === 'event_date' && $value ) {
        return wp_date( get_option( 'date_format' ), strtotime( $value ) );
    }

    // Hide a value from visitors only
    if ( $public && $key === 'internal_note' ) {
        return '';
    }

    return $value;
}, 10, 4 );

siteperspectives_public_protected_meta

TYPE ⇢ Filter

This filter allows developers to allow specific protected meta keys (keys that start with an underscore) to be shown as data on the public sitemap shortcode. Protected meta is hidden from visitors by default. Only add keys that are safe to show publicly.

Example Usage

PHP
/**
 * Allow a protected meta key to appear on the public sitemap.
 *
 * @param array $keys Allowed protected meta keys.
 *
 * @return array Modified keys.
 */
add_filter( 'siteperspectives_public_protected_meta', function( $keys ) {
    $keys[] = '_product_sku';

    return $keys;
} );

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.