code = $code; $this->message = $message; } /** * Returns the status of a feature * * 0 is no issues * 1 is usable but there are warnngs * 2 is not usable * * @var int * @since 2.2 */ public $code; /** * Optional message to describe status code * * @var string|array * @since 2.2 */ public $message; } class EP_Feature { /** * Feature slug * * @var string * @since 2.1 */ public $slug; /** * Feature pretty title * * @var string * @since 2.1 */ public $title; /** * Optional feature default settings * * @since 2.2 * @var array */ public $default_settings = array(); /** * Contains registered callback to execute after setup * * @since 2.1 * @var callback */ public $setup_cb; /** * Contains registered callback to output feature summary in feature box * * @since 2.1 * @var callback */ public $feature_box_summary_cb; /** * Contains registered callback to output feature long description in feature box * * @since 2.1 * @var callback */ public $feature_box_long_cb; /** * Output optional extra settings fields * * @since 2.2 * @var callback */ public $feature_box_settings_cb; /** * Contains registered callback to execute after activation * * @since 2.1 * @var callback */ public $post_activation_cb; /** * True if the feature requires content reindexing after activating * * @since 2.1 * @var [type] */ public $requires_install_reindex; /** * Initiate the feature, setting all relevant instance variables * * @since 2.1 */ public function __construct( $args ) { foreach ( $args as $key => $value ) { $this->$key = $value; } do_action( 'ep_feature_create', $this ); } /** * Run on every page load for feature to set itself up * * @since 2.1 */ public function setup() { if ( ! empty( $this->setup_cb ) ) { call_user_func( $this->setup_cb, $this ); } do_action( 'ep_feature_setup', $this->slug, $this ); } /** * Returns requirements status of feature * * @since 2.2 * @return EP_Feature_Requirements_Status */ public function requirements_status() { $status = new EP_Feature_Requirements_Status( 0 ); if ( ! empty( $this->requirements_status_cb ) ) { $status = call_user_func( $this->requirements_status_cb, $status, $this ); } return apply_filters( 'ep_feature_requirements_status', $status, $this ); } /** * Return feature settings * * @since 2.2.1 * @return array|bool */ public function get_settings() { if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { $feature_settings = get_site_option( 'ep_feature_settings', array() ); } else { $feature_settings = get_option( 'ep_feature_settings', array() ); } return ( ! empty( $feature_settings[ $this->slug ] ) ) ? $feature_settings[ $this->slug ] : false; } /** * Returns true if feature is active * * @since 2.2 * @return boolean */ public function is_active() { if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) { $feature_settings = get_site_option( 'ep_feature_settings', array() ); } else { $feature_settings = get_option( 'ep_feature_settings', array() ); } $active = false; if ( ! empty( $feature_settings[ $this->slug ] ) && $feature_settings[ $this->slug ]['active'] ) { $active = true; } return apply_filters( 'ep_feature_active', $active, $feature_settings, $this ); } /** * Ran after a feature is activated * * @since 2.1 */ public function post_activation() { if ( ! empty( $this->post_activation_cb ) ) { call_user_func( $this->post_activation_cb, $this ); } do_action( 'ep_feature_post_activation', $this->slug, $this ); } /** * Outputs feature box * * @since 2.1 */ public function output_feature_box() { if ( ! empty( $this->feature_box_summary_cb ) ) { call_user_func( $this->feature_box_summary_cb, $this ); } do_action( 'ep_feature_box_summary', $this->slug, $this ); if ( ! empty( $this->feature_box_long_cb ) ) { ?>
feature_box_full_cb ) ) { call_user_func( $this->feature_box_full_cb, $this ); } do_action( 'ep_feature_box_full', $this->slug, $this ); } public function output_settings_box() { $requirements_status = $this->requirements_status(); ?> message ) ) : $messages = (array) $requirements_status->message; ?>