BP_Theme_Compat

Theme Compatibility base class.

Description

This is only intended to be extended, and is included here as a basic guide for future Theme Packs to use. BP_Legacy is a good example of extending this class.

Parameters

$properties

(Required) An array of properties describing the theme compat package.

  • 'id'
    (string) ID of the package. Must be unique.
  • 'name'
    (string) Name of the theme. This should match the name given in style.css.
  • 'version'
    (string) Theme version. Used for busting script and style browser caches.
  • 'dir'
    (string) Filesystem path of the theme.
  • 'url'
    (string) Base URL of the theme.

Source

File: bp-core/classes/class-bp-theme-compat.php

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class BP_Theme_Compat {
 
    /**
     * Template package properties, as passed to the constructor.
     *
     * @since BuddyPress 1.7.0
     * @var array
     */
    protected $_data = array();
 
    /**
     * Pass the $properties to the object on creation.
     *
     * @since BuddyPress 1.7.0
     *
     * @param array $properties Array of properties for BP_Theme_Compat.
     */
    public function __construct( Array $properties = array() ) {
        $this->_data = $properties;
    }
 
    /**
     * Set up the BuddyPress-specific theme compat methods.
     *
     * Themes should use this method in their constructor.
     *
     * @since BuddyPress 1.7.0
     */
    protected function start() {
        // Sanity check.
        if ( ! bp_use_theme_compat_with_current_theme() ) {
            return;
        }
 
        // Setup methods.
        $this->setup_globals();
        $this->setup_actions();
    }
 
    /**
     * Set up global data for your template package.
     *
     * Meant to be overridden in your class. See
     * {@link BP_Legacy::setup_globals()} for an example.
     *
     * @since BuddyPress 1.7.0
     */
    protected function setup_globals() {}
 
    /**
     * Set up theme hooks for your template package.
     *
     * Meant to be overridden in your class. See
     * {@link BP_Legacy::setup_actions()} for an example.
     *
     * @since BuddyPress 1.7.0
     */
    protected function setup_actions() {}
 
    /**
     * Set a theme's property.
     *
     * @since BuddyPress 1.7.0
     *
     * @param string $property Property name.
     * @param mixed  $value    Property value.
     * @return bool True on success, false on failure.
     */
    public function __set( $property, $value ) {
        return $this->_data[$property] = $value;
    }
 
    /**
     * Get a theme's property.
     *
     * @since BuddyPress 1.7.0
     *
     * @param string $property Property name.
     * @return mixed The value of the property if it exists, otherwise an
     *               empty string.
     */
    public function __get( $property ) {
        return array_key_exists( $property, $this->_data ) ? $this->_data[$property] : '';
    }
}

Changelog

Changelog
Version Description
BuddyPress 1.7.0 Introduced.

Methods

  • __construct — Pass the $properties to the object on creation.
  • __get — Get a theme's property.
  • __set — Set a theme's property.
  • setup_actions — Set up theme hooks for your template package.
  • setup_globals — Set up global data for your template package.
  • start — Set up the BuddyPress-specific theme compat methods.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.