BP_Activity_Component::late_includes()

Late includes method.


Description Description

Only load up certain code when on specific pages.


Source Source

File: bp-activity/classes/class-bp-activity-component.php

	public function late_includes() {
		// Bail if PHPUnit is running.
		if ( defined( 'BP_TESTS_DIR' ) ) {
			return;
		}

		/*
		 * Load activity action and screen code if PHPUnit isn't running.
		 *
		 * For PHPUnit, we load these files in tests/phpunit/includes/install.php.
		 */
		if ( bp_is_current_component( 'activity' ) ) {
			// Authenticated actions - Only fires when JS is disabled.
			if ( is_user_logged_in() &&
				in_array( bp_current_action(), array( 'delete', 'spam', 'post', 'reply', 'favorite', 'unfavorite' ), true )
			) {
				require $this->path . 'bp-activity/actions/' . bp_current_action() . '.php';
			}

			// RSS feeds.
			if ( bp_is_current_action( 'feed' ) || bp_is_action_variable( 'feed', 0 ) ) {
				require $this->path . 'bp-activity/actions/feeds.php';
			}

			// Screens - Directory.
			if ( bp_is_activity_directory() ) {
				require $this->path . 'bp-activity/screens/directory.php';
			}

			// Screens - User main nav.
			if ( bp_is_user() ) {
				require $this->path . 'bp-activity/screens/just-me.php';
			}

			/**
			 * Screens - User secondary nav.
			 *
			 * For these specific actions, slugs can be customized using `BP_{COMPONENT}_SLUGS`.
			 * As a result, we need to map filenames with slugs.
			 */
			$filenames = array(
				'favorites' => 'favorites',
				'mentions'  => 'mentions',
			);

			if ( bp_is_active( 'friends' ) ) {
				$filenames[bp_get_friends_slug()] = 'friends';
			}

			if ( bp_is_active( 'groups' ) ) {
				$filenames[bp_get_groups_slug()] = 'groups';
			}

			// The slug is the current action requested.
			$slug = bp_current_action();

			if ( bp_is_user() && isset( $filenames[ $slug ] ) ) {
				require $this->path . 'bp-activity/screens/' . $filenames[ $slug ] . '.php';
			}

			// Screens - Single permalink.
			if ( bp_is_current_action( 'p' ) || is_numeric( bp_current_action() ) ) {
				require $this->path . 'bp-activity/screens/permalink.php';
			}

			// Theme compatibility.
			new BP_Activity_Theme_Compat();
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.